From 03e65eb03bf0bfaafa797daf91e80e8308968db3 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 26 Jan 2016 14:13:04 -0800 Subject: Implement funopen64. Bug: http://b/24807045 Change-Id: I161920978161389be34b707cc6ce8e05f760d552 --- tests/stdio_test.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/stdio_test.cpp') diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 89bf04a8e..7f412c13c 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -1091,6 +1091,41 @@ TEST(STDIO_TEST, fseek_ftell_unseekable) { ASSERT_EQ(ESPIPE, errno); fclose(fp); +#else + GTEST_LOG_(INFO) << "glibc uses fopencookie instead.\n"; +#endif +} + +TEST(STDIO_TEST, funopen_EINVAL) { +#if defined(__BIONIC__) + errno = 0; + ASSERT_EQ(nullptr, funopen(nullptr, nullptr, nullptr, nullptr, nullptr)); + ASSERT_EQ(EINVAL, errno); +#else + GTEST_LOG_(INFO) << "glibc uses fopencookie instead.\n"; +#endif +} + +TEST(STDIO_TEST, funopen_seek) { +#if defined(__BIONIC__) + auto read_fn = [](void*, char*, int) { return -1; }; + + auto seek_fn = [](void*, fpos_t, int) -> fpos_t { return 0xfedcba12; }; + auto seek64_fn = [](void*, fpos64_t, int) -> fpos64_t { return 0xfedcba12345678; }; + + FILE* fp = funopen(nullptr, read_fn, nullptr, seek_fn, nullptr); + ASSERT_TRUE(fp != nullptr); + fpos_t pos; + ASSERT_EQ(0, fgetpos(fp, &pos)); + ASSERT_EQ(0xfedcba12LL, pos); + + FILE* fp64 = funopen64(nullptr, read_fn, nullptr, seek64_fn, nullptr); + ASSERT_TRUE(fp64 != nullptr); + fpos64_t pos64; + ASSERT_EQ(0, fgetpos64(fp64, &pos64)); + ASSERT_EQ(0xfedcba12345678, pos64); +#else + GTEST_LOG_(INFO) << "glibc uses fopencookie instead.\n"; #endif } -- cgit v1.2.3