1 //------------------------------------------------------------------------------
2 // ValidateInstantiationTester.cpp
3 //
4 /**
5 Testing for validate_instantiation(BMessage* archive, const char* className)
6 @note The AllParamsInvalid() and ArchiveInvalid() test are not to be run
7 against the original implementation, as it does not validate the
8 archive parameter with a resulting segment violation.
9 */
10 //------------------------------------------------------------------------------
11
12 // Standard Includes -----------------------------------------------------------
13 #include <errno.h>
14
15 // System Includes -------------------------------------------------------------
16 #include <Message.h>
17
18 // Project Includes ------------------------------------------------------------
19
20 // Local Includes --------------------------------------------------------------
21 #include "ValidateInstantiationTester.h"
22
23 // Local Defines ---------------------------------------------------------------
24
25 // Globals ---------------------------------------------------------------------
26 const char* gClassName = "FooBar";
27 const char* gBogusClassName = "BarFoo";
28
29 //------------------------------------------------------------------------------
30 /**
31 validate_instantiation(BMessage* archive, const char* className)
32 @case All parameters invalid (i.e., NULL)
33 @param archive NULL
34 @param className NULL
35 @results Returns false.
36 errno is set to B_BAD_VALUE.
37 */
AllParamsInvalid()38 void TValidateInstantiationTest::AllParamsInvalid()
39 {
40 errno = B_OK;
41 CPPUNIT_ASSERT(!validate_instantiation(NULL, NULL));
42 CPPUNIT_ASSERT(errno == B_BAD_VALUE);
43 }
44 //------------------------------------------------------------------------------
45 /**
46 validate_instantiation(BMessage* archive, const char* className)
47 @case Valid archive, invalid className (i.e., NULL)
48 @param archive Valid BMessage pointer
49 @param className NULL
50 @results Returns false.
51 errno is set to B_MISMATCHED_VALUES.
52 */
ClassNameParamInvalid()53 void TValidateInstantiationTest::ClassNameParamInvalid()
54 {
55 errno = B_OK;
56 BMessage Archive;
57 CPPUNIT_ASSERT(!validate_instantiation(&Archive, NULL));
58 CPPUNIT_ASSERT(errno == B_MISMATCHED_VALUES);
59 }
60 //------------------------------------------------------------------------------
61 /**
62 validate_instantiation(BMessage* archive, const char* className)
63 @case Invalid archive (i.e., NULL), valid className
64 @param archive NULL
65 @param className A valid C-string
66 @results Returns false.
67 errno is set to B_BAD_VALUE.
68 @note Do not run this test against the original implementation
69 as it does not verify the validity of archive, resulting
70 in a segment violation.
71 */
ArchiveParamInvalid()72 void TValidateInstantiationTest::ArchiveParamInvalid()
73 {
74 errno = B_OK;
75 CPPUNIT_ASSERT(!validate_instantiation(NULL, gClassName));
76 CPPUNIT_ASSERT(errno == B_BAD_VALUE);
77 }
78 //------------------------------------------------------------------------------
79 /**
80 validate_instantiation(BMessage* archive, const char* className)
81 @case Valid archive and className with no string field "class"
82 in archive
83 @param archive Valid BMessage pointer
84 @param className Valid C-string
85 @results Returns false.
86 errno is set to B_MISMATCHED_VALUES.
87 */
ClassFieldEmpty()88 void TValidateInstantiationTest::ClassFieldEmpty()
89 {
90 errno = B_OK;
91 BMessage Archive;
92 CPPUNIT_ASSERT(!validate_instantiation(&Archive, gClassName));
93 CPPUNIT_ASSERT(errno == B_MISMATCHED_VALUES);
94 }
95 //------------------------------------------------------------------------------
96 /**
97 validate_instantiation(BMessage* archive, const char* className)
98 @case Valid archive with string field "class"; className does
99 not match the content of "class"
100 @param archive Valid BMessage pointer with string field "class"
101 @param className Valid C-string which does not match archive field
102 "class"
103 @results Returns false.
104 errno is set to B_MISMATCHED_VALUES.
105 */
ClassFieldBogus()106 void TValidateInstantiationTest::ClassFieldBogus()
107 {
108 errno = B_OK;
109 BMessage Archive;
110 Archive.AddString("class", gClassName);
111 CPPUNIT_ASSERT(!validate_instantiation(&Archive, gBogusClassName));
112 CPPUNIT_ASSERT(errno == B_MISMATCHED_VALUES);
113 }
114 //------------------------------------------------------------------------------
115 /**
116 validate_instantiation(BMessage* archive, const char* className)
117 @case All parameters valid
118 @param archive Valid BMessage pointer with string field "class"
119 containing a class name
120 @param className Valid C-string which matches contents of archive field
121 "class"
122 @results Returns true.
123 errno is set to B_OK.
124 */
AllValid()125 void TValidateInstantiationTest::AllValid()
126 {
127 errno = B_OK;
128 BMessage Archive;
129 Archive.AddString("class", gClassName);
130 CPPUNIT_ASSERT(validate_instantiation(&Archive, gClassName));
131 CPPUNIT_ASSERT(errno == B_OK);
132 }
133 //------------------------------------------------------------------------------
Suite()134 CppUnit::Test* TValidateInstantiationTest::Suite()
135 {
136 CppUnit::TestSuite* SuiteOfTests = new CppUnit::TestSuite;
137 #if !defined(TEST_R5)
138 ADD_TEST(SuiteOfTests, TValidateInstantiationTest, AllParamsInvalid);
139 #endif
140 ADD_TEST(SuiteOfTests, TValidateInstantiationTest, ClassNameParamInvalid);
141 #if !defined(TEST_R5)
142 ADD_TEST(SuiteOfTests, TValidateInstantiationTest, ArchiveParamInvalid);
143 #endif
144 ADD_TEST(SuiteOfTests, TValidateInstantiationTest, ClassFieldEmpty);
145 ADD_TEST(SuiteOfTests, TValidateInstantiationTest, ClassFieldBogus);
146 ADD_TEST(SuiteOfTests, TValidateInstantiationTest, AllValid);
147
148 return SuiteOfTests;
149 }
150 //------------------------------------------------------------------------------
151
152 /*
153 * $Log $
154 *
155 * $Id $
156 *
157 */
158
159
160
161