1 """
2 This module implements the unit tests for
3 read 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_read_data(self, is_array_type, random_fnc, elm_size, elm_type, pack_fnc,
19 read_fnc, method_name):
20 """
21 Tests whether random data types are successfully read 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 read_fnc: function
33 @param read_fnc: function in the atomic_data_processor to read 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
40 rand_data = create_rand_data(is_array_type, random_fnc)
41
42 write_rand_data(is_array_type, b, rand_data, elm_size, elm_type, pack_fnc)
43
44
45 victor_buf = VictorBuffer(b.getvalue())
46
47 ret_data = read_fnc(victor_buf)
48
49 compare_data(is_array_type, self, rand_data, ret_data, method_name, exact_equal)
50
51
53 """
54 Tests whether random chars are successfully read by atomic_data_processor
55 """
56 self.generic_test_read_data(type_non_array, create_random_char, oid_dict[charoid][data_size_field],
57 charoid, struct_char.pack, Atomic_Data_Processor().read_char, 'read_char')
58
60 """
61 Tests whether random bools are successfully read by atomic_data_processor
62 """
63 self.generic_test_read_data(type_non_array, create_random_bool, oid_dict[booloid][data_size_field],
64 booloid, struct_bool.pack, Atomic_Data_Processor().read_bool, 'read_bool')
65
67 """
68 Tests whether random int2s are successfully read by atomic_data_processor
69 """
70 self.generic_test_read_data(type_non_array, create_random_int2, oid_dict[int2oid][data_size_field],
71 int2oid, struct_int2.pack, Atomic_Data_Processor().read_int2, 'read_int2')
72
73
80
81
83 """
84 Tests whether random int8s are successfully read by atomic_data_processor
85 """
86 self.generic_test_read_data(type_non_array, create_random_int8, oid_dict[int8oid][data_size_field],
87 int8oid, struct_int8.pack, Atomic_Data_Processor().read_int8, 'read_int8')
88
89
91 """
92 Tests whether random float4s are successfully read by atomic_data_processor
93 """
94 self.generic_test_read_data(type_non_array, create_random_float4, oid_dict[float4oid][data_size_field],
95 float4oid, struct_float4.pack, Atomic_Data_Processor().read_float4, 'read_float4')
96
97
99 """
100 Tests whether random float8s are successfully read by atomic_data_processor
101 """
102 self.generic_test_read_data(type_non_array, create_random_float8, oid_dict[float8oid][data_size_field],
103 float8oid, struct_float8.pack, Atomic_Data_Processor().read_float8, 'read_float8')
104
105
107 """
108 Tests whether random char arrays are successfully read by atomic_data_processor
109 """
110 self.generic_test_read_data(type_1d_array, create_random_char, oid_dict[charoid][data_size_field],
111 charoid, struct_char.pack, Atomic_Data_Processor().read_char_array, 'read_char_array')
112
113
115 """
116 Tests whether random bool arrays are successfully read by atomic_data_processor
117 """
118 self.generic_test_read_data(type_1d_array, create_random_bool, oid_dict[booloid][data_size_field],
119 booloid, struct_bool.pack, Atomic_Data_Processor().read_bool_array, 'read_bool_array')
120
121
123 """
124 Tests whether random int2 arrays are successfully read by atomic_data_processor
125 """
126 self.generic_test_read_data(type_1d_array, create_random_int2, oid_dict[int2oid][data_size_field],
127 int2oid, struct_int2.pack, Atomic_Data_Processor().read_int2_array, 'read_int2_array')
128
129
136
137
139 """
140 Tests whether random int8 arrays are successfully read by atomic_data_processor
141 """
142 self.generic_test_read_data(type_1d_array, create_random_int8, oid_dict[int8oid][data_size_field],
143 int8oid, struct_int8.pack, Atomic_Data_Processor().read_int8_array, 'read_int8_array')
144
145
147 """
148 Tests whether random float4 arrays are successfully read by atomic_data_processor
149 """
150 self.generic_test_read_data(type_1d_array, create_random_float4, oid_dict[float4oid][data_size_field],
151 float4oid, struct_float4.pack, Atomic_Data_Processor().read_float4_array, 'read_float4_array')
152
153
155 """
156 Tests whether random float8 arrays are successfully read by atomic_data_processor
157 """
158 self.generic_test_read_data(type_1d_array, create_random_float8, oid_dict[float8oid][data_size_field],
159 float8oid, struct_float8.pack, Atomic_Data_Processor().read_float8_array, 'read_float8_array')
160
162 """
163 Tests whether random float8 2d arrays are successfully read by atomic_data_processor
164 """
165 self.generic_test_read_data(type_2d_array, create_random_float8, oid_dict[float8oid][data_size_field],
166 float8oid, struct_float8.pack, Atomic_Data_Processor().read_float8_2d_array,
167 'read_float8_2d_array')
168