diff options
author | Jack Lloyd <[email protected]> | 2017-06-04 05:27:34 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-06-04 05:27:34 -0400 |
commit | 35300742dc496a74c7a700259de7b1f400d782e7 (patch) | |
tree | 15c796d08f750f53ef6990213bf26917b8c2339f | |
parent | d6e7c9ea7f029026d84ce2828a26310dd9882679 (diff) |
Add basic test for TPM UUID class
Constify some member functions
-rw-r--r-- | src/lib/prov/tpm/uuid.h | 6 | ||||
-rw-r--r-- | src/tests/test_tpm.cpp | 29 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/lib/prov/tpm/uuid.h b/src/lib/prov/tpm/uuid.h index 0094f4f83..0cfe6a46f 100644 --- a/src/lib/prov/tpm/uuid.h +++ b/src/lib/prov/tpm/uuid.h @@ -86,14 +86,14 @@ class UUID return h; } - const std::vector<uint8_t> binary_value() const { return m_uuid; } + const std::vector<uint8_t>& binary_value() const { return m_uuid; } - bool operator==(const UUID& other) + bool operator==(const UUID& other) const { return m_uuid == other.m_uuid; } - bool operator!=(const UUID& other) { return !(*this == other); } + bool operator!=(const UUID& other) const { return !(*this == other); } bool is_valid() const { return m_uuid.size() == 16; } diff --git a/src/tests/test_tpm.cpp b/src/tests/test_tpm.cpp index 039dd2551..267af4e89 100644 --- a/src/tests/test_tpm.cpp +++ b/src/tests/test_tpm.cpp @@ -8,6 +8,7 @@ #if defined(BOTAN_HAS_TPM) #include <botan/tpm.h> + #include <botan/uuid.h> #endif namespace Botan_Tests { @@ -80,6 +81,34 @@ class TPM_Tests : public Test BOTAN_REGISTER_TEST("tpm", TPM_Tests); +class UUID_Tests : public Test + { + public: + std::vector<Test::Result> run() override + { + Test::Result result("UUID"); + + const Botan::UUID empty_uuid; + + result.test_eq("Uninitialized UUID not valid", empty_uuid.is_valid(), false); + + const Botan::UUID random_uuid(Test::rng()); + result.test_eq("Random UUID is valid", empty_uuid.is_valid(), false); + + const Botan::UUID binary_copy(random_uuid.binary_value()); + result.confirm("UUID copied by binary equals original", random_uuid == binary_copy); + + std::string uuid_str = random_uuid.to_string(); + + const Botan::UUID string_copy(random_uuid.to_string()); + result.confirm("UUID copied by string equals original", random_uuid == string_copy); + + return {result}; + } + }; + +BOTAN_REGISTER_TEST("tpm_uuid", UUID_Tests); + #endif } |