Convert asn1_test to GTest.
BUG=129
Change-Id: I0af881c6f50a558a220853084e53189b8919e41e
Reviewed-on: https://boringssl-review.googlesource.com/14206
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Steven Valdez <svaldez@google.com>
Reviewed-by: Steven Valdez <svaldez@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt
index 6bb05cc..81efad4 100644
--- a/crypto/CMakeLists.txt
+++ b/crypto/CMakeLists.txt
@@ -211,6 +211,7 @@
add_executable(
crypto_test
+ asn1/asn1_test.cc
chacha/chacha_test.cc
curve25519/x25519_test.cc
dh/dh_test.cc
diff --git a/crypto/asn1/CMakeLists.txt b/crypto/asn1/CMakeLists.txt
index cd1ee8c..bfc97d0 100644
--- a/crypto/asn1/CMakeLists.txt
+++ b/crypto/asn1/CMakeLists.txt
@@ -39,14 +39,3 @@
x_bignum.c
x_long.c
)
-
-add_executable(
- asn1_test
-
- asn1_test.cc
-
- $<TARGET_OBJECTS:test_support>
-)
-
-target_link_libraries(asn1_test crypto)
-add_dependencies(all_tests asn1_test)
diff --git a/crypto/asn1/asn1_test.cc b/crypto/asn1/asn1_test.cc
index 77a1ee0..accf3ba 100644
--- a/crypto/asn1/asn1_test.cc
+++ b/crypto/asn1/asn1_test.cc
@@ -14,10 +14,13 @@
#include <stdio.h>
+#include <gtest/gtest.h>
+
#include <openssl/asn1.h>
-#include <openssl/crypto.h>
#include <openssl/err.h>
+#include "../test/test_util.h"
+
// kTag128 is an ASN.1 structure with a universal tag with number 128.
static const uint8_t kTag128[] = {
@@ -38,42 +41,22 @@
0x1f, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x01, 0x00,
};
-static bool TestLargeTags() {
+TEST(ASN1Test, LargeTags) {
const uint8_t *p = kTag258;
bssl::UniquePtr<ASN1_TYPE> obj(d2i_ASN1_TYPE(NULL, &p, sizeof(kTag258)));
- if (obj) {
- fprintf(stderr, "Parsed value with illegal tag (type = %d).\n", obj->type);
- return false;
- }
+ EXPECT_FALSE(obj) << "Parsed value with illegal tag" << obj->type;
ERR_clear_error();
p = kTagOverflow;
obj.reset(d2i_ASN1_TYPE(NULL, &p, sizeof(kTagOverflow)));
- if (obj) {
- fprintf(stderr, "Parsed value with tag overflow (type = %d).\n", obj->type);
- return false;
- }
+ EXPECT_FALSE(obj) << "Parsed value with tag overflow" << obj->type;
ERR_clear_error();
p = kTag128;
obj.reset(d2i_ASN1_TYPE(NULL, &p, sizeof(kTag128)));
- if (!obj || obj->type != 128 || obj->value.asn1_string->length != 1 ||
- obj->value.asn1_string->data[0] != 0) {
- fprintf(stderr, "Failed to parse value with tag 128.\n");
- ERR_print_errors_fp(stderr);
- return false;
- }
-
- return true;
-}
-
-int main() {
- CRYPTO_library_init();
-
- if (!TestLargeTags()) {
- return 1;
- }
-
- printf("PASS\n");
- return 0;
+ ASSERT_TRUE(obj);
+ EXPECT_EQ(128, obj->type);
+ const uint8_t kZero = 0;
+ EXPECT_EQ(Bytes(&kZero, 1), Bytes(obj->value.asn1_string->data,
+ obj->value.asn1_string->length));
}
diff --git a/util/all_tests.json b/util/all_tests.json
index a6e672f..d5c6e54 100644
--- a/util/all_tests.json
+++ b/util/all_tests.json
@@ -1,6 +1,5 @@
[
["crypto/aes/aes_test", "crypto/aes/aes_tests.txt"],
- ["crypto/asn1/asn1_test"],
["crypto/base64/base64_test"],
["crypto/bio/bio_test"],
["crypto/bn/bn_test", "crypto/bn/bn_tests.txt"],