File: large_str_test.cc

package info (click to toggle)
rlvm 0.14-5.2
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 17,104 kB
  • sloc: cpp: 91,574; ansic: 39,346; perl: 768; sh: 320; python: 181; makefile: 8
file content (696 lines) | stat: -rw-r--r-- 22,704 bytes parent folder | download | duplicates (6)
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
// -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi:tw=80:et:ts=2:sts=2
//
// -----------------------------------------------------------------------
//
// This file is part of RLVM, a RealLive virtual machine clone.
//
// -----------------------------------------------------------------------
//
// Copyright (C) 2006, 2007 Elliot Glaysher
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
// -----------------------------------------------------------------------

#include "gtest/gtest.h"

#include "modules/module_str.h"
#include "libreallive/archive.h"
#include "libreallive/intmemref.h"

#include "machine/rlmachine.h"

#include "test_system/test_system.h"

#include "test_utils.h"

#include <string>
#include <iostream>

using namespace std;
using namespace libreallive;

// Tests strcpy_0, which should copy the string valid int strS[0].
//
// Corresponding kepago listing:
//
//   strS[0] = "valid"
//
TEST(LargeModuleStrTest, strcpy0) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strcpy_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  string one = rlmachine.GetStringValue(STRS_LOCATION, 0);
  EXPECT_EQ("valid", one) << "strcpy_0 script failed to set value";
}

// Tests strcpy_1, which should copy the first 2 chracters into strS[0].
//
// Corresponding kepago listing:
//
//   strcpy(strS[0], "valid", 2)
//
TEST(LargeModuleStrTest, strcpy1) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strcpy_1.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  string one = rlmachine.GetStringValue(STRS_LOCATION, 0);
  EXPECT_EQ("va", one) << "strcpy_1 script failed to set value";
}

// Tests strclear_0, which should clear the value of a string.
//
// Corresponding kepago listing:
//
//   strS[0] = "valid"
//   strS[1] = "valid"
//   strclear(strS[0])
//
TEST(LargeModuleStrTest, strclear0) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strclear_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  string one = rlmachine.GetStringValue(STRS_LOCATION, 0);
  EXPECT_EQ("", one) << "strclear_0 script failed to unset value";

  // We include this check to make sure the machine is sane and that
  // the first assignment works, so strclear doesn't appear to work
  // because assignment failed.
  string two = rlmachine.GetStringValue(STRS_LOCATION, 1);
  EXPECT_EQ("valid", two) << "strclear_0 script failed to set value";
}

// Tests strclear_1, which should clear out a whole range of values.
//
//   strS[0] = "valid"
//   strS[1] = "valid"
//   strS[2] = "valid"
//   strclear(strS[0], strS[1])
TEST(LargeModuleStrTest, strclear1) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strclear_1.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  string one = rlmachine.GetStringValue(STRS_LOCATION, 0);
  EXPECT_EQ("", one) << "strclear_1 script failed to unset value";
  string two = rlmachine.GetStringValue(STRS_LOCATION, 1);
  EXPECT_EQ("", two) << "strclear_1 script failed to unset value";

  // We include this check to make sure the machine is sane and that
  // the first assignment works, so strclear doesn't appear to work
  // because assignment failed.
  string three = rlmachine.GetStringValue(STRS_LOCATION, 2);
  EXPECT_EQ("valid", three) << "strclear_1 script failed to set value";
}

// Tests strcat, which should end up with the string "valid" in strS[0].
//
// Corresponding kepago listing:
//
//   strS[0] = "va"
//   strS[0] += "lid"
//
TEST(LargeModuleStrTest, strcat) {  // NOLINT
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strcat_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  string one = rlmachine.GetStringValue(STRS_LOCATION, 0);
  EXPECT_EQ("valid", one) << "strcat script failed to set value";
}

// Tests strlen. Should be 5, for "vaild"
//
// Corresponding kepago listing:
//
//   strS[0] = "valid"
//   intA[0] = strlen(strS[0])
//
TEST(LargeModuleStrTest, strlen) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strlen_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  int one = rlmachine.GetIntValue(IntMemRef('A', 0));
  EXPECT_EQ(5, one) << "strlen script failed to set the strlen(\"valid\") to 5";
}

