Pyrogenesis  trunk
test_path.h
Go to the documentation of this file.
1 /* Copyright (c) 2010 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #include "lib/self_test.h"
24 
25 #include "lib/self_test.h"
26 #include "lib/res/file/path.h"
27 
28 class TestPath : public CxxTest::TestSuite
29 {
30 public:
32  {
33  char N_path[PATH_MAX] = {0};
34  TS_ASSERT_OK(file_make_native_path("a/b/c", N_path));
35 #if OS_WIN
36  TS_ASSERT_STR_EQUALS(N_path, "a\\b\\c");
37 #else
38  TS_ASSERT_STR_EQUALS(N_path, "a/b/c");
39 #endif
40 
41  char P_path[PATH_MAX] = {0};
42  TS_ASSERT_OK(file_make_portable_path("a\\b\\c", P_path));
43 #if OS_WIN
44  TS_ASSERT_STR_EQUALS(P_path, "a/b/c");
45 #else
46  // sounds strange, but correct: on non-Windows, \\ didn't
47  // get recognized as separators and weren't converted.
48  TS_ASSERT_STR_EQUALS(P_path, "a\\b\\c");
49 #endif
50 
51  }
52 
53  // file_make_full_*_path is left untested (hard to do so)
54 
55  void test_pool()
56  {
57  // .. return same address for same string?
58  const char* atom1 = path_Pool->UniqueCopy("a/bc/def");
59  const char* atom2 = path_Pool->UniqueCopy("a/bc/def");
60  TS_ASSERT_EQUALS(atom1, atom2);
61 
62  // .. early out (already in pool) check works?
63  const char* atom3 = path_Pool->UniqueCopy(atom1);
64  TS_ASSERT_EQUALS(atom3, atom1);
65 
66  // is it reported as in pool?
67  TS_ASSERT(path_Pool()->Contains(atom1));
68 
69  // path_Pool()->RandomString
70  // see if the atom added above eventually comes out when a
71  // random one is returned from the pool.
72  int tries_left;
73  for(tries_left = 1000; tries_left != 0; tries_left--)
74  {
75  const char* random_name = path_Pool->RandomString();
76  if(random_name == atom1)
77  break;
78  }
79  TS_ASSERT(tries_left != 0);
80  }
81 };
void test_pool()
Definition: test_path.h:55
#define PATH_MAX
Definition: wposix_types.h:101
#define TS_ASSERT_STR_EQUALS(str1, str2)
Definition: self_test.h:108
Definition: test_path.h:28
#define TS_ASSERT_OK(expr)
Definition: self_test.h:106
void test_conversion()
Definition: test_path.h:31