Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/testing/test/util/ConvertTest.cc @ 9477

Last change on this file since 9477 was 9356, checked in by landauf, 12 years ago

details

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1#include <gtest/gtest.h>
2#include "util/Convert.h"
3#include "util/Math.h"
4#include "util/MathConvert.h"
5
6namespace orxonox
7{
8    TEST(multi_cast, ToString)
9    {
10        // int
11        EXPECT_EQ("5", multi_cast<std::string>(static_cast<int>(5)));
12        EXPECT_EQ("-13", multi_cast<std::string>(static_cast<int>(-13)));
13
14        // unsigned int
15        EXPECT_EQ("0", multi_cast<std::string>(static_cast<unsigned int>(0)));
16        EXPECT_EQ("4000000000", multi_cast<std::string>(static_cast<unsigned int>(4000000000LL)));
17
18        // float
19        EXPECT_EQ("0", multi_cast<std::string>(0.0f));
20        EXPECT_EQ("10", multi_cast<std::string>(10.0f));
21        EXPECT_EQ("123.456", multi_cast<std::string>(123.456f));
22        EXPECT_EQ("1.234e+012", multi_cast<std::string>(1234000000000.0f));
23
24        // double
25        EXPECT_EQ("0", multi_cast<std::string>(0.0));
26        EXPECT_EQ("10", multi_cast<std::string>(10.0));
27        EXPECT_EQ("123.456", multi_cast<std::string>(123.456));
28        EXPECT_EQ("1.234e+012", multi_cast<std::string>(1234000000000.0));
29
30        // char
31        EXPECT_EQ("a", multi_cast<std::string>('a'));
32        EXPECT_EQ("\n", multi_cast<std::string>('\n'));
33
34        // bool
35        EXPECT_EQ("true", multi_cast<std::string>(true));
36        EXPECT_EQ("false", multi_cast<std::string>(false));
37
38        // string
39        EXPECT_EQ("testTEST123", multi_cast<std::string>("testTEST123"));
40        EXPECT_EQ("", multi_cast<std::string>(""));
41
42        // TODO: Check consistency of conversion depending on MathConvert.h and reversibility
43/*
44        // Vector2
45        EXPECT_EQ("Vector2(10.1, 20)", multi_cast<std::string>(Vector2(10.1, 20)));
46
47        // Vector3
48        EXPECT_EQ("Vector3(10.1, 20, 300000)", multi_cast<std::string>(Vector3(10.1, 20, 300000)));
49
50        // Vector4
51        EXPECT_EQ("Vector4(10.1, 20, 300000, -321)", multi_cast<std::string>(Vector4(10.1, 20, 300000, -321)));
52
53        // Quaternion
54        EXPECT_EQ("Quaternion(10.1, 20, 300000, -321)", multi_cast<std::string>(Quaternion(10.1, 20, 300000, -321)));
55
56        // ColourValue
57        EXPECT_EQ("ColourValue(10.1, 20, 300000, -321)", multi_cast<std::string>(ColourValue(10.1, 20, 300000, -321)));
58
59        // Radian
60        EXPECT_EQ("Radian(1.234)", multi_cast<std::string>(Radian(1.234)));
61
62        // Degree
63        EXPECT_EQ("Degree(123)", multi_cast<std::string>(Degree(123)));
64*/
65    }
66
67    TEST(multi_cast, FromString)
68    {
69        // int
70        EXPECT_EQ(5, multi_cast<int>(std::string("5")));
71        EXPECT_EQ(-13, multi_cast<int>(std::string("-13")));
72
73        // unsigned int
74        EXPECT_EQ(0U, multi_cast<unsigned int>(std::string("0")));
75        EXPECT_EQ(4000000000LL, multi_cast<unsigned int>(std::string("4000000000")));
76
77        // float
78        EXPECT_EQ(0.0f, multi_cast<float>(std::string("0")));
79        EXPECT_EQ(10.0f, multi_cast<float>(std::string("10")));
80        EXPECT_EQ(123.456f, multi_cast<float>(std::string("123.456")));
81        EXPECT_EQ(1234000000000.0f, multi_cast<float>(std::string("1.234e+012")));
82
83        // double
84        EXPECT_EQ(0.0, multi_cast<double>(std::string("0")));
85        EXPECT_EQ(10.0, multi_cast<double>(std::string("10")));
86        EXPECT_EQ(123.456, multi_cast<double>(std::string("123.456")));
87        EXPECT_EQ(1234000000000.0, multi_cast<double>(std::string("1.234e+012")));
88
89        // char
90        EXPECT_EQ('a', multi_cast<char>(std::string("a")));
91        EXPECT_EQ('\n', multi_cast<char>(std::string("\n")));
92        EXPECT_EQ('\0', multi_cast<char>(std::string("")));
93        EXPECT_EQ('1', multi_cast<char>(std::string("123")));
94
95        // bool
96        EXPECT_TRUE(multi_cast<bool>(std::string("true")));
97        EXPECT_FALSE(multi_cast<bool>(std::string("false")));
98        EXPECT_FALSE(multi_cast<bool>(std::string("0")));
99        EXPECT_FALSE(multi_cast<bool>(std::string("0.123")));
100        EXPECT_TRUE(multi_cast<bool>(std::string("1")));
101        EXPECT_TRUE(multi_cast<bool>(std::string("123.456")));
102
103        // TODO: Check consistency of conversion depending on MathConvert.h and reversibility
104/*
105        // Vector2
106        EXPECT_EQ(Vector2(10.1, 20), multi_cast<Vector2>(std::string("Vector2(10.1, 20)")));
107
108        // Vector3
109        EXPECT_EQ(Vector3(10.1, 20, 300000), multi_cast<Vector3>(std::string("Vector3(10.1, 20, 300000)")));
110
111        // Vector4
112        EXPECT_EQ(Vector4(10.1, 20, 300000, -321), multi_cast<Vector4>(std::string("Vector4(10.1, 20, 300000, -321)")));
113
114        // Quaternion
115        EXPECT_EQ(Quaternion(10.1, 20, 300000, -321), multi_cast<Quaternion>(std::string("Quaternion(10.1, 20, 300000, -321)")));
116
117        // ColourValue
118        EXPECT_EQ(ColourValue(10.1, 20, 300000, -321), multi_cast<ColourValue>(std::string("ColourValue(10.1, 20, 300000, -321)")));
119
120        // Radian
121        EXPECT_EQ(Radian(1.234), multi_cast<Radian>(std::string("Radian(1.234)")));
122
123        // Degree
124        EXPECT_EQ(Degree(123), multi_cast<Degree>(std::string("Degree(123)")));
125*/
126    }
127}
Note: See TracBrowser for help on using the repository browser.