1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25 #ifndef ATAP_UNITTEST_UTIL_H_
26 #define ATAP_UNITTEST_UTIL_H_
27
28 #include <gtest/gtest.h>
29
30 namespace atap {
31
32 // These two functions are in atap_sysdeps_posix_testing.cc and is
33 // used for finding memory leaks.
34 void testing_memory_reset();
35 size_t testing_memory_all_freed();
36
37 // Base-class used for unit test.
38 class BaseAtapTest : public ::testing::Test {
39 public:
BaseAtapTest()40 BaseAtapTest() {}
41
42 protected:
~BaseAtapTest()43 virtual ~BaseAtapTest() {}
44
SetUp()45 virtual void SetUp() override {
46 // Reset memory leak tracing
47 atap::testing_memory_reset();
48 }
49
TearDown()50 virtual void TearDown() override {
51 // Ensure all memory has been freed.
52 EXPECT_TRUE(atap::testing_memory_all_freed());
53 }
54 };
55
56 const char kCaP256PrivateKey[] = "test/data/ca_p256_private.bin";
57 const char kCaX25519PrivateKey[] = "test/data/ca_x25519_private.bin";
58 const char kCaX25519PublicKey[] = "test/data/ca_x25519_public.bin";
59 const char kIssueP256OperationStartPath[] =
60 "test/data/issue_p256_operation_start.bin";
61 const char kIssueX25519InnerCaResponsePath[] =
62 "test/data/issue_x25519_inner_ca_response.bin";
63 const char kIssueX25519OperationStartPath[] =
64 "test/data/issue_x25519_operation_start.bin";
65 const char kProductIdHash[] = "test/data/product_id_hash.bin";
66
67 // Returns |buf| + |*index|, then increments |*index| by |value|. Used for
68 // validating the contents of a serialized structure.
next(const uint8_t * buf,uint32_t * index,uint32_t value)69 inline uint8_t* next(const uint8_t* buf, uint32_t* index, uint32_t value) {
70 uint8_t* retval = (uint8_t*)&buf[*index];
71 *index += value;
72 return retval;
73 }
74
75 } // namespace atap
76
77 #endif /* ATAP_UNITTEST_UTIL_H_ */
78