vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / bpropertyinfo / PropertyFlattenTest.cpp
blobb64d914938d4ef6319fb2b6f1788da579a2ac7dc
1 /*
2 $Id: PropertyFlattenTest.cpp 1218 2002-09-28 00:19:49Z shatty $
4 This file implements the flatten test for the OpenBeOS BPropertyInfo code.
5 This class tests the following usecases:
6 - Fixed Size
7 - Type Code
8 - Allows Type Code
9 - Flattened Size
10 - Flatten
15 #include "PropertyFlattenTest.h"
17 #include <assert.h>
19 #include <ByteOrder.h>
23 * Method: PropertyFlattenTest::PropertyFlattenTest()
24 * Descr: This is the constructor for this class.
25 */
27 PropertyFlattenTest::PropertyFlattenTest(std::string name) :
28 PropertyTestcase(name)
34 * Method: PropertyFlattenTest::~PropertyFlattenTest()
35 * Descr: This is the destructor for this class.
38 PropertyFlattenTest::~PropertyFlattenTest()
44 * Method: PropertyFlattenTest::TestProperty()
45 * Descr: This member function performs this test.
46 */
48 void PropertyFlattenTest::TestProperty(
49 BPropertyInfo *propTest,
50 const property_info *prop_list,
51 const value_info *value_list,
52 int32 prop_count,
53 int32 value_count,
54 ssize_t flat_size,
55 const char *lflat_data,
56 const char *bflat_data)
58 char buffer[768];
60 assert(!propTest->IsFixedSize());
61 assert(propTest->TypeCode() == B_PROPERTY_INFO_TYPE);
62 assert(propTest->AllowsTypeCode(B_PROPERTY_INFO_TYPE));
63 assert(!propTest->AllowsTypeCode(B_TIME_TYPE));
64 assert(propTest->FlattenedSize() == flat_size);
65 assert(propTest->Flatten(buffer, sizeof(buffer)/ sizeof(buffer[0])) == B_OK);
66 if (B_HOST_IS_BENDIAN) {
67 assert(memcmp(buffer, bflat_data, propTest->FlattenedSize()) == 0);
68 } else {
69 assert(memcmp(buffer, lflat_data, propTest->FlattenedSize()) == 0);
75 * Method: PropertyFlattenTest::suite()
76 * Descr: This static member function returns a test caller for performing
77 * all combinations of "PropertyFlattenTest".
80 Test *PropertyFlattenTest::suite(void)
82 typedef CppUnit::TestCaller<PropertyFlattenTest>
83 PropertyFlattenTestCaller;
85 return(new PropertyFlattenTestCaller("BPropertyInfo::Flatten Test", &PropertyFlattenTest::PerformTest));