aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dirent_test.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2014-11-06 19:55:09 -0800
committerYabin Cui <yabinc@google.com>2014-11-07 10:20:32 -0800
commit5ca4a9e2da46db30ad6d8556b61679d138aaf88d (patch)
treefe013b8b41e1eb1388c5f76931f6f1c24331f905 /tests/dirent_test.cpp
parent9df70403d95f5cfe6824e38a9a6c35f9b9bbc76a (diff)
downloadandroid_bionic-5ca4a9e2da46db30ad6d8556b61679d138aaf88d.tar.gz
android_bionic-5ca4a9e2da46db30ad6d8556b61679d138aaf88d.tar.bz2
android_bionic-5ca4a9e2da46db30ad6d8556b61679d138aaf88d.zip
implement missing seekdir and telldir
Bug: 18266863 Change-Id: I189ee949d4f7ccee099f3341e349cd969d25480f
Diffstat (limited to 'tests/dirent_test.cpp')
-rw-r--r--tests/dirent_test.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/dirent_test.cpp b/tests/dirent_test.cpp
index 6aadb3768..214dd78c8 100644
--- a/tests/dirent_test.cpp
+++ b/tests/dirent_test.cpp
@@ -231,3 +231,50 @@ TEST(dirent, rewinddir) {
ASSERT_EQ(pass1[i], pass2[i]);
}
}
+
+TEST(dirent, seekdir_telldir) {
+ DIR* d = opendir("/proc/self");
+ ASSERT_TRUE(d != NULL);
+ std::vector<long> offset_list;
+ std::vector<std::string> name_list;
+ dirent* e = NULL;
+
+ offset_list.push_back(telldir(d));
+ ASSERT_EQ(0L, offset_list.back());
+
+ while ((e = readdir(d)) != NULL) {
+ name_list.push_back(e->d_name);
+ offset_list.push_back(telldir(d));
+ // Make sure telldir() point to the next entry.
+ ASSERT_EQ(e->d_off, offset_list.back());
+ }
+
+ long end_offset = telldir(d);
+ // telldir() should not pass the end of the file.
+ ASSERT_EQ(offset_list.back(), end_offset);
+ offset_list.pop_back();
+
+ for (size_t i = 0; i < offset_list.size(); ++i) {
+ seekdir(d, offset_list[i]);
+ ASSERT_EQ(offset_list[i], telldir(d));
+ e = readdir(d);
+ ASSERT_TRUE(e != NULL);
+ ASSERT_STREQ(name_list[i].c_str(), e->d_name);
+ }
+ for (int i = static_cast<int>(offset_list.size()) - 1; i >= 0; --i) {
+ seekdir(d, offset_list[i]);
+ ASSERT_EQ(offset_list[i], telldir(d));
+ e = readdir(d);
+ ASSERT_TRUE(e != NULL);
+ ASSERT_STREQ(name_list[i].c_str(), e->d_name);
+ }
+
+ // Seek to the end, read NULL.
+ seekdir(d, end_offset);
+ ASSERT_EQ(end_offset, telldir(d));
+ errno = 0;
+ ASSERT_EQ(NULL, readdir(d));
+ ASSERT_EQ(0, errno);
+
+ ASSERT_EQ(0, closedir(d));
+}