brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 4a5965e Raw
121 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <sstream>10 11// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >12// class basic_istringstream13 14// explicit basic_istringstream(const basic_string<charT,traits,allocator>& str,15//                              ios_base::openmode which = ios_base::in);16 17#include <sstream>18#include <cassert>19 20#include "test_macros.h"21#include "operator_hijacker.h"22 23int main(int, char**)24{25    {26        std::istringstream ss(" 123 456");27        assert(ss.rdbuf() != nullptr);28        assert(ss.good());29        assert(ss.str() == " 123 456");30        int i = 0;31        ss >> i;32        assert(i == 123);33        ss >> i;34        assert(i == 456);35    }36    {37      std::basic_istringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(" 123 456");38      assert(ss.rdbuf() != nullptr);39      assert(ss.good());40      assert(ss.str() == " 123 456");41      int i = 0;42      ss >> i;43      assert(i == 123);44      ss >> i;45      assert(i == 456);46    }47    {48        std::istringstream ss(" 123 456", std::ios_base::out);49        assert(ss.rdbuf() != nullptr);50        assert(ss.good());51        assert(ss.str() == " 123 456");52        int i = 0;53        ss >> i;54        assert(i == 123);55        ss >> i;56        assert(i == 456);57    }58    {59      std::basic_istringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(60          " 123 456", std::ios_base::out);61      assert(ss.rdbuf() != nullptr);62      assert(ss.good());63      assert(ss.str() == " 123 456");64      int i = 0;65      ss >> i;66      assert(i == 123);67      ss >> i;68      assert(i == 456);69    }70#ifndef TEST_HAS_NO_WIDE_CHARACTERS71    {72        std::wistringstream ss(L" 123 456");73        assert(ss.rdbuf() != nullptr);74        assert(ss.good());75        assert(ss.str() == L" 123 456");76        int i = 0;77        ss >> i;78        assert(i == 123);79        ss >> i;80        assert(i == 456);81    }82    {83      std::basic_istringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss(84          L" 123 456");85      assert(ss.rdbuf() != nullptr);86      assert(ss.good());87      assert(ss.str() == L" 123 456");88      int i = 0;89      ss >> i;90      assert(i == 123);91      ss >> i;92      assert(i == 456);93    }94    {95        std::wistringstream ss(L" 123 456", std::ios_base::out);96        assert(ss.rdbuf() != nullptr);97        assert(ss.good());98        assert(ss.str() == L" 123 456");99        int i = 0;100        ss >> i;101        assert(i == 123);102        ss >> i;103        assert(i == 456);104    }105    {106      std::basic_istringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss(107          L" 123 456", std::ios_base::out);108      assert(ss.rdbuf() != nullptr);109      assert(ss.good());110      assert(ss.str() == L" 123 456");111      int i = 0;112      ss >> i;113      assert(i == 123);114      ss >> i;115      assert(i == 456);116    }117#endif118 119  return 0;120}121