Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1381)

Unified Diff: mojo/edk/system/options_validation_unittest.cc

Issue 623883002: Revert "Move mojo edk into mojo/edk" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/options_validation.h ('k') | mojo/edk/system/platform_handle_dispatcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/options_validation_unittest.cc
diff --git a/mojo/edk/system/options_validation_unittest.cc b/mojo/edk/system/options_validation_unittest.cc
deleted file mode 100644
index f410f24070c8eb580d83c9fd207264bddb8f5091..0000000000000000000000000000000000000000
--- a/mojo/edk/system/options_validation_unittest.cc
+++ /dev/null
@@ -1,130 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/edk/system/options_validation.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "mojo/public/c/system/macros.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace system {
-namespace {
-
-// Declare a test options struct just as we do in actual public headers.
-
-typedef uint32_t TestOptionsFlags;
-
-MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment);
-struct MOJO_ALIGNAS(8) TestOptions {
- uint32_t struct_size;
- TestOptionsFlags flags;
- uint32_t member1;
- uint32_t member2;
-};
-MOJO_COMPILE_ASSERT(sizeof(TestOptions) == 16, TestOptions_has_wrong_size);
-
-const uint32_t kSizeOfTestOptions = static_cast<uint32_t>(sizeof(TestOptions));
-
-TEST(OptionsValidationTest, Valid) {
- {
- const TestOptions kOptions = {kSizeOfTestOptions};
- UserOptionsReader<TestOptions> reader(MakeUserPointer(&kOptions));
- EXPECT_TRUE(reader.is_valid());
- EXPECT_TRUE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, flags, reader));
- EXPECT_TRUE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, member1, reader));
- EXPECT_TRUE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, member2, reader));
- }
- {
- const TestOptions kOptions = {static_cast<uint32_t>(
- offsetof(TestOptions, struct_size) + sizeof(uint32_t))};
- UserOptionsReader<TestOptions> reader(MakeUserPointer(&kOptions));
- EXPECT_TRUE(reader.is_valid());
- EXPECT_FALSE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, flags, reader));
- EXPECT_FALSE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, member1, reader));
- EXPECT_FALSE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, member2, reader));
- }
-
- {
- const TestOptions kOptions = {
- static_cast<uint32_t>(offsetof(TestOptions, flags) + sizeof(uint32_t))};
- UserOptionsReader<TestOptions> reader(MakeUserPointer(&kOptions));
- EXPECT_TRUE(reader.is_valid());
- EXPECT_TRUE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, flags, reader));
- EXPECT_FALSE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, member1, reader));
- EXPECT_FALSE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, member2, reader));
- }
- {
- MOJO_ALIGNAS(8) char buf[sizeof(TestOptions) + 100] = {};
- TestOptions* options = reinterpret_cast<TestOptions*>(buf);
- options->struct_size = kSizeOfTestOptions + 1;
- UserOptionsReader<TestOptions> reader(MakeUserPointer(options));
- EXPECT_TRUE(reader.is_valid());
- EXPECT_TRUE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, flags, reader));
- EXPECT_TRUE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, member1, reader));
- EXPECT_TRUE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, member2, reader));
- }
- {
- MOJO_ALIGNAS(8) char buf[sizeof(TestOptions) + 100] = {};
- TestOptions* options = reinterpret_cast<TestOptions*>(buf);
- options->struct_size = kSizeOfTestOptions + 4;
- UserOptionsReader<TestOptions> reader(MakeUserPointer(options));
- EXPECT_TRUE(reader.is_valid());
- EXPECT_TRUE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, flags, reader));
- EXPECT_TRUE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, member1, reader));
- EXPECT_TRUE(OPTIONS_STRUCT_HAS_MEMBER(TestOptions, member2, reader));
- }
-}
-
-TEST(OptionsValidationTest, Invalid) {
- // Size too small:
- for (size_t i = 0; i < sizeof(uint32_t); i++) {
- TestOptions options = {static_cast<uint32_t>(i)};
- UserOptionsReader<TestOptions> reader(MakeUserPointer(&options));
- EXPECT_FALSE(reader.is_valid()) << i;
- }
-}
-
-// These test invalid arguments that should cause death if we're being paranoid
-// about checking arguments (which we would want to do if, e.g., we were in a
-// true "kernel" situation, but we might not want to do otherwise for
-// performance reasons). Probably blatant errors like passing in null pointers
-// (for required pointer arguments) will still cause death, but perhaps not
-// predictably.
-TEST(OptionsValidationTest, InvalidDeath) {
- const char kMemoryCheckFailedRegex[] = "Check failed";
-
- // Null:
- EXPECT_DEATH_IF_SUPPORTED(
- { UserOptionsReader<TestOptions> reader((NullUserPointer())); },
- kMemoryCheckFailedRegex);
-
- // Unaligned:
- EXPECT_DEATH_IF_SUPPORTED(
- {
- UserOptionsReader<TestOptions> reader(
- MakeUserPointer(reinterpret_cast<const TestOptions*>(1)));
- },
- kMemoryCheckFailedRegex);
- // Note: The current implementation checks the size only after checking the
- // alignment versus that required for the |uint32_t| size, so it won't die in
- // the expected way if you pass, e.g., 4. So we have to manufacture a valid
- // pointer at an offset of alignment 4.
- EXPECT_DEATH_IF_SUPPORTED(
- {
- uint32_t buffer[100] = {};
- TestOptions* options = (reinterpret_cast<uintptr_t>(buffer) % 8 == 0)
- ? reinterpret_cast<TestOptions*>(&buffer[1])
- : reinterpret_cast<TestOptions*>(&buffer[0]);
- options->struct_size = static_cast<uint32_t>(sizeof(TestOptions));
- UserOptionsReader<TestOptions> reader(MakeUserPointer(options));
- },
- kMemoryCheckFailedRegex);
-}
-
-} // namespace
-} // namespace system
-} // namespace mojo
« no previous file with comments | « mojo/edk/system/options_validation.h ('k') | mojo/edk/system/platform_handle_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698