// Tests strcmp; make sure that it gives the same values as normal strcmp.
//
// Corresponding kepago listing:
//
//   strS[0] = "a"
//   strS[1] = "b"
//   strS[2] = "b"
//   strS[3] = "c"
//   intA[0] = strcmp(strS[0], strS[1])
//   intA[1] = strcmp(strS[1], strS[2])
//   intA[2] = strcmp(strS[2], strS[3])
//
TEST(LargeModuleStrTest, strcmp) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strcmp_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ(strcmp("a", "b"), rlmachine.GetIntValue(IntMemRef('A', 0)))
      << "Different values for strcmp(\"a\", \"b\")";
  EXPECT_EQ(strcmp("b", "b"), rlmachine.GetIntValue(IntMemRef('A', 1)))
      << "Different values for strcmp(\"b\", \"b\")";
  EXPECT_EQ(strcmp("b", "c"), rlmachine.GetIntValue(IntMemRef('A', 2)))
      << "Different values for strcmp(\"b\", \"c\")";
}

// First strsub_0 test. Make sure it works on ASCII strings.
TEST(LargeModuleStrTest, strsub0_ascii) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strsub_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("lid", rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "strsub returned wrong value";
}

// Second strsub_0 test. Make sure it works on Shift_JIS strings.
//
//   strS[0] = "わたしの名前、まだ覚えてる?"
//   strS[1] = strsub(strS[0], 7)
//
TEST(LargeModuleStrTest, strsub0_shiftjis) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strsub_1.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("\x82\xDC\x82\xBE\x8A\x6F\x82\xA6\x82\xC4\x82\xE9\x81\x48",
            rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "strsub returned wrong value";
}

// First strsub_1 test. Make sure it deals with ASCII.
//
//   strS[0] = "valid"
//   strS[1] = strsub(strS[0], 1, 2)
//
TEST(LargeModuleStrTest, strsub1_ascii) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strsub_2.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("al", rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "strsub returned wrong value";
}

// Second strsub_1 test. Make sure it works on Shift_JIS strings.
//
//  strS[0] = "わたしの名前、まだ覚えてる?"
//  strS[1] = strsub(strS[0], 7)
//
TEST(LargeModuleStrTest, strsub1_shiftjis) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strsub_3.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("\x96\xBC\x91\x4F", rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "strsub returned wrong value";
}

// Strrsub test. (We don't need to test this on Shift_JIS since this
// calls the same code path as strsub, with just a different offset
// method.)
//
//   strS[0] = "valid"
//   strS[1] = strrsub(strS[0], 2)
//
TEST(LargeModuleStrTest, strrsub_0) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strrsub_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("id", rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "strrsub returned wrong value";
}

// Strrsub test.
//
//  strS[0] = "valid"
//  strS[1] = strrsub(strS[0], 2, 1)
//
TEST(LargeModuleStrTest, strrsub_1) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strrsub_1.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("i", rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "strrsub returned wrong value";
}

// strcharlen test on ASCII strings
//
//  strS[0] = "valid"
//  intA[0] = strcharlen(strS[0])
//
TEST(LargeModuleStrTest, strcharlen_ascii) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strcharlen_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ(5, rlmachine.GetIntValue(IntMemRef('A', 0)))
      << "strcharlen returned wrong value";
}

// strcharlen test on Shift_JIS strings
//
//   strS[0] = "わたしの名前、まだ覚えてる?"
//   intA[0] = strcharlen(strS[0])
//
TEST(LargeModuleStrTest, srcharlen_shiftjis) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strcharlen_1.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ(14, rlmachine.GetIntValue(IntMemRef('A', 0)))
      << "strcharlen returned wrong value";
}

// strtrunc test on ASCII characters
//
//   strS[0] = "valid"
//   strtrunc(strS[0], 2)
//
TEST(LargeModuleStrTest, strtrunc_ascii) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strtrunc_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("va", rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "strtrunc returned wrong value";
}

// strtrunc test on Shift-JIS characters
TEST(LargeModuleStrTest, strtrunc_shiftjis) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strtrunc_1.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("\x82\xED\x82\xBD\x82\xB5",
            rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "strtrunc returned wrong value";
}

// Test hantozen() on ASCII numbers
//
//   strS[0] = "12345"
//   strS[0] = hantozen()
//
TEST(LargeModuleStrTest, hantozen_ascii) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/hantozen_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54",
            rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "hantozen returned wrong value";
}

// Test hantozen() on half width katakana; should convert them to full
// width katakana.
//
//   strS[0] = "ワタシノナマエ"
//   strS[0] = hantozen()
//
TEST(LargeModuleStrTest, hantozen_half_width_katakana) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/hantozen_1.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("\x83\x8F\x83\x5E\x83\x56\x83\x6D\x83\x69\x83\x7D\x83\x47",
            rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "hantozen returned wrong value";
}

