7f3790610908fbe3e1d5cab0ab24689a66cf5f17
[libacl.git] / test / string_convert.cpp
1 /*******************************************************
2  *  Unit test for the String class
3  *
4  * test conversion operations
5  ******************************************************
6  *
7  */
8
9 #include "String.h"
10 #include <assert.h>
11
12 int main()
13 {
14
15    // Construct a string from a number
16
17    String s1(12);
18
19    std::cout << s1 << " is contructed from the number 12\n";
20    assert(s1 == "12");
21
22    String s2(2.32);
23
24    std::cout << s2 << " is contructed from the number 2.32\n";
25    assert(s2 == "2.320");
26
27    int    n;
28    double f;
29
30    String s3("42");
31    n = int(s3);
32    std::cout << "String " << s3 << " converts into number " << n << "\n";
33    assert(n == 42);
34
35    String s4("3.1415");
36    f = double(s4);
37    std::cout << "String " << s4 << " converts into number " << f << "\n";
38    assert(f == 3.1415);
39
40    int     k;
41    double  x;
42
43    String s5("not a number");
44    k = int(s5);
45    std::cout << "String " << s5 << " converts into number " << k << "\n";
46    assert(k == 0);
47
48    x = double(s5);
49    std::cout << "String " << s5 << " converts into number " << x << "\n";
50    assert(x == 0.0);
51
52    return 0;
53 }
54