| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/nacl/nacl_validation_db.h" | 5 #include "chrome/nacl/nacl_validation_db.h" |
| 6 #include "chrome/nacl/nacl_validation_query.h" | 6 #include "chrome/nacl/nacl_validation_query.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 // This test makes sure that validation signature generation is performed | 9 // This test makes sure that validation signature generation is performed |
| 10 // correctly. In effect, this means that we are checking all of the data | 10 // correctly. In effect, this means that we are checking all of the data |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 "1234567890123456789012345678901234567890123456789012345678901234567890"; | 32 "1234567890123456789012345678901234567890123456789012345678901234567890"; |
| 33 | 33 |
| 34 class MockValidationDB : public NaClValidationDB { | 34 class MockValidationDB : public NaClValidationDB { |
| 35 public: | 35 public: |
| 36 MockValidationDB() | 36 MockValidationDB() |
| 37 : did_query_(false), | 37 : did_query_(false), |
| 38 did_set_(false), | 38 did_set_(false), |
| 39 status_(true) { | 39 status_(true) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool QueryKnownToValidate(const std::string& signature) { | 42 virtual bool QueryKnownToValidate(const std::string& signature) OVERRIDE { |
| 43 // The typecast is needed to work around gtest trying to take the address | 43 // The typecast is needed to work around gtest trying to take the address |
| 44 // of a constant. | 44 // of a constant. |
| 45 EXPECT_EQ((int) NaClValidationQuery::kDigestLength, | 45 EXPECT_EQ((int) NaClValidationQuery::kDigestLength, |
| 46 (int) signature.length()); | 46 (int) signature.length()); |
| 47 EXPECT_FALSE(did_query_); | 47 EXPECT_FALSE(did_query_); |
| 48 EXPECT_FALSE(did_set_); | 48 EXPECT_FALSE(did_set_); |
| 49 did_query_ = true; | 49 did_query_ = true; |
| 50 memcpy(query_signature_, signature.data(), | 50 memcpy(query_signature_, signature.data(), |
| 51 NaClValidationQuery::kDigestLength); | 51 NaClValidationQuery::kDigestLength); |
| 52 return status_; | 52 return status_; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void SetKnownToValidate(const std::string& signature) { | 55 virtual void SetKnownToValidate(const std::string& signature) OVERRIDE { |
| 56 // The typecast is needed to work around gtest trying to take the address | 56 // The typecast is needed to work around gtest trying to take the address |
| 57 // of a constant. | 57 // of a constant. |
| 58 ASSERT_EQ((int) NaClValidationQuery::kDigestLength, | 58 ASSERT_EQ((int) NaClValidationQuery::kDigestLength, |
| 59 (int) signature.length()); | 59 (int) signature.length()); |
| 60 EXPECT_TRUE(did_query_); | 60 EXPECT_TRUE(did_query_); |
| 61 EXPECT_FALSE(did_set_); | 61 EXPECT_FALSE(did_set_); |
| 62 did_set_ = true; | 62 did_set_ = true; |
| 63 memcpy(set_signature_, signature.data(), | 63 memcpy(set_signature_, signature.data(), |
| 64 NaClValidationQuery::kDigestLength); | 64 NaClValidationQuery::kDigestLength); |
| 65 // Signatures should be the same. | 65 // Signatures should be the same. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 86 scoped_ptr<MockValidationDB> db; | 86 scoped_ptr<MockValidationDB> db; |
| 87 scoped_ptr<NaClValidationQueryContext> context; | 87 scoped_ptr<NaClValidationQueryContext> context; |
| 88 scoped_ptr<NaClValidationQuery> query; | 88 scoped_ptr<NaClValidationQuery> query; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 class NaClValidationQueryTest : public ::testing::Test { | 91 class NaClValidationQueryTest : public ::testing::Test { |
| 92 protected: | 92 protected: |
| 93 scoped_ptr<TestQuery> query1; | 93 scoped_ptr<TestQuery> query1; |
| 94 scoped_ptr<TestQuery> query2; | 94 scoped_ptr<TestQuery> query2; |
| 95 | 95 |
| 96 void SetUp() { | 96 virtual void SetUp() { |
| 97 query1.reset(new TestQuery(kKey, kVersion)); | 97 query1.reset(new TestQuery(kKey, kVersion)); |
| 98 query2.reset(new TestQuery(kKey, kVersion)); | 98 query2.reset(new TestQuery(kKey, kVersion)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void AssertQuerySame() { | 101 void AssertQuerySame() { |
| 102 ASSERT_TRUE(query1->db->did_query_); | 102 ASSERT_TRUE(query1->db->did_query_); |
| 103 ASSERT_TRUE(query2->db->did_query_); | 103 ASSERT_TRUE(query2->db->did_query_); |
| 104 ASSERT_EQ(0, memcmp(query1->db->query_signature_, | 104 ASSERT_EQ(0, memcmp(query1->db->query_signature_, |
| 105 query2->db->query_signature_, | 105 query2->db->query_signature_, |
| 106 NaClValidationQuery::kDigestLength)); | 106 NaClValidationQuery::kDigestLength)); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 query1->query->AddData(kShortData, sizeof(kShortData)); | 267 query1->query->AddData(kShortData, sizeof(kShortData)); |
| 268 query1->query->QueryKnownToValidate(); | 268 query1->query->QueryKnownToValidate(); |
| 269 | 269 |
| 270 query2->query->AddData(kShortData, sizeof(kShortData)); | 270 query2->query->AddData(kShortData, sizeof(kShortData)); |
| 271 query2->query->QueryKnownToValidate(); | 271 query2->query->QueryKnownToValidate(); |
| 272 | 272 |
| 273 AssertQueryDifferent(); | 273 AssertQueryDifferent(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 } | 276 } |
| OLD | NEW |