Changeset 21073 in vbox for trunk/src/VBox/Runtime/testcase
- Timestamp:
- Jun 30, 2009 3:01:09 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstUtf8.cpp
r20606 r21073 42 42 #include <iprt/err.h> 43 43 #include <iprt/test.h> 44 #include <iprt/ministring_cpp.h> 44 45 45 46 #include <stdlib.h> /** @todo use our random. */ … … 926 927 927 928 929 void testMinistring(RTTEST hTest) 930 { 931 RTTestSub(hTest, "class ministring"); 932 933 #define CHECK(expr) \ 934 do { \ 935 if (!(expr)) \ 936 RTTestFailed(hTest, "%d: FAILED %s", __LINE__, #expr); \ 937 } while (0) 938 939 #define CHECK_DUMP(expr, value) \ 940 do { \ 941 if (!(expr)) \ 942 RTTestFailed(hTest, "%d: FAILED %s, got \"%s\"", __LINE__, #expr, value); \ 943 } while (0) 944 945 #define CHECK_DUMP_I(expr) \ 946 do { \ 947 if (!(expr)) \ 948 RTTestFailed(hTest, "%d: FAILED %s, got \"%d\"", __LINE__, #expr, expr); \ 949 } while (0) 950 951 ministring empty; 952 CHECK( (empty.length() == 0) ); 953 CHECK( (empty.capacity() == 0) ); 954 955 ministring sixbytes("12345"); 956 CHECK( (sixbytes.length() == 5) ); 957 CHECK( (sixbytes.capacity() == 6) ); 958 959 sixbytes.append("678"); 960 CHECK( (sixbytes.length() == 8) ); 961 CHECK( (sixbytes.capacity() == 9) ); 962 963 char *psz = sixbytes.mutableRaw(); 964 // 12345678 965 // ^ 966 // 0123456 967 psz[6] = '\0'; 968 sixbytes.jolt(); 969 CHECK( (sixbytes.length() == 6) ); 970 CHECK( (sixbytes.capacity() == 7) ); 971 972 ministring morebytes("tobereplaced"); 973 morebytes = "newstring "; 974 morebytes.append(sixbytes); 975 976 CHECK_DUMP( (morebytes == "newstring 123456"), morebytes.c_str() ); 977 978 ministring third(morebytes); 979 third.reserve(100 * 1024); // 100 KB 980 CHECK_DUMP( (third == "newstring 123456"), morebytes.c_str() ); 981 CHECK( (third.capacity() == 100 * 1024) ); 982 CHECK( (third.length() == morebytes.length()) ); // must not have changed 983 984 ministring copy1(morebytes); 985 ministring copy2 = morebytes; 986 CHECK( (copy1 == copy2) ); 987 988 copy1 = NULL; 989 CHECK( (copy1.isNull()) ); 990 991 copy1 = ""; 992 CHECK( (copy1.isEmpty()) ); 993 994 CHECK( (ministring("abc") < ministring("def")) ); 995 CHECK( (ministring("abc") != ministring("def")) ); 996 CHECK_DUMP_I( (ministring("def") > ministring("abc")) ); 997 998 copy2.setNull(); 999 for (int i = 0; 1000 i < 100; 1001 ++i) 1002 { 1003 copy2.reserve(50); // should be ignored after 50 loops 1004 copy2.append("1"); 1005 } 1006 CHECK( (copy2.length() == 100) ); 1007 1008 #undef CHECK 1009 } 1010 928 1011 int main() 929 1012 { … … 946 1029 TstRTStrXCmp(hTest); 947 1030 testStrStr(hTest); 1031 1032 testMinistring(hTest); 1033 948 1034 Benchmarks(hTest); 949 1035
Note:
See TracChangeset
for help on using the changeset viewer.