ndb_test_platform.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:2k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #include <ndb_global.h>
  14. #include <my_sys.h>
  15. #include <BaseString.hpp>
  16. /*
  17.  * Test BaseString::snprintf
  18.  */
  19. static
  20. int test_snprintf(const char * fmt, int buf_sz, int result)
  21. {
  22.   int ret;
  23.   char buf[100];
  24.   ret = BaseString::snprintf(buf, buf_sz, fmt);
  25.   
  26.   if(ret < 0)
  27.   {
  28.     printf("BaseString::snprint returns %d with size=%d and strlen(fmt)=%dn",
  29.    ret, buf_sz, strlen(fmt));
  30.     return -1;
  31.   }
  32.   
  33.   if(ret+1 == buf_sz)
  34.   {
  35.     printf("BaseString::snprint truncates returns %d with size=%d and strlen(fmt)=%dn",
  36.    ret, buf_sz, strlen(fmt));
  37.     return -1;
  38.   }
  39.   
  40.   if(ret != result)
  41.   {
  42.     printf("BaseString::snprint returns incorrect value: returned=%d != expected=%dn",
  43.    ret, result);
  44.     return -1;
  45.   }
  46.   for(ret = 0; ret+1 < buf_sz && ret < result; ret++)
  47.   {
  48.     if(buf[ret] != fmt[ret])
  49.     {
  50.       printf("BaseString::snprint Incorrect value in output buffer: "
  51.      "size=%d returned=expected=%d at pos=%d result=%d  != expected=%dn",
  52.              buf_sz, result, ret, buf[ret], fmt[ret]);
  53.       return -1;
  54.     }
  55.   }
  56.   return 0;
  57. }
  58. int
  59. main(void)
  60. {
  61.   /*
  62.    * Test BaseString::snprintf
  63.    */
  64.   if(test_snprintf("test", 1, 4))
  65.     return -1;
  66.   if(test_snprintf("test", 0, 4))
  67.     return -1;
  68.   
  69.   if(test_snprintf("test", 100, 4))
  70.     return -1;
  71.   /*
  72.    * Test UintPtr
  73.    */
  74.   if (sizeof(UintPtr) != sizeof(Uint32*))
  75.   {
  76.     printf("sizeof(UintPtr)=%d != sizeof(Uint32*)=%dn",
  77.    sizeof(UintPtr), sizeof(Uint32*));
  78.     return -1;
  79.   }
  80.   return 0;
  81. }