Skip to content
Snippets Groups Projects
Commit 58a5afe8 authored by Jan David Mol's avatar Jan David Mol
Browse files

SW-644: Fixed test for tFileLocator which used conflicting precedence...

SW-644: Fixed test for tFileLocator which used conflicting precedence resolution wrt (merged) design. Conflict was whether looking in a provided subdir takes precedence (test said yes, code says no)
parent 330b41a3
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,14 @@ ...@@ -38,6 +38,14 @@
} \ } \
} while(0) } 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; using namespace LOFAR;
int errors; int errors;
...@@ -49,12 +57,11 @@ void setup(const string& progname) ...@@ -49,12 +57,11 @@ void setup(const string& progname)
{ {
string tmpdir(progname + "_tmp"); string tmpdir(progname + "_tmp");
string subdir(tmpdir + "/foo"); string subdir(tmpdir + "/foo");
string filename("bar.baz");
// Ignore mkdir() errors; they will be caught later anyway. // Ignore mkdir() errors; they will be caught later anyway.
mkdir(tmpdir.c_str(), S_IRWXU); mkdir(tmpdir.c_str(), S_IRWXU);
mkdir(subdir.c_str(), S_IRWXU); mkdir(subdir.c_str(), S_IRWXU);
ASSERT(ofstream((tmpdir + "/" + filename).c_str())); ASSERT(ofstream((tmpdir + "/bar.baz").c_str()));
ASSERT(ofstream((subdir + "/" + filename).c_str())); ASSERT(ofstream((subdir + "/foo.bar").c_str()));
ASSERT(chdir(tmpdir.c_str()) == 0); ASSERT(chdir(tmpdir.c_str()) == 0);
} }
...@@ -216,6 +223,8 @@ int main (int, char *argv[]) { ...@@ -216,6 +223,8 @@ int main (int, char *argv[]) {
// Note: the files and directories used in the two tests below // Note: the files and directories used in the two tests below
// were created by the setup() function. // were created by the setup() function.
// Locate file with no subdir set
string filename("bar.baz"); string filename("bar.baz");
string subdir; string subdir;
string refpath; string refpath;
...@@ -224,15 +233,18 @@ int main (int, char *argv[]) { ...@@ -224,15 +233,18 @@ int main (int, char *argv[]) {
LOG_INFO_STR ("Trying to locate file '" << filename << "'"); LOG_INFO_STR ("Trying to locate file '" << filename << "'");
refpath = "./" + (subdir.empty() ? "" : subdir + "/") + filename; refpath = "./" + (subdir.empty() ? "" : subdir + "/") + filename;
LOG_INFO_STR("fullname = " << Locator2.locate(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"; subdir += "foo";
filename = "foo.bar";
LOG_INFO_STR ("Setting subdir to '" << subdir << "'"); LOG_INFO_STR ("Setting subdir to '" << subdir << "'");
Locator2.setSubdir(subdir); Locator2.setSubdir(subdir);
LOG_INFO_STR ("Trying to locate file '" << filename << "'"); LOG_INFO_STR ("Trying to locate file '" << filename << "'");
refpath = "./" + (subdir.empty() ? "" : subdir + "/") + filename; refpath = "./" + (subdir.empty() ? "" : subdir + "/") + filename;
LOG_INFO_STR("fullname = " << Locator2.locate(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"); LOG_INFO ("Creating fileLocator with two variables");
FileLocator Locator3("$LOFARROOT:$LOFARROOT"); FileLocator Locator3("$LOFARROOT:$LOFARROOT");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment