OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [tests/] [bvt07.cpp] - Blame information for rev 819

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// This file is part of the uSTL library, an STL implementation.
2
//
3
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
4
// This file is free software, distributed under the MIT License.
5
 
6
#include "stdtest.h"
7
 
8
void MyFormat (const char* fmt, ...) __attribute__((__format__(__printf__,1,2)));
9
 
10
void TestString (void)
11
{
12
    static const char c_TestString1[] = "123456789012345678901234567890";
13
    static const char c_TestString2[] = "abcdefghijklmnopqrstuvwxyz";
14
    static const char c_TestString3[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
15
    string s1 (c_TestString1);
16
    string s2 (VectorRange (c_TestString2));
17
    string s3 (s1);
18
 
19
    cout << s1 << endl;
20
    cout << s2 << endl;
21
    cout << s3 << endl;
22
    s3.reserve (48);
23
    s3.resize (20);
24
 
25
    uoff_t i;
26
    for (i = 0; i < s3.length(); ++ i)
27
        s3.at(i) = s3.at(i);
28
    for (i = 0; i < s3.length(); ++ i)
29
        s3[i] = s3[i];
30
    cout.format ("%s\ns3.size() = %zu, max_size() = ", s3.c_str(), s3.size());
31
    if (s3.max_size() == SIZE_MAX - 1)
32
        cout << "(SIZE_MAX/elsize)-1";
33
    else
34
        cout << s3.max_size();
35
    cout.format (", capacity() = %zu\n", s3.capacity());
36
 
37
    s1.unlink();
38
    s1 = c_TestString2;
39
    s1 += c_TestString3;
40
    s1 += '$';
41
    cout << s1 << endl;
42
 
43
    s1 = "Hello";
44
    s2.unlink();
45
    s2 = "World";
46
    s3 = s1 + s2;
47
    cout << s3 << endl;
48
    s3 = "Concatenated ";
49
    s3 += s1.c_str();
50
    s3 += s2;
51
    s3 += " string.";
52
    cout << s3 << endl;
53
 
54
    if (s1 < s2)
55
        cout << "s1 < s2\n";
56
    if (s1 == s1)
57
        cout << "s1 == s1\n";
58
    if (s1[0] != s1[0])
59
        cout << "s1[0] != s1[0]\n";
60
 
61
    string s4;
62
    s4.link (s1);
63
    if (s1 == s4)
64
        cout << "s1 == s4\n";
65
 
66
    s1 = c_TestString1;
67
    string s5 (s1.begin() + 4, s1.begin() + 4 + 5);
68
    string s6 (s1.begin() + 4, s1.begin() + 4 + 5);
69
    if (s5 == s6)
70
        cout.format ("%s == %s\n", s5.c_str(), s6.c_str());
71
    string tail (s1.begin() + 7, s1.end());
72
    cout.format ("&s1[7] = %s\n", tail.c_str());
73
 
74
    cout.format ("initial:\t\t%s\n", s1.c_str());
75
    cout << "erase(5,find(9)-5)\t";
76
    s1.erase (5, s1.find ('9')-5);
77
    cout << s1 << endl;
78
    cout << "erase(5,5)\t\t";
79
    s1.erase (s1.begin() + 5, 2U);
80
    s1.erase (5, 3);
81
    assert (!*s1.end());
82
    cout << s1 << endl;
83
    cout << "push_back('x')\t\t";
84
    s1.push_back ('x');
85
    assert (!*s1.end());
86
    cout << s1 << endl;
87
    cout << "pop_back()\n";
88
    s1.pop_back();
89
    assert (!*s1.end());
90
    cout << "insert(10,#)\t\t";
91
    s1.insert (s1.begin() + 10, '#');
92
    assert (!*s1.end());
93
    cout << s1 << endl;
94
    cout << "replace(0,5,@)\t\t";
95
    s1.replace (s1.begin(), s1.begin() + 5, 1, '@');
96
    assert (!*s1.end());
97
    cout << s1 << endl;
98
 
99
    s1 = c_TestString1;
100
    cout.format ("8 found at %zu\n", s1.find ('8'));
101
    cout.format ("9 found at %zu\n", s1.find ("9"));
102
    cout.format ("7 rfound at %zu\n", s1.rfind ('7'));
103
    cout.format ("7 rfound again at %zu\n", s1.rfind ('7', s1.rfind ('7') - 1));
104
    cout.format ("67 rfound at %zu\n", s1.rfind ("67"));
105
    if (s1.rfind("X") == string::npos)
106
        cout << "X was not rfound\n";
107
    else
108
        cout.format ("X rfound at %zu\n", s1.rfind ("X"));
109
    uoff_t poundfound = s1.find ("#");
110
    if (poundfound != string::npos)
111
        cout.format ("# found at %zu\n", poundfound);
112
    cout.format ("[456] found at %zu\n", s1.find_first_of ("456"));
113
    cout.format ("[456] last found at %zu\n", s1.find_last_of ("456"));
114
 
115
    s2.clear();
116
    assert (!*s2.end());
117
    if (s2.empty())
118
        cout.format ("s2 is empty [%s], capacity %zu bytes\n", s2.c_str(), s2.capacity());
119
 
120
    s2.format ("<const] %d, %s, 0x%08X", 42, "[rfile>", 0xDEADBEEF);
121
    cout.format ("<%zu bytes of %zu> Format '%s'\n", s2.length(), s2.capacity(), s2.c_str());
122
    MyFormat ("'<const] %d, %s, 0x%08X'", 42, "[rfile>", 0xDEADBEEF);
123
 
124
    cout.format ("hash_value(s2) = %08X, string::hash(s2) = %08X\n", hash_value (s2.begin()), string::hash (s2.begin(), s2.end()));
125
}
126
 
127
void MyFormat (const char* fmt, ...)
128
{
129
    string buf;
130
    simd::reset_mmx();
131
    va_list args;
132
    va_start (args, fmt);
133
    buf.vformat (fmt, args);
134
    cout.format ("Custom vararg MyFormat: %s\n", buf.c_str());
135
    va_end (args);
136
}
137
 
138
StdBvtMain (TestString)

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.