// Tests zentohan on fullwidth ASCII characters.
//
//   strS[0] = "12345"
//   strS[0] = zentohan()
//
TEST(LargeModuleStrTest, hantozen_fullwidth_ascii) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/zentohan_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("12345", rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "zentohan returned wrong value";
}

// Tests zentohan on fullwidth katakana characters.
//
//   strS[0] = "ワタシノナマエ"
//   strS[0] = zentohan()
//
TEST(LargeModuleStrTest, zentohan_fullwidth_katakana) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/zentohan_1.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("\xDC\xC0\xBC\xC9\xC5\xCF\xB4",
            rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "zentohan returned wrong value";
}

// Test Uppercase_0
//
//   strS[0] = "Valid"
//   // This syntax hurts my brain
//   strS[0] = Uppercase()
//
TEST(LargeModuleStrTest, Uppercase_0) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/uppercase_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("VALID", rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "Uppercase returned wrong value";
}

// Test Uppercase_1
//
//   strS[0] = "Valid"
//   // This syntax hurts my brain
//   strS[0] = Uppercase()
//
TEST(LargeModuleStrTest, Uppercase_1) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/uppercase_1.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("Valid", rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "Uppercase touched strS[0]";
  EXPECT_EQ("VALID", rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "Uppercase returned wrong value";
}

// Test Lowercase_0
//
//   strS[0] = "Valid"
//   // This syntax hurts my brain
//   strS[0] = Lowercase()
//
TEST(LargeModuleStrTest, Lowercase_0) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/lowercase_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("valid", rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "Lowercase returned wrong value";
}

// Test Lowercase_1.
//
//   strS[0] = "Valid"
//   // This syntax hurts my brain
//   strS[1] = Lowercase(strS[0])
//
TEST(LargeModuleStrTest, Lowercase_1) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/lowercase_1.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("Valid", rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "Lowercase touched strS[0]";
  EXPECT_EQ("valid", rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "Lowercase returned wrong value";
}

// Test itoa_ws's various stuff
//
//   strS[0] = itoa_ws(-1)
//   strS[1] = itoa_ws(-1, 3)
//   strS[2] = itoa_ws(3)
//   strS[3] = itoa_ws(1, 3)
//
TEST(LargeModuleStrTest, itoa_ws) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/itoa_ws_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("\x81\x7C\x82\x50", rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "itoa_ws set wrong value for strS[0]";
  EXPECT_EQ("\x81\x7C\x81\x40\x81\x40\x82\x50",
            rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "itoa_ws set wrong value for strS[1]";
  EXPECT_EQ("\x82\x52", rlmachine.GetStringValue(STRS_LOCATION, 2))
      << "itoa_ws set wrong value for strS[2]";
  EXPECT_EQ("\x81\x40\x81\x40\x82\x50",
            rlmachine.GetStringValue(STRS_LOCATION, 3))
      << "itoa_ws set wrong value for strS[3]";
}

// Test itoa_s, which shouldn't be as hard to write as itoa_ws. -_-
//
//   strS[0] = itoa_s(-1)
//   strS[1] = itoa_s(-1, 3)
//   strS[2] = itoa_s(3)
//   strS[3] = itoa_s(1, 3)
//
TEST(LargeModuleStrTest, itoa_s) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/itoa_s_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("-1", rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "itoa_s set wrong value for strS[0]";
  EXPECT_EQ("-  1", rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "itoa_s set wrong value for strS[1]";
  EXPECT_EQ("3", rlmachine.GetStringValue(STRS_LOCATION, 2))
      << "itoa_s set wrong value for strS[2]";
  EXPECT_EQ("  1", rlmachine.GetStringValue(STRS_LOCATION, 3))
      << "itoa_s set wrong value for strS[3]";
}

// Test itoa_w, which shouldn't be as hard to write as itoa_ws. -_-
//
//   strS[0] = itoa_w(-1)
//   strS[1] = itoa_w(-1, 3)
//   strS[2] = itoa_w(3)
//   strS[3] = itoa_w(1, 3)
//
TEST(LargeModuleStrTest, itoa_w) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/itoa_w_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("\x81\x7C\x82\x50", rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "itoa_w set wrong value for strS[0]";
  EXPECT_EQ("\x81\x7C\x82\x4F\x82\x4F\x82\x50",
            rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "itoa_w set wrong value for strS[1]";
  EXPECT_EQ("\x82\x52", rlmachine.GetStringValue(STRS_LOCATION, 2))
      << "itoa_w set wrong value for strS[2]";
  EXPECT_EQ("\x82\x4F\x82\x4F\x82\x50",
            rlmachine.GetStringValue(STRS_LOCATION, 3))
      << "itoa_w set wrong value for strS[3]";
}

// Test itoa
//
//   strS[0] = itoa(-1)
//   strS[1] = itoa(-1, 3)
//   strS[2] = itoa(3)
//   strS[3] = itoa(1, 3)
//
TEST(LargeModuleStrTest, itoa) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/itoa_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ("-1", rlmachine.GetStringValue(STRS_LOCATION, 0))
      << "itoa set wrong value for strS[0]";
  EXPECT_EQ("-001", rlmachine.GetStringValue(STRS_LOCATION, 1))
      << "itoa set wrong value for strS[1]";
  EXPECT_EQ("3", rlmachine.GetStringValue(STRS_LOCATION, 2))
      << "itoa set wrong value for strS[2]";
  EXPECT_EQ("001", rlmachine.GetStringValue(STRS_LOCATION, 3))
      << "itoa set wrong value for strS[3]";
}

// Tests atoi.
//
//   intA[0] = atoi("15")
//   intA[1] = atoi("   15")
//   intA[2] = atoi("-12")
//   intA[3] = atoi("5  27")
//   intA[4] = atoi("asdf")
//
TEST(LargeModuleStrTest, atoi) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/atoi_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ(15, rlmachine.GetIntValue(IntMemRef('A', 0)))
      << "atoi returned wrong value for intA[0]";
  EXPECT_EQ(15, rlmachine.GetIntValue(IntMemRef('A', 1)))
      << "atoi returned wrong value for intA[1]";
  EXPECT_EQ(-12, rlmachine.GetIntValue(IntMemRef('A', 2)))
      << "atoi returned wrong value for intA[2]";
  EXPECT_EQ(5, rlmachine.GetIntValue(IntMemRef('A', 3)))
      << "atoi returned wrong value for intA[3]";
  EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 4)))
      << "atoi returned wrong value for intA[4]";
}

