summaryrefslogtreecommitdiff
path: root/src/tests/eina/eina_test_value.c
diff options
context:
space:
mode:
authorVladislav Brovko <v.brovko@samsung.com>2013-07-17 15:20:08 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-07-18 16:19:26 +0900
commit56adc51e8333540f5b9a46437f177b407a29668f (patch)
tree088d1c4c45e239aa7b6c13bd5a6fee2b43416b77 /src/tests/eina/eina_test_value.c
parent14a32521c8e7d0120a7138c495739792cfcc989c (diff)
eina: add Eina_Value tests convert from short, int.
Diffstat (limited to 'src/tests/eina/eina_test_value.c')
-rw-r--r--src/tests/eina/eina_test_value.c458
1 files changed, 458 insertions, 0 deletions
diff --git a/src/tests/eina/eina_test_value.c b/src/tests/eina/eina_test_value.c
index 5262c75673..fc74e8bad7 100644
--- a/src/tests/eina/eina_test_value.c
+++ b/src/tests/eina/eina_test_value.c
@@ -1042,6 +1042,460 @@ START_TEST(eina_value_test_convert_uchar)
1042 eina_shutdown(); 1042 eina_shutdown();
1043} 1043}
1044END_TEST 1044END_TEST
1045
1046START_TEST(eina_value_test_convert_short)
1047{
1048 Eina_Value *value, conv;
1049 short s;
1050 int i;
1051 long l;
1052 int64_t i64;
1053 unsigned short us;
1054 unsigned int ui;
1055 unsigned long ul;
1056 uint64_t u64;
1057 float f;
1058 double d;
1059 const char *str;
1060
1061 eina_init();
1062
1063 value = eina_value_new(EINA_VALUE_TYPE_SHORT);
1064 fail_unless(value != NULL);
1065
1066 fail_unless(eina_value_set(value, 12345));
1067
1068 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1069 fail_unless(eina_value_convert(value, &conv));
1070 fail_unless(eina_value_get(&conv, &us));
1071 fail_unless(us == 12345);
1072 eina_value_flush(&conv);
1073
1074 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
1075 fail_unless(eina_value_convert(value, &conv));
1076 fail_unless(eina_value_get(&conv, &ui));
1077 fail_unless(ui == 12345);
1078 eina_value_flush(&conv);
1079
1080 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
1081 fail_unless(eina_value_convert(value, &conv));
1082 fail_unless(eina_value_get(&conv, &ul));
1083 fail_unless(ul == 12345);
1084 eina_value_flush(&conv);
1085
1086 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
1087 fail_unless(eina_value_convert(value, &conv));
1088 fail_unless(eina_value_get(&conv, &u64));
1089 fail_unless(u64 == 12345);
1090 eina_value_flush(&conv);
1091
1092 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
1093 fail_unless(eina_value_convert(value, &conv));
1094 fail_unless(eina_value_get(&conv, &s));
1095 fail_unless(s == 12345);
1096 eina_value_flush(&conv);
1097
1098 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
1099 fail_unless(eina_value_convert(value, &conv));
1100 fail_unless(eina_value_get(&conv, &i));
1101 fail_unless(i == 12345);
1102 eina_value_flush(&conv);
1103
1104 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
1105 fail_unless(eina_value_convert(value, &conv));
1106 fail_unless(eina_value_get(&conv, &l));
1107 fail_unless(l == 12345);
1108 eina_value_flush(&conv);
1109
1110 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
1111 fail_unless(eina_value_convert(value, &conv));
1112 fail_unless(eina_value_get(&conv, &i64));
1113 fail_unless(i64 == 12345);
1114 eina_value_flush(&conv);
1115
1116 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1117 fail_unless(eina_value_convert(value, &conv));
1118 fail_unless(eina_value_get(&conv, &f));
1119 fail_unless(CHECK_FP(f, 12345));
1120 eina_value_flush(&conv);
1121
1122 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1123 fail_unless(eina_value_convert(value, &conv));
1124 fail_unless(eina_value_get(&conv, &d));
1125 fail_unless(CHECK_FP(d, 12345));
1126 eina_value_flush(&conv);
1127
1128 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
1129 fail_unless(eina_value_convert(value, &conv));
1130 fail_unless(eina_value_get(&conv, &str));
1131 fail_unless(str != NULL);
1132 ck_assert_str_eq(str, "12345");
1133 eina_value_flush(&conv);
1134
1135 /* negative tests */
1136 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1137 // value too big
1138 fail_if(eina_value_convert(value, &conv));
1139 eina_value_flush(&conv);
1140
1141 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1142 // value too big
1143 fail_if(eina_value_convert(value, &conv));
1144 eina_value_flush(&conv);
1145
1146 // check negative value
1147 fail_unless(eina_value_set(value, -12345));
1148
1149 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1150 // value should be positive
1151 fail_if(eina_value_convert(value, &conv));
1152 eina_value_flush(&conv);
1153
1154 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1155 // value should be positive
1156 fail_if(eina_value_convert(value, &conv));
1157 eina_value_flush(&conv);
1158
1159 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
1160 // value should be positive
1161 fail_if(eina_value_convert(value, &conv));
1162 eina_value_flush(&conv);
1163
1164 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
1165 // value should be positive
1166 fail_if(eina_value_convert(value, &conv));
1167 eina_value_flush(&conv);
1168
1169 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
1170 // value should be positive
1171 fail_if(eina_value_convert(value, &conv));
1172 eina_value_flush(&conv);
1173
1174 eina_value_free(value);
1175 eina_shutdown();
1176}
1177END_TEST
1178
1179START_TEST(eina_value_test_convert_ushort)
1180{
1181 Eina_Value *value, conv;
1182 int i;
1183 long l;
1184 int64_t i64;
1185 unsigned short us;
1186 unsigned int ui;
1187 unsigned long ul;
1188 uint64_t u64;
1189 float f;
1190 double d;
1191 const char *str;
1192
1193 eina_init();
1194
1195 value = eina_value_new(EINA_VALUE_TYPE_USHORT);
1196 fail_unless(value != NULL);
1197
1198 fail_unless(eina_value_set(value, 54321));
1199
1200 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1201 fail_unless(eina_value_convert(value, &conv));
1202 fail_unless(eina_value_get(&conv, &us));
1203 fail_unless(us == 54321);
1204 eina_value_flush(&conv);
1205
1206 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
1207 fail_unless(eina_value_convert(value, &conv));
1208 fail_unless(eina_value_get(&conv, &ui));
1209 fail_unless(ui == 54321);
1210 eina_value_flush(&conv);
1211
1212 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
1213 fail_unless(eina_value_convert(value, &conv));
1214 fail_unless(eina_value_get(&conv, &ul));
1215 fail_unless(ul == 54321);
1216 eina_value_flush(&conv);
1217
1218 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
1219 fail_unless(eina_value_convert(value, &conv));
1220 fail_unless(eina_value_get(&conv, &u64));
1221 fail_unless(u64 == 54321);
1222 eina_value_flush(&conv);
1223
1224 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
1225 fail_unless(eina_value_convert(value, &conv));
1226 fail_unless(eina_value_get(&conv, &i));
1227 fail_unless(i == 54321);
1228 eina_value_flush(&conv);
1229
1230 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
1231 fail_unless(eina_value_convert(value, &conv));
1232 fail_unless(eina_value_get(&conv, &l));
1233 fail_unless(l == 54321);
1234 eina_value_flush(&conv);
1235
1236 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
1237 fail_unless(eina_value_convert(value, &conv));
1238 fail_unless(eina_value_get(&conv, &i64));
1239 fail_unless(i64 == 54321);
1240 eina_value_flush(&conv);
1241
1242 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1243 fail_unless(eina_value_convert(value, &conv));
1244 fail_unless(eina_value_get(&conv, &f));
1245 fail_unless(CHECK_FP(f, 54321));
1246 eina_value_flush(&conv);
1247
1248 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1249 fail_unless(eina_value_convert(value, &conv));
1250 fail_unless(eina_value_get(&conv, &d));
1251 fail_unless(CHECK_FP(d, 54321));
1252 eina_value_flush(&conv);
1253
1254 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
1255 fail_unless(eina_value_convert(value, &conv));
1256 fail_unless(eina_value_get(&conv, &str));
1257 fail_unless(str != NULL);
1258 ck_assert_str_eq(str, "54321");
1259 eina_value_flush(&conv);
1260
1261 /* negative tests */
1262 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1263 // value too big
1264 fail_if(eina_value_convert(value, &conv));
1265 eina_value_flush(&conv);
1266
1267 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1268 // value too big
1269 fail_if(eina_value_convert(value, &conv));
1270 eina_value_flush(&conv);
1271
1272 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
1273 // value too big
1274 fail_if(eina_value_convert(value, &conv));
1275 eina_value_flush(&conv);
1276
1277 eina_value_free(value);
1278 eina_shutdown();
1279}
1280END_TEST
1281
1282START_TEST(eina_value_test_convert_int)
1283{
1284 Eina_Value *value, conv;
1285 int i;
1286 long l;
1287 int64_t i64;
1288 unsigned int ui;
1289 unsigned long ul;
1290 uint64_t u64;
1291 float f;
1292 double d;
1293 const char *str;
1294
1295 eina_init();
1296
1297 value = eina_value_new(EINA_VALUE_TYPE_INT);
1298 fail_unless(value != NULL);
1299
1300 const int max_positive_signed_4_bytes = 0x7FFFFFFF;
1301
1302 fail_unless(eina_value_set(value, max_positive_signed_4_bytes));
1303
1304 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
1305 fail_unless(eina_value_convert(value, &conv));
1306 fail_unless(eina_value_get(&conv, &ui));
1307 fail_unless(ui == (unsigned int)max_positive_signed_4_bytes);
1308 eina_value_flush(&conv);
1309
1310 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
1311 fail_unless(eina_value_convert(value, &conv));
1312 fail_unless(eina_value_get(&conv, &ul));
1313 fail_unless(ul == (unsigned long)max_positive_signed_4_bytes);
1314 eina_value_flush(&conv);
1315
1316 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
1317 fail_unless(eina_value_convert(value, &conv));
1318 fail_unless(eina_value_get(&conv, &u64));
1319 fail_unless(u64 == (uint64_t)max_positive_signed_4_bytes);
1320 eina_value_flush(&conv);
1321
1322 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
1323 fail_unless(eina_value_convert(value, &conv));
1324 fail_unless(eina_value_get(&conv, &i));
1325 fail_unless(i == max_positive_signed_4_bytes);
1326 eina_value_flush(&conv);
1327
1328 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
1329 fail_unless(eina_value_convert(value, &conv));
1330 fail_unless(eina_value_get(&conv, &l));
1331 fail_unless(l == max_positive_signed_4_bytes);
1332 eina_value_flush(&conv);
1333
1334 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
1335 fail_unless(eina_value_convert(value, &conv));
1336 fail_unless(eina_value_get(&conv, &i64));
1337 fail_unless(i64 == max_positive_signed_4_bytes);
1338 eina_value_flush(&conv);
1339
1340 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1341 fail_unless(eina_value_convert(value, &conv));
1342 fail_unless(eina_value_get(&conv, &f));
1343 fail_unless(CHECK_FP(f, max_positive_signed_4_bytes));
1344 eina_value_flush(&conv);
1345
1346 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1347 fail_unless(eina_value_convert(value, &conv));
1348 fail_unless(eina_value_get(&conv, &d));
1349 fail_unless(CHECK_FP(d, max_positive_signed_4_bytes));
1350 eina_value_flush(&conv);
1351
1352 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
1353 fail_unless(eina_value_convert(value, &conv));
1354 fail_unless(eina_value_get(&conv, &str));
1355 fail_unless(str != NULL);
1356 ck_assert_str_eq(str, "2147483647"); // "2147483647" == 0x7FFFFFFF
1357 eina_value_flush(&conv);
1358
1359 /* negative tests */
1360 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1361 // value too big
1362 fail_if(eina_value_convert(value, &conv));
1363 eina_value_flush(&conv);
1364
1365 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
1366 // value too big
1367 fail_if(eina_value_convert(value, &conv));
1368 eina_value_flush(&conv);
1369
1370 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1371 // value too big
1372 fail_if(eina_value_convert(value, &conv));
1373 eina_value_flush(&conv);
1374
1375 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1376 // value too big
1377 fail_if(eina_value_convert(value, &conv));
1378 eina_value_flush(&conv);
1379
1380 // check negative value
1381 fail_unless(eina_value_set(value, -1234567890));
1382
1383 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1384 // value should be positive
1385 fail_if(eina_value_convert(value, &conv));
1386 eina_value_flush(&conv);
1387
1388 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1389 // value should be positive
1390 fail_if(eina_value_convert(value, &conv));
1391 eina_value_flush(&conv);
1392
1393 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
1394 // value should be positive
1395 fail_if(eina_value_convert(value, &conv));
1396 eina_value_flush(&conv);
1397
1398 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
1399 // value should be positive
1400 fail_if(eina_value_convert(value, &conv));
1401 eina_value_flush(&conv);
1402
1403 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
1404 // value should be positive
1405 fail_if(eina_value_convert(value, &conv));
1406 eina_value_flush(&conv);
1407
1408 eina_value_free(value);
1409 eina_shutdown();
1410}
1411END_TEST
1412
1413START_TEST(eina_value_test_convert_uint)
1414{
1415 Eina_Value *value, conv;
1416 unsigned int ui;
1417 unsigned long ul;
1418 uint64_t u64;
1419 float f;
1420 double d;
1421 const char *str;
1422
1423 eina_init();
1424
1425 value = eina_value_new(EINA_VALUE_TYPE_UINT);
1426 fail_unless(value != NULL);
1427
1428 const unsigned int max_positive_unsigned_4_bytes = 0xFFFFFFFF;
1429
1430 fail_unless(eina_value_set(value, max_positive_unsigned_4_bytes));
1431
1432 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
1433 fail_unless(eina_value_convert(value, &conv));
1434 fail_unless(eina_value_get(&conv, &ui));
1435 fail_unless(ui == max_positive_unsigned_4_bytes);
1436 eina_value_flush(&conv);
1437
1438 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
1439 fail_unless(eina_value_convert(value, &conv));
1440 fail_unless(eina_value_get(&conv, &ul));
1441 fail_unless(ul == max_positive_unsigned_4_bytes);
1442 eina_value_flush(&conv);
1443
1444 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
1445 fail_unless(eina_value_convert(value, &conv));
1446 fail_unless(eina_value_get(&conv, &u64));
1447 fail_unless(u64 == max_positive_unsigned_4_bytes);
1448 eina_value_flush(&conv);
1449
1450 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1451 fail_unless(eina_value_convert(value, &conv));
1452 fail_unless(eina_value_get(&conv, &f));
1453 fail_unless(CHECK_FP(f, max_positive_unsigned_4_bytes));
1454 eina_value_flush(&conv);
1455
1456 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1457 fail_unless(eina_value_convert(value, &conv));
1458 fail_unless(eina_value_get(&conv, &d));
1459 fail_unless(CHECK_FP(d, max_positive_unsigned_4_bytes));
1460 eina_value_flush(&conv);
1461
1462 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
1463 fail_unless(eina_value_convert(value, &conv));
1464 fail_unless(eina_value_get(&conv, &str));
1465 fail_unless(str != NULL);
1466 ck_assert_str_eq(str, "4294967295"); // 4294967295 == 0xFFFFFFFF
1467 eina_value_flush(&conv);
1468
1469 /* negative tests */
1470 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1471 // value too big
1472 fail_if(eina_value_convert(value, &conv));
1473 eina_value_flush(&conv);
1474
1475 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
1476 // value too big
1477 fail_if(eina_value_convert(value, &conv));
1478 eina_value_flush(&conv);
1479
1480 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
1481 // value too big
1482 fail_if(eina_value_convert(value, &conv));
1483 eina_value_flush(&conv);
1484
1485 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1486 // value too big
1487 fail_if(eina_value_convert(value, &conv));
1488 eina_value_flush(&conv);
1489
1490 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1491 // value too big
1492 fail_if(eina_value_convert(value, &conv));
1493 eina_value_flush(&conv);
1494
1495 eina_value_free(value);
1496 eina_shutdown();
1497}
1498END_TEST
1045 1499
1046START_TEST(eina_value_test_convert_long) 1500START_TEST(eina_value_test_convert_long)
1047{ 1501{
@@ -2152,6 +2606,10 @@ eina_test_value(TCase *tc)
2152 tcase_add_test(tc, eina_value_test_to_string); 2606 tcase_add_test(tc, eina_value_test_to_string);
2153 tcase_add_test(tc, eina_value_test_convert_char); 2607 tcase_add_test(tc, eina_value_test_convert_char);
2154 tcase_add_test(tc, eina_value_test_convert_uchar); 2608 tcase_add_test(tc, eina_value_test_convert_uchar);
2609 tcase_add_test(tc, eina_value_test_convert_short);
2610 tcase_add_test(tc, eina_value_test_convert_ushort);
2611 tcase_add_test(tc, eina_value_test_convert_int);
2612 tcase_add_test(tc, eina_value_test_convert_uint);
2155 tcase_add_test(tc, eina_value_test_convert_long); 2613 tcase_add_test(tc, eina_value_test_convert_long);
2156 tcase_add_test(tc, eina_value_test_convert_ulong); 2614 tcase_add_test(tc, eina_value_test_convert_ulong);
2157 // TODO: other converters... 2615 // TODO: other converters...