Add negative manual test
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 28 Mar 2024 10:48:10 +0000 (11:48 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 12 Apr 2024 10:05:05 +0000 (12:05 +0200)
Change-Id: I05425eb8bb2d215730e06a9877bc8841b6b0ec31

tests/man_tests.cpp

index 99b2a3e297b4f36cfb1619be2c2304b827f7125f..348830cbd5be4ec6f48c3e8fd95592bb74ce02e8 100644 (file)
@@ -33,6 +33,7 @@ struct TestContents {
     Buffer credentialRawId;
     Buffer userId;
     unsigned transports = WAUTHN_TRANSPORT_NONE;
+    bool negative = false;
 };
 
 void DisplayQR(struct TestContents &contents)
@@ -97,14 +98,18 @@ void DisplayQRCallback(const char *qr_contents, void *data)
 {
     std::string encoded(qr_contents);
 
-    if ((static_cast<TestContents *>(data))->path.empty() || !qr_contents) {
+    auto testContents = static_cast<TestContents *>(data);
+    if (testContents->path.empty() || !qr_contents) {
         std::cout << "qrcode_callback failed" << std::endl;
-        std::cout << "QRcode path: " << static_cast<TestContents *>(data)->path << std::endl;
+        std::cout << "QRcode path: " << testContents->path << std::endl;
         std::cout << "qr_contents: " << qr_contents << std::endl;
-        (static_cast<TestContents *>(data))->status = false;
+        testContents->status = false;
         return;
     }
-    GenerateAndDisplayQR(encoded, *static_cast<TestContents *>(data));
+    if (testContents->negative)
+        GenerateAndDisplayQR("https://tinyurl.com/5x2bcwjy", *testContents);
+    else
+        GenerateAndDisplayQR(encoded, *testContents);
 }
 
 Buffer ToBuffer(wauthn_const_buffer_s buff) { return Buffer{buff.data, buff.data + buff.size}; }
@@ -261,9 +266,13 @@ bool Test(struct TestContents &testContents)
 
 } // anonymous namespace
 
-int main()
+int main(int argc, char *argv[])
 {
     TestContents testContents = {true, "/tmp/qrcode.png", {}, {}, WAUTHN_TRANSPORT_NONE};
+
+    if (argc > 1 && std::string_view("-n") == argv[1])
+        testContents.negative = true;
+
     int ret = 0;
     if (Test(testContents))
         std::cout << "Test passed.\n";