Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 1 | // Copyright (C) 2006-2010 David Sugar, Tycho Softworks. |
| 2 | // |
| 3 | // This file is part of GNU uCommon C++. |
| 4 | // |
| 5 | // GNU uCommon C++ is free software: you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU Lesser General Public License as published |
| 7 | // by the Free Software Foundation, either version 3 of the License, or |
| 8 | // (at your option) any later version. |
| 9 | // |
| 10 | // GNU uCommon C++ is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU Lesser General Public License for more details. |
| 14 | // |
| 15 | // You should have received a copy of the GNU Lesser General Public License |
| 16 | // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | #ifndef DEBUG |
| 19 | #define DEBUG |
| 20 | #endif |
| 21 | |
| 22 | #include <ucommon/ucommon.h> |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | |
| 26 | using namespace UCOMMON_NAMESPACE; |
| 27 | |
| 28 | static string_t testing("second test"); |
| 29 | |
| 30 | extern "C" int main() |
| 31 | { |
| 32 | char buff[33]; |
| 33 | char *tokens = NULL; |
| 34 | unsigned count = 0; |
| 35 | const char *tp; |
| 36 | const char *array[5]; |
| 37 | |
| 38 | assert(max(3, 2) == 3); |
| 39 | |
| 40 | String::fill(buff, 32, ' '); |
| 41 | stringbuf<128> mystr; |
| 42 | mystr = (string_t)"hello" + (string_t)" this is a test"; |
| 43 | assert(eq_case("hello this is a test", *mystr)); |
| 44 | assert(eq_case("second test", *testing)); |
| 45 | assert(eq_case(" Is a test", mystr(-10))); |
| 46 | mystr = " abc 123 \n "; |
| 47 | assert(eq_case("abc 123", String::strip(mystr.c_mem(), " \n"))); |
| 48 | String::set(buff, sizeof(buff), "this is \"a test\""); |
| 49 | while(NULL != (tp = String::token(buff, &tokens, " ", "\"\"")) && count < 4) |
| 50 | array[count++] = tp; |
| 51 | assert(count == 3); |
| 52 | assert(eq_case(array[1], "is")); |
| 53 | assert(eq_case(array[2], "a test")); |
| 54 | |
| 55 | unsigned char core[4] = {0x01, 0x10, 0x2f, 0x45}; |
| 56 | char hexbuf[12]; |
| 57 | |
| 58 | assert(String::hexdump(core, hexbuf, "3-1") == 9); |
| 59 | assert(eq(hexbuf, "01102f-45")); |
| 60 | |
| 61 | unsigned char hcore[4]; |
| 62 | |
| 63 | String::hexpack(hcore, hexbuf, "3-1"); |
| 64 | assert(String::hexdump(hcore, hexbuf, "3-1") == 9); |
| 65 | assert(eq(hexbuf, "01102f-45")); |
| 66 | |
| 67 | String numstr = "-33.5,25"; |
| 68 | Real num1; |
| 69 | Unsigned num2; |
| 70 | |
| 71 | numstr % num1 % "," % num2; |
| 72 | assert(num1 == -33.5); |
| 73 | assert(num2 == 25); |
| 74 | assert(numstr.len() == 0); |
| 75 | |
| 76 | char *test = strdup(str("hello") + " test" + str((short)13)); |
| 77 | assert(eq(test, "hello test13")); |
| 78 | |
| 79 | char *cdup = dup<char>(test[6]); |
| 80 | assert(eq(cdup, "test13")); |
| 81 | |
| 82 | return 0; |
| 83 | } |