Merge "tests: Replace the O_RDONLY in access(2)." am: 3b9645288e

am: baf422229d

Change-Id: I444696a344f8b37b852469e36b7cc6a925c9fc80
This commit is contained in:
Tao Bao
2016-12-22 17:28:33 +00:00
committed by android-build-merger
2 changed files with 16 additions and 8 deletions
+1 -2
View File
@@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
#include <fcntl.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
@@ -79,7 +78,7 @@ TEST(recovery, persist) {
std::string buf; std::string buf;
EXPECT_TRUE(android::base::ReadFileToString(myFilename, &buf)); EXPECT_TRUE(android::base::ReadFileToString(myFilename, &buf));
EXPECT_EQ(myContent, buf); EXPECT_EQ(myContent, buf);
if (access(myFilename.c_str(), O_RDONLY) == 0) { if (access(myFilename.c_str(), F_OK) == 0) {
fprintf(stderr, "Removing persistent test data, " fprintf(stderr, "Removing persistent test data, "
"check if reconstructed on reboot\n"); "check if reconstructed on reboot\n");
} }
+15 -6
View File
@@ -15,7 +15,6 @@
*/ */
#include <errno.h> #include <errno.h>
#include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <memory> #include <memory>
@@ -42,10 +41,10 @@ TEST(ZipTest, ExtractPackageRecursive) {
// Make sure all the files are extracted correctly. // Make sure all the files are extracted correctly.
std::string path(td.path); std::string path(td.path);
ASSERT_EQ(0, access((path + "/a.txt").c_str(), O_RDONLY)); ASSERT_EQ(0, access((path + "/a.txt").c_str(), F_OK));
ASSERT_EQ(0, access((path + "/b.txt").c_str(), O_RDONLY)); ASSERT_EQ(0, access((path + "/b.txt").c_str(), F_OK));
ASSERT_EQ(0, access((path + "/b/c.txt").c_str(), O_RDONLY)); ASSERT_EQ(0, access((path + "/b/c.txt").c_str(), F_OK));
ASSERT_EQ(0, access((path + "/b/d.txt").c_str(), O_RDONLY)); ASSERT_EQ(0, access((path + "/b/d.txt").c_str(), F_OK));
// The content of the file is the same as expected. // The content of the file is the same as expected.
std::string content1; std::string content1;
@@ -54,7 +53,16 @@ TEST(ZipTest, ExtractPackageRecursive) {
std::string content2; std::string content2;
ASSERT_TRUE(android::base::ReadFileToString(path + "/b/d.txt", &content2)); ASSERT_TRUE(android::base::ReadFileToString(path + "/b/d.txt", &content2));
ASSERT_EQ(kBTxtContents, content2); ASSERT_EQ(kDTxtContents, content2);
CloseArchive(handle);
// Clean up.
ASSERT_EQ(0, unlink((path + "/a.txt").c_str()));
ASSERT_EQ(0, unlink((path + "/b.txt").c_str()));
ASSERT_EQ(0, unlink((path + "/b/c.txt").c_str()));
ASSERT_EQ(0, unlink((path + "/b/d.txt").c_str()));
ASSERT_EQ(0, rmdir((path + "/b").c_str()));
} }
TEST(ZipTest, OpenFromMemory) { TEST(ZipTest, OpenFromMemory) {
@@ -76,6 +84,7 @@ TEST(ZipTest, OpenFromMemory) {
ASSERT_NE(-1, tmp_binary.fd); ASSERT_NE(-1, tmp_binary.fd);
ASSERT_EQ(0, ExtractEntryToFile(handle, &binary_entry, tmp_binary.fd)); ASSERT_EQ(0, ExtractEntryToFile(handle, &binary_entry, tmp_binary.fd));
CloseArchive(handle);
sysReleaseMap(&map); sysReleaseMap(&map);
} }