|
2904
|
1 // This file is part of the uSTL library, an STL implementation. |
|
|
2 // |
|
3152
|
3 // Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net> |
|
2904
|
4 // This file is free software, distributed under the MIT License. |
|
|
5 |
|
|
6 #include "stdtest.h" |
|
|
7 |
|
|
8 void WriteCML (const memblock& l) |
|
|
9 { |
|
|
10 cout.format ("memblock{%zu}: ", l.size()); |
|
|
11 const char* pc = reinterpret_cast<const char*>(l.cdata()); |
|
|
12 size_t nc = l.size(); |
|
|
13 while (nc && pc[nc - 1] == 0) |
|
|
14 -- nc; |
|
|
15 cout.write (l.cdata(), nc); |
|
|
16 cout << endl; |
|
|
17 } |
|
|
18 |
|
|
19 void TestMB (void) |
|
|
20 { |
|
|
21 char strTest[] = "abcdefghijklmnopqrstuvwxyz"; |
|
|
22 const size_t strTestLen = strlen(strTest); |
|
|
23 const char* cstrTest = strTest; |
|
|
24 |
|
|
25 memblock a, b; |
|
|
26 a.link (strTest, strTestLen); |
|
|
27 if (a.begin() != strTest) |
|
|
28 cout << "begin() failed on memblock\n"; |
|
|
29 if (a.begin() + 5 != &strTest[5]) |
|
|
30 cout << "begin() + 5 failed on memblock\n"; |
|
|
31 if (0 != memcmp (a.begin(), strTest, strTestLen)) |
|
|
32 cout << "memcmp failed on memblock\n"; |
|
|
33 WriteCML (a); |
|
|
34 b.link (cstrTest, strTestLen); |
|
|
35 if (b.data() != cstrTest) |
|
|
36 cout << "begin() of const failed on memblock\n"; |
|
|
37 if (b.cmemlink::begin() != cstrTest) |
|
|
38 cout << "cmemlink::begin() failed on memblock\n"; |
|
|
39 WriteCML (b); |
|
|
40 if (!(a == b)) |
|
|
41 cout << "operator== failed on memblock\n"; |
|
|
42 b.copy_link(); |
|
|
43 if (b.data() == NULL || b.cdata() == cstrTest) |
|
|
44 cout << "copy_link failed on memblock\n"; |
|
|
45 if (!(a == b)) |
|
|
46 cout << "copy_link didn't copy\n"; |
|
|
47 b.resize (strTestLen - 2); |
|
|
48 a = b; |
|
|
49 if (a.begin() == b.begin()) |
|
|
50 cout << "Assignment does not copy a link\n"; |
|
|
51 a.deallocate(); |
|
3152
|
52 a.assign (strTest, strTestLen); |
|
2904
|
53 WriteCML (a); |
|
|
54 a.insert (a.begin() + 5, 9); |
|
|
55 a.fill (a.begin() + 5, "-", 1, 9); |
|
|
56 WriteCML (a); |
|
|
57 a.erase (a.begin() + 2, 7); |
|
|
58 a.fill (a.end() - 7, "=", 1, 7); |
|
|
59 WriteCML (a); |
|
|
60 a.fill (a.begin() + 5, "TEST", 4, 3); |
|
|
61 WriteCML (a); |
|
|
62 |
|
|
63 a.resize (26 + 24); |
|
|
64 a.fill (a.begin() + 26, "-+=", 3, 24 / 3); |
|
|
65 WriteCML (a); |
|
|
66 a.resize (0); |
|
|
67 WriteCML (a); |
|
|
68 a.resize (strTestLen + strTestLen / 2); |
|
|
69 WriteCML (a); |
|
|
70 } |
|
|
71 |
|
|
72 StdBvtMain (TestMB) |