test_ios_pos_types.cpp revision 5abe6dfaae971d3c0d1c8e3349b0d2b2ae83cc97
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/ios_pos_types.h" 31#ifndef ANDROID_ASTL_IOS_POS_TYPES__ 32#error "Wrong header included!!" 33#endif 34#include "common.h" 35 36#include <limits> 37 38namespace android { 39using std::fpos; 40using std::streamoff; 41 42bool testConstructor() { 43 { 44 fpos p; 45 46 EXPECT_TRUE(streamoff(p) == 0); 47 } 48 { 49 fpos p(1000); 50 51 EXPECT_TRUE(streamoff(p) == 1000); 52 } 53 return true; 54} 55 56bool testComparator() { 57 { 58 fpos p1(100); 59 fpos p2(100); 60 61 EXPECT_TRUE(p1 == p2); 62 EXPECT_FALSE(p1 != p2); 63 } 64 { 65 fpos p1(100); 66 fpos p2(200); 67 68 EXPECT_TRUE(p1 != p2); 69 EXPECT_FALSE(p1 == p2); 70 } 71 return true; 72} 73 74bool testIncrDecr() { 75 fpos p(100); 76 77 p += 0; 78 EXPECT_TRUE(streamoff(p) == 100); 79 80 p -= 0; 81 EXPECT_TRUE(streamoff(p) == 100); 82 83 p += 100; 84 EXPECT_TRUE(streamoff(p) == 200); 85 86 // overflow -> nop 87 p += std::numeric_limits<long long>::max(); 88 EXPECT_TRUE(streamoff(p) == 200); 89 90 p -= 1000; 91 EXPECT_TRUE(streamoff(p) == -800); 92 93 // overflow -> nop 94 p -= std::numeric_limits<long long>::min(); 95 EXPECT_TRUE(streamoff(p) == -800); 96 97 return true; 98} 99 100 101} // namespace android 102 103int main(int argc, char **argv){ 104 FAIL_UNLESS(testConstructor); 105 FAIL_UNLESS(testComparator); 106 FAIL_UNLESS(testIncrDecr); 107 return kPassed; 108} 109