Re: [mitk-users] Access resources in a test instance
As an addendum to Saschas answer, we do do not have a json reader for IOUtil, so the second mentioned way would be the way to go. Von: Sascha Zelzer [mailto:sascha.zel...@gmail.com] Gesendet: Mittwoch, 4. April 2018 19:39 An: mitk-users@lists.sourceforge.net Betreff: Re: [mitk-users] Access resources in a test instance Hi, this cannot work since mitk::IOUtil::Load("/some/path") expects its string argument to represent a path in some local file system. It cannot know that what you pass in is the name of some embedded resource in your module. However, there is a mitk::IOUtil::Load overload [1] that takes a ModuleResouce instance as first argument. You can also create a ModuleResourceStream object and read the embedded binary data from it (just like you do with normal C++ stream objects). Best, Sascha [1] http://docs.mitk.org/nightly/classmitk_1_1IOUtil.html#a04c23c6cf7834ddce66831376740ae2d On 03/29/2018 10:28 PM, Alex Valcourt Caron wrote: Hi, I am presently trying to access some files placed in a Resources folder in my test directory, which I included to my build via the set(RESOURCE_FILES ...) cmake variable in my files.cmake. I was wondering how to access them via my test classes however. mitk::IOUtil::Load doesn't seem to know where to find them with just the file names (example : I have a file named "fiber.json" and try to load it with mitk::IOUtil::Load("fiber.json")). I want my tests to be path agnostic so the resource mechanism seems to me the way to do it. However, I have to admit I am having trouble understanding how the building of the project handles it. Can somebody point to me where the files should be located via the way I am presently including them (I found a .zip with them, but that is all) ? Or what is missing to make them accessible through this way (if possible) ? I would prefer not having to make use of the mitkAddCustomModuleTest function if possible. I don't know neither if it would work with my test classes. Thanks , Alex -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ mitk-users mailing list mitk-users@lists.sourceforge.net<mailto:mitk-users@lists.sourceforge.net> https://lists.sourceforge.net/lists/listinfo/mitk-users -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ mitk-users mailing list mitk-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mitk-users
Re: [mitk-users] Access resources in a test instance
Hi, this cannot work since mitk::IOUtil::Load("/some/path") expects its string argument to represent a path in some local file system. It cannot know that what you pass in is the name of some embedded resource in your module. However, there is a mitk::IOUtil::Load overload [1] that takes a ModuleResouce instance as first argument. You can also create a ModuleResourceStream object and read the embedded binary data from it (just like you do with normal C++ stream objects). Best, Sascha [1] http://docs.mitk.org/nightly/classmitk_1_1IOUtil.html#a04c23c6cf7834ddce66831376740ae2d On 03/29/2018 10:28 PM, Alex Valcourt Caron wrote: > > Hi, > > > I am presently trying to access some files placed in a Resources > folder in my test directory, which I included to my build via the > set(RESOURCE_FILES ...) cmake variable in my files.cmake. > > > I was wondering how to access them via my test classes however. > mitk::IOUtil::Load doesn't seem to know where to find them with just > the file names (example : I have a file named "fiber.json" and try to > load it with mitk::IOUtil::Load("fiber.json")). > > > I want my tests to be path agnostic so the resource mechanism seems to > me the way to do it. However, I have to admit I am having trouble > understanding how the building of the project handles it. > > > Can somebody point to me where the files should be located via the way > I am presently including them (I found a .zip with them, but that is > all) ? Or what is missing to make them accessible through this way (if > possible) ? > > > I would prefer not having to make use of the mitkAddCustomModuleTest > function if possible. I don't know neither if it would work with my > test classes. > > > Thanks , > > Alex > > > > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > > ___ > mitk-users mailing list > mitk-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mitk-users -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ mitk-users mailing list mitk-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mitk-users
Re: [mitk-users] Access resources in a test instance
Hi Alex, I am loading my own jsons from resources here: https://github.com/MITK/MITK/blob/master/Modules/CEST/files.cmake https://github.com/MITK/MITK/blob/master/Modules/CEST/src/mitkCustomTagParser.cpp#L337-L350 Hope this helps, Best, Caspar Von: Alex Valcourt Caron [mailto:alex.valcourt.ca...@usherbrooke.ca] Gesendet: Donnerstag, 29. März 2018 22:29 An: mitk-users@lists.sourceforge.net Betreff: [mitk-users] Access resources in a test instance Hi, I am presently trying to access some files placed in a Resources folder in my test directory, which I included to my build via the set(RESOURCE_FILES ...) cmake variable in my files.cmake. I was wondering how to access them via my test classes however. mitk::IOUtil::Load doesn't seem to know where to find them with just the file names (example : I have a file named "fiber.json" and try to load it with mitk::IOUtil::Load("fiber.json")). I want my tests to be path agnostic so the resource mechanism seems to me the way to do it. However, I have to admit I am having trouble understanding how the building of the project handles it. Can somebody point to me where the files should be located via the way I am presently including them (I found a .zip with them, but that is all) ? Or what is missing to make them accessible through this way (if possible) ? I would prefer not having to make use of the mitkAddCustomModuleTest function if possible. I don't know neither if it would work with my test classes. Thanks , Alex -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ mitk-users mailing list mitk-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mitk-users