Skip to content

Commit c79274e

Browse files
authored
Merge pull request InsightSoftwareConsortium#5884 from hjmjohnson/convert-itkstdstreamstatesavetest-to-itkstdstreamstatesavegtest
ENH: Convert itkStdStreamStateSaveTest to itkStdStreamStateSaveGTest
2 parents 9bfc81b + 2336918 commit c79274e

2 files changed

Lines changed: 22 additions & 24 deletions

File tree

Modules/Core/Common/test/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ set(
9090
itkTimeProbeTest.cxx
9191
itkTimeProbeTest2.cxx
9292
itkSpatialOrientationTest.cxx
93-
itkStdStreamStateSaveTest.cxx
9493
VNLSparseLUSolverTraitsTest.cxx
9594
itkSobelOperatorImageConvolutionTest.cxx
9695
itkSobelOperatorImageFilterTest.cxx
@@ -866,12 +865,6 @@ itk_add_test(
866865
ITKCommon1TestDriver
867866
itkPointGeometryTest
868867
)
869-
itk_add_test(
870-
NAME itkStdStreamStateSaveTest
871-
COMMAND
872-
ITKCommon1TestDriver
873-
itkStdStreamStateSaveTest
874-
)
875868

876869
#
877870
# This test should be enabled if you suspect that the memory leak detector
@@ -1800,6 +1793,7 @@ set(
18001793
itkSpatialOrientationAdaptorGTest.cxx
18011794
itkAnatomicalOrientationGTest.cxx
18021795
itkAutoPointerGTest.cxx
1796+
itkStdStreamStateSaveGTest.cxx
18031797
)
18041798
creategoogletestdriver(ITKCommon "${ITKCommon-Test_LIBRARIES}" "${ITKCommonGTests}")
18051799
# If `-static` was passed to CMAKE_EXE_LINKER_FLAGS, compilation fails. No need to

Modules/Core/Common/test/itkStdStreamStateSaveTest.cxx renamed to Modules/Core/Common/test/itkStdStreamStateSaveGTest.cxx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
*
1717
*=========================================================================*/
1818

19-
#include "itkTestingMacros.h"
2019
#include "itkStdStreamStateSave.h"
20+
#include "itkGTest.h"
2121

2222
#include <sstream>
23-
#include <cstdlib>
2423

25-
int
26-
itkStdStreamStateSaveTest(int, char *[])
24+
TEST(StdStreamStateSave, RestoresCoutState)
2725
{
2826
// Set the fillch of std::cout with an explicit default fill character
2927
std::cout.fill(' ');
@@ -55,10 +53,24 @@ itkStdStreamStateSaveTest(int, char *[])
5553

5654
} // coutState goes out of scope and will restore original format state
5755

56+
// Verify that the default is reset for std::cout
57+
EXPECT_EQ(std::cout.precision(), defaultPrecision);
58+
EXPECT_EQ(std::cout.width(), defaultWidth);
59+
EXPECT_EQ(std::cout.fill(), defaultFill);
60+
EXPECT_EQ(std::cout.flags(), defaultFlags);
61+
}
62+
63+
TEST(StdStreamStateSave, RestoresStringStreamState)
64+
{
5865
std::stringstream stream;
5966
// Set the fillch of std::stringstream with an explicit default fill character
6067
stream.fill(' ');
6168

69+
const std::streamsize defaultPrecision = stream.precision();
70+
const std::streamsize defaultWidth = stream.width();
71+
const char defaultFill = stream.fill();
72+
const std::ios_base::fmtflags defaultFlags = stream.flags();
73+
6274
constexpr int originalInt{ 10 };
6375
{
6476
const itk::StdStreamStateSave sstreamState(stream);
@@ -86,18 +98,10 @@ itkStdStreamStateSaveTest(int, char *[])
8698
// is still in effect.
8799
int inputInt = 0;
88100
stream >> inputInt;
89-
ITK_TEST_EXPECT_EQUAL(originalInt, inputInt);
90-
91-
// Verify that the default is reset for std::cout
92-
ITK_TEST_EXPECT_EQUAL(std::cout.precision(), defaultPrecision);
93-
ITK_TEST_EXPECT_EQUAL(std::cout.width(), defaultWidth);
94-
ITK_TEST_EXPECT_EQUAL(std::cout.fill(), defaultFill);
95-
ITK_TEST_EXPECT_EQUAL(std::cout.flags(), defaultFlags);
96-
97-
ITK_TEST_EXPECT_EQUAL(stream.precision(), defaultPrecision);
98-
ITK_TEST_EXPECT_EQUAL(stream.width(), defaultWidth);
99-
ITK_TEST_EXPECT_EQUAL(stream.fill(), defaultFill);
100-
ITK_TEST_EXPECT_EQUAL(stream.flags(), defaultFlags);
101+
EXPECT_EQ(originalInt, inputInt);
101102

102-
return EXIT_SUCCESS;
103+
EXPECT_EQ(stream.precision(), defaultPrecision);
104+
EXPECT_EQ(stream.width(), defaultWidth);
105+
EXPECT_EQ(stream.fill(), defaultFill);
106+
EXPECT_EQ(stream.flags(), defaultFlags);
103107
}

0 commit comments

Comments
 (0)