Skip to content

Commit

Permalink
Merge pull request equinor#583 from joakim-hove/use-TestArea
Browse files Browse the repository at this point in the history
Use c++ TestArea
  • Loading branch information
joakim-hove authored Mar 18, 2019
2 parents f144347 + dab0e34 commit ca4182a
Show file tree
Hide file tree
Showing 31 changed files with 56 additions and 109 deletions.
6 changes: 2 additions & 4 deletions lib/ecl/tests/ecl_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <ert/ecl/ecl_endian_flip.hpp>

void test_writable(size_t data_size) {
test_work_area_type * work_area = test_work_area_alloc("ecl_file_writable");
ecl::util::TestArea ta("file_writable");
const char * data_file_name = "test_file";

ecl_kw_type * kw = ecl_kw_alloc("TEST_KW", data_size, ECL_INT);
Expand All @@ -54,11 +54,10 @@ void test_writable(size_t data_size) {
}

ecl_kw_free(kw);
test_work_area_free( work_area );
}

void test_truncated() {
test_work_area_type * work_area = test_work_area_alloc("ecl_file_truncated" );
ecl::util::TestArea ta("truncate_file");
int num_kw;
{
ecl_grid_type * grid = ecl_grid_alloc_rectangular(20,20,20,1,1,1,NULL);
Expand All @@ -84,7 +83,6 @@ void test_truncated() {
test_assert_true( ecl_file_get_size( ecl_file) < num_kw );
ecl_file_close( ecl_file );
}
test_work_area_free( work_area );
}


Expand Down
10 changes: 4 additions & 6 deletions lib/ecl/tests/ecl_file_equinor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ void test_close_stream1(const char * src_file , const char * target_file ) {


void test_writable(const char * src_file ) {
test_work_area_type * work_area = test_work_area_alloc("ecl_file_writable" );
ecl::util::TestArea ta("file_writable");
char * fname = util_split_alloc_filename( src_file );

test_work_area_copy_file( work_area , src_file );
ta.copy_file(src_file);
{
test_flags( fname );
ecl_file_type * ecl_file = ecl_file_open( fname , ECL_FILE_WRITABLE);
Expand All @@ -127,7 +127,6 @@ void test_writable(const char * src_file ) {
swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 );
test_assert_true( util_double_approx_equal( ecl_kw_iget_float( swat , 0 ) , 1000 ));
}
test_work_area_free( work_area );
}


Expand All @@ -138,16 +137,15 @@ int main( int argc , char ** argv) {
const char * target_file = argv[2];

{
test_work_area_type * work_area = test_work_area_alloc("ecl_file");
ecl::util::TestArea ta("file_equinor");

test_work_area_copy_file( work_area , src_file );
ta.copy_file( src_file );
test_loadall(src_file , target_file );

test_close_stream1( src_file , target_file);
test_close_stream2( src_file , target_file);
test_writable( src_file );

test_work_area_free( work_area );
}
exit(0);
}
3 changes: 1 addition & 2 deletions lib/ecl/tests/ecl_file_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void test_create_file_kw() {
test_assert_int_equal( ecl_file_kw_get_size( file_kw0 ) , 1000 );
test_assert_true( ecl_type_is_equal( ecl_file_kw_get_data_type( file_kw0 ) , ECL_FLOAT ));
{
test_work_area_type * work_area = test_work_area_alloc("file_kw");
ecl::util::TestArea ta("file_kw");
{
FILE * ostream = util_fopen("file_kw" , "w");
ecl_file_kw_fwrite( file_kw0 , ostream );
Expand Down Expand Up @@ -101,7 +101,6 @@ void test_create_file_kw() {
test_assert_NULL( ecl_file_kw_fread_alloc_multiple( istream , 10));
fclose( istream );
}
test_work_area_free( work_area );
}
ecl_file_kw_free( file_kw0 );
ecl_file_kw_free( file_kw1 );
Expand Down
14 changes: 6 additions & 8 deletions lib/ecl/tests/ecl_fmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@

#include <ert/ecl/ecl_util.hpp>

void test_content( test_work_area_type * work_area , const char * src_file , bool fmt_file ) {
test_work_area_install_file( work_area , src_file );
void test_content( const ecl::util::TestArea& ta , const char * src_file , bool fmt_file ) {
ta.copy_file(src_file);
{
char * base_name;
bool fmt;
util_alloc_file_components( src_file , NULL , &base_name , NULL);
util_copy_file( src_file , base_name );

test_assert_true( ecl_util_fmt_file( base_name , &fmt ));
test_assert_bool_equal( fmt , fmt_file );
}
Expand All @@ -41,6 +39,7 @@ void test_content( test_work_area_type * work_area , const char * src_file , boo




void test_small( ) {
bool fmt;

Expand All @@ -56,7 +55,7 @@ void test_small( ) {


int main(int argc , char ** argv) {
test_work_area_type * work_area = test_work_area_alloc( "ecl_fmt");
ecl::util::TestArea ta("ecl_fmt");
{
const char * binary_file = argv[1];
const char * text_file = argv[2];
Expand All @@ -78,10 +77,9 @@ int main(int argc , char ** argv) {

test_assert_false(ecl_util_fmt_file( "TEST_DOES_NOT_EXIST" , &fmt_file ));

test_content( work_area , binary_file , false );
test_content( work_area , text_file , true );
test_content( ta , binary_file , false );
test_content( ta , text_file , true );
test_small( );
}
test_work_area_free( work_area );
exit(0);
}
9 changes: 3 additions & 6 deletions lib/ecl/tests/ecl_grid_add_nnc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ void simple_test() {

verify_simple_nnc( grid0 );
{
test_work_area_type * test_area = test_work_area_alloc("ecl_grid_nnc");
ecl::util::TestArea ta("simple_nnc");
ecl_grid_type * grid1;
ecl_grid_fwrite_EGRID2( grid0 , "TEST.EGRID" , ECL_METRIC_UNITS);
grid1 = ecl_grid_alloc( "TEST.EGRID" );

verify_simple_nnc( grid1 );
ecl_grid_free( grid1 );
test_work_area_free( test_area );
}
ecl_grid_free( grid0 );
}
Expand All @@ -90,14 +89,13 @@ void overwrite_test() {

verify_simple_nnc( grid0 );
{
test_work_area_type * test_area = test_work_area_alloc("ecl_grid_nnc");
ecl::util::TestArea ta("overwrite");
ecl_grid_type * grid1;
ecl_grid_fwrite_EGRID2( grid0 , "TEST.EGRID" , ECL_METRIC_UNITS);
grid1 = ecl_grid_alloc( "TEST.EGRID" );

verify_simple_nnc( grid1 );
ecl_grid_free( grid1 );
test_work_area_free( test_area );
}
ecl_grid_free( grid0 );
}
Expand All @@ -118,14 +116,13 @@ void list_test() {

verify_simple_nnc( grid0 );
{
test_work_area_type * test_area = test_work_area_alloc("ecl_grid_nnc");
ecl::util::TestArea ta("list_test");
ecl_grid_type * grid1;
ecl_grid_fwrite_EGRID2( grid0 , "TEST.EGRID" , ECL_METRIC_UNITS);
grid1 = ecl_grid_alloc( "TEST.EGRID" );

verify_simple_nnc( grid1 );
ecl_grid_free( grid1 );
test_work_area_free( test_area );
}
ecl_grid_free( grid0 );
}
Expand Down
3 changes: 1 addition & 2 deletions lib/ecl/tests/ecl_grid_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void export_mapaxes( const ecl_grid_type * grid , ecl_file_type * ecl_file ) {


int main(int argc , char ** argv) {
test_work_area_type * work_area = test_work_area_alloc("grid_export");
ecl::util::TestArea ta("grid_export");
{
const char * test_grid = "TEST.EGRID";
const char * grid_file;
Expand All @@ -181,5 +181,4 @@ int main(int argc , char ** argv) {
ecl_grid_free( ecl_grid );
}
}
test_work_area_free( work_area );
}
5 changes: 1 addition & 4 deletions lib/ecl/tests/ecl_grid_ext_actnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

void test_1() {

test_work_area_type * work_area = test_work_area_alloc("ext_actnum_main_grid");
ecl::util::TestArea ta("test1");
{
const char * filename = "FILE.EGRID";

Expand Down Expand Up @@ -53,9 +53,6 @@ void test_1() {
ecl_grid_free( grid );

}
test_work_area_free( work_area );


}


Expand Down
6 changes: 2 additions & 4 deletions lib/ecl/tests/ecl_grid_init_fwrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


void test_write_depth(const ecl_grid_type * grid) {
test_work_area_type * test_area = test_work_area_alloc("write_depth");
ecl::util::TestArea ta("write_depth");
{
fortio_type * init_file = fortio_open_writer( "INIT" , false , ECL_ENDIAN_FLIP );
ecl_grid_fwrite_depth( grid , init_file , ECL_METRIC_UNITS);
Expand All @@ -47,12 +47,11 @@ void test_write_depth(const ecl_grid_type * grid) {

ecl_file_close(init_file);
}
test_work_area_free( test_area );
}


void test_write_dims(const ecl_grid_type * grid) {
test_work_area_type * test_area = test_work_area_alloc("write_dims");
ecl::util::TestArea ta("write_dims");
{
fortio_type * init_file = fortio_open_writer( "INIT" , false , ECL_ENDIAN_FLIP );
ecl_grid_fwrite_dims( grid , init_file , ECL_METRIC_UNITS );
Expand All @@ -74,7 +73,6 @@ void test_write_dims(const ecl_grid_type * grid) {
}
ecl_file_close(init_file);
}
test_work_area_free( test_area );
}


Expand Down
4 changes: 1 addition & 3 deletions lib/ecl/tests/ecl_grid_unit_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ void test_GRID(const char * filename, ert_ecl_unit_enum unit_system) {


int main(int argc, char **argv) {
test_work_area_type * work_area = test_work_area_alloc("grid_export");
ecl::util::TestArea ta("grid_unit_system");

test_EGRID("METRIC.EGRID", ECL_METRIC_UNITS);
test_EGRID("FIELD.EGRID", ECL_FIELD_UNITS);
test_GRID("METRIC.GRID", ECL_METRIC_UNITS);
test_GRID("FIELD.GRID", ECL_FIELD_UNITS);

test_work_area_free(work_area);
}
3 changes: 1 addition & 2 deletions lib/ecl/tests/ecl_init_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ void test_write_header() {
int ny = 10;
int nz = 5;

ecl::util::TestArea ta("WRITE_header");
int_vector_type * actnum = int_vector_alloc( nx*ny*nz , 1 );
test_work_area_type * test_area = test_work_area_alloc( "ecl_init_file" );
time_t start_time = util_make_date_utc(15 , 12 , 2010 );
ecl_grid_type * ecl_grid;

Expand Down Expand Up @@ -84,7 +84,6 @@ void test_write_header() {
ecl_init_file_fwrite_header( f , ecl_grid , NULL , ECL_METRIC_UNITS, 7 , start_time );
fortio_fclose( f );
}
test_work_area_free( test_area );
}


Expand Down
6 changes: 2 additions & 4 deletions lib/ecl/tests/ecl_kw_fread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void test_truncated(const char * filename , offset_type truncate_size) {


void test_fread_alloc() {
test_work_area_type * work_area = test_work_area_alloc("ecl_kw_fread" );
ecl::util::TestArea ta("fread_alloc");
{
ecl_kw_type * kw1 = ecl_kw_alloc( "INT" , 100 , ECL_INT );
int i;
Expand Down Expand Up @@ -74,11 +74,10 @@ void test_fread_alloc() {
}
ecl_kw_free( kw1 );
}
test_work_area_free( work_area );
}

void test_kw_io_charlength() {
test_work_area_type * work_area = test_work_area_alloc("ecl_kw_io_charlength");
ecl::util::TestArea ta("io_charlength");
{
const char * KW0 = "QWERTYUI";
const char * KW1 = "ABCDEFGHIJTTTTTTTTTTTTTTTTTTTTTTABCDEFGHIJKLMNOP";
Expand Down Expand Up @@ -121,7 +120,6 @@ void test_kw_io_charlength() {
ecl_kw_free( ecl_kw_out0 );
ecl_kw_free( ecl_kw_out1 );
}
test_work_area_free( work_area );
}


Expand Down
3 changes: 1 addition & 2 deletions lib/ecl/tests/ecl_kw_grdecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int main(int argc , char ** argv) {
ecl_kw_iset_int(ecl_kw , i , i );

{
test_work_area_type * work_area = test_work_area_alloc("ecl_kw_grdecl");
ecl::util::TestArea ta("kw_grdecl");
FILE * stream = util_fopen( "FILE.grdecl" , "w");

ecl_kw_fprintf_grdecl(ecl_kw , stream );
Expand Down Expand Up @@ -65,7 +65,6 @@ int main(int argc , char ** argv) {
ecl_kw_free( ecl_kw2 );
}
fclose( stream );
test_work_area_free( work_area );
}
ecl_kw_free( ecl_kw );

Expand Down
3 changes: 1 addition & 2 deletions lib/ecl/tests/ecl_nnc_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void test_create_empty() {
}

void test_create_simple() {
test_work_area_type * work_area = test_work_area_alloc("nnc-INIT");
ecl::util::TestArea ta("nnc_geometry");
{
int nx = 10;
int ny = 10;
Expand Down Expand Up @@ -67,7 +67,6 @@ void test_create_simple() {
}
ecl_grid_free( grid0 );
}
test_work_area_free( work_area );
}


Expand Down
3 changes: 1 addition & 2 deletions lib/ecl/tests/ecl_rft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ void test_rft_read_write(const char * rft_file){
ecl_rft_node_type * old_node = ecl_rft_file_iget_node(rft, 0);
ecl_rft_node_type * new_node = ecl_rft_node_alloc_new("DUMMY", "R", ecl_rft_node_get_date(old_node), ecl_rft_node_get_days(old_node));
nodes[2]=new_node;
test_work_area_type * work_area = test_work_area_alloc("RFT_RW");
ecl::util::TestArea ta("rft");

ecl_rft_file_update("eclipse.rft", nodes,3, ECL_METRIC_UNITS);
test_work_area_free(work_area);
free(nodes);
}

Expand Down
Loading

0 comments on commit ca4182a

Please sign in to comment.