ctkDICOMDatabaseTest7.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QCoreApplication>
  16. #include <QDir>
  17. // ctkDICOMCore includes
  18. #include "ctkDICOMDatabase.h"
  19. // STD includes
  20. #include <iostream>
  21. #include <cstdlib>
  22. int ctkDICOMDatabaseTest7( int argc, char * argv [] )
  23. {
  24. QCoreApplication app(argc, argv);
  25. ctkDICOMDatabase database;
  26. QDir databaseDirectory = QDir::temp();
  27. databaseDirectory.remove("ctkDICOMDatabase.sql");
  28. databaseDirectory.remove("ctkDICOMTagCache.sql");
  29. QFileInfo databaseFile(databaseDirectory, QString("database.test"));
  30. database.openDatabase(databaseFile.absoluteFilePath());
  31. bool res = database.initializeDatabase();
  32. if (!res)
  33. {
  34. std::cerr << "ctkDICOMDatabase::initializeDatabase() failed." << std::endl;
  35. return EXIT_FAILURE;
  36. }
  37. std::cerr << "Database is in " << databaseDirectory.path().toStdString() << std::endl;
  38. // try to call fileValue with bogus data: invalid filename and arbitrary tag
  39. // - should not trigger and exception
  40. // (see https://github.com/commontk/CTK/issues/706)
  41. // - result should be empty string
  42. // (see https://github.com/commontk/CTK/issues/749)
  43. QString result = database.fileValue("/tmp/file-that-does-not-exist", "00ff,eeee");
  44. if (result != "")
  45. {
  46. std::cerr << "ctkDICOMDatabase::fileValue() failed for file that doesn't exist." << std::endl;
  47. return EXIT_FAILURE;
  48. }
  49. //
  50. // Close and clean up
  51. //
  52. database.closeDatabase();
  53. return EXIT_SUCCESS;
  54. }