Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "LMS1xx/lms_buffer.h"
00024 #include "gtest/gtest.h"
00025
00026 #include <errno.h>
00027 #include <unistd.h>
00028
00029
00030 class BufferTest : public :: testing :: Test
00031 {
00032 virtual void SetUp()
00033 {
00034 ASSERT_NE(-1, pipe(fds_));
00035 ASSERT_NE(0, fds_[0]);
00036 ASSERT_NE(0, fds_[1]);
00037 }
00038
00039 virtual void TearDown()
00040 {
00041 close(fds_[0]);
00042 close(fds_[1]);
00043 }
00044
00045 protected:
00046 LMSBuffer buf_;
00047 int fds_[2];
00048 };
00049
00050
00051 TEST_F(BufferTest, single)
00052 {
00053 ASSERT_NE(-1, write(fds_[1], "\x02ghij\x03", 6)) << "Error code: " << errno;
00054 buf_.readFrom(fds_[0]);
00055
00056
00057 ASSERT_STREQ("\x02ghij", buf_.getNextBuffer());
00058 }
00059
00060 TEST_F(BufferTest, split)
00061 {
00062 ASSERT_NE(-1, write(fds_[1], "\x02ghij", 5)) << "Error code: " << errno;
00063 buf_.readFrom(fds_[0]);
00064 EXPECT_EQ(NULL, buf_.getNextBuffer());
00065
00066 ASSERT_NE(-1, write(fds_[1], "abcde", 5)) << "Error code: " << errno;
00067 buf_.readFrom(fds_[0]);
00068 EXPECT_EQ(NULL, buf_.getNextBuffer());
00069
00070 ASSERT_NE(-1, write(fds_[1], "fghijk\x03", 7)) << "Error code: " << errno;
00071 buf_.readFrom(fds_[0]);
00072 EXPECT_STREQ("\x02ghijabcdefghijk", buf_.getNextBuffer());
00073 }
00074
00075 TEST_F(BufferTest, extra_bytes)
00076 {
00077 ASSERT_NE(-1, write(fds_[1], "abc\x02ghijk\x03stuv", 14)) << "Error code: " << errno;
00078 buf_.readFrom(fds_[0]);
00079 EXPECT_STREQ("\x02ghijk", buf_.getNextBuffer());
00080 buf_.popLastBuffer();
00081
00082 ASSERT_NE(-1, write(fds_[1], "abc\x02ghjk\x03stuv", 14)) << "Error code: " << errno;
00083 buf_.readFrom(fds_[0]);
00084 EXPECT_STREQ("\x02ghjk", buf_.getNextBuffer());
00085 }
00086
00087 TEST_F(BufferTest, multiple)
00088 {
00089 ASSERT_NE(-1, write(fds_[1], "\x02gh\x03\x02jk\x03xyz\x02ty\x03", 15)) << "Error code: " << errno;
00090 buf_.readFrom(fds_[0]);
00091
00092 EXPECT_STREQ("\x02gh", buf_.getNextBuffer());
00093 buf_.popLastBuffer();
00094 EXPECT_STREQ("\x02jk", buf_.getNextBuffer());
00095 buf_.popLastBuffer();
00096 EXPECT_STREQ("\x02ty", buf_.getNextBuffer());
00097 buf_.popLastBuffer();
00098 }
00099
00100 int main(int argc, char **argv)
00101 {
00102 testing::InitGoogleTest(&argc, argv);
00103 return RUN_ALL_TESTS();
00104 }