summaryrefslogtreecommitdiffstats
path: root/init/util_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-02-06 12:19:48 -0800
committerElliott Hughes <enh@google.com>2015-02-06 14:20:30 -0800
commitf682b4786a4093efb23bf80d69bf80eb274b145b (patch)
tree8af209a035867fd30720e6e6da1b8b581aab871d /init/util_test.cpp
parentd558530ba90cb6218fe8e255c71a034c3fe1ea58 (diff)
downloadsystem_core-f682b4786a4093efb23bf80d69bf80eb274b145b.zip
system_core-f682b4786a4093efb23bf80d69bf80eb274b145b.tar.gz
system_core-f682b4786a4093efb23bf80d69bf80eb274b145b.tar.bz2
Clean up reading and writing in init.
This isn't particularly useful in and of itself, but it does introduce the first (trivial) unit test, improves the documentation (including details about how to debug init crashes), and made me aware of how unpleasant the existing parser is. I also fixed a bug in passing --- unless you thought the "peboot" and "pm" commands were features... Bug: 19217569 Change-Id: I6ab76129a543ce3ed3dab52ef2c638009874c3de
Diffstat (limited to 'init/util_test.cpp')
-rw-r--r--init/util_test.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/init/util_test.cpp b/init/util_test.cpp
new file mode 100644
index 0000000..e9a1581
--- /dev/null
+++ b/init/util_test.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "util.h"
+
+#include <errno.h>
+#include <gtest/gtest.h>
+
+TEST(util, read_file_ENOENT) {
+ std::string s("hello");
+ errno = 0;
+ EXPECT_FALSE(read_file("/proc/does-not-exist", &s));
+ EXPECT_EQ(ENOENT, errno);
+ EXPECT_EQ("", s); // s was cleared.
+}
+
+TEST(util, read_file_success) {
+ std::string s("hello");
+ EXPECT_TRUE(read_file("/proc/version", &s));
+ EXPECT_GT(s.length(), 6U);
+ EXPECT_EQ('\n', s[s.length() - 1]);
+ s[5] = 0;
+ EXPECT_STREQ("Linux", s.c_str());
+}