summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-01-22 15:13:38 -0800
committerElliott Hughes <enh@google.com>2015-01-22 15:28:48 -0800
commit0ed7e08cda2547fa6b23813035a7b34a8889d163 (patch)
tree6e1bfc95b4fbe1129232b08bd44f72ab631ae5f9 /tests
parentd5d9221b9c96a8213b0a83dde468653d49e76dd8 (diff)
downloadbionic-0ed7e08cda2547fa6b23813035a7b34a8889d163.zip
bionic-0ed7e08cda2547fa6b23813035a7b34a8889d163.tar.gz
bionic-0ed7e08cda2547fa6b23813035a7b34a8889d163.tar.bz2
Fix the stdio.fread_EOF test.
Another sizeof/strlen screwup caused by trying to be too clever. Use std::string instead. Also fix all the ASSERT_STREQ calls in this file that had the arguments the right^Wwrong way round. If I ever see Kent Beck... Change-Id: I47a1bdfee99cf4e7bed9b398f3158a308fbcf1e8
Diffstat (limited to 'tests')
-rw-r--r--tests/stdio_test.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index d32d0b8..0e24325 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -107,7 +107,7 @@ TEST(stdio, getdelim) {
ASSERT_FALSE(feof(fp));
ASSERT_EQ(getdelim(&word_read, &allocated_length, ' ', fp), static_cast<int>(strlen(expected[i])));
ASSERT_GE(allocated_length, strlen(expected[i]));
- ASSERT_STREQ(word_read, expected[i]);
+ ASSERT_STREQ(expected[i], word_read);
}
// The last read should have set the end-of-file indicator for the stream.
ASSERT_TRUE(feof(fp));
@@ -171,7 +171,7 @@ TEST(stdio, getline) {
while ((read_char_count = getline(&line_read, &allocated_length, fp)) != -1) {
ASSERT_EQ(read_char_count, static_cast<int>(strlen(line_written)));
ASSERT_GE(allocated_length, strlen(line_written));
- ASSERT_STREQ(line_read, line_written);
+ ASSERT_STREQ(line_written, line_read);
++read_line_count;
}
ASSERT_EQ(read_line_count, line_count);
@@ -890,22 +890,23 @@ TEST(stdio, fread_unbuffered_pathological_performance) {
}
TEST(stdio, fread_EOF) {
- const char* digits = "0123456789";
- FILE* fp = fmemopen((char*) digits, sizeof(digits), "r");
+ std::string digits("0123456789");
+ FILE* fp = fmemopen(&digits[0], digits.size(), "r");
// Try to read too much, but little enough that it still fits in the FILE's internal buffer.
char buf1[4 * 4];
memset(buf1, 0, sizeof(buf1));
ASSERT_EQ(2U, fread(buf1, 4, 4, fp));
- ASSERT_STREQ(buf1, "01234567");
+ ASSERT_STREQ("0123456789", buf1);
ASSERT_TRUE(feof(fp));
rewind(fp);
- char buf2[4 * 4];
+ // Try to read way too much so stdio tries to read more direct from the stream.
+ char buf2[4 * 4096];
memset(buf2, 0, sizeof(buf2));
ASSERT_EQ(2U, fread(buf2, 4, 4096, fp));
- ASSERT_STREQ(buf2, "01234567");
+ ASSERT_STREQ("0123456789", buf2);
ASSERT_TRUE(feof(fp));
fclose(fp);