summaryrefslogtreecommitdiff
path: root/src/tests/eina/eina_test_value.c
diff options
context:
space:
mode:
authorValerii Kanunik <v.kanunik@samsung.com>2013-03-25 12:55:42 +0900
committerCedric BAIL <cedric.bail@samsung.com>2013-03-25 13:00:00 +0900
commit940543d972d77cb30aad2594a50a06fc68f52c8c (patch)
tree26ad71ad8f557753b63be352b914b9d4d1b5b05a /src/tests/eina/eina_test_value.c
parent1737dab7ec9d4f66c4c1fa221d128f78041b1175 (diff)
eina: improve Eina_Value coverage.
Added test 1: eina_value_test_convert_long. Added test 2: eina_value_test_convert_ulong. Signed-off-by: Cedric BAIL <cedric.bail@samsung.com>
Diffstat (limited to 'src/tests/eina/eina_test_value.c')
-rw-r--r--src/tests/eina/eina_test_value.c281
1 files changed, 281 insertions, 0 deletions
diff --git a/src/tests/eina/eina_test_value.c b/src/tests/eina/eina_test_value.c
index c64174933f..5262c75673 100644
--- a/src/tests/eina/eina_test_value.c
+++ b/src/tests/eina/eina_test_value.c
@@ -1043,6 +1043,285 @@ START_TEST(eina_value_test_convert_uchar)
1043} 1043}
1044END_TEST 1044END_TEST
1045 1045
1046START_TEST(eina_value_test_convert_long)
1047{
1048 Eina_Value *value, conv;
1049 char c;
1050 short s;
1051 int i;
1052 long l;
1053 int64_t i64;
1054 unsigned char uc;
1055 unsigned short us;
1056 unsigned int ui;
1057 unsigned long ul;
1058 uint64_t u64;
1059 float f;
1060 double d;
1061 const char *str;
1062
1063 eina_init();
1064
1065 value = eina_value_new(EINA_VALUE_TYPE_LONG);
1066 fail_unless(value != NULL);
1067
1068 fail_unless(eina_value_set(value, 32l));
1069
1070 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1071 fail_unless(eina_value_convert(value, &conv));
1072 fail_unless(eina_value_get(&conv, &uc));
1073 fail_unless(uc == 32);
1074 eina_value_flush(&conv);
1075
1076 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1077 fail_unless(eina_value_convert(value, &conv));
1078 fail_unless(eina_value_get(&conv, &us));
1079 fail_unless(us == 32);
1080 eina_value_flush(&conv);
1081
1082 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
1083 fail_unless(eina_value_convert(value, &conv));
1084 fail_unless(eina_value_get(&conv, &ui));
1085 fail_unless(ui == 32);
1086 eina_value_flush(&conv);
1087
1088 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
1089 fail_unless(eina_value_convert(value, &conv));
1090 fail_unless(eina_value_get(&conv, &ul));
1091 fail_unless(ul == 32ul);
1092 eina_value_flush(&conv);
1093
1094 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
1095 fail_unless(eina_value_convert(value, &conv));
1096 fail_unless(eina_value_get(&conv, &u64));
1097 fail_unless(u64 == 32ull);
1098 eina_value_flush(&conv);
1099
1100 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1101 fail_unless(eina_value_convert(value, &conv));
1102 fail_unless(eina_value_get(&conv, &c));
1103 fail_unless(c == 32);
1104 eina_value_flush(&conv);
1105
1106 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
1107 fail_unless(eina_value_convert(value, &conv));
1108 fail_unless(eina_value_get(&conv, &s));
1109 fail_unless(s == 32);
1110 eina_value_flush(&conv);
1111
1112 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
1113 fail_unless(eina_value_convert(value, &conv));
1114 fail_unless(eina_value_get(&conv, &i));
1115 fail_unless(i == 32);
1116 eina_value_flush(&conv);
1117
1118 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
1119 fail_unless(eina_value_convert(value, &conv));
1120 fail_unless(eina_value_get(&conv, &l));
1121 fail_unless(l == 32l);
1122 eina_value_flush(&conv);
1123
1124 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
1125 fail_unless(eina_value_convert(value, &conv));
1126 fail_unless(eina_value_get(&conv, &i64));
1127 fail_unless(i64 == 32ll);
1128 eina_value_flush(&conv);
1129
1130 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1131 fail_unless(eina_value_convert(value, &conv));
1132 fail_unless(eina_value_get(&conv, &f));
1133 fail_unless(CHECK_FP(f, 32));
1134 eina_value_flush(&conv);
1135
1136 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1137 fail_unless(eina_value_convert(value, &conv));
1138 fail_unless(eina_value_get(&conv, &d));
1139 fail_unless(CHECK_FP(d, 32));
1140 eina_value_flush(&conv);
1141
1142 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
1143 fail_unless(eina_value_convert(value, &conv));
1144 fail_unless(eina_value_get(&conv, &str));
1145 fail_unless(str != NULL);
1146 ck_assert_str_eq(str, "32");
1147 eina_value_flush(&conv);
1148
1149 /* negative tests */
1150 fail_unless(eina_value_set(value, 128l));
1151 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1152 fail_if(eina_value_convert(value, &conv));
1153 eina_value_flush(&conv);
1154
1155 fail_unless(eina_value_set(value, 256l));
1156 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1157 fail_if(eina_value_convert(value, &conv));
1158 eina_value_flush(&conv);
1159
1160 fail_unless(eina_value_set(value, 32768l));
1161 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
1162 fail_if(eina_value_convert(value, &conv));
1163 eina_value_flush(&conv);
1164
1165 fail_unless(eina_value_set(value, 65536l));
1166 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1167 fail_if(eina_value_convert(value, &conv));
1168 eina_value_flush(&conv);
1169
1170 fail_unless(eina_value_set(value, -32l));
1171
1172 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1173 fail_if(eina_value_convert(value, &conv));
1174 eina_value_flush(&conv);
1175
1176 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1177 fail_if(eina_value_convert(value, &conv));
1178 eina_value_flush(&conv);
1179
1180 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
1181 fail_if(eina_value_convert(value, &conv));
1182 eina_value_flush(&conv);
1183
1184 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
1185 fail_if(eina_value_convert(value, &conv));
1186 eina_value_flush(&conv);
1187
1188 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
1189 fail_if(eina_value_convert(value, &conv));
1190 eina_value_flush(&conv);
1191
1192 eina_value_free(value);
1193 eina_shutdown();
1194}
1195END_TEST
1196
1197START_TEST(eina_value_test_convert_ulong)
1198{
1199 Eina_Value *value, conv;
1200 char c;
1201 short s;
1202 int i;
1203 long l;
1204 int64_t i64;
1205 unsigned char uc;
1206 unsigned short us;
1207 unsigned int ui;
1208 unsigned long ul;
1209 uint64_t u64;
1210 float f;
1211 double d;
1212 const char *str;
1213
1214 eina_init();
1215
1216 value = eina_value_new(EINA_VALUE_TYPE_ULONG);
1217 fail_unless(value != NULL);
1218
1219 fail_unless(eina_value_set(value, 42ul));
1220
1221 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1222 fail_unless(eina_value_convert(value, &conv));
1223 fail_unless(eina_value_get(&conv, &uc));
1224 fail_unless(uc == 42);
1225 eina_value_flush(&conv);
1226
1227 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1228 fail_unless(eina_value_convert(value, &conv));
1229 fail_unless(eina_value_get(&conv, &us));
1230 fail_unless(us == 42);
1231 eina_value_flush(&conv);
1232
1233 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
1234 fail_unless(eina_value_convert(value, &conv));
1235 fail_unless(eina_value_get(&conv, &ui));
1236 fail_unless(ui == 42);
1237 eina_value_flush(&conv);
1238
1239 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
1240 fail_unless(eina_value_convert(value, &conv));
1241 fail_unless(eina_value_get(&conv, &ul));
1242 fail_unless(ul == 42ul);
1243 eina_value_flush(&conv);
1244
1245 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
1246 fail_unless(eina_value_convert(value, &conv));
1247 fail_unless(eina_value_get(&conv, &u64));
1248 fail_unless(u64 == 42ull);
1249 eina_value_flush(&conv);
1250
1251 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1252 fail_unless(eina_value_convert(value, &conv));
1253 fail_unless(eina_value_get(&conv, &c));
1254 fail_unless(c == 42);
1255 eina_value_flush(&conv);
1256
1257 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
1258 fail_unless(eina_value_convert(value, &conv));
1259 fail_unless(eina_value_get(&conv, &s));
1260 fail_unless(s == 42);
1261 eina_value_flush(&conv);
1262
1263 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
1264 fail_unless(eina_value_convert(value, &conv));
1265 fail_unless(eina_value_get(&conv, &i));
1266 fail_unless(i == 42);
1267 eina_value_flush(&conv);
1268
1269 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
1270 fail_unless(eina_value_convert(value, &conv));
1271 fail_unless(eina_value_get(&conv, &l));
1272 fail_unless(l == 42l);
1273 eina_value_flush(&conv);
1274
1275 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
1276 fail_unless(eina_value_convert(value, &conv));
1277 fail_unless(eina_value_get(&conv, &i64));
1278 fail_unless(i64 == 42ll);
1279 eina_value_flush(&conv);
1280
1281 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1282 fail_unless(eina_value_convert(value, &conv));
1283 fail_unless(eina_value_get(&conv, &f));
1284 fail_unless(CHECK_FP(f, 42));
1285 eina_value_flush(&conv);
1286
1287 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1288 fail_unless(eina_value_convert(value, &conv));
1289 fail_unless(eina_value_get(&conv, &d));
1290 fail_unless(CHECK_FP(d, 42));
1291 eina_value_flush(&conv);
1292
1293 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
1294 fail_unless(eina_value_convert(value, &conv));
1295 fail_unless(eina_value_get(&conv, &str));
1296 fail_unless(str != NULL);
1297 ck_assert_str_eq(str, "42");
1298 eina_value_flush(&conv);
1299
1300 /* negative tests */
1301 fail_unless(eina_value_set(value, 128ul));
1302 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1303 fail_if(eina_value_convert(value, &conv));
1304 eina_value_flush(&conv);
1305
1306 fail_unless(eina_value_set(value, 256ul));
1307 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1308 fail_if(eina_value_convert(value, &conv));
1309 eina_value_flush(&conv);
1310
1311 fail_unless(eina_value_set(value, 32768ul));
1312 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
1313 fail_if(eina_value_convert(value, &conv));
1314 eina_value_flush(&conv);
1315
1316 fail_unless(eina_value_set(value, 65536ul));
1317 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1318 fail_if(eina_value_convert(value, &conv));
1319 eina_value_flush(&conv);
1320
1321 eina_value_free(value);
1322 eina_shutdown();
1323}
1324END_TEST
1046 1325
1047START_TEST(eina_value_test_array) 1326START_TEST(eina_value_test_array)
1048{ 1327{
@@ -1873,6 +2152,8 @@ eina_test_value(TCase *tc)
1873 tcase_add_test(tc, eina_value_test_to_string); 2152 tcase_add_test(tc, eina_value_test_to_string);
1874 tcase_add_test(tc, eina_value_test_convert_char); 2153 tcase_add_test(tc, eina_value_test_convert_char);
1875 tcase_add_test(tc, eina_value_test_convert_uchar); 2154 tcase_add_test(tc, eina_value_test_convert_uchar);
2155 tcase_add_test(tc, eina_value_test_convert_long);
2156 tcase_add_test(tc, eina_value_test_convert_ulong);
1876 // TODO: other converters... 2157 // TODO: other converters...
1877 tcase_add_test(tc, eina_value_test_array); 2158 tcase_add_test(tc, eina_value_test_array);
1878 tcase_add_test(tc, eina_value_test_list); 2159 tcase_add_test(tc, eina_value_test_list);