summaryrefslogtreecommitdiff
path: root/tests/StringBuilderTest/main.cpp
blob: c06034a634af3866db467655bfdb3e14119b817b (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
/*
 * small tests for class StringBuilder
 */
#include <StringBuilder.h>
#include <FileReader.h>
#include <LineReader.h>
#include <File.h>
#include <string.h>
#include <iostream>

#define NEW_LINE '\n'

void rangeTests()
{                           // 12345678901
  static const char *sample = "Hello World";
  cStringBuilder *sb;
  int chunkSize = strlen(sample) - 4;
  char *result;

  std::cout << sample << " has length: " << strlen(sample) << std::endl;

  for (int i=0; i < 6; ++i) {
      std::cout << "check chunkSize of " << chunkSize + i << std::endl;
      sb = new cStringBuilder(chunkSize + i);

      sb->Append(sample).Append(NEW_LINE);
      result = sb->toString();

      std::cout << "assembled text looks like: " << std::endl << result;
      free(result);
      delete sb;
      }
}

void basicTests()
{
  cStringBuilder sb(179);

  sb.Append("hello World").Append(NEW_LINE);
  sb.Append("logical default true: ").Append(true).Append(NEW_LINE);
  sb.Append("logical default false: ").Append(false).Append(NEW_LINE);
  sb.Append("logical true value: ").Append(true, "true", "false").Append(NEW_LINE);
  sb.Append("logical false value: ").Append(false, "true", "false").Append(NEW_LINE);
  sb.Append("double: ").Append(3.1456789).Append(NEW_LINE);
  sb.Append("unsigned long: ").Append((size_t) 91237485l).Append(NEW_LINE);
  sb.Append("long: ").Append(1234567890l).Append(NEW_LINE);
  sb.Append("int: ").Append(512).Append(NEW_LINE);

  char *result = sb.toString();

  std::cout << "sizeof assembled text: " << sb.Size() << std::endl;
  std::cout << "assembled text looks like:" << std::endl << result;

  free(result);
}

void lineReaderTest()
{
  cLineReader lr(new cFileReader(new cFile("srclient.conf")));
  const char *line = NULL;

  while ((line = lr.ReadLine())) {
        std::cout << "line: " << line << std::endl;
        }
  lr.Close();
  cFile::Cleanup();
}

int main()
{
  lineReaderTest();
  basicTests();
  rangeTests();

  return 0;
}