@@ -57,6 +57,22 @@ static bool CompareFormatReal(const char *format, std::uint64_t xInt,
5757 return CompareFormatReal (format, x, expect, got);
5858}
5959
60+ static bool CompareFormatInteger (
61+ const char *format, std::int64_t x, const char *expect, std::string &got) {
62+ char buffer[800 ];
63+ auto cookie{IONAME (BeginInternalFormattedOutput)(
64+ buffer, sizeof buffer, format, std::strlen (format))};
65+ EXPECT_TRUE (IONAME (OutputInteger64)(cookie, x));
66+ auto status{IONAME (EndIoStatement)(cookie)};
67+ EXPECT_EQ (status, 0 );
68+ got = std::string{buffer, sizeof buffer};
69+ auto lastNonBlank{got.find_last_not_of (" " )};
70+ if (lastNonBlank != std::string::npos) {
71+ got.resize (lastNonBlank + 1 );
72+ }
73+ return CompareFormattedStrings (expect, got);
74+ }
75+
6076struct IOApiTests : CrashHandlerFixture {};
6177
6278TEST (IOApiTests, HelloWorldOutputTest) {
@@ -693,6 +709,71 @@ TEST(IOApiTests, FormatDoubleValues) {
693709 }
694710}
695711
712+ TEST (IOApiTests, FormatIntegerValues) {
713+ using IntTestCaseTy = std::tuple<const char *, std::int64_t , const char *>;
714+ static const std::vector<IntTestCaseTy> intTestCases{
715+ {" (I4)" , 0 , " 0" },
716+ {" (I4)" , 1 , " 1" },
717+ {" (I4)" , 9999 , " 9999" },
718+ {" (SP,I4)" , 1 , " +1" },
719+ {" (SP,I4)" , 9999 , " ****" },
720+ {" (SP,I4)" , 999 , " +999" },
721+ {" (I4)" , -1 , " -1" },
722+ {" (I4)" , -9999 , " ****" },
723+ {" (I4)" , -999 , " -999" },
724+ {" (I4.2)" , 1 , " 01" },
725+ {" (I4.2)" , -1 , " -01" },
726+ {" (I4.2)" , 999 , " 999" },
727+ {" (I4.4)" , 999 , " 0999" },
728+ {" (I0)" , 0 , " 0" },
729+ {" (I0)" , 1 , " 1" },
730+ {" (I0)" , 9999 , " 9999" },
731+ {" (SP,I0)" , 1 , " +1" },
732+ {" (SP,I0)" , 9999 , " +9999" },
733+ {" (SP,I0)" , 999 , " +999" },
734+ {" (I0)" , -1 , " -1" },
735+ {" (I0)" , -9999 , " -9999" },
736+ {" (I0)" , -999 , " -999" },
737+ {" (I0.2)" , 1 , " 01" },
738+ {" (I0.2)" , -1 , " -01" },
739+ {" (I0.2)" , 999 , " 999" },
740+ {" (I0.4)" , 999 , " 0999" },
741+ {" (G4)" , 0 , " 0" },
742+ {" (G4)" , 1 , " 1" },
743+ {" (G4)" , 9999 , " 9999" },
744+ {" (SP,G4)" , 1 , " +1" },
745+ {" (SP,G4)" , 9999 , " ****" },
746+ {" (SP,G4)" , 999 , " +999" },
747+ {" (G4)" , -1 , " -1" },
748+ {" (G4)" , -9999 , " ****" },
749+ {" (G4)" , -999 , " -999" },
750+ {" (G4.2)" , 1 , " 1" },
751+ {" (G4.2)" , -1 , " -1" },
752+ {" (G4.2)" , 999 , " 999" },
753+ {" (G4.4)" , 999 , " 999" },
754+ {" (G0)" , 0 , " 0" },
755+ {" (G0)" , 1 , " 1" },
756+ {" (G0)" , 9999 , " 9999" },
757+ {" (SP,G0)" , 1 , " +1" },
758+ {" (SP,G0)" , 9999 , " +9999" },
759+ {" (SP,G0)" , 999 , " +999" },
760+ {" (G0)" , -1 , " -1" },
761+ {" (G0)" , -9999 , " -9999" },
762+ {" (G0)" , -999 , " -999" },
763+ {" (G0.2)" , 1 , " 1" },
764+ {" (G0.2)" , -1 , " -1" },
765+ {" (G0.2)" , 999 , " 999" },
766+ {" (G0.4)" , 999 , " 999" },
767+ };
768+
769+ for (auto const &[fmt, value, expect] : intTestCases) {
770+ std::string got;
771+ ASSERT_TRUE (CompareFormatInteger (fmt, value, expect, got))
772+ << " Failed to format " << fmt << " , expected '" << expect << " ', got '"
773+ << got << " '" ;
774+ }
775+ }
776+
696777// ------------------------------------------------------------------------------
697778// / Tests for input formatting real values
698779// ------------------------------------------------------------------------------
0 commit comments