00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef DEBUG
00019 #define DEBUG
00020 #endif
00021
00022 #include <ucommon/ucommon.h>
00023
00024 #include <stdio.h>
00025
00026 using namespace UCOMMON_NAMESPACE;
00027
00028 static string_t testing("second test");
00029
00030 extern "C" int main()
00031 {
00032 char buff[33];
00033 char *tokens = NULL;
00034 unsigned count = 0;
00035 const char *tp;
00036 const char *array[5];
00037
00038 assert(max(3, 2) == 3);
00039
00040 String::fill(buff, 32, ' ');
00041 stringbuf<128> mystr;
00042 mystr = (string_t)"hello" + (string_t)" this is a test";
00043 assert(eq_case("hello this is a test", *mystr));
00044 assert(eq_case("second test", *testing));
00045 assert(eq_case(" Is a test", mystr(-10)));
00046 mystr = " abc 123 \n ";
00047 assert(eq_case("abc 123", String::strip(mystr.c_mem(), " \n")));
00048 String::set(buff, sizeof(buff), "this is \"a test\"");
00049 while(NULL != (tp = String::token(buff, &tokens, " ", "\"\"")) && count < 4)
00050 array[count++] = tp;
00051 assert(count == 3);
00052 assert(eq_case(array[1], "is"));
00053 assert(eq_case(array[2], "a test"));
00054
00055 unsigned char core[4] = {0x01, 0x10, 0x2f, 0x45};
00056 char hexbuf[12];
00057
00058 assert(String::hexdump(core, hexbuf, "3-1") == 9);
00059 assert(eq(hexbuf, "01102f-45"));
00060
00061 unsigned char hcore[4];
00062
00063 String::hexpack(hcore, hexbuf, "3-1");
00064 assert(String::hexdump(hcore, hexbuf, "3-1") == 9);
00065 assert(eq(hexbuf, "01102f-45"));
00066
00067 String numstr = "-33.5,25";
00068 Real num1;
00069 Unsigned num2;
00070
00071 numstr % num1 % "," % num2;
00072 assert(num1 == -33.5);
00073 assert(num2 == 25);
00074 assert(numstr.len() == 0);
00075
00076 char *test = strdup(str("hello") + " test" + str((short)13));
00077 assert(eq(test, "hello test13"));
00078
00079 char *cdup = dup<char>(test[6]);
00080 assert(eq(cdup, "test13"));
00081
00082 return 0;
00083 }