// Tests digits.
//
//   intA[0] = digits(1)
//   intA[1] = digits(20)
//   intA[2] = digits(-20)
//
TEST(LargeModuleStrTest, digits) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/digits_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ(1, rlmachine.GetIntValue(IntMemRef('A', 0)))
      << "digits returned wrong value for intA[0]";
  EXPECT_EQ(2, rlmachine.GetIntValue(IntMemRef('A', 1)))
      << "digits returned wrong value for intA[1]";
  EXPECT_EQ(2, rlmachine.GetIntValue(IntMemRef('A', 2)))
      << "digits returned wrong value for intA[2]";
}

// Tests strpos.
//
//   intA[0] = strpos("equal", "equal")
//   intA[1] = strpos("This is the the repitition test.", "the")
//   intA[2] = strpos("Itaiyo", "Uguu~")
//
TEST(LargeModuleStrTest, strpos) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strpos_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 0)))
      << "strpos returned wrong value for intA[0]";
  EXPECT_EQ(8, rlmachine.GetIntValue(IntMemRef('A', 1)))
      << "strpos returned wrong value for intA[1]";
  EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 2)))
      << "strpos returned wrong value for intA[2]";
}

// Tests strlpos.
//
//   intA[0] = strlpos("equal", "equal")
//   intA[1] = strlpos("This is the the repitition test.", "the")
//   intA[2] = strlpos("Itaiyo", "Uguu~")
//
TEST(LargeModuleStrTest, strlpos) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strlpos_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 0)))
      << "strlpos returned wrong value for intA[0]";
  EXPECT_EQ(12, rlmachine.GetIntValue(IntMemRef('A', 1)))
      << "strlpos returned wrong value for intA[1]";
  EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 2)))
      << "strlpos returned wrong value for intA[2]";
}

// Tests strused.
//
//   strS[1] = "Used"
//   intA[0] = strused(strS[0])
//   intA[1] = strused(strS[1])
//
TEST(LargeModuleStrTest, strused) {
  libreallive::Archive arc(locateTestCase("Module_Str_SEEN/strused_0.TXT"));
  TestSystem system;
  RLMachine rlmachine(system, arc);
  rlmachine.AttachModule(new StrModule);
  rlmachine.ExecuteUntilHalted();

  EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 0)))
      << "strused returned wrong value for intA[0]";
  EXPECT_EQ(1, rlmachine.GetIntValue(IntMemRef('A', 1)))
      << "strused returned wrong value for intA[1]";
}