#include "gtest/gtest.h" #include "RifColumnBasedUserDataParser.h" #include "RifEclipseUserDataParserTools.h" //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST( FixedWidthDataParser, BasicUsage ) { QString data = R"(1 ------------------------------------------------------------------------------------------------------------------------------- SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 ------------------------------------------------------------------------------------------------------------------------------- DATE FGIRH FVPT FWPT FOPT FLPT FLPTH FGPT FOPTH FGPTH SM3/DAY RM3 SM3 SM3 SM3 SM3 SM3 SM3 SM3 *10**3 *10**3 *10**3 *10**3 *10**3 *10**6 *10**3 *10**6 0 0 0 0 0 0 0 0 0 ------------------------------------------------------------------------------------------------------------------------------- 6-NOV-1997 0 0 0 0 0 0 0 0 0 7-NOV-1997 0 5.749954 0.004548 4.379801 4.384350 4.347700 0.476000 4.347700 0.482595 8-NOV-1997 0 13.76883 0.010841 10.48852 10.49936 10.41106 1.139745 10.41106 1.155627 9-NOV-1997 0 19.38692 0.015243 14.76847 14.78372 14.65899 1.604722 14.65899 1.627147 )"; std::stringstream streamData; streamData.str( data.toStdString() ); std::vector tableHeaderLines = RifEclipseUserDataParserTools::findValidHeaderLines( streamData ); EXPECT_EQ( size_t( 4 ), tableHeaderLines.size() ); { std::string line; std::getline( streamData, line ); std::string firstDataLine = "6-NOV-1997"; size_t foundPos = line.find_first_of( firstDataLine ); EXPECT_TRUE( foundPos != std::string::npos ); } auto colHeaders = RifEclipseUserDataParserTools::splitIntoColumnHeaders( tableHeaderLines ); EXPECT_EQ( size_t( 10 ), colHeaders.size() ); EXPECT_TRUE( colHeaders[9][0].find_first_of( "FGPTH" ) != std::string::npos ); EXPECT_TRUE( colHeaders[9][1].find_first_of( "SM3" ) != std::string::npos ); EXPECT_TRUE( colHeaders[9][2].find_first_of( "*10**6" ) != std::string::npos ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST( FixedWidthDataParser, ColumnData ) { std::vector> columnData; { std::vector col; col.push_back( "FGPTH" ); col.push_back( "SM3" ); col.push_back( "*10**6" ); columnData.push_back( col ); } auto ci = RifEclipseUserDataParserTools::columnInfoFromColumnHeaders( columnData ); EXPECT_EQ( size_t( 1 ), ci.size() ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST( FixedWidthDataParser, DetectFixedWidth ) { QString data = R"(1 ------------------------------------------------------------------------------------------------------------------------------- SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 ------------------------------------------------------------------------------------------------------------------------------- DATE YEARS NEWTON MLINEARS DAY MONTH YEAR NEWTON TCPU ELAPSED YEARS SECONDS SECONDS ------------------------------------------------------------------------------------------------------------------------------- 6-NOV-1997 0 0 0 6 11 1997 0 4.880000 9.720000 7-NOV-1997 0.002738 3 28 7 11 1997 3 5.240000 10.11000 8-NOV-1997 0.006556 4 42 8 11 1997 4 5.730000 10.60000 9-NOV-1997 0.009231 3 28 9 11 1997 3 6.080000 10.95000 10-NOV-1997 0.011462 4 32 10 11 1997 4 6.500000 11.37000 11-NOV-1997 0.013710 4 35 11 11 1997 4 6.940001 11.81000 11-NOV-1997 0.015950 3 25 11 11 1997 3 7.270000 12.14000 12-NOV-1997 0.018477 4 35 12 11 1997 4 7.710001 12.58000 13-NOV-1997 0.020190 3 24 13 11 1997 3 8.040000 12.91000 14-NOV-1997 0.021903 3 27 14 11 1997 3 8.380000 13.25000 14-NOV-1997 0.024232 2 17 14 11 1997 2 8.640000 13.57000 17-NOV-1997 0.030838 3 26 17 11 1997 3 8.980000 13.91000 19-NOV-1997 0.037060 3 30 19 11 1997 3 9.350000 14.28000 1 ------------------------------------------------------------------------------------------------------------------------------- SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 ------------------------------------------------------------------------------------------------------------------------------- DATE RGIR RGPR RGIPG RGIPL RGIT RGPT RWIR RWPR RWPT SM3/DAY SM3/DAY SM3 SM3 SM3 SM3 SM3/DAY SM3/DAY SM3 *10**3 *10**3 *10**3 *10**3 1 1 1 1 1 1 1 1 1 ------------------------------------------------------------------------------------------------------------------------------- 6-NOV-1997 0 0 5426677. 591448.1 0 0 0 0 0 7-NOV-1997 0 2396930. 5424424. 591498.1 0 2396.930 0 -21.6173 -21.6173 8-NOV-1997 0 -250487. 5423940. 591966.2 0 2047.598 0 -11124.0 -15535.3 9-NOV-1997 0 2829432. 5421400. 591952.3 0 4812.102 0 -17.8744 -15552.8 10-NOV-1997 0 -280634. 5421285. 592209.2 0 4583.461 0 -10959.9 -24482.1 11-NOV-1997 0 2830404. 5419148. 592196.6 0 6908.132 0 -10.3646 -24490.7 11-NOV-1997 0 -295420. 5419071. 592429.6 0 6666.499 0 -10081.2 -32736.4 12-NOV-1997 0 2653586. 5416835. 592407.6 0 9116.355 0 1.209827 -32735.3 13-NOV-1997 0 -360534. 5416802. 592585.4 0 8890.818 0 -9987.70 -38983.3 14-NOV-1997 0 2637960. 5415305. 592557.9 0 10541.03 0 14.09936 -38974.5 14-NOV-1997 392181.0 1892660. 5414172. 592553.9 333.6561 12151.25 0 12.94364 -38963.4 17-NOV-1997 392181.0 -248070. 5414992. 592978.2 1279.883 11552.73 0 -6587.17 -54856.5 19-NOV-1997 392181.0 2105310. 5411504. 592928.2 2171.132 16337.13 0 50.99986 -54740.6 1 ------------------------------------------------------------------------------------------------------------------------------- SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 ------------------------------------------------------------------------------------------------------------------------------- DATE RWIP ROPR ROIR ROIT ROIPG ROIPL ROPT WBP5 WBP5 SM3 SM3/DAY SM3/DAY SM3 SM3 SM3 SM3 BARSA BARSA *10**3 C-4H B-2H 1 1 1 1 1 1 1 ------------------------------------------------------------------------------------------------------------------------------- 6-NOV-1997 11497.27 0 0 0 311329.6 5356031. 0 267.8818 272.3813 7-NOV-1997 11497.30 136.0644 0 0 310820.4 5356412. 136.0644 267.5505 271.7487 8-NOV-1997 11512.83 -2235.10 0 0 307801.2 5359464. -2981.04 267.9665 271.5258 9-NOV-1997 11512.86 164.4799 0 0 307597.5 5359512. -2820.33 267.7249 271.3749 10-NOV-1997 11521.80 -2242.95 0 0 307640.1 5361289. -4647.73 267.9192 271.2401 11-NOV-1997 11521.82 167.4484 0 0 307474.1 5361327. -4510.20 267.6667 271.1284 11-NOV-1997 11530.07 -2050.93 0 0 307511.9 5362954. -6187.72 267.9205 271.0045 12-NOV-1997 11530.08 159.2625 0 0 307328.3 5362987. -6040.69 267.6598 270.8947 13-NOV-1997 11536.33 -2048.92 0 0 307366.7 5364262. -7322.42 267.8667 270.8219 14-NOV-1997 11536.33 163.7713 0 0 307245.2 5364278. -7219.97 267.6961 270.7566 14-NOV-1997 11536.32 110.5641 0 0 307121.3 5364291. -7125.90 267.7364 270.6674 17-NOV-1997 11552.19 -1263.74 0 0 307151.2 5367307. -10175.0 268.3125 270.3454 19-NOV-1997 11552.09 133.3163 0 0 306850.8 5367300. -9872.00 267.8979 270.1126 1 ------------------------------------------------------------------------------------------------------------------------------- SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 USER dtb MACHINE stj-lcb01-01-03 ------------------------------------------------------------------------------------------------------------------------------- DATE WWCT WWCT WWCTH WWCTH WWCTH WWCTH WWCTH WWCTH WWCTH D-3BH B-1BH C-4H B-2H D-1H B-1AH B-4H B-4AH C-1H ------------------------------------------------------------------------------------------------------------------------------- 6-NOV-1997 0 0 0 0 0 0 0 0 0 7-NOV-1997 0 0 0 0 0 0 0 0 0 8-NOV-1997 0 0 0 0 0 0 0 0 0 9-NOV-1997 0 0 0 0 0 0 0 0 0 10-NOV-1997 0 0 0 0 0 0 0 0 0 11-NOV-1997 0 0 0 0 0 0 0 0 0 11-NOV-1997 0 0 0 0 0 0 0 0 0 12-NOV-1997 0 0 0 0 0 0 0 0 0 13-NOV-1997 0 0 0 0 0 0 0 0 0 14-NOV-1997 0 0 0 0 0 0 0 0 0 14-NOV-1997 0 0 0 0 0 0 0 0 0 17-NOV-1997 0 0 0 0 0 0 0 0 0 19-NOV-1997 0 0 0 0 0 0 0 0 0 )"; EXPECT_TRUE( RifEclipseUserDataParserTools::isFixedWidthHeader( data.toStdString() ) ); RifColumnBasedUserDataParser parser( data ); auto tables = parser.tableData(); EXPECT_EQ( size_t( 1 ), tables.size() ); EXPECT_EQ( size_t( 37 ), tables[0].columnInfos().size() ); EXPECT_EQ( size_t( 13 ), tables[0].columnInfos()[0].textValues.size() ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST( FixedWidthDataParser, VaryingTimeStepCount ) { QString data = "1 " " \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 " " \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " DATE YEARS NEWTON MLINEARS DAY MONTH YEAR NEWTON " " TCPU ELAPSED \n" " YEARS " " SECONDS SECONDS \n" " " " \n" " " " \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " 6-NOV-1997 0 0 0 6 11 1997 " "0 4.880000 9.720000 \n" " 7-NOV-1997 0.002738 3 28 7 11 1997 " "3 5.240000 10.11000 \n" " 8-NOV-1997 0.006556 4 42 8 11 1997 " "4 5.730000 10.60000 \n" "1 " " \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 " " \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " DATE RGIR RGPR RGIPG RGIPL RGIT RGPT RWIR " " RWPR RWPT \n" " SM3/DAY SM3/DAY SM3 SM3 SM3 SM3 " "SM3/DAY SM3/DAY SM3 \n" " *10**3 *10**3 *10**3 *10**3 " " \n" " " " \n" " 1 1 1 1 1 1 1 " " 1 1 \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " 6-NOV-1997 0 0 5426677. 591448.1 0 0 " "0 0 0 \n" " 7-NOV-1997 0 2396930. 5424424. 591498.1 0 2396.930 " "0 -21.6173 -21.6173 \n" " 8-NOV-1997 0 -250487. 5423940. 591966.2 0 2047.598 " "0 -11124.0 -15535.3 \n" " 9-NOV-1997 0 2829432. 5421400. 591952.3 0 4812.102 " "0 -17.8744 -15552.8 \n"; RifColumnBasedUserDataParser parser( data ); auto tables = parser.tableData(); EXPECT_EQ( size_t( 2 ), tables.size() ); EXPECT_EQ( size_t( 3 ), tables[0].columnInfos()[0].itemCount() ); EXPECT_EQ( size_t( 4 ), tables[1].columnInfos()[0].itemCount() ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST( FixedWidthDataParser, HandlingOfStepType ) { QString data = R"(1 ------------------------------------------------------------------------------------------------------------------------------- SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 USER dtb MACHINE stj-lcb01-01-03 ------------------------------------------------------------------------------------------------------------------------------- DATE YEARS NEWTON MLINEARS DAY MONTH YEAR NEWTON TCPU ELAPSED YEARS SECONDS SECONDS ------------------------------------------------------------------------------------------------------------------------------- 6-NOV-1997 0 0 0 6 11 1997 0 4.880000 9.720000 7-NOV-1997 0.002738 3 28 7 11 1997 3 5.240000 10.11000 8-NOV-1997 0.006556 4 42 8 11 1997 4 5.730000 10.60000 9-NOV-1997 0.009231 3 28 9 11 1997 3 6.080000 10.95000 10-NOV-1997 0.011462 4 32 10 11 1997 4 6.500000 11.37000 11-NOV-1997 0.013710 4 35 11 11 1997 4 6.940001 11.81000 11-NOV-1997 0.015950 3 25 11 11 1997 3 7.270000 12.14000 12-NOV-1997 0.018477 4 35 12 11 1997 4 7.710001 12.58000 13-NOV-1997 0.020190 3 24 13 11 1997 3 8.040000 12.91000 14-NOV-1997 0.021903 3 27 14 11 1997 3 8.380000 13.25000 14-NOV-1997 0.024232 2 17 14 11 1997 2 8.640000 13.57000 17-NOV-1997 0.030838 3 26 17 11 1997 3 8.980000 13.91000 19-NOV-1997 0.037060 3 30 19 11 1997 3 9.350000 14.28000 21-NOV-1997 0.042841 4 35 21 11 1997 4 9.790001 14.71000 23-NOV-1997 0.049239 5 45 23 11 1997 5 10.33000 15.26000 25-NOV-1997 0.054613 3 25 25 11 1997 3 10.67000 15.60000 28-NOV-1997 0.061135 3 27 28 11 1997 3 11.01000 15.94000 29-NOV-1997 0.064791 3 23 29 11 1997 3 11.33000 16.26000 1 ------------------------------------------------------------------------------------------------------------------------------- SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 USER dtb MACHINE stj-lcb01-01-03 ------------------------------------------------------------------------------------------------------------------------------- DATE TIMESTEP TCPUTS TCPUDAY MLINEARS MSUMLINS NLINEARS STEPTYPE TELAPLIN MSUMNEWT DAYS SECONDS SEC/D SECONDS ------------------------------------------------------------------------------------------------------------------------------- 6-NOV-1997 0 4.880000 0 0 0 0 0 0 7-NOV-1997 1.000000 5.240000 5.240000 28 28 9.333333 INIT 0.361071 3 8-NOV-1997 1.394612 0.490000 0.351352 42 70 10.50000 TRNC 0.151429 7 9-NOV-1997 0.977053 0.350000 0.358220 28 98 9.333333 TRNC 0.111735 10 10-NOV-1997 0.814727 0.420000 0.515510 32 130 8.000000 TRNC 0.087462 14 11-NOV-1997 0.821321 0.430000 0.523547 35 165 8.750000 TRNC 0.071576 18 11-NOV-1997 0.817933 0.320000 0.391230 25 190 8.333333 TRNC 0.063895 21 12-NOV-1997 0.923225 0.430000 0.465759 35 225 8.750000 TRNC 0.055911 25 13-NOV-1997 0.625564 0.320000 0.511538 24 249 8.000000 HALF 0.051847 28 14-NOV-1997 0.625564 0.340000 0.543509 27 276 9.000000 REPT 0.048007 31 14-NOV-1997 0.850771 0.240000 0.282097 17 293 8.500000 TRNC 0.046314 33 17-NOV-1997 2.412731 0.340000 0.140919 26 319 8.666667 TRNC 0.043605 36 19-NOV-1997 2.272543 0.360000 0.158413 30 349 10.00000 TRNC 0.040917 39 21-NOV-1997 2.111558 0.440000 0.208377 35 384 8.750000 TRNC 0.038307 43 23-NOV-1997 2.336865 0.540000 0.231079 45 429 9.000000 TRNC 0.035571 48 25-NOV-1997 1.962967 0.330000 0.168113 25 454 8.333333 EFF+ 0.034361 51 28-NOV-1997 2.382306 0.340000 0.142719 27 481 9.000000 TRNC 0.033139 54 29-NOV-1997 1.335130 0.310000 0.232187 23 504 7.666667 HALF 0.032262 57 )"; RifColumnBasedUserDataParser parser( data ); auto tables = parser.tableData(); EXPECT_EQ( size_t( 1 ), tables.size() ); EXPECT_EQ( size_t( 19 ), tables[0].columnInfos().size() ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST( FixedWidthDataParser, ParsingOfHeaderWithCompletions ) { QString data = R"(1 ------------------------------------------------------------------------------------------------------------------------------- SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 USER dtb MACHINE stj-lcb01-01-03 ------------------------------------------------------------------------------------------------------------------------------- DATE CWIR CWIR CWIR CWIR CWIR CWIR CWIR CWIR CWIR SM3/DAY SM3/DAY SM3/DAY SM3/DAY SM3/DAY SM3/DAY SM3/DAY SM3/DAY SM3/DAY F-1H F-1H F-2H F-2H F-2H F-2H F-2H F-2H F-2H 12 85 22 12 85 5 18 83 1 18 83 2 18 83 3 18 83 6 18 83 7 18 83 8 18 83 10 ------------------------------------------------------------------------------------------------------------------------------- 6-NOV-1997 0 0 0 0 0 0 0 0 0 7-NOV-1997 9.231156 0 4.764449 0.281349 0.745133 0.265189 0.920954 0.836619 3.560058 8-NOV-1997 14.24625 0 -0.32936 -0.02394 -0.03676 -0.01107 -0.04118 -0.04043 -0.20764 9-NOV-1997 18.14752 0 12.64910 0.550845 1.412629 0.484177 1.673316 1.510174 6.306583 10-NOV-1997 22.47141 0 -0.43799 -0.08433 -0.22154 -0.06072 -0.22558 -0.22200 -1.14752 11-NOV-1997 26.39600 0 4.129149 0.249054 0.636686 0.220191 0.752644 0.669143 2.670208 11-NOV-1997 30.89960 0 -0.42792 -0.07257 -0.18697 -0.06075 -0.22589 -0.22287 -1.16095 12-NOV-1997 34.92273 0 2.787762 0.204226 0.520520 0.173727 0.588237 0.516083 1.973659 13-NOV-1997 37.70422 0 -0.45489 -0.08366 -0.21913 -0.07483 -0.27827 -0.27465 -1.43221 14-NOV-1997 40.17989 0 1.737699 0.167881 0.426118 0.136267 0.456785 0.394921 1.435897 14-NOV-1997 41.75888 0 -0.03586 0.081980 0.190420 0.058727 0.180976 0.136145 0.240186 17-NOV-1997 55.30696 0 -0.39500 -0.05166 -0.13519 -0.05874 -0.22546 -0.23077 -1.29799 19-NOV-1997 57.85853 0 -0.06687 0.071926 0.165751 0.048624 0.144723 0.101929 0.076216 21-NOV-1997 66.37193 0 -0.41220 -0.05978 -0.16607 -0.06713 -0.26004 -0.26881 -1.54050 23-NOV-1997 66.17105 0 -0.16977 0.031785 0.060331 0.015140 0.026817 -0.00778 -0.45987 25-NOV-1997 71.57468 0 -0.35382 -0.03761 -0.11790 -0.04534 -0.18728 -0.20627 -1.31764 )"; std::stringstream streamData; streamData.str( data.toStdString() ); std::vector tableHeaderLines = RifEclipseUserDataParserTools::findValidHeaderLines( streamData ); EXPECT_EQ( size_t( 4 ), tableHeaderLines.size() ); auto colHeaders = RifEclipseUserDataParserTools::splitIntoColumnHeaders( tableHeaderLines ); EXPECT_EQ( size_t( 10 ), colHeaders.size() ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST( FixedWidthDataParser, DifferentStartDate ) { QString data = "1 " " \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 " " \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " DATE YEARS NEWTON MLINEARS DAY MONTH YEAR NEWTON " " TCPU ELAPSED \n" " YEARS " " SECONDS SECONDS \n" " " " \n" " " " \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " 6-NOV-1997 0 0 0 6 11 1997 " "0 4.880000 9.720000 \n" " 7-NOV-1997 0.002738 3 28 7 11 1997 " "3 5.240000 10.11000 \n" " 8-NOV-1997 0.006556 4 42 8 11 1997 " "4 5.730000 10.60000 \n" "1 " " \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 " " \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " DATE RGIR RGPR RGIPG RGIPL RGIT RGPT RWIR " " RWPR RWPT \n" " SM3/DAY SM3/DAY SM3 SM3 SM3 SM3 " "SM3/DAY SM3/DAY SM3 \n" " *10**3 *10**3 *10**3 *10**3 " " \n" " " " \n" " 1 1 1 1 1 1 1 " " 1 1 \n" " --------------------------------------------------------------------------------------------------" "-----------------------------\n" " 7-NOV-1997 0 2396930. 5424424. 591498.1 0 2396.930 " "0 -21.6173 -21.6173 \n" " 8-NOV-1997 0 -250487. 5423940. 591966.2 0 2047.598 " "0 -11124.0 -15535.3 \n" " 9-NOV-1997 0 2829432. 5421400. 591952.3 0 4812.102 " "0 -17.8744 -15552.8 \n"; RifColumnBasedUserDataParser parser( data ); auto tables = parser.tableData(); EXPECT_EQ( size_t( 2 ), tables.size() ); }