void TestCML (void) { const char hello[] = "Hello world!"; const char* phello = hello; // const storage is sometimes copied on pointing cmemlink a, b; a.link (phello, VectorSize(hello)); if (a.begin() != phello) cout.format ("a.begin() failed: %p != %p\n", a.begin(), phello); a.link (VectorRange (hello)); if (*(const char*)(a.begin() + 5) != hello[5]) cout.format ("begin()[5] failed: %c != %c\n", *(const char*)(a.begin() + 5), VectorElement(hello,5)); if (a.size() != VectorSize(hello)) cout << "link to VectorRange doesn't work\n"; if (0 != memcmp (a.begin(), hello, VectorSize(hello))) cout << "memcmp failed on cmemlink\n"; b.static_link (hello); WriteCML (a); WriteCML (b); if (!(a == b)) cout << "operator== failed on cmemlink\n"; b.resize (VectorSize(hello) - 5); a = b; WriteCML (a); }
void TestCML (void) { const char hello[] = "Hello world!"; const char* phello = hello; // const storage is sometimes copied on pointing cmemlink a, b; a.link (phello, VectorSize(hello)); if (a.begin() != phello) { cout << "a.begin() failed: " << ios::hex << uintptr_t(a.begin()); cout << " != " << uintptr_t(phello) << ios::dec << endl; } a.link (VectorRange (hello)); if (*(const char*)(a.begin() + 5) != hello[5]) { cout << "begin()[5] failed: " << *(const char*)(a.begin() + 5); cout << " != " << hello[5] << endl; } if (a.size() != VectorSize(hello)) cout << "link to VectorRange doesn't work" << endl; if (0 != memcmp (a.begin(), hello, VectorSize(hello))) cout << "memcmp failed on cmemlink" << endl; b.static_link (hello); WriteCML (a); WriteCML (b); if (!(a == b)) cout << "operator== failed on cmemlink" << endl; b.resize (VectorSize(hello) - 5); a = b; WriteCML (a); }