PM: Changes in unit tests.
* Adds macros for checking null-ness of pointers in tests. This makes it
safer and less error-prone: gtest seems to be inconsistent in its
treatment of pointer values, so having our own wrappers and making
them perform uniformly is good.
* Regulates the use of ASSERT vs EXPECT in unit tests: the former must
be used if subsequent test logic depends on the condition tested (for
example, a pointer being dereferenced later is not null, or a provider
module initialized correctly). The latter will fail the test but would
allow it to keep executing (aka non-critical failure).
* General revision of existing unit test code. Minor changes in
random_provider.h.
BUG=None
TEST=Builds and passes unit tests.
Change-Id: I2ada0fbd96db4cb0c0d631c2e350873853116fc2
Reviewed-on: https://chromium-review.googlesource.com/184449
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/policy_manager/pmtest_utils.h b/policy_manager/pmtest_utils.h
new file mode 100644
index 0000000..6adfec4
--- /dev/null
+++ b/policy_manager/pmtest_utils.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_PMTEST_UTILS_H
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_PMTEST_UTILS_H
+
+// Convenience macros for checking null-ness of pointers.
+//
+// Purportedly, gtest should support pointer comparison when the first argument
+// is a pointer (e.g. NULL). It is therefore appropriate to use
+// {ASSERT,EXPECT}_{EQ,NE} for our purposes. However, gtest fails to realize
+// that NULL is a pointer when used with the _NE variants, unless we explicitly
+// cast it to a pointer type, and so we inject this casting.
+//
+// Note that checking nullness of the content of a scoped_ptr requires getting
+// the inner pointer value via get().
+#define PMTEST_ASSERT_NULL(p) ASSERT_EQ(NULL, p)
+#define PMTEST_ASSERT_NOT_NULL(p) ASSERT_NE(reinterpret_cast<void*>(NULL), p)
+#define PMTEST_EXPECT_NULL(p) EXPECT_EQ(NULL, p)
+#define PMTEST_EXPECT_NOT_NULL(p) EXPECT_NE(reinterpret_cast<void*>(NULL), p)
+
+#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_PMTEST_UTILS_H