Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#include "Headers/Defines.h"

#include "Core/Headers/StringHelper.h"
#include "Platform/File/Headers/FileManagement.h"


namespace Divide {

//TEST_FAILURE_INDENT(4);
// We are using third party string libraries (STL, Boost, EASTL) that went through proper testing
// This list of tests only verifies utility functions

namespace {
    template <U64 NUM>
    struct test_const
    {
        static const U64 value = NUM;
    };
};

vectorImpl<stringImpl> getFiles(const stringImpl& input, const std::regex& pattern) {
    std::smatch matches;
    istringstreamImpl inputStream(input);
    stringImpl line;
    vectorImpl<stringImpl> include_file;
    while (std::getline(inputStream, line)) {
        if (std::regex_search(line, matches, pattern)) {
            include_file.emplace_back(Util::Trim(matches[1].str().c_str()));
        }
    }

    return include_file;
}

TEST(RegexSuccessTest)
{
    PreparePlatform();

    {
        const stringImpl& inputInclude1("#include \"blaBla.h\"");
        const stringImpl& inputInclude2("#include <blaBla.h>");
        const stringImpl& inputInclude3("# include \"blaBla.h\"");
        const stringImpl& inputInclude4("   #include <  blaBla.h>");
        const stringImpl& resultInclude("blaBla.h");

        vectorImpl<stringImpl> temp1 = getFiles(inputInclude1, Paths::g_includePattern);
        CHECK_TRUE(temp1.size() == 1);
        if (!temp1.empty()) {
            CHECK_EQUAL(resultInclude, temp1.front());
        }

        vectorImpl<stringImpl> temp2 = getFiles(inputInclude2, Paths::g_includePattern);
        CHECK_TRUE(temp2.size() == 1);
        if (!temp2.empty()) {
            CHECK_EQUAL(resultInclude, temp2.front());
        }

        vectorImpl<stringImpl> temp3 = getFiles(inputInclude3, Paths::g_includePattern);
        CHECK_TRUE(temp3.size() == 1);
        if (!temp3.empty()) {
            CHECK_EQUAL(resultInclude, temp3.front());
        }
        vectorImpl<stringImpl> temp4 = getFiles(inputInclude4, Paths::g_includePattern);
        CHECK_TRUE(temp4.size() == 1);
        if (!temp4.empty()) {
            CHECK_EQUAL(resultInclude, temp4.front());
        }

    }
    {
        const stringImpl& inputUse1("use(\"blaBla.h\")");
        const stringImpl& inputUse2("use( \"blaBla.h\")");
        const stringImpl& inputUse3("      use         (\"blaBla.h\")");
        const stringImpl& inputUse4("use(\"blaBla.h\"         )");
        const stringImpl& resultUse("blaBla.h");

        vectorImpl<stringImpl> temp1 = getFiles(inputUse1, Paths::g_usePattern);
        CHECK_TRUE(temp1.size() == 1);
        if (!temp1.empty()) {
            CHECK_EQUAL(resultUse, temp1.front());
        }

        vectorImpl<stringImpl> temp2 = getFiles(inputUse2, Paths::g_usePattern);
        CHECK_TRUE(temp2.size() == 1);
        if (!temp2.empty()) {
            CHECK_EQUAL(resultUse, temp2.front());
        }

        vectorImpl<stringImpl> temp3 = getFiles(inputUse3, Paths::g_usePattern);
        CHECK_TRUE(temp3.size() == 1);
        if (!temp3.empty()) {
            CHECK_EQUAL(resultUse, temp3.front());
        }
        vectorImpl<stringImpl> temp4 = getFiles(inputUse4, Paths::g_usePattern);
        CHECK_TRUE(temp4.size() == 1);
        if (!temp4.empty()) {
            CHECK_EQUAL(resultUse, temp4.front());
        }
    }
}

TEST(RegexFailTest)
{
    {
        const stringImpl& inputInclude1("#include\"blaBla.h\"");
        const stringImpl& inputInclude2("#include<blaBla.h>");
        const stringImpl& inputInclude3("# include \"blaBla.h");
        const stringImpl& inputInclude4("   include <  blaBla.h>");

        vectorImpl<stringImpl> temp1 = getFiles(inputInclude1, Paths::g_includePattern);
        CHECK_FALSE(temp1.size() == 1);
        vectorImpl<stringImpl> temp2 = getFiles(inputInclude2, Paths::g_includePattern);
        CHECK_FALSE(temp2.size() == 1);
        vectorImpl<stringImpl> temp3 = getFiles(inputInclude3, Paths::g_includePattern);
        CHECK_FALSE(temp3.size() == 1);
        vectorImpl<stringImpl> temp4 = getFiles(inputInclude4, Paths::g_includePattern);
        CHECK_FALSE(temp4.size() == 1);
    }
    {
        const stringImpl& inputUse1("use(\"blaBla.h)");
        const stringImpl& inputUse2("usadfse( \"blaBla.h\")");
        const stringImpl& inputUse3("      use    ---   (\"blaBla.h\")");

        vectorImpl<stringImpl> temp1 = getFiles(inputUse1, Paths::g_usePattern);
        CHECK_FALSE(temp1.size() == 1);
        vectorImpl<stringImpl> temp2 = getFiles(inputUse2, Paths::g_usePattern);
        CHECK_FALSE(temp2.size() == 1);
        vectorImpl<stringImpl> temp3 = getFiles(inputUse3, Paths::g_usePattern);
        CHECK_FALSE(temp3.size() == 1);
    }
}

TEST(TestReplaceInPlace)
{
    stringImpl input("STRING TO BE TESTED");

    const stringImpl match("TO BE");
    const stringImpl replacement("HAS BEEN");
    const stringImpl output("STRING HAS BEEN TESTED");

    Util::ReplaceStringInPlace(input, match, replacement);
    CHECK_EQUAL(input, output);
}

TEST(TestPermutations)
{
    const stringImpl input("ABC");
    vectorImpl<stringImpl> permutations;
    Util::GetPermutations(input, permutations);
    CHECK_TRUE(permutations.size() == 6);
}

TEST(TestNumberParse)
{
    const stringImpl input1("2");
    const stringImpl input2("b");
    CHECK_TRUE(Util::IsNumber(input1));
    CHECK_FALSE(Util::IsNumber(input2));
}

TEST(TestCharTrail)
{
    const stringImpl input("abcdefg");
    const stringImpl extension("efg");
    CHECK_TRUE(Util::GetTrailingCharacters(input, 3) == extension);
    CHECK_TRUE(Util::GetTrailingCharacters(input, 20) == input);

    size_t length = 4;
    CHECK_TRUE(Util::GetTrailingCharacters(input, length).size() == length);
}

TEST(TestCmpNoCase)
{
    const stringImpl inputA("aBcdEf");
    const stringImpl inputB("ABCdef");
    const stringImpl inputC("abcdefg");
    CHECK_TRUE(Util::CompareIgnoreCase(inputA, inputA));
    CHECK_TRUE(Util::CompareIgnoreCase(inputA, inputB));
    CHECK_FALSE(Util::CompareIgnoreCase(inputB, inputC));
}

TEST(TestExtension) {
    const stringImpl input("something.ext");
    const stringImpl ext1("ext");
    const stringImpl ext2("bak");
    CHECK_TRUE(hasExtension(input, ext1));
    CHECK_FALSE(hasExtension(input, ext2));
}

TEST(TestStringSplit) {
    const stringImpl input1("a b c d");
    const vectorImpl<stringImpl> result = {"a", "b", "c", "d"};

    CHECK_EQUAL(Util::Split(input1, ' '), result);
    CHECK_TRUE(Util::Split(input1, ',').size() == 1);
    CHECK_TRUE(Util::Split(input1, ',')[0] == input1);

    const stringImpl input2("a,b,c,d");
    CHECK_EQUAL(Util::Split(input2, ','), result);
}

TEST(TestFilePathSplit) {
    const stringImpl input("/path/path2/path4/file.test");
    const stringImpl result1("file.test");
    const stringImpl result2("/path/path2/path4/");

    FileWithPath fileResult = splitPathToNameAndLocation(input);
    CHECK_EQUAL(fileResult._path, result2);
    CHECK_EQUAL(fileResult._fileName, result1);
}

TEST(TestLineCount) {

    const stringImpl input1("bla");
    const stringImpl input2("bla\nbla");
    const stringImpl input3("bla\nbla\nbla");

    CHECK_EQUAL(Util::LineCount(input1), 1u);
    CHECK_EQUAL(Util::LineCount(input2), 2u);
    CHECK_EQUAL(Util::LineCount(input3), 3u);
}

TEST(TestStringTrim) {
    const stringImpl input1("  abc");
    const stringImpl input2("abc  ");
    const stringImpl input3("  abc  ");
    const stringImpl result("abc");

    CHECK_EQUAL(Util::Ltrim(input1), result);
    CHECK_EQUAL(Util::Ltrim(input2), input2);
    CHECK_EQUAL(Util::Ltrim(input3), input2);
    CHECK_EQUAL(Util::Ltrim(result), result);

    CHECK_EQUAL(Util::Rtrim(input1), input1);
    CHECK_EQUAL(Util::Rtrim(input2), result);
    CHECK_EQUAL(Util::Rtrim(input3), input1);
    CHECK_EQUAL(Util::Rtrim(result), result);

    CHECK_EQUAL(Util::Trim(input1), result);
    CHECK_EQUAL(Util::Trim(input2), result);
    CHECK_EQUAL(Util::Trim(input3), result);
    CHECK_EQUAL(Util::Trim(result), result);
}

TEST(TestStringFormat) {
    const char* input1("A %s b is %d %s");
    const char* input2("%2.2f");
    const stringImpl result1("A is ok, b is 2 \n");
    const stringImpl result2("12.21");

    CHECK_EQUAL(Util::StringFormat(input1, "is ok,", 2, "\n"), result1);
    CHECK_EQUAL(Util::StringFormat(input2, 12.2111f), result2);
}

TEST(TestCharRemove) {
    char input[] = {'a', 'b', 'c', 'b', 'd', '7', 'b', '\0' };
    char result[] = { 'a', 'c', 'd', '7', '\0'};

    Util::CStringRemoveChar(&input[0], 'b');

    CHECK_EQUAL(strlen(input), strlen(result));

    char* in = input;
    char* res = result;
    while(*in != '\0') {
        CHECK_EQUAL(*in, *res);

        in++; res++;
    }
}

TEST(HashIsConstantExpr)
{
    constexpr char* str = "TEST test TEST";

    constexpr U64 value = test_const<_ID(str)>::value;
    CHECK_EQUAL(value, _ID_RT(str));
}

TEST(TestRuntimeID)
{
    const char* str = "TEST String garbagegarbagegarbage";
    U64 input1 = _ID(str);
    CHECK_EQUAL(input1, _ID_RT(str));
    CHECK_EQUAL(_ID_RT(str), _ID_RT(stringImpl(str)));
    CHECK_EQUAL(input1, _ID_RT(stringImpl(str)));
}

TEST(TestStringAllocator)
{
    const char* input = "TEST test TEST";
    stringImpl input1(input);
    stringImplFast input2(input);
    for( U8 i = 0; i < input1.size(); ++i) {
        CHECK_EQUAL(input1[i], input2[i]);
    }
}

TEST(TestStringStream)
{
    stringImpl result1;
    stringImplFast result2;
    stringstreamImplFast s;
    const char* input = "TEST-test-TEST";
    s << input;
    s >> result1;
    CHECK_EQUAL(result1, stringImpl(input));
    s.clear();
    s << input;
    s >> result2;
    CHECK_EQUAL(result2, stringImplFast(input));
}

}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/UnitTests/Engine-Tests/Tests/StringTests.cpp

Diff revisions: vs.
Revision Author Commited Message
879 Diff Diff IonutCava picture IonutCava Sun 19 Mar, 2017 19:29:46 +0000

[IonutCava]
- GLSL updates:
— Interface block correction to support tessellation shaders automatically
— Fixed line counting issues with the preprocessor

851 Diff Diff IonutCava picture IonutCava Mon 06 Feb, 2017 23:38:14 +0000

[IonutCava]
- Replaced most RenderStage params with RenderStagePass types
- More work on water rendering

846 Diff Diff IonutCava picture IonutCava Fri 03 Feb, 2017 22:41:05 +0000

[IonutCava]
- More scripting work

833 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 22:04:33 +0000

[IonutCava]
- Fix most build errors. Divide-Server does not build for now.

832 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 17:23:11 +0000

[IonutCava]
- More path related work
- Initial code to centralize file I/O (does not compile yet)

831 Diff Diff IonutCava picture IonutCava Wed 25 Jan, 2017 23:52:34 +0000

[IonutCava]
- More path related updates

830 Diff Diff IonutCava picture IonutCava Wed 25 Jan, 2017 17:29:44 +0000

[IonutCava]
- Add a new Platform element: File
— Move all predefined paths to FileManagement System
- Split MathHelper into MathHelper and StringHelper

817 Diff Diff IonutCava picture IonutCava Sun 15 Jan, 2017 21:29:59 +0000

[IonutCava]
- Add a new Unit component to SGNs that holds NPC/Player/etc. objects
- Add support for multiple keyboard+mouse combos and joysticks and add mapping between these and players

796 Diff Diff IonutCava picture IonutCava Wed 23 Nov, 2016 20:04:11 +0000

[IonutCava]
- Fix a bad if statement in the RenderingComponent class relating additional texture dependencies that prevented non-Debug builds from using additional textures
- Fix a race condition relating to texture loading
- Small code cleanup

680 IonutCava picture IonutCava Thu 14 Apr, 2016 16:15:38 +0000

[IonutCava]
- Added a mat2 class (untested)
- Added static asserts to matrices, vectors and quaternions to allow only arithmetic (sans bool) data types
- Added more vector unit tests
- Added unit tests for matrices
- D32 finally renamed to D64 as the VC++ compiler is considered as the reference compiler