1 """
2 This module implements the unit tests for
3 write of the atomic data types.
4 """
5
6 import random
7 import unittest
8 import StringIO
9 import HTMLTestRunner
10 import traceback
11 import sys
12
13 from unittest_helper import *
14 from tuple_processor import *
15 import cStringIO
16
18 - def generic_test_write_data(self, is_array_type, random_fnc, elm_size, elm_type, pack_fnc,
19 write_fnc, method_name):
20 """
21 Tests whether random data types are successfully written by atomic_data_processor
22 @type is_array_type: number
23 @param is_array_type: whether data type is non-array, 1d array or 2d array
24 @type random_fnc: function
25 @param random_fnc: random function that creates a random atomic data
26 @type elm_size: number
27 @param elm_size: Size of the atomic type (e.g. char is 1)
28 @type elm_type: number
29 @param elm_type: oid of the data type
30 @type pack_fnc: function
31 @param pack_fnc: pack function that converts atomic data to the binary representation
32 @type write_fnc: function
33 @param write_fnc: function in the atomic_data_processor to write the atomic data
34 @type method_name: string
35 @param method_name: the name of the method who calls this generic method
36 """
37 for i in range(test_num):
38 b = cStringIO.StringIO()
39 comp_b = cStringIO.StringIO()
40
41 rand_data = create_rand_data(is_array_type, random_fnc)
42
43 write_rand_data(is_array_type, comp_b, rand_data, elm_size, elm_type, pack_fnc)
44
45 write_fnc(b, rand_data)
46 self.assertEqual(b.getvalue(), comp_b.getvalue(), method_name + ' fails')
47
48
50 """
51 Tests whether random chars are successfully written by atomic_data_processor
52 """
53 self.generic_test_write_data(type_non_array, create_random_char, oid_dict[charoid][data_size_field],
54 charoid, struct_char.pack, Atomic_Data_Processor().write_char, 'write_char')
55
56
58 """
59 Tests whether random bools are successfully written by atomic_data_processor
60 """
61 self.generic_test_write_data(type_non_array, create_random_bool, oid_dict[booloid][data_size_field],
62 booloid, struct_bool.pack, Atomic_Data_Processor().write_bool, 'write_bool')
63
64
66 """
67 Tests whether random int2s are successfully written by atomic_data_processor
68 """
69 self.generic_test_write_data(type_non_array, create_random_int2, oid_dict[int2oid][data_size_field],
70 int2oid, struct_int2.pack, Atomic_Data_Processor().write_int2, 'write_int2')
71
72
79
80
82 """
83 Tests whether random int8s are successfully written by atomic_data_processor
84 """
85 self.generic_test_write_data(type_non_array, create_random_int8, oid_dict[int8oid][data_size_field],
86 int8oid, struct_int8.pack, Atomic_Data_Processor().write_int8, 'write_int8')
87
88
89
91 """
92 Tests whether random float4s are successfully written by atomic_data_processor
93 """
94 self.generic_test_write_data(type_non_array, create_random_float4, oid_dict[float4oid][data_size_field],
95 float4oid, struct_float4.pack, Atomic_Data_Processor().write_float4, 'write_float4')
96
97
99 """
100 Tests whether random float8s are successfully written by atomic_data_processor
101 """
102 self.generic_test_write_data(type_non_array, create_random_float8, oid_dict[float8oid][data_size_field],
103 float8oid, struct_float8.pack, Atomic_Data_Processor().write_float8, 'write_float8')
104
105
106
108 """
109 Tests whether random char arrays are successfully written by atomic_data_processor
110 """
111 self.generic_test_write_data(type_1d_array, create_random_char, oid_dict[charoid][data_size_field],
112 charoid, struct_char.pack, Atomic_Data_Processor().write_char_array, 'write_char_array')
113
114
116 """
117 Tests whether random bool arrays are successfully written by atomic_data_processor
118 """
119 self.generic_test_write_data(type_1d_array, create_random_bool, oid_dict[booloid][data_size_field],
120 booloid, struct_bool.pack, Atomic_Data_Processor().write_bool_array, 'write_bool_array')
121
122
124 """
125 Tests whether random int2 arrays are successfully written by atomic_data_processor
126 """
127 self.generic_test_write_data(type_1d_array, create_random_int2, oid_dict[int2oid][data_size_field],
128 int2oid, struct_int2.pack, Atomic_Data_Processor().write_int2_array, 'write_int2_array')
129
130
137
138
140 """
141 Tests whether random int8 arrays are successfully written by atomic_data_processor
142 """
143 self.generic_test_write_data(type_1d_array, create_random_int8, oid_dict[int8oid][data_size_field],
144 int8oid, struct_int8.pack, Atomic_Data_Processor().write_int8_array, 'write_int8_array')
145
146
148 """
149 Tests whether random float4 arrays are successfully written by atomic_data_processor
150 """
151 self.generic_test_write_data(type_1d_array, create_random_float4, oid_dict[float4oid][data_size_field],
152 float4oid, struct_float4.pack, Atomic_Data_Processor().write_float4_array,
153 'write_float4_array')
154
155
157 """
158 Tests whether random float8 arrays are successfully written by atomic_data_processor
159 """
160 self.generic_test_write_data(type_1d_array, create_random_float8, oid_dict[float8oid][data_size_field],
161 float8oid, struct_float8.pack, Atomic_Data_Processor().write_float8_array,
162 'write_float8_array')
163
164
166 """
167 Tests whether random float8 2d arrays are successfully written by atomic_data_processor
168 """
169 self.generic_test_write_data(type_2d_array, create_random_float8, oid_dict[float8oid][data_size_field],
170 float8oid, struct_float8.pack, Atomic_Data_Processor().write_float8_2d_array,
171 'write_float8_2d_array')
172