summaryrefslogtreecommitdiff
path: root/tests/src/CoreMangLib/cti/system/text/stringbuilder/stringbuilderappend.cs
blob: 16b69168557af334317c9f1091dfba653b4e6c3e (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
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
using System;
using System.Text;
using TestLibrary;
using System.Globalization;

class StringBuilderAppend
{
    static int Main()
    {
        StringBuilderAppend test = new StringBuilderAppend();

        TestFramework.BeginTestCase("StringBuilder.Append");

        if (test.RunTests())
        {
            TestFramework.EndTestCase();
            TestFramework.LogInformation("PASS");
            return 100;
        }
        else
        {
            TestFramework.EndTestCase();
            TestFramework.LogInformation("FAIL");
            return 0;
        }

    }

    public bool RunTests()
    {
        bool ret = true;

        // Positive Tests
        ret &= Test001();
        ret &= Test002();
        ret &= Test003();
        ret &= Test004();
        ret &= Test005();
        ret &= Test019();
        ret &= Test021();
        ret &= Test022();
        ret &= Test023();

        ret &= Test010();
        ret &= Test011();
        ret &= Test012();
        ret &= Test013();
        ret &= Test014();
        ret &= Test020();
        ret &= Test024();

        ret &= Test025();
        ret &= Test026();
        ret &= Test027();
        ret &= Test028();
        ret &= Test029();
        ret &= Test030();
        ret &= Test031();
        ret &= Test032();
        ret &= Test033();
        ret &= Test034();
        ret &= Test035();
        ret &= Test036();
        ret &= Test037();
        ret &= Test038();

        ret &= Test039();
        ret &= Test040();
        ret &= Test041();
        ret &= Test042();

        // Negative Tests
        ret &= Test006();
        ret &= Test007();
        ret &= Test008();
        ret &= Test009();

        ret &= Test015();
        ret &= Test016();
        ret &= Test017();
        ret &= Test018();

        return ret;
    }

    public bool Test001() { return PositiveTest("Testing", 1, 6, "esting", "00A");}
    public bool Test002() { return PositiveTest(new string('a', 5000), 0, 5000, new string('a',5000), "00B");}
    public bool Test003() { return PositiveTest("Testing", 1, 0, string.Empty, "00C");}
    public bool Test004() { return PositiveTest(null, 0, 0, string.Empty, "00D");}
    public bool Test005() { return PositiveTest(string.Empty, 0, 0, string.Empty, "00E");}

    public bool Test019() { return NegativeTest("Testing", -5, 0, typeof(ArgumentOutOfRangeException), "00J"); }
    public bool Test006() { return NegativeTest(null, 0, 1, typeof(ArgumentNullException), "00F"); }
    public bool Test007() { return NegativeTest("a", -1, 1, typeof(ArgumentOutOfRangeException), "00G"); }
    public bool Test008() { return NegativeTest("a", 0, -1, typeof(ArgumentOutOfRangeException), "00H"); }
    public bool Test009() { return NegativeTest("a", 0, 3, typeof(ArgumentOutOfRangeException), "00I"); }

    public bool Test010() { return PositiveTest2(new char[] {'T', 'e', 's', 't', 'i', 'n', 'g'}, 1, 6, "esting", "00A1"); }
    public bool Test011() { char[] chars = new char[5000]; for (int i = 0; i < 5000; i++) chars[i] = 'a';
                            return PositiveTest2(chars, 0, 5000, new string('a', 5000), "00B1"); }
    public bool Test012() { return PositiveTest2(new char[] {'T', 'e', 's', 't', 'i', 'n', 'g'}, 1, 0, string.Empty, "00C1"); }
    public bool Test013() { return PositiveTest2(null, 0, 0, string.Empty, "00D1"); }
    public bool Test014() { return PositiveTest2(new char[] { }, 0, 0, string.Empty, "00E1"); }

    public bool Test020() { return NegativeTest2(new char[] { 'T', 'e', 's', 't', 'i', 'n', 'g' }, -5, 0, typeof(ArgumentOutOfRangeException), "00J1"); }
    public bool Test015() { return NegativeTest2(null, 0, 1, typeof(ArgumentNullException), "00F1"); }
    public bool Test016() { return NegativeTest2(new char[] { 'T', 'e', 's', 't', 'i', 'n', 'g' }, - 1, 1, typeof(ArgumentOutOfRangeException), "00G1"); }
    public bool Test017() { return NegativeTest2(new char[] { 'T', 'e', 's', 't', 'i', 'n', 'g' }, 0, -1, typeof(ArgumentOutOfRangeException), "00H1"); }
    public bool Test018() { return NegativeTest2(new char[] { 'T' }, 0, 3, typeof(ArgumentOutOfRangeException), "00I1"); }

    public bool Test021() { return PositiveTest3('T', 6, "TTTTTT", "00A2"); }
    public bool Test022() { return PositiveTest3('a', 5000, new string('a', 5000), "00B2"); }
    public bool Test023() { return PositiveTest3('a', 0, string.Empty, "00C2"); }

    public bool Test024() { return NegativeTest3('a', -1, typeof(ArgumentOutOfRangeException), "00G2"); }

    public bool Test025() { return PositiveTest4<byte>(1, "00K"); }
    public bool Test026() { return PositiveTest4<sbyte>(-1, "00L"); }
    public bool Test027() { return PositiveTest4<bool>(true, "00M"); }
    public bool Test028() { return PositiveTest4<char>('t', "00N"); }
    public bool Test029() { return PositiveTest4<short>(short.MaxValue, "00O"); }
    public bool Test030() { return PositiveTest4<int>(int.MaxValue, "00P"); }
    public bool Test031() { return PositiveTest4<long>(long.MaxValue, "00Q"); }
    public bool Test032() { return PositiveTest4<float>(3.14f, "00R"); }
    public bool Test033() { return PositiveTest4<double>(3.1415927, "00S"); }
    public bool Test034() { return PositiveTest4<ushort>(17, "00T"); }
    public bool Test035() { return PositiveTest4<uint>(uint.MaxValue, "00U"); }
    public bool Test036() { return PositiveTest4<ulong>(ulong.MaxValue, "00V"); }
    public bool Test037() { return PositiveTest4<object>(null, "00W"); }
    public bool Test038() { return PositiveTest4<object>(new StringBuilder("Testing"), "00X"); }

    public bool Test039() { return PositiveTest5(new char[] { 'T', 'e', 's', 't' }, "Test", "00Y"); }
    public bool Test040() { char[] chars = new char[5000]; 
                            for (int i = 0; i < 5000; i++) chars[i] = 'a';
                            return PositiveTest5(chars, new string('a', 5000), "00Z"); }
    public bool Test041() { return PositiveTest5(new char[] {  }, String.Empty, "0AA"); }
    public bool Test042() { return PositiveTest5(null, String.Empty, "0AB"); }


    public bool PositiveTest(string str, int index, int count, string expected, string id)
    {
        bool result = true;
        TestFramework.BeginScenario(id + ": Append");
        try
        {
            StringBuilder sb = new StringBuilder("Test");
            sb.Append(str, index, count);
            string output = sb.ToString();
            expected = "Test" + expected;
            if (output != expected)
            {
                result = false;
                TestFramework.LogError("001", "Error in " + id + ", unexpected append result. Actual string " + output + ", Expected: " + expected);
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("002", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return result;
    }

    public bool PositiveTest2(char[] str, int index, int count, string expected, string id)
    {
        bool result = true;
        TestFramework.BeginScenario(id + ": Append");
        try
        {
            StringBuilder sb = new StringBuilder("Test");
            sb.Append(str, index, count);
            string output = sb.ToString();
            expected = "Test" + expected;
            if (output != expected)
            {
                result = false;
                TestFramework.LogError("001a", "Error in " + id + ", unexpected append result. Actual string " + output + ", Expected: " + expected);
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("002a", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return result;
    }

    public bool PositiveTest3(char str, int count, string expected, string id)
    {
        bool result = true;
        TestFramework.BeginScenario(id + ": Append");
        try
        {
            StringBuilder sb = new StringBuilder("Test");
            sb.Append(str, count);
            string output = sb.ToString();
            expected = "Test" + expected;
            if (output != expected)
            {
                result = false;
                TestFramework.LogError("001b", "Error in " + id + ", unexpected append result. Actual string " + output + ", Expected: " + expected);
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("002b", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return result;
    }

    public bool PositiveTest4<T>(T str, string id)
    {
        bool result = true;
        TestFramework.BeginScenario(id + ": Append");
        try
        {
            StringBuilder sb = new StringBuilder("Test");
            sb.Append(str);
            string output = sb.ToString();
            string expected = ((str == null)?"Test":"Test" + str.ToString());
            if (output != expected)
            {
                result = false;
                TestFramework.LogError("001c", "Error in " + id + ", unexpected append result. Actual string " + output + ", Expected: " + expected);
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("002c", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return result;
    }

    public bool PositiveTest5(char[] str, string expected, string id)
    {
        bool result = true;
        TestFramework.BeginScenario(id + ": Append");
        try
        {
            StringBuilder sb = new StringBuilder("Test");
            sb.Append(str);
            string output = sb.ToString();
            expected = "Test" + expected;
            if (output != expected)
            {
                result = false;
                TestFramework.LogError("001d", "Error in " + id + ", unexpected append result. Actual string " + output + ", Expected: " + expected);
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("002d", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return result;
    }

    public bool NegativeTest(string str, int index, int count, Type expected, string id)
    {
        bool result = true;
        TestFramework.BeginScenario(id + ": Append");
        try
        {
            StringBuilder sb = new StringBuilder("Test");

            sb.Append(str, index, count);
            string output = sb.ToString();
            result = false;
            TestFramework.LogError("003", "Error in " + id + ", Expected exception not thrown. No exception. Actual string " + output + ", Expected: " + expected.ToString());
        }
        catch (Exception exc)
        {
            if (exc.GetType() != expected)
            {
                result = false;
                TestFramework.LogError("004", "Unexpected exception in " + id + ", expected type: " + expected.ToString() + ", Actual excpetion: " + exc.ToString());
            }
        }
        return result;
    }

    public bool NegativeTest2(char[] str, int index, int count, Type expected, string id)
    {
        bool result = true;
        TestFramework.BeginScenario(id + ": Append");
        try
        {
            StringBuilder sb = new StringBuilder("Test");

            sb.Append(str, index, count);
            string output = sb.ToString();
            result = false;
            TestFramework.LogError("003b", "Error in " + id + ", Expected exception not thrown. No exception. Actual string " + output + ", Expected: " + expected.ToString());
        }
        catch (Exception exc)
        {
            if (exc.GetType() != expected)
            {
                result = false;
                TestFramework.LogError("004b", "Unexpected exception in " + id + ", expected type: " + expected.ToString() + ", Actual excpetion: " + exc.ToString());
            }
        }
        return result;
    }


    public bool NegativeTest3(char str, int count, Type expected, string id)
    {
        bool result = true;
        TestFramework.BeginScenario(id + ": Append");
        try
        {
            StringBuilder sb = new StringBuilder("Test");

            sb.Append(str, count);
            string output = sb.ToString();
            result = false;
            TestFramework.LogError("003c", "Error in " + id + ", Expected exception not thrown. No exception. Actual string " + output + ", Expected: " + expected.ToString());
        }
        catch (Exception exc)
        {
            if (exc.GetType() != expected)
            {
                result = false;
                TestFramework.LogError("004c", "Unexpected exception in " + id + ", expected type: " + expected.ToString() + ", Actual excpetion: " + exc.ToString());
            }
        }
        return result;
    }
}