Commit 2ed5f49a795d91faddc723bbbb561e485094e23a

Authored by m-holger
Committed by Jay Berkenbilt
1 parent b3bf0290

C-API expose QPDFObjectHandle::getValueAs... accessors

include/qpdf/qpdf-c.h
@@ -707,26 +707,50 @@ extern "C" { @@ -707,26 +707,50 @@ extern "C" {
707 707
708 QPDF_DLL 708 QPDF_DLL
709 QPDF_BOOL qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh); 709 QPDF_BOOL qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh);
  710 + QPDF_DLL
  711 + QPDF_BOOL qpdf_oh_get_value_as_bool(
  712 + qpdf_data qpdf, qpdf_oh oh, QPDF_BOOL* value);
710 713
711 QPDF_DLL 714 QPDF_DLL
712 long long qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh); 715 long long qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh);
713 QPDF_DLL 716 QPDF_DLL
  717 + QPDF_BOOL qpdf_oh_get_value_as_longlong(
  718 + qpdf_data qpdf, qpdf_oh oh, long long* value);
  719 + QPDF_DLL
714 int qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh); 720 int qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh);
715 QPDF_DLL 721 QPDF_DLL
  722 + QPDF_BOOL qpdf_oh_get_value_as_int(
  723 + qpdf_data qpdf, qpdf_oh oh, int* value);
  724 + QPDF_DLL
716 unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh); 725 unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh);
717 QPDF_DLL 726 QPDF_DLL
  727 + QPDF_BOOL qpdf_oh_get_value_as_ulonglong(
  728 + qpdf_data qpdf, qpdf_oh oh, unsigned long long* value);
  729 + QPDF_DLL
718 unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh); 730 unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh);
  731 + QPDF_DLL
  732 + QPDF_BOOL qpdf_oh_get_value_as_uint(
  733 + qpdf_data qpdf, qpdf_oh oh, unsigned int* value);
719 734
720 QPDF_DLL 735 QPDF_DLL
721 char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh); 736 char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh);
  737 + QPDF_DLL
  738 + QPDF_BOOL qpdf_oh_get_value_as_real(
  739 + qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
722 740
723 QPDF_DLL 741 QPDF_DLL
724 QPDF_BOOL qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh); 742 QPDF_BOOL qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh);
725 QPDF_DLL 743 QPDF_DLL
726 double qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh); 744 double qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh);
  745 + QPDF_DLL
  746 + QPDF_BOOL qpdf_oh_get_value_as_number(
  747 + qpdf_data qpdf, qpdf_oh oh, double* value);
727 748
728 QPDF_DLL 749 QPDF_DLL
729 char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh); 750 char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh);
  751 + QPDF_DLL
  752 + QPDF_BOOL qpdf_oh_get_value_as_name(
  753 + qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
730 754
731 /* Return the length of the last string returned. This enables you 755 /* Return the length of the last string returned. This enables you
732 * to retrieve the entire string for cases in which a char* 756 * to retrieve the entire string for cases in which a char*
@@ -747,8 +771,14 @@ extern "C" { @@ -747,8 +771,14 @@ extern "C" {
747 QPDF_DLL 771 QPDF_DLL
748 char const* qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh); 772 char const* qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh);
749 QPDF_DLL 773 QPDF_DLL
  774 + QPDF_BOOL qpdf_oh_get_value_as_string(
  775 + qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
  776 + QPDF_DLL
750 char const* qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh); 777 char const* qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh);
751 QPDF_DLL 778 QPDF_DLL
  779 + QPDF_BOOL qpdf_oh_get_value_as_utf8(
  780 + qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
  781 + QPDF_DLL
752 char const* qpdf_oh_get_binary_string_value( 782 char const* qpdf_oh_get_binary_string_value(
753 qpdf_data qpdf, qpdf_oh oh, size_t* length); 783 qpdf_data qpdf, qpdf_oh oh, size_t* length);
754 QPDF_DLL 784 QPDF_DLL
libqpdf/qpdf-c.cc
@@ -1238,6 +1238,22 @@ QPDF_BOOL qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh) @@ -1238,6 +1238,22 @@ QPDF_BOOL qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh)
1238 }); 1238 });
1239 } 1239 }
1240 1240
  1241 +QPDF_BOOL qpdf_oh_get_value_as_bool(
  1242 + qpdf_data qpdf, qpdf_oh oh, QPDF_BOOL* value)
  1243 +{
  1244 + return do_with_oh<QPDF_BOOL>(
  1245 + qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
  1246 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_bool");
  1247 + bool v = *value;
  1248 + QPDF_BOOL result = o.getValueAsBool(v);
  1249 + if (result)
  1250 + {
  1251 + *value = v;
  1252 + }
  1253 + return result;
  1254 + });
  1255 +}
  1256 +
1241 long long qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh) 1257 long long qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh)
1242 { 1258 {
1243 return do_with_oh<long long>( 1259 return do_with_oh<long long>(
@@ -1247,6 +1263,16 @@ long long qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh) @@ -1247,6 +1263,16 @@ long long qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh)
1247 }); 1263 });
1248 } 1264 }
1249 1265
  1266 +QPDF_BOOL qpdf_oh_get_value_as_longlong(
  1267 + qpdf_data qpdf, qpdf_oh oh, long long* value)
  1268 +{
  1269 + return do_with_oh<QPDF_BOOL>(
  1270 + qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
  1271 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_longlong");
  1272 + return o.getValueAsInt(*value);
  1273 + });
  1274 +}
  1275 +
1250 int qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh) 1276 int qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh)
1251 { 1277 {
1252 return do_with_oh<int>( 1278 return do_with_oh<int>(
@@ -1256,6 +1282,16 @@ int qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh) @@ -1256,6 +1282,16 @@ int qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh)
1256 }); 1282 });
1257 } 1283 }
1258 1284
  1285 +QPDF_BOOL qpdf_oh_get_value_as_int(
  1286 + qpdf_data qpdf, qpdf_oh oh, int* value)
  1287 +{
  1288 + return do_with_oh<QPDF_BOOL>(
  1289 + qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
  1290 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_int");
  1291 + return o.getValueAsInt(*value);
  1292 + });
  1293 +}
  1294 +
1259 unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh) 1295 unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh)
1260 { 1296 {
1261 return do_with_oh<unsigned long long>( 1297 return do_with_oh<unsigned long long>(
@@ -1265,6 +1301,16 @@ unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh) @@ -1265,6 +1301,16 @@ unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh)
1265 }); 1301 });
1266 } 1302 }
1267 1303
  1304 +QPDF_BOOL qpdf_oh_get_value_as_ulonglong(
  1305 + qpdf_data qpdf, qpdf_oh oh, unsigned long long* value)
  1306 +{
  1307 + return do_with_oh<QPDF_BOOL>(
  1308 + qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
  1309 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_ulonglong");
  1310 + return o.getValueAsUInt(*value);
  1311 + });
  1312 +}
  1313 +
1268 unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh) 1314 unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh)
1269 { 1315 {
1270 return do_with_oh<unsigned int>( 1316 return do_with_oh<unsigned int>(
@@ -1274,6 +1320,16 @@ unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh) @@ -1274,6 +1320,16 @@ unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh)
1274 }); 1320 });
1275 } 1321 }
1276 1322
  1323 +QPDF_BOOL qpdf_oh_get_value_as_uint(
  1324 + qpdf_data qpdf, qpdf_oh oh, unsigned int* value)
  1325 +{
  1326 + return do_with_oh<QPDF_BOOL>(
  1327 + qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
  1328 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_uint");
  1329 + return o.getValueAsUInt(*value);
  1330 + });
  1331 +}
  1332 +
1277 char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh) 1333 char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh)
1278 { 1334 {
1279 return do_with_oh<char const*>( 1335 return do_with_oh<char const*>(
@@ -1284,6 +1340,22 @@ char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh) @@ -1284,6 +1340,22 @@ char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh)
1284 }); 1340 });
1285 } 1341 }
1286 1342
  1343 +QPDF_BOOL qpdf_oh_get_value_as_real(
  1344 + qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
  1345 +{
  1346 + return do_with_oh<QPDF_BOOL>(
  1347 + qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
  1348 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_real");
  1349 + auto result = o.getValueAsReal(qpdf->tmp_string);
  1350 + if (result)
  1351 + {
  1352 + *value = qpdf->tmp_string.c_str();
  1353 + *length = qpdf->tmp_string.length();
  1354 + }
  1355 + return result;
  1356 + });
  1357 +}
  1358 +
1287 double qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh) 1359 double qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh)
1288 { 1360 {
1289 return do_with_oh<double>( 1361 return do_with_oh<double>(
@@ -1293,6 +1365,16 @@ double qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh) @@ -1293,6 +1365,16 @@ double qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh)
1293 }); 1365 });
1294 } 1366 }
1295 1367
  1368 +QPDF_BOOL qpdf_oh_get_value_as_number(
  1369 + qpdf_data qpdf, qpdf_oh oh, double* value)
  1370 +{
  1371 + return do_with_oh<QPDF_BOOL>(
  1372 + qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
  1373 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_number");
  1374 + return o.getValueAsNumber(*value);
  1375 + });
  1376 +}
  1377 +
1296 char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh) 1378 char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh)
1297 { 1379 {
1298 return do_with_oh<char const*>( 1380 return do_with_oh<char const*>(
@@ -1303,6 +1385,22 @@ char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh) @@ -1303,6 +1385,22 @@ char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh)
1303 }); 1385 });
1304 } 1386 }
1305 1387
  1388 +QPDF_BOOL qpdf_oh_get_value_as_name(
  1389 + qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
  1390 +{
  1391 + return do_with_oh<QPDF_BOOL>(
  1392 + qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
  1393 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_name");
  1394 + auto result = o.getValueAsName(qpdf->tmp_string);
  1395 + if (result)
  1396 + {
  1397 + *value = qpdf->tmp_string.c_str();
  1398 + *length = qpdf->tmp_string.length();
  1399 + }
  1400 + return result;
  1401 + });
  1402 +}
  1403 +
1306 char const* qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh) 1404 char const* qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh)
1307 { 1405 {
1308 return do_with_oh<char const*>( 1406 return do_with_oh<char const*>(
@@ -1313,6 +1411,22 @@ char const* qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh) @@ -1313,6 +1411,22 @@ char const* qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh)
1313 }); 1411 });
1314 } 1412 }
1315 1413
  1414 +QPDF_BOOL qpdf_oh_get_value_as_string(
  1415 + qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
  1416 +{
  1417 + return do_with_oh<QPDF_BOOL>(
  1418 + qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
  1419 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_string");
  1420 + auto result = o.getValueAsString(qpdf->tmp_string);
  1421 + if (result)
  1422 + {
  1423 + *value = qpdf->tmp_string.c_str();
  1424 + *length = qpdf->tmp_string.length();
  1425 + }
  1426 + return result;
  1427 + });
  1428 +}
  1429 +
1316 char const* qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh) 1430 char const* qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh)
1317 { 1431 {
1318 return do_with_oh<char const*>( 1432 return do_with_oh<char const*>(
@@ -1323,6 +1437,22 @@ char const* qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh) @@ -1323,6 +1437,22 @@ char const* qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh)
1323 }); 1437 });
1324 } 1438 }
1325 1439
  1440 +QPDF_BOOL qpdf_oh_get_value_as_utf8(
  1441 + qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
  1442 +{
  1443 + return do_with_oh<QPDF_BOOL>(
  1444 + qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
  1445 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_utf8");
  1446 + auto result = o.getValueAsUTF8(qpdf->tmp_string);
  1447 + if (result)
  1448 + {
  1449 + *value = qpdf->tmp_string.c_str();
  1450 + *length = qpdf->tmp_string.length();
  1451 + }
  1452 + return result;
  1453 + });
  1454 +}
  1455 +
1326 char const* qpdf_oh_get_binary_string_value( 1456 char const* qpdf_oh_get_binary_string_value(
1327 qpdf_data qpdf, qpdf_oh oh, size_t* length) 1457 qpdf_data qpdf, qpdf_oh oh, size_t* length)
1328 { 1458 {
qpdf/qpdf-ctest.c
@@ -673,26 +673,78 @@ static void test25(char const* infile, @@ -673,26 +673,78 @@ static void test25(char const* infile,
673 673
674 /* Parse objects from a string */ 674 /* Parse objects from a string */
675 qpdf_oh parsed = qpdf_oh_parse( 675 qpdf_oh parsed = qpdf_oh_parse(
676 - qpdf, "[ 1 2.0 (3\xf7) << /Four [/Five] >> null true ]"); 676 + qpdf, "[ 1 2.0 (3\xf7) << /Four [/Five] >> null true false /Six]");
677 qpdf_oh p_int = qpdf_oh_get_array_item(qpdf, parsed, 0); 677 qpdf_oh p_int = qpdf_oh_get_array_item(qpdf, parsed, 0);
678 qpdf_oh p_real = qpdf_oh_get_array_item(qpdf, parsed, 1); 678 qpdf_oh p_real = qpdf_oh_get_array_item(qpdf, parsed, 1);
679 qpdf_oh p_string = qpdf_oh_get_array_item(qpdf, parsed, 2); 679 qpdf_oh p_string = qpdf_oh_get_array_item(qpdf, parsed, 2);
680 qpdf_oh p_dict = qpdf_oh_get_array_item(qpdf, parsed, 3); 680 qpdf_oh p_dict = qpdf_oh_get_array_item(qpdf, parsed, 3);
681 qpdf_oh p_null = qpdf_oh_get_array_item(qpdf, parsed, 4); 681 qpdf_oh p_null = qpdf_oh_get_array_item(qpdf, parsed, 4);
682 qpdf_oh p_bool = qpdf_oh_get_array_item(qpdf, parsed, 5); 682 qpdf_oh p_bool = qpdf_oh_get_array_item(qpdf, parsed, 5);
  683 + qpdf_oh p_bool_f = qpdf_oh_get_array_item(qpdf, parsed, 6);
  684 + qpdf_oh p_name = qpdf_oh_get_array_item(qpdf, parsed, 7);
683 assert(qpdf_oh_is_integer(qpdf, p_int) && 685 assert(qpdf_oh_is_integer(qpdf, p_int) &&
684 qpdf_oh_get_int_value_as_int(qpdf, p_int) == 1); 686 qpdf_oh_get_int_value_as_int(qpdf, p_int) == 1);
  687 + long long l = 0;
  688 + assert(qpdf_oh_get_value_as_longlong(qpdf, p_bool, &l) == QPDF_FALSE);
  689 + assert((qpdf_oh_get_value_as_longlong(qpdf, p_int, &l) == QPDF_TRUE) &&
  690 + (l == 1));
  691 + int i = 0;
  692 + assert(qpdf_oh_get_value_as_int(qpdf, p_bool, &i) == QPDF_FALSE);
  693 + assert((qpdf_oh_get_value_as_int(qpdf, p_int, &i) == QPDF_TRUE) &&
  694 + (i == 1));
  695 + unsigned long long ul = 0u;
  696 + assert(qpdf_oh_get_value_as_ulonglong(qpdf, p_bool, &ul) == QPDF_FALSE);
  697 + assert((qpdf_oh_get_value_as_ulonglong(qpdf, p_int, &ul) == QPDF_TRUE) &&
  698 + (ul == 1u));
  699 + unsigned int u = 0u;
  700 + assert(qpdf_oh_get_value_as_uint(qpdf, p_bool, &u) == QPDF_FALSE);
  701 + assert((qpdf_oh_get_value_as_uint(qpdf, p_int, &u) == QPDF_TRUE) &&
  702 + (u == 1u));
  703 + double d = 0.0;
  704 + assert(qpdf_oh_get_value_as_number(qpdf, p_bool, &d) == QPDF_FALSE);
  705 + assert((qpdf_oh_get_value_as_number(qpdf, p_int, &d) == QPDF_TRUE) &&
  706 + (((d - 1.0) * (d - 1.0)) < 1e-100));
685 assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer); 707 assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer);
686 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0); 708 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0);
687 assert(qpdf_oh_is_real(qpdf, p_real) && 709 assert(qpdf_oh_is_real(qpdf, p_real) &&
688 (strcmp(qpdf_oh_get_real_value(qpdf, p_real), "2.0") == 0) && 710 (strcmp(qpdf_oh_get_real_value(qpdf, p_real), "2.0") == 0) &&
689 qpdf_oh_get_numeric_value(qpdf, p_real) == 2.0); 711 qpdf_oh_get_numeric_value(qpdf, p_real) == 2.0);
  712 + const char* r = "";
  713 + size_t length = 0;
  714 + assert((qpdf_oh_get_value_as_real(qpdf, p_name, &r, &length) ==
  715 + QPDF_FALSE) &&
  716 + (strcmp(r, "") == 0) &&
  717 + (length == 0));
  718 + assert((qpdf_oh_get_value_as_real(qpdf, p_real, &r, &length) ==
  719 + QPDF_TRUE) &&
  720 + (strcmp(r, "2.0") == 0) &&
  721 + (length == 3));
690 assert(qpdf_oh_get_type_code(qpdf, p_real) == ot_real); 722 assert(qpdf_oh_get_type_code(qpdf, p_real) == ot_real);
691 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_real), "real") == 0); 723 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_real), "real") == 0);
692 assert(qpdf_oh_is_string(qpdf, p_string) && 724 assert(qpdf_oh_is_string(qpdf, p_string) &&
693 (strcmp(qpdf_oh_get_string_value(qpdf, p_string), "3\xf7") == 0) && 725 (strcmp(qpdf_oh_get_string_value(qpdf, p_string), "3\xf7") == 0) &&
694 (strcmp(qpdf_oh_get_utf8_value(qpdf, p_string), "3\xc3\xb7") == 0) && 726 (strcmp(qpdf_oh_get_utf8_value(qpdf, p_string), "3\xc3\xb7") == 0) &&
695 (strcmp(qpdf_oh_unparse_binary(qpdf, p_string), "<33f7>") == 0)); 727 (strcmp(qpdf_oh_unparse_binary(qpdf, p_string), "<33f7>") == 0));
  728 + const char* str = "";
  729 + length = 0;
  730 + assert((qpdf_oh_get_value_as_string(qpdf, p_name, &str, &length) ==
  731 + QPDF_FALSE) &&
  732 + (strcmp(str, "") == 0) &&
  733 + (length == 0));
  734 + assert((qpdf_oh_get_value_as_string(qpdf, p_string, &str, &length) ==
  735 + QPDF_TRUE) &&
  736 + (strcmp(str, "3\xf7") == 0) &&
  737 + (length == 2));
  738 + const char* utf8 = "";
  739 + length = 0;
  740 + assert((qpdf_oh_get_value_as_utf8(qpdf, p_name, &utf8, &length) ==
  741 + QPDF_FALSE) &&
  742 + (strcmp(utf8, "") == 0) &&
  743 + (length == 0));
  744 + assert((qpdf_oh_get_value_as_utf8(qpdf, p_string, &utf8, &length) ==
  745 + QPDF_TRUE) &&
  746 + (strcmp(utf8, "3\xc3\xb7") == 0) &&
  747 + (length == 3));
696 assert(qpdf_oh_get_type_code(qpdf, p_string) == ot_string); 748 assert(qpdf_oh_get_type_code(qpdf, p_string) == ot_string);
697 assert(! qpdf_oh_is_name_and_equals(qpdf, p_string, "3\xf7")); 749 assert(! qpdf_oh_is_name_and_equals(qpdf, p_string, "3\xf7"));
698 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_string), "string") == 0); 750 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_string), "string") == 0);
@@ -709,8 +761,25 @@ static void test25(char const* infile, @@ -709,8 +761,25 @@ static void test25(char const* infile,
709 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_null), "null") == 0); 761 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_null), "null") == 0);
710 assert(qpdf_oh_is_bool(qpdf, p_bool) && 762 assert(qpdf_oh_is_bool(qpdf, p_bool) &&
711 (qpdf_oh_get_bool_value(qpdf, p_bool) == QPDF_TRUE)); 763 (qpdf_oh_get_bool_value(qpdf, p_bool) == QPDF_TRUE));
  764 + QPDF_BOOL b = QPDF_FALSE;
  765 + assert((qpdf_oh_get_value_as_bool(qpdf, p_int, &b) == QPDF_FALSE) &&
  766 + b == QPDF_FALSE);
  767 + assert((qpdf_oh_get_value_as_bool(qpdf, p_bool, &b) == QPDF_TRUE) &&
  768 + b == QPDF_TRUE);
  769 + assert((qpdf_oh_get_value_as_bool(qpdf, p_bool_f, &b) == QPDF_TRUE) &&
  770 + b == QPDF_FALSE);
712 assert(qpdf_oh_get_type_code(qpdf, p_bool) == ot_boolean); 771 assert(qpdf_oh_get_type_code(qpdf, p_bool) == ot_boolean);
713 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_bool), "boolean") == 0); 772 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_bool), "boolean") == 0);
  773 + const char* n = "";
  774 + length = 0;
  775 + assert((qpdf_oh_get_value_as_name(qpdf, p_string, &n, &length) ==
  776 + QPDF_FALSE) &&
  777 + (strcmp(n, "") == 0) &&
  778 + (length == 0));
  779 + assert((qpdf_oh_get_value_as_name(qpdf, p_name, &n, &length) ==
  780 + QPDF_TRUE) &&
  781 + (strcmp(n, "/Six") == 0) &&
  782 + (length == 4));
714 qpdf_oh_erase_item(qpdf, parsed, 4); 783 qpdf_oh_erase_item(qpdf, parsed, 4);
715 qpdf_oh_insert_item( 784 qpdf_oh_insert_item(
716 qpdf, parsed, 2, 785 qpdf, parsed, 2,
qpdf/qpdf.testcov
@@ -477,16 +477,26 @@ qpdf-c array to wrap_in_array 0 @@ -477,16 +477,26 @@ qpdf-c array to wrap_in_array 0
477 qpdf-c non-array to wrap_in_array 0 477 qpdf-c non-array to wrap_in_array 0
478 qpdf-c called qpdf_oh_parse 0 478 qpdf-c called qpdf_oh_parse 0
479 qpdf-c called qpdf_oh_get_bool_value 0 479 qpdf-c called qpdf_oh_get_bool_value 0
  480 +qpdf-c called qpdf_oh_get_value_as_bool 0
480 qpdf-c called qpdf_oh_get_int_value 0 481 qpdf-c called qpdf_oh_get_int_value 0
  482 +qpdf-c called qpdf_oh_get_value_as_longlong 0
481 qpdf-c called qpdf_oh_get_int_value_as_int 0 483 qpdf-c called qpdf_oh_get_int_value_as_int 0
  484 +qpdf-c called qpdf_oh_get_value_as_int 0
482 qpdf-c called qpdf_oh_get_uint_value 0 485 qpdf-c called qpdf_oh_get_uint_value 0
  486 +qpdf-c called qpdf_oh_get_value_as_ulonglong 0
483 qpdf-c called qpdf_oh_get_uint_value_as_uint 0 487 qpdf-c called qpdf_oh_get_uint_value_as_uint 0
  488 +qpdf-c called qpdf_oh_get_value_as_uint 0
484 qpdf-c called qpdf_oh_get_real_value 0 489 qpdf-c called qpdf_oh_get_real_value 0
  490 +qpdf-c called qpdf_oh_get_value_as_real 0
485 qpdf-c called qpdf_oh_is_number 0 491 qpdf-c called qpdf_oh_is_number 0
  492 +qpdf-c called qpdf_oh_get_value_as_number 0
486 qpdf-c called qpdf_oh_get_numeric_value 0 493 qpdf-c called qpdf_oh_get_numeric_value 0
487 qpdf-c called qpdf_oh_get_name 0 494 qpdf-c called qpdf_oh_get_name 0
  495 +qpdf-c called qpdf_oh_get_value_as_name 0
488 qpdf-c called qpdf_oh_get_string_value 0 496 qpdf-c called qpdf_oh_get_string_value 0
  497 +qpdf-c called qpdf_oh_get_value_as_string 0
489 qpdf-c called qpdf_oh_get_utf8_value 0 498 qpdf-c called qpdf_oh_get_utf8_value 0
  499 +qpdf-c called qpdf_oh_get_value_as_utf8 0
490 qpdf-c called qpdf_oh_get_array_n_items 0 500 qpdf-c called qpdf_oh_get_array_n_items 0
491 qpdf-c called qpdf_oh_get_array_item 0 501 qpdf-c called qpdf_oh_get_array_item 0
492 qpdf-c called qpdf_oh_begin_dict_key_iter 0 502 qpdf-c called qpdf_oh_begin_dict_key_iter 0