8#ifndef INCLUDED_BSLX_TESTINSTREAM
9#define INCLUDED_BSLX_TESTINSTREAM
375#include <bslscm_version.h>
386#include <bsl_cstddef.h>
387#include <bsl_iosfwd.h>
388#include <bsl_string.h>
389#include <bsl_vector.h>
411 const char *d_buffer;
413 bsl::size_t d_numBytes;
422 bsl::size_t d_cursor;
469 bsl::size_t numExpectedBytes);
477 void throwExceptionIfInputLimitExhausted(
const TypeCode::Enum& code);
546 void reset(
const char *buffer, bsl::size_t numBytes);
557 void seek(bsl::size_t offset);
1119 operator const void *()
const;
1122 bsl::size_t
cursor()
const;
1127 const char *
data()
const;
1152 bsl::size_t
length()
const;
1165template <
class TYPE>
1174#ifdef BDE_BUILD_TARGET_EXC
1183class TestInStream_ProxyBase {
1186 virtual ~TestInStream_ProxyBase()
1191 virtual void setInputLimit(
int limit)
const = 0;
1200template <
class BSLX_STREAM_TYPE>
1201class TestInStream_Proxy:
public TestInStream_ProxyBase {
1204 BSLX_STREAM_TYPE *d_stream_p;
1209 TestInStream_Proxy(BSLX_STREAM_TYPE *stream)
1210 : d_stream_p(stream)
1221 d_stream_p->setInputLimit(limit);
1227template <
class BSLX_STREAM_TYPE>
1229TestInStream_Proxy<BSLX_STREAM_TYPE>
1230TestInStream_getProxy(BSLX_STREAM_TYPE *stream)
1232 return TestInStream_Proxy<BSLX_STREAM_TYPE>(stream);
1237#ifndef BSLX_TESTINSTREAM_EXCEPTION_TEST_BEGIN
1238#define BSLX_TESTINSTREAM_EXCEPTION_TEST_BEGIN(BSLX_TESTINSTREAM) \
1240 const bslx::TestInStream_ProxyBase& testInStream = \
1241 bslx::TestInStream_getProxy(&BSLX_TESTINSTREAM); \
1243 static int firstTime = 1; \
1244 if (veryVerbose && firstTime) bsl::cout << \
1245 "### BSLX EXCEPTION TEST -- (ENABLED) --" << '\n'; \
1248 if (veryVeryVerbose) bsl::cout << \
1249 "### Begin BSLX exception test." << '\n'; \
1250 int bslxExceptionCounter = 0; \
1251 static int bslxExceptionLimit = 100; \
1252 testInStream.setInputLimit(bslxExceptionCounter); \
1259#ifndef BSLX_TESTINSTREAM_EXCEPTION_TEST_BEGIN
1260#define BSLX_TESTINSTREAM_EXCEPTION_TEST_BEGIN(testInStream) \
1262 static int firstTime = 1; \
1263 if (verbose && firstTime) { \
1264 bsl::cout << "### BSLX EXCEPTION TEST -- (NOT ENABLED) --" << '\n'; \
1276#ifdef BDE_BUILD_TARGET_EXC
1278#ifndef BSLX_TESTINSTREAM_EXCEPTION_TEST_END
1279#define BSLX_TESTINSTREAM_EXCEPTION_TEST_END \
1280 } catch (bslx::TestInStreamException& e) { \
1281 if ((veryVerbose && bslxExceptionLimit) || veryVeryVerbose) \
1283 --bslxExceptionLimit; \
1284 bsl::cout << "(" << bslxExceptionCounter << ')'; \
1285 if (veryVeryVerbose) { \
1286 bsl::cout << " BSLX EXCEPTION: " \
1287 << "input limit = " \
1288 << bslxExceptionCounter \
1290 << "last data type = " \
1293 else if (0 == bslxExceptionLimit) { \
1294 bsl::cout << " [ Note: 'bslxExceptionLimit' reached. ]"; \
1296 bsl::cout << '\n'; \
1298 testInStream.setInputLimit(++bslxExceptionCounter); \
1301 testInStream.setInputLimit(-1); \
1304 if (veryVeryVerbose) { \
1305 bsl::cout << "### End BSLX exception test." << '\n'; \
1312#ifndef BSLX_TESTINSTREAM_EXCEPTION_TEST_END
1313#define BSLX_TESTINSTREAM_EXCEPTION_TEST_END
1330void TestInStream::throwExceptionIfInputLimitExhausted(
1333#ifdef BDE_BUILD_TARGET_EXC
1334 if (0 <= d_inputLimit) {
1336 if (0 > d_inputLimit) {
1337 throw TestInStreamException(code);
1349 d_validFlag =
false;
1365 d_numBytes = numBytes;
1373 d_buffer = srcData.
data();
1374 d_numBytes = srcData.
length();
1391 d_inputLimit = limit;
1397 d_quietFlag = flagValue;
1402TestInStream::operator
const void *()
const
1404 return isValid() ? this : 0;
1416 return d_numBytes ? d_buffer : 0;
1422 return d_inputLimit;
1449template <
class TYPE>
Definition bslstl_string.h:1281
Definition bslstl_stringref.h:372
const CHAR_TYPE * data() const
Definition bslstl_stringref.h:936
size_type length() const
Definition bslstl_stringref.h:958
Definition bslx_testinstream.h:408
TestInStream(const bslstl::StringRef &srcData)
Create a test input stream containing the specified srcData.
TestInStream & getUint64(bsls::Types::Uint64 &variable)
void reset()
Definition bslx_testinstream.h:1353
TestInStream & getArrayFloat64(double *variables, int numVariables)
TestInStream & getInt56(bsls::Types::Int64 &variable)
TestInStream & getInt24(int &variable)
TestInStream & getArrayUint8(unsigned char *variables, int numVariables)
TestInStream & getArrayFloat32(float *variables, int numVariables)
friend bsl::ostream & operator<<(bsl::ostream &, const TestInStream &)
TestInStream & getLength(int &variable)
TestInStream & getArrayUint32(unsigned int *variables, int numVariables)
TestInStream & getArrayInt8(signed char *variables, int numVariables)
TestInStream & getString(bsl::string &variable)
bool isQuiet() const
Definition bslx_testinstream.h:1432
TestInStream & getFloat32(float &variable)
TestInStream & getArrayUint40(bsls::Types::Uint64 *variables, int numVariables)
TestInStream & getInt64(bsls::Types::Int64 &variable)
TestInStream & getUint16(unsigned short &variable)
TestInStream & getArrayUint8(char *variables, int numVariables)
void invalidate()
Definition bslx_testinstream.h:1347
bool isEmpty() const
Definition bslx_testinstream.h:1426
TestInStream(const char *buffer, bsl::size_t numBytes)
TestInStream & getArrayUint64(bsls::Types::Uint64 *variables, int numVariables)
TestInStream & getInt40(bsls::Types::Int64 &variable)
bsl::size_t length() const
Definition bslx_testinstream.h:1444
TestInStream & getInt48(bsls::Types::Int64 &variable)
TestInStream & getUint32(unsigned int &variable)
TestInStream & getArrayUint48(bsls::Types::Uint64 *variables, int numVariables)
TestInStream & getArrayUint56(bsls::Types::Uint64 *variables, int numVariables)
int inputLimit() const
Definition bslx_testinstream.h:1420
~TestInStream()
Destroy this test input stream.
TestInStream & getUint40(bsls::Types::Uint64 &variable)
TestInStream & getInt32(int &variable)
TestInStream & getVersion(int &variable)
TestInStream & getArrayInt16(short *variables, int numVariables)
TestInStream & getArrayInt56(bsls::Types::Int64 *variables, int numVariables)
TestInStream & getArrayInt32(int *variables, int numVariables)
TestInStream & getArrayInt48(bsls::Types::Int64 *variables, int numVariables)
TestInStream & getArrayInt8(char *variables, int numVariables)
TestInStream & getArrayInt40(bsls::Types::Int64 *variables, int numVariables)
TestInStream & getUint8(unsigned char &variable)
TestInStream & getArrayInt64(bsls::Types::Int64 *variables, int numVariables)
void seek(bsl::size_t offset)
Definition bslx_testinstream.h:1380
void setInputLimit(int limit)
Definition bslx_testinstream.h:1389
TestInStream & getArrayInt24(int *variables, int numVariables)
bool isValid() const
Definition bslx_testinstream.h:1438
const char * data() const
Definition bslx_testinstream.h:1414
TestInStream & getArrayUint16(unsigned short *variables, int numVariables)
bsl::size_t cursor() const
Return the index of the next byte to be extracted from this stream.
Definition bslx_testinstream.h:1408
TestInStream & getUint8(char &variable)
TestInStream & getUint56(bsls::Types::Uint64 &variable)
TestInStream & getInt16(short &variable)
TestInStream & getArrayUint24(unsigned int *variables, int numVariables)
TestInStream & getInt8(char &variable)
TestInStream & getUint48(bsls::Types::Uint64 &variable)
TestInStream & getFloat64(double &variable)
void setQuiet(bool flagValue)
Definition bslx_testinstream.h:1395
TestInStream & getUint24(unsigned int &variable)
TestInStream & getInt8(signed char &variable)
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
STREAM & bdexStreamIn(STREAM &stream, VALUE_TYPE &variable)
Definition bslx_instreamfunctions.h:1247
Definition bslx_byteinstream.h:377
bsl::ostream & operator<<(bsl::ostream &stream, const ByteInStream &object)
ByteInStream & operator>>(ByteInStream &stream, TYPE &value)
Definition bslx_byteinstream.h:1986
unsigned long long Uint64
Definition bsls_types.h:137
long long Int64
Definition bsls_types.h:132
Enum
Definition bslx_typecode.h:156