vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / bmessage / MessageInt32ItemTest.cpp
blob98f116ec03f6c3884e7da3cf6451f77c84c5d5b9
1 //------------------------------------------------------------------------------
2 // MessageInt32ItemTest.cpp
3 //
4 //------------------------------------------------------------------------------
6 // Standard Includes -----------------------------------------------------------
7 #include <stdio.h>
8 #include <posix/string.h>
10 // System Includes -------------------------------------------------------------
11 #include <Message.h>
13 // Project Includes ------------------------------------------------------------
15 // Local Includes --------------------------------------------------------------
16 #include "MessageInt32ItemTest.h"
18 // Local Defines ---------------------------------------------------------------
20 // Globals ---------------------------------------------------------------------
22 #ifndef USE_TEMPLATES
23 //------------------------------------------------------------------------------
24 void TMessageInt32ItemTest::MessageInt32ItemTest1()
26 BMessage msg;
27 int32 out = 0;
28 CPPUNIT_ASSERT(msg.FindInt32("an int32", &out) == B_NAME_NOT_FOUND);
29 CPPUNIT_ASSERT(out == 0);
30 CPPUNIT_ASSERT(msg.FindInt32("an int32") == 0);
31 CPPUNIT_ASSERT(!msg.HasInt32("an int32"));
32 const void* ptr = &out;
33 ssize_t size;
34 CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, &ptr, &size) ==
35 B_NAME_NOT_FOUND);
36 CPPUNIT_ASSERT(ptr == NULL);
38 //------------------------------------------------------------------------------
39 void TMessageInt32ItemTest::MessageInt32ItemTest2()
41 BMessage msg;
42 int32 in = 1234;
43 int32 out = 0;
44 CPPUNIT_ASSERT(msg.AddInt32("an int32", in) == B_OK);
45 CPPUNIT_ASSERT(msg.HasInt32("an int32"));
46 CPPUNIT_ASSERT(msg.FindInt32("an int32") == in);
47 CPPUNIT_ASSERT(msg.FindInt32("an int32", &out) == B_OK);
48 CPPUNIT_ASSERT(out == in);
49 int32* pout;
50 ssize_t size;
51 CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, (const void**)&pout,
52 &size) == B_OK);
53 CPPUNIT_ASSERT(*pout == in);
54 CPPUNIT_ASSERT(size == sizeof (int32));
56 //------------------------------------------------------------------------------
57 void TMessageInt32ItemTest::MessageInt32ItemTest3()
59 BMessage msg;
60 int32 in = 1234;
61 int32 in2 = 7890;
62 int32 out = 0;
63 CPPUNIT_ASSERT(msg.AddInt32("an int32", in) == B_OK);
64 CPPUNIT_ASSERT(msg.ReplaceInt32("an int32", in2) == B_OK);
65 CPPUNIT_ASSERT(msg.HasInt32("an int32"));
66 CPPUNIT_ASSERT(msg.FindInt32("an int32") == in2);
67 CPPUNIT_ASSERT(msg.FindInt32("an int32", &out) == B_OK);
68 CPPUNIT_ASSERT(out == in2);
69 out = 0;
70 int32* pout;
71 ssize_t size;
72 CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, (const void**)&pout,
73 &size) == B_OK);
74 CPPUNIT_ASSERT(*pout == in2);
75 CPPUNIT_ASSERT(size == sizeof (int32));
77 //------------------------------------------------------------------------------
78 void TMessageInt32ItemTest::MessageInt32ItemTest4()
80 BMessage msg;
81 int32 out = 0;
82 CPPUNIT_ASSERT(msg.FindInt32("an int32", 1, &out) == B_NAME_NOT_FOUND);
83 CPPUNIT_ASSERT(out == 0);
84 CPPUNIT_ASSERT(msg.FindInt32("an int32", 1) == 0);
85 CPPUNIT_ASSERT(!msg.HasInt32("an int32", 1));
86 const void* ptr = &out;
87 ssize_t size;
88 CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, 1, &ptr, &size) ==
89 B_NAME_NOT_FOUND);
90 CPPUNIT_ASSERT(ptr == NULL);
92 //------------------------------------------------------------------------------
93 void TMessageInt32ItemTest::MessageInt32ItemTest5()
95 BMessage msg;
96 int32 in[] = { 123, 456, 789 };
97 int32 out = 0;
98 int32* pout;
99 ssize_t size;
101 for (int32 i = 0; i < sizeof (in) / sizeof (int32); ++i)
103 CPPUNIT_ASSERT(msg.AddInt32("an int32", in[i]) == B_OK);
106 for (int32 i = 0; i < sizeof (in) / sizeof (int32); ++i)
108 CPPUNIT_ASSERT(msg.HasInt32("an int32", i));
109 CPPUNIT_ASSERT(msg.FindInt32("an int32", i) == in[i]);
110 CPPUNIT_ASSERT(msg.FindInt32("an int32", i, &out) == B_OK);
111 CPPUNIT_ASSERT(out == in[i]);
112 CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, i,
113 (const void**)&pout, &size) == B_OK);
114 CPPUNIT_ASSERT(*pout == in[i]);
115 CPPUNIT_ASSERT(size == sizeof (int32));
118 //------------------------------------------------------------------------------
119 void TMessageInt32ItemTest::MessageInt32ItemTest6()
121 BMessage msg;
122 int32 in[] = { 123, 456, 789 };
123 int32 in2 = 654;
124 int32 out = 0;
125 const int rIndex = 2;
127 for (int32 i = 0; i < sizeof (in) / sizeof (int32); ++i)
129 CPPUNIT_ASSERT(msg.AddInt32("an int32", in[i]) == B_OK);
132 CPPUNIT_ASSERT(msg.ReplaceInt32("an int32", rIndex, in2) == B_OK);
133 CPPUNIT_ASSERT(msg.HasInt32("an int32", rIndex));
134 CPPUNIT_ASSERT(msg.FindInt32("an int32", rIndex) == in2);
135 CPPUNIT_ASSERT(msg.FindInt32("an int32", rIndex, &out) == B_OK);
136 CPPUNIT_ASSERT(out == in2);
137 out = 0;
138 int32* pout;
139 ssize_t size;
140 CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, rIndex,
141 (const void**)&pout, &size) == B_OK);
142 CPPUNIT_ASSERT(*pout == in2);
143 CPPUNIT_ASSERT(size == sizeof (int32));
145 //------------------------------------------------------------------------------
146 void TMessageInt32ItemTest::MessageInt32ItemTest7()
148 BMessage msg;
149 int32 in = 1234;
150 int32 out = 0;
151 CPPUNIT_ASSERT(msg.AddData("an int32", B_INT32_TYPE, (const void*)&in,
152 sizeof (int32)) == B_OK);
153 CPPUNIT_ASSERT(msg.HasInt32("an int32"));
154 CPPUNIT_ASSERT(msg.FindInt32("an int32") == in);
155 CPPUNIT_ASSERT(msg.FindInt32("an int32", &out) == B_OK);
156 CPPUNIT_ASSERT(out == in);
157 int32* pout;
158 ssize_t size;
159 CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, (const void**)&pout,
160 &size) == B_OK);
161 CPPUNIT_ASSERT(*pout == in);
162 CPPUNIT_ASSERT(size == sizeof (int32));
164 //------------------------------------------------------------------------------
165 void TMessageInt32ItemTest::MessageInt32ItemTest8()
167 BMessage msg;
168 int32 in[] = { 123, 456, 789 };
169 int32 out = 0;
170 int32* pout;
171 ssize_t size;
173 for (int32 i = 0; i < sizeof (in) / sizeof (int32); ++i)
175 CPPUNIT_ASSERT(msg.AddData("an int32", B_INT32_TYPE,
176 (const void*)&in[i], sizeof (int32)) == B_OK);
179 for (int32 i = 0; i < sizeof (in) / sizeof (int32); ++i)
181 CPPUNIT_ASSERT(msg.HasInt32("an int32", i));
182 CPPUNIT_ASSERT(msg.FindInt32("an int32", i) == in[i]);
183 CPPUNIT_ASSERT(msg.FindInt32("an int32", i, &out) == B_OK);
184 CPPUNIT_ASSERT(out == in[i]);
185 CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, i,
186 (const void**)&pout, &size) == B_OK);
187 CPPUNIT_ASSERT(*pout == in[i]);
188 CPPUNIT_ASSERT(size == sizeof (int32));
191 //------------------------------------------------------------------------------
192 TestSuite* TMessageInt32ItemTest::Suite()
194 TestSuite* suite = new TestSuite("BMessage::Add/Find/Replace/HasRect()");
196 ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest1);
197 ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest2);
198 ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest3);
199 ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest4);
200 ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest5);
201 ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest6);
202 ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest7);
203 ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest8);
205 return suite;
207 //------------------------------------------------------------------------------
208 #endif
211 * $Log $
213 * $Id $