diff --git a/LCS/Common/test/tFileLocator.cc b/LCS/Common/test/tFileLocator.cc index 5978ff071fc49d3d84ab806cd5b4b29599f8ff74..effbb92d226de496cb0a9d6e7d7c8883e23de2df 100644 --- a/LCS/Common/test/tFileLocator.cc +++ b/LCS/Common/test/tFileLocator.cc @@ -38,6 +38,14 @@ } \ } while(0) +#define CHECK_EQUAL(a,b) \ + do { \ + if ((a) != (b)) { \ + errors++; \ + LOG_ERROR_STR("Check '" #a " == " #b "' failed: " << a << " != " << b); \ + } \ + } while(0) + using namespace LOFAR; int errors; @@ -49,12 +57,11 @@ void setup(const string& progname) { string tmpdir(progname + "_tmp"); string subdir(tmpdir + "/foo"); - string filename("bar.baz"); // Ignore mkdir() errors; they will be caught later anyway. mkdir(tmpdir.c_str(), S_IRWXU); mkdir(subdir.c_str(), S_IRWXU); - ASSERT(ofstream((tmpdir + "/" + filename).c_str())); - ASSERT(ofstream((subdir + "/" + filename).c_str())); + ASSERT(ofstream((tmpdir + "/bar.baz").c_str())); + ASSERT(ofstream((subdir + "/foo.bar").c_str())); ASSERT(chdir(tmpdir.c_str()) == 0); } @@ -216,6 +223,8 @@ int main (int, char *argv[]) { // Note: the files and directories used in the two tests below // were created by the setup() function. + + // Locate file with no subdir set string filename("bar.baz"); string subdir; string refpath; @@ -224,15 +233,18 @@ int main (int, char *argv[]) { LOG_INFO_STR ("Trying to locate file '" << filename << "'"); refpath = "./" + (subdir.empty() ? "" : subdir + "/") + filename; LOG_INFO_STR("fullname = " << Locator2.locate(filename)); - CHECK(Locator2.locate(filename) == realpath(refpath)); + CHECK_EQUAL(realpath(Locator2.locate(filename)), realpath(refpath)); + // Locate file in a subdir (need to locate a different file, since + // locating the file without using the subdir takes preference) subdir += "foo"; + filename = "foo.bar"; LOG_INFO_STR ("Setting subdir to '" << subdir << "'"); Locator2.setSubdir(subdir); LOG_INFO_STR ("Trying to locate file '" << filename << "'"); refpath = "./" + (subdir.empty() ? "" : subdir + "/") + filename; LOG_INFO_STR("fullname = " << Locator2.locate(filename)); - CHECK(Locator2.locate(filename) == realpath(refpath)); + CHECK_EQUAL(realpath(Locator2.locate(filename)), realpath(refpath)); LOG_INFO ("Creating fileLocator with two variables"); FileLocator Locator3("$LOFARROOT:$LOFARROOT");