1 """
2 This module implements the unit tests for
3 read and write together 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
20 """
21 Tests whether random data types are successfully read and 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 write_fnc: function
27 @param write_fnc: function in the atomic_data_processor to write the atomic data
28 @type read_fnc: function
29 @param read_fnc: function in the atomic_data_processor to read the atomic data
30 @type method_name: string
31 @param method_name: the name of the method who calls this generic method
32 """
33 for i in range(test_num):
34 b = cStringIO.StringIO()
35
36 rand_data = create_rand_data(is_array_type, random_fnc)
37 write_fnc(b, rand_data)
38 ret_data = read_fnc(VictorBuffer(b.getvalue()))
39
40 compare_data(is_array_type, self, rand_data, ret_data, method_name, exact_equal)
41
42
50
51
52
60
61
69
70
78
79
87
88
96
97
105
106
108 """
109 Tests whether random char arrays are successfully read and written by atomic_data_processor
110 """
111 self.generic_test_round_trip_data(type_1d_array, create_random_char,
112 Atomic_Data_Processor().write_char_array,
113 Atomic_Data_Processor().read_char_array, 'round_trip_char_array')
114
115
117 """
118 Tests whether random bool arrays are successfully read and written by atomic_data_processor
119 """
120 self.generic_test_round_trip_data(type_1d_array, create_random_bool,
121 Atomic_Data_Processor().write_bool_array,
122 Atomic_Data_Processor().read_bool_array, 'round_trip_bool_array')
123
124
126 """
127 Tests whether random int2 arrays are successfully read and written by atomic_data_processor
128 """
129 self.generic_test_round_trip_data(type_1d_array, create_random_int2,
130 Atomic_Data_Processor().write_int2_array,
131 Atomic_Data_Processor().read_int2_array, 'round_trip_int2_array')
132
133
135 """
136 Tests whether random int4 arrays are successfully read and written by atomic_data_processor
137 """
138 self.generic_test_round_trip_data(type_1d_array, create_random_int4,
139 Atomic_Data_Processor().write_int4_array,
140 Atomic_Data_Processor().read_int4_array, 'round_trip_int4_array')
141
142
144 """
145 Tests whether random int8 arrays are successfully read and written by atomic_data_processor
146 """
147 self.generic_test_round_trip_data(type_1d_array, create_random_int8,
148 Atomic_Data_Processor().write_int8_array,
149 Atomic_Data_Processor().read_int8_array, 'round_trip_int8_array')
150
151
153 """
154 Tests whether random float4 arrays are successfully read and written by atomic_data_processor
155 """
156 self.generic_test_round_trip_data(type_1d_array, create_random_float4,
157 Atomic_Data_Processor().write_float4_array,
158 Atomic_Data_Processor().read_float4_array, 'round_trip_float4_array')
159
160
162 """
163 Tests whether random float8 arrays are successfully read and written by atomic_data_processor
164 """
165 self.generic_test_round_trip_data(type_1d_array, create_random_float8,
166 Atomic_Data_Processor().write_float8_array,
167 Atomic_Data_Processor().read_float8_array, 'round_trip_float8_array')
168
169
171 """
172 Tests whether random float8 2d arrays are successfully read and written by atomic_data_processor
173 """
174 self.generic_test_round_trip_data(type_2d_array, create_random_float8,
175 Atomic_Data_Processor().write_float8_2d_array,
176 Atomic_Data_Processor().read_float8_2d_array, 'round_trip_float8_2d_array')
177