1 //------------------------------------------------------------------------------
2 // BArchivableTester.cpp
3 //
4 /**
5 BArchivable tests
6 @note InvalidArchiveShallow() and InvalidArchiveDeep() are not tested
7 against the original implementation as it does not handle NULL
8 parameters gracefully.
9 */
10 //------------------------------------------------------------------------------
11
12 // Standard Includes -----------------------------------------------------------
13
14 // System Includes -------------------------------------------------------------
15 #include <Message.h>
16
17 // Project Includes ------------------------------------------------------------
18
19 // Local Includes --------------------------------------------------------------
20 #include "BArchivableTester.h"
21
22 // Local Defines ---------------------------------------------------------------
23
24 // Globals ---------------------------------------------------------------------
25
26 //------------------------------------------------------------------------------
27 /**
28 BArchivable::Perform(perform_code d, void* arg)
29 @case Any
30 @param d Not used
31 @param arg Not used
32 @results Returns B_ERROR in all cases.
33 */
TestPerform()34 void TBArchivableTestCase::TestPerform()
35 {
36 BArchivable Archive;
37 CPPUNIT_ASSERT(Archive.Perform(0, NULL) == B_ERROR);
38 }
39 //------------------------------------------------------------------------------
40 /**
41 BArchivable::Archive(BMessage* into, bool deep)
42 @case Invalid archive, shallow archiving
43 @param into NULL
44 @param deep false
45 @results Returns B_BAD_VALUE.
46 */
InvalidArchiveShallow()47 void TBArchivableTestCase::InvalidArchiveShallow()
48 {
49 BArchivable Archive;
50 CPPUNIT_ASSERT(Archive.Archive(NULL, false) == B_BAD_VALUE);
51 }
52 //------------------------------------------------------------------------------
53 /**
54 BArchivable::Archive(BMessage* into, bool deep)
55 @case Valid archive, shallow archiving
56 @param into Valid BMessage pointer
57 @param deep false
58 @results Returns B_OK.
59 Resultant archive has a string field labeled "class".
60 Field "class" contains the string "BArchivable".
61 */
62 #include <stdio.h>
63 #include <Debug.h>
ValidArchiveShallow()64 void TBArchivableTestCase::ValidArchiveShallow()
65 {
66 BMessage Storage;
67 BArchivable Archive;
68 CPPUNIT_ASSERT(Archive.Archive(&Storage, false) == B_OK);
69 const char* name;
70 CPPUNIT_ASSERT(Storage.FindString("class", &name) == B_OK);
71 printf("\n%s\n", name);
72 CPPUNIT_ASSERT(strcmp(name, "BArchivable") == 0);
73 }
74 //------------------------------------------------------------------------------
75 /**
76 BArchivable::Archive(BMessage* into, bool deep)
77 @case Invalid archive, deep archiving
78 @param into NULL
79 @param deep true
80 @results Returns B_BAD_VALUE
81 */
InvalidArchiveDeep()82 void TBArchivableTestCase::InvalidArchiveDeep()
83 {
84 BArchivable Archive;
85 CPPUNIT_ASSERT(Archive.Archive(NULL, true) == B_BAD_VALUE);
86 }
87 //------------------------------------------------------------------------------
88 /**
89 BArchivable::Archive(BMessage* into, bool deep)
90 @case Valid archive, deep archiving
91 @param into Valid BMessage pointer
92 @param deep true
93 @results Returns B_OK.
94 Resultant archive has a string field labeled "class".
95 Field "class" contains the string "BArchivable".
96 */
ValidArchiveDeep()97 void TBArchivableTestCase::ValidArchiveDeep()
98 {
99 BMessage Storage;
100 BArchivable Archive;
101 CPPUNIT_ASSERT(Archive.Archive(&Storage, true) == B_OK);
102 const char* name;
103 CPPUNIT_ASSERT(Storage.FindString("class", &name) == B_OK);
104 CPPUNIT_ASSERT(strcmp(name, "BArchivable") == 0);
105 }
106 //------------------------------------------------------------------------------
Suite()107 CppUnit::Test* TBArchivableTestCase::Suite()
108 {
109 CppUnit::TestSuite* SuiteOfTests = new CppUnit::TestSuite;
110 ADD_TEST(SuiteOfTests, TBArchivableTestCase, TestPerform);
111 #if !defined(TEST_R5)
112 ADD_TEST(SuiteOfTests, TBArchivableTestCase, InvalidArchiveShallow);
113 #endif
114 ADD_TEST(SuiteOfTests, TBArchivableTestCase, ValidArchiveShallow);
115 #if !defined(TEST_R5)
116 ADD_TEST(SuiteOfTests, TBArchivableTestCase, InvalidArchiveDeep);
117 #endif
118 ADD_TEST(SuiteOfTests, TBArchivableTestCase, ValidArchiveDeep);
119
120 return SuiteOfTests;
121 }
122 //------------------------------------------------------------------------------
123
124
125 /*
126 * $Log $
127 *
128 * $Id $
129 *
130 */
131
132
133
134