summaryrefslogtreecommitdiff
path: root/ecos/packages/language/cxx/ustl/current/tests/bvt01.cpp
blob: beeef97af8aba4ad6f90c7c49ada4d5770c77d39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.

#include "stdtest.h"

void WriteCML (const cmemlink& l)
{
    cout.format ("memlink{%zu}: ", l.size());
    const char* pc = reinterpret_cast<const char*>(l.cdata());
    size_t nc = l.size();
    if (pc[nc - 1] == 0)
	-- nc;
    cout.write (l.cdata(), nc);
    cout << endl;
}

void TestML (void)
{
    char str[] = "abcdefghijklmnopqrstuvwzyz";
    memlink::const_pointer cstr = str;

    memlink a, b;
    a.static_link (str);
    if (a.begin() != str)
	cout << "begin() failed on memlink\n";
    a.link (VectorRange(str));
    if (a.begin() + 5 != &str[5])
	cout << "begin() + 5 failed on memlink\n";
    if (0 != memcmp (a.begin(), str, VectorSize(str)))
	cout << "memcmp failed on memlink\n";
    WriteCML (a);
    b.link (cstr, VectorSize(str));
    if (b.data() != cstr)
	cout << "begin() of const failed on cmemlink\n";
    if (b.cmemlink::begin() != cstr)
	cout << "begin() failed on cmemlink\n";
    WriteCML (b);
    if (!(a == b))
	cout << "operator== failed on cmemlink\n";
    b.resize (VectorSize(str) - 2);
    a = b;
    if (a.data() != b.data())
	cout << "begin() after assignment failed on cmemlink\n";
    a.relink (str, VectorSize(str) - 1);
    WriteCML (a);
    a.insert (a.begin() + 5, 9);
    a.fill (a.begin() + 5, "-", 1, 9);
    WriteCML (a);
    a.erase (a.begin() + 9, 7);
    a.fill (a.end() - 7, "=", 1, 7);
    WriteCML (a);
    a.fill (a.begin() + 5, "TEST", 4, 3); 
    WriteCML (a);
    copy_n (cstr, VectorSize(str) - 1, a.begin());
    WriteCML (a);
}

StdBvtMain (TestML)