Tutorial 21 - Using files as test data input

// tutorial21.ot
group "tutorial_21";

include "stdio.h";

table otfiles(char *) filelist "." name "*.ot";

test ("Check if all ot-files starts with //")
{
  iterate( filename ) from otfiles
  {
    FILE* f = fopen(filename, "r");
    verify(f != NULL);
    char buf[2];
    fread(buf, 1, 2, f);
    output("%s\n", filename);
    verify(op_strncmp("//", buf, 2) == 0);
    fclose(f);
  }
}

A very useful thing is that you can traverse a directory for files in a spcified directory with a specified name. The name can (and will normally) have wildcards. In our example, the directory is "." (our current directory) and we will find all files ending with ".ot". What we get is the filename (including full path). Then we can use this filename to open the file, or do something else with it. If you add recursively at the end, we will iterate over all files in the subdirectories of the start directory too.

=========================================================================
Opera Testsuite
=========================================================================

=========================================================================
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial21.ot(2):  tutorial_21 
=========================================================================
  Check if all ot-files starts with // .......................... E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial1.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial10.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial11.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial12.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial13.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial14.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial15.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial16.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial17.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial18.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial19.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial2.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial20.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial21.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial3.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial4.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial5.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial6.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial7.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial8.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial9.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutoriala.ot
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutoriale1.ot
FAILED
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial21.ot(17): 'strncmp("//", buf, 2)' should be 0. The value is -1
=========================================================================
1 test run, 1 test failed, 0 tests skipped, 0 tests OK
Place a breakpoint in testsuite_break_here() to debug the failed test
=========================================================================