summaryrefslogtreecommitdiffstats
path: root/runtime/tests/string/string2.c
blob: ccf3997a16192b6b5868237baf38cf2683c2bde2 (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
/* test of Strings */

/* use very small buffer size for testing */
#define STP_STRING_SIZE 20
#define STP_NUM_STRINGS 1
#include "runtime.h"

int main ()
{
  String str = _stp_string_init (0);

 /* can we see output? */
  _stp_sprintf(str, "ABCDE\n");
  _stp_print(str);


  /* overflow */
  str = _stp_string_init (0);
  _stp_sprintf(str, "1234567890123456789012345\n");
  _stp_sprintf(str, "XYZZY\n");
  _stp_print(str);
  _stp_printf("\n");

  /* small string then overflow string */
  str = _stp_string_init (0);
  _stp_sprintf(str,"XYZZY\n");
  _stp_sprintf(str,"1234567890123456789012345");
  _stp_print(str);
  _stp_printf("\n");

  /* two small string that overflow */
  str = _stp_string_init (0);
  _stp_sprintf(str,"abcdefghij");
  _stp_sprintf(str,"123456789");
  _stp_print(str);
  _stp_printf("\n");

  /* two small string that overflow */
  str = _stp_string_init (0);
  _stp_sprintf(str,"abcdefghij");
  _stp_sprintf(str,"1234567890X");
  _stp_print(str);
  _stp_printf("\n");

  str = _stp_string_init (0);
  _stp_sprintf(str,"12345\n");
  _stp_sprintf(str,"67890\n");
  _stp_sprintf(str,"abcde\n");
  _stp_print(str);

  str = _stp_string_init (0);
  _stp_sprintf(str,"12345");
  _stp_sprintf(str,"67890");
  _stp_sprintf(str,"abcde");
  _stp_sprintf(str,"fghij");
  _stp_print(str);
  _stp_printf("\n");

  /* null string */
  str = _stp_string_init (0);
  _stp_sprintf(str,"");
  _stp_sprintf(str,"");
  _stp_sprintf(str,"Q\n");
  _stp_print(str);

  _stp_print_flush();
  return 0;
}