1 /* -*- c++ -*- */
2 /*
3 * Copyright (C) 2010 The Android Open Source Project
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #include "../include/streambuf"
31 #ifndef ANDROID_ASTL_STREAMBUF__
32 #error "Wrong header included!!"
33 #endif
34 #include "common.h"
35
36 #include <char_traits.h>
37
38 namespace android {
39 using std::char_traits;
40
41 class streambuf: public std::streambuf {
42 public:
streambuf()43 streambuf() {
44 setp(mBuffer, mBuffer + sizeof(mBuffer));
45 traits_type::assign(mBuffer, sizeof(mBuffer), 'X');
46 }
47
48 char mBuffer[5];
49 };
50
testSputc()51 bool testSputc() {
52 streambuf buf;
53
54 EXPECT_TRUE(buf.sputc('A') == 65);
55 EXPECT_TRUE(buf.sputc('B') == 66);
56 EXPECT_TRUE(buf.sputc('C') == 67);
57 EXPECT_TRUE(buf.sputc('D') == 68);
58 EXPECT_TRUE(buf.sputc('E') == 69);
59 // TODO: The sputc implementation has been changed to use
60 // sputn. This is non standard so disabling the tests below for
61 // now.
62 // EXPECT_TRUE(buf.sputc('F') == char_traits<char>::eof());
63 // EXPECT_TRUE(buf.sputc('G') == char_traits<char>::eof());
64 return true;
65 }
66
testSputn()67 bool testSputn() {
68 streambuf buf;
69
70 EXPECT_TRUE(buf.sputn("ABCDE", 5) == 5);
71 EXPECT_TRUE(buf.sputn("F", 1) == 0);
72 return true;
73 }
74
75 } // namespace android
76
main(int argc,char ** argv)77 int main(int argc, char **argv){
78 FAIL_UNLESS(testSputc);
79 FAIL_UNLESS(testSputn);
80 return kPassed;
81 }
82