-
Notifications
You must be signed in to change notification settings - Fork 373
Use CPPUNIT_ASSERT_EQUAL instead of CPPUNIT_ASSERT #807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
This shows the actual incorrect value
WalkthroughUpdated test assertions in ObjectTests.cpp from equality comparisons using CPPUNIT_ASSERT(rv == CKR_XXX) to CPPUNIT_ASSERT_EQUAL(CKR_XXX, rv). No test logic or control flow changed. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, although I think it reads better with the arguments swapped, "assert that this variable under test rv equals this golden reference constant CKR_OK"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
src/lib/test/ObjectTests.cpp (1)
705-953
: Fix legacy CPPUNIT_ASSERT(rv == CKR_*) usages across the test suiteWe ran the provided regex search and uncovered numerous occurrences of the old-style assertions in tests under src/lib/test and src/lib/session_mgr/test. To ensure consistency and clear diagnostics, please replace every instance of:
•
CPPUNIT_ASSERT(rv == CKR_<CODE>);
•CPPUNIT_ASSERT(CKR_<CODE> == rv);
with the new pattern:
CPPUNIT_ASSERT_EQUAL(CKR_<CODE>, rv);
Files that need updating (non-exhaustive list):
- src/lib/test/ForkTests.cpp
- src/lib/test/UserTests.cpp
- src/lib/test/SessionTests.cpp
- src/lib/test/TokenTests.cpp
- src/lib/test/InitTests.cpp
- src/lib/test/SignVerifyTests.cpp
- src/lib/test/RandomTests.cpp
- src/lib/test/InfoTests.cpp
- src/lib/test/SymmetricAlgorithmTests.cpp
- src/lib/test/DigestTests.cpp
- src/lib/test/AsymWrapUnwrapTests.cpp
- src/lib/test/DeriveTests.cpp
- src/lib/test/AsymEncryptDecryptTests.cpp
- src/lib/session_mgr/test/SessionManagerTests.cpp
Once updated, re-run:
rg -n --pretty 'CPPUNIT_ASSERT\s*\(\s*(rv\s*==|==\s*rv)\s*CKR_'
to confirm no legacy asserts remain.
🧹 Nitpick comments (2)
src/lib/test/ObjectTests.cpp (2)
1476-1477
: Optional: extend the pattern to other equality checks for better diffsThere are still several equality assertions using raw comparison within CPPUNIT_ASSERT (e.g., “4 == ulObjectCount”, “objectSize == CK_UNAVAILABLE_INFORMATION”, memcmp(...) == 0). Converting the plain equality ones to CPPUNIT_ASSERT_EQUAL will produce clearer failure output for the actual values.
For example:
-CPPUNIT_ASSERT(4 == ulObjectCount); +CPPUNIT_ASSERT_EQUAL((CK_ULONG)4, ulObjectCount); -CPPUNIT_ASSERT(objectSize == CK_UNAVAILABLE_INFORMATION); +CPPUNIT_ASSERT_EQUAL((CK_ULONG)CK_UNAVAILABLE_INFORMATION, objectSize);Leave memcmp-based checks as-is unless you introduce helpers to pretty-print buffers.
Also applies to: 1489-1489, 1501-1501, 1513-1513, 1221-1221, 943-944, 2265-2266
754-756
: Nit: CK_RV values print in decimal; consider hex for readabilityCppUnit prints integral types in decimal by default, which is less readable for CKR_* codes. If useful, introduce a small helper (either a custom assertion_traits<CK_RV> or an ASSERT_CKR_EQ macro that formats std::hex) to render CK_RV in hex. Optional, but it makes failures faster to triage.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/lib/test/ObjectTests.cpp
(40 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/lib/test/ObjectTests.cpp (1)
src/lib/test/ObjectTests.h (1)
ObjectTests
(41-185)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: macOS (openssl)
- GitHub Check: Windows (x86, openssl)
- GitHub Check: macOS (botan)
- GitHub Check: Linux with OpenSSL 3.0
- GitHub Check: Linux with Botan
- GitHub Check: Linux with OpenSSL 1.1.1
🔇 Additional comments (34)
src/lib/test/ObjectTests.cpp (34)
97-99
: Good switch to CPPUNIT_ASSERT_EQUAL(expected, actual) for CK_RV checksThe conversions here correctly use expected-first ordering and will yield clearer diffs for failing return values.
Also applies to: 121-123, 126-128, 152-154, 159-161
193-197
: Consistent assert conversions in certificate attribute checksThese follow the same expected/actual order and keep the semantics identical while improving diagnostics.
Also applies to: 199-201
236-239
: LGTM: assert_equal usage in X509 certificate attribute readsThe changes correctly assert CKR_OK for both length and value fetches.
Also applies to: 249-251
309-312
: LGTM: key attribute checks use CPPUNIT_ASSERT_EQUAL correctlyNo behavior change; better failure output for CRYPTOKI calls.
Also applies to: 315-317
358-361
: LGTM: public key attribute checks converted properlyExpected value is first, return value is second — correct.
Also applies to: 364-366
411-414
: LGTM: private key attribute checks converted properlyAccurate usage; improves readability of failures.
Also applies to: 417-419
451-454
: LGTM: attribute mutability tests now show actual CK_RV on failureHelpful improvement across wrap-with-trusted and sensitive attribute transitions.
Also applies to: 456-458, 460-462, 472-474, 476-478, 480-482
496-498
: LGTM: RSA public key attribute reads assert CKR_OKMatches the intended semantics; clearer failure messages.
Also applies to: 502-504
533-535
: LGTM: RSA private key attribute reads assert CKR_OKOrdering and intent are correct.
Also applies to: 539-541
754-756
: LGTM: initialization and first create/destroy checks convertedExpected vs. actual ordering is correct for all CKR_* here.
Also applies to: 762-770
785-794
: LGTM: read-only + user session assertions converted properlyThese changes preserve logic and increase test output clarity.
Also applies to: 795-806
815-833
: LGTM: read-write session (no login) cases convertedAccurate use of CPPUNIT_ASSERT_EQUAL; no regressions.
Also applies to: 834-841
846-865
: LGTM: read-write + user session conversionsAll CKR checks converted correctly.
Also applies to: 866-877, 879-881
886-899
: LGTM: read-write + SO session conversionsExpected-first ordering across the block looks good.
Also applies to: 900-917
967-969
: LGTM: testCopyObject CK_RV assertions convertedCovers the allow/deny flows; expected constants are first, rv second — correct throughout.
Also applies to: 971-979, 991-999, 1003-1011, 1016-1017, 1022-1023, 1025-1027
1030-1035
: LGTM: copy rules and template consistency conversionsThe new assertions will make violations easier to diagnose.
Also applies to: 1037-1046, 1049-1053, 1060-1061, 1063-1071, 1073-1075
1103-1113
: LGTM: destroy object flow uses CPPUNIT_ASSERT_EQUAL throughoutThis significantly improves output when negative paths fail.
Also applies to: 1115-1121, 1123-1129, 1131-1139, 1140-1145, 1147-1157, 1159-1161, 1163-1181, 1183-1189
1201-1203
: LGTM: get object size path converted correctlyAssertions on CRYPTOKI calls now consistent with the rest of the file.
Also applies to: 1205-1211, 1213-1220, 1223-1225
1238-1244
: LGTM: get attribute value path converted correctlyArgument validation and happy-path checks are clearer now.
Also applies to: 1246-1252, 1254-1268, 1270-1276
1338-1344
: LGTM: set attribute value path convertedThe read-only and action-prohibited flows now show actual CK_RV on failure.
Also applies to: 1346-1352, 1354-1368, 1375-1389, 1392-1400, 1403-1410
1426-1432
: LGTM: find objects flow convertedGreat coverage of logged-in and logged-out scenarios; the new asserts are consistent.
Also applies to: 1434-1440, 1442-1468, 1470-1477, 1481-1482, 1485-1489, 1493-1501, 1504-1514
1527-1533
: LGTM: key generation flow convertedAll CKR paths use the improved assertion macro.
Also applies to: 1535-1541, 1543-1558, 1560-1567, 1569-1585
1596-1602
: LGTM: certificate creation flow convertedTemplate incomplete and read-only attribute update cases clearly reported now.
Also applies to: 1604-1613, 1619-1621
1639-1645
: LGTM: default data attributes setup convertedInitialization and create checks now consistent with the rest.
Also applies to: 1647-1653, 1655-1658
1684-1690
: LGTM: default X509 cert attributes setup convertedAccurate expected-first ordering; no logic change.
Also applies to: 1692-1698, 1701-1705
1736-1742
: LGTM: default RSA public attributes setup convertedAll relevant CKR paths updated.
Also applies to: 1744-1750, 1753-1758
1799-1805
: LGTM: default RSA private attributes setup convertedConsistent use of CPPUNIT_ASSERT_EQUAL.
Also applies to: 1807-1814, 1816-1823
1854-1860
: LGTM: always/never attribute tests convertedThese will be easier to debug if a token deviates from the spec.
Also applies to: 1862-1868, 1870-1878, 1882-1884, 1886-1890
1924-1930
: LGTM: sensitive attribute tests convertedClearer negative and positive path reporting.
Also applies to: 1932-1938, 1942-1944, 1949-1956
1979-1985
: LGTM: invalid attribute access convertedAccurate expected CKR values asserted.
Also applies to: 1987-1993, 1995-1997
2034-2040
: LGTM: re-authentication flows convertedThese cover a lot of nuanced states; the improved assertions are beneficial.
Also applies to: 2042-2048, 2050-2068, 2070-2078, 2080-2086, 2088-2102, 2105-2116, 2119-2125
2136-2142
: LGTM: allowed mechanisms tests convertedUsing CPPUNIT_ASSERT_EQUAL for CKR values improves test clarity.
Also applies to: 2144-2156, 2159-2168, 2171-2194
2234-2240
: LGTM: template attribute tests convertedInitialization and attribute fetch sequences now consistently assert CKR results.
Also applies to: 2242-2248, 2257-2260, 2263-2266, 2288-2290
2322-2328
: LGTM: secret key creation and KCV checks convertedReturn code assertions across all key types are correctly switched.
Also applies to: 2330-2336, 2379-2387, 2391-2399, 2403-2411, 2415-2423, 2427-2435
This is done because of the reporting in the failure where it prints expected and the actual value. It expects the first value to be the expected as it's clear from the definition:
|
Aha! Then the correct order, it is. Greetings from Yoda. ;) |
This shows the actual incorrect value
Summary by CodeRabbit