summaryrefslogtreecommitdiffstats
path: root/libutils/tests
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2015-03-13 22:39:54 -0700
committerDan Albert <danalbert@google.com>2015-03-14 16:36:18 -0700
commit98ff77204cef9bb8f0f27420833233622060a09e (patch)
tree54d1196083e2e4dc4b53353a2a77be6abd265066 /libutils/tests
parentf1c2ba490ef979b3d347f08535ab8b817e917e62 (diff)
downloadsystem_core-98ff77204cef9bb8f0f27420833233622060a09e.zip
system_core-98ff77204cef9bb8f0f27420833233622060a09e.tar.gz
system_core-98ff77204cef9bb8f0f27420833233622060a09e.tar.bz2
Create libbase.
Move StringPrintf and the string based file I/O from libutils to libbase. Change-Id: I0297a6063874b9d92100e0dd5123fddfbda932fe
Diffstat (limited to 'libutils/tests')
-rw-r--r--libutils/tests/Android.mk2
-rw-r--r--libutils/tests/file_test.cpp98
-rw-r--r--libutils/tests/stringprintf_test.cpp58
3 files changed, 0 insertions, 158 deletions
diff --git a/libutils/tests/Android.mk b/libutils/tests/Android.mk
index ce288ca..634f44f 100644
--- a/libutils/tests/Android.mk
+++ b/libutils/tests/Android.mk
@@ -26,11 +26,9 @@ LOCAL_SRC_FILES := \
BasicHashtable_test.cpp \
BlobCache_test.cpp \
BitSet_test.cpp \
- file_test.cpp \
Looper_test.cpp \
LruCache_test.cpp \
String8_test.cpp \
- stringprintf_test.cpp \
Unicode_test.cpp \
Vector_test.cpp \
diff --git a/libutils/tests/file_test.cpp b/libutils/tests/file_test.cpp
deleted file mode 100644
index cea18b6..0000000
--- a/libutils/tests/file_test.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2013 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 "utils/file.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <gtest/gtest.h>
-
-class TemporaryFile {
- public:
- TemporaryFile() {
- init("/data/local/tmp");
- if (fd == -1) {
- init("/tmp");
- }
- }
-
- ~TemporaryFile() {
- close(fd);
- unlink(filename);
- }
-
- int fd;
- char filename[1024];
-
- private:
- void init(const char* tmp_dir) {
- snprintf(filename, sizeof(filename), "%s/TemporaryFile-XXXXXX", tmp_dir);
- fd = mkstemp(filename);
- }
-};
-
-TEST(file, ReadFileToString_ENOENT) {
- std::string s("hello");
- errno = 0;
- ASSERT_FALSE(android::ReadFileToString("/proc/does-not-exist", &s));
- EXPECT_EQ(ENOENT, errno);
- EXPECT_EQ("", s); // s was cleared.
-}
-
-TEST(file, ReadFileToString_success) {
- std::string s("hello");
- ASSERT_TRUE(android::ReadFileToString("/proc/version", &s)) << errno;
- EXPECT_GT(s.length(), 6U);
- EXPECT_EQ('\n', s[s.length() - 1]);
- s[5] = 0;
- EXPECT_STREQ("Linux", s.c_str());
-}
-
-TEST(file, WriteStringToFile) {
- TemporaryFile tf;
- ASSERT_TRUE(tf.fd != -1);
- ASSERT_TRUE(android::WriteStringToFile("abc", tf.filename)) << errno;
- std::string s;
- ASSERT_TRUE(android::ReadFileToString(tf.filename, &s)) << errno;
- EXPECT_EQ("abc", s);
-}
-
-TEST(file, WriteStringToFile2) {
- TemporaryFile tf;
- ASSERT_TRUE(tf.fd != -1);
- ASSERT_TRUE(android::WriteStringToFile("abc", tf.filename, 0660, getuid(), getgid())) << errno;
- struct stat sb;
- ASSERT_EQ(0, stat(tf.filename, &sb));
- ASSERT_EQ(0660U, (sb.st_mode & ~S_IFMT));
- ASSERT_EQ(getuid(), sb.st_uid);
- ASSERT_EQ(getgid(), sb.st_gid);
- std::string s;
- ASSERT_TRUE(android::ReadFileToString(tf.filename, &s)) << errno;
- EXPECT_EQ("abc", s);
-}
-
-TEST(file, WriteStringToFd) {
- TemporaryFile tf;
- ASSERT_TRUE(tf.fd != -1);
- ASSERT_TRUE(android::WriteStringToFd("abc", tf.fd));
-
- ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET)) << errno;
-
- std::string s;
- ASSERT_TRUE(android::ReadFdToString(tf.fd, &s)) << errno;
- EXPECT_EQ("abc", s);
-}
diff --git a/libutils/tests/stringprintf_test.cpp b/libutils/tests/stringprintf_test.cpp
deleted file mode 100644
index f995452..0000000
--- a/libutils/tests/stringprintf_test.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2011 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 <utils/stringprintf.h>
-
-#include <gtest/gtest.h>
-
-TEST(StringPrintfTest, HexSizeT) {
- size_t size = 0x00107e59;
- EXPECT_EQ("00107e59", android::StringPrintf("%08zx", size));
- EXPECT_EQ("0x00107e59", android::StringPrintf("0x%08zx", size));
-}
-
-TEST(StringPrintfTest, StringAppendF) {
- std::string s("a");
- android::StringAppendF(&s, "b");
- EXPECT_EQ("ab", s);
-}
-
-TEST(StringPrintfTest, Errno) {
- errno = 123;
- android::StringPrintf("hello %s", "world");
- EXPECT_EQ(123, errno);
-}
-
-void TestN(size_t n) {
- char* buf = new char[n + 1];
- memset(buf, 'x', n);
- buf[n] = '\0';
- std::string s(android::StringPrintf("%s", buf));
- EXPECT_EQ(buf, s);
- delete[] buf;
-}
-
-TEST(StringPrintfTest, At1023) {
- TestN(1023);
-}
-
-TEST(StringPrintfTest, At1024) {
- TestN(1024);
-}
-
-TEST(StringPrintfTest, At1025) {
- TestN(1025);
-}