* the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tocc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 *  along with Tocc.  If not, see <http://www.gnu.org/licenses/>.
 */


#include <catch.hpp>

#include "libtocc/front_end/manager.h"
#include "libtocc/common/database_exceptions.h"


TEST_CASE("Manager::get tests")
{
  libtocc::Manager manager("/tmp/tocctests/");

  SECTION("file not found error")
  {
    REQUIRE_THROWS_AS(
        manager.get_file_info("e31b6da"),
        libtocc::DatabaseScriptLogicalError);
  }
}
  // Creating an instance of the manager.
  libtocc::Manager manager("/tmp/tocctests/");

  SECTION("Importing a file with no property")
  {
    // Importing the file with no property.
    libtocc::FileInfo test_file =
        manager.import_file("/tmp/tocctests/tocc_test_file_to_import_2");
    // Checking if it's OK.
    REQUIRE(strcmp(test_file.get_title(), "tocc_test_file_to_import_2") == 0);
    REQUIRE(strcmp(test_file.get_traditional_path(), "") == 0);
    REQUIRE(test_file.get_tags().size() == 0);

    // Getting the file again.
    libtocc::FileInfo fetched_test_file = manager.get_file_info(test_file.get_id());
    // Checking if it's OK.
    REQUIRE(strcmp(fetched_test_file.get_title(), "tocc_test_file_to_import_2") == 0);
    REQUIRE(strcmp(fetched_test_file.get_traditional_path(), "") == 0);
    REQUIRE(fetched_test_file.get_tags().size() == 0);
  }

  SECTION("Importing the file with Title and Traditional Path")
  {
    libtocc::FileInfo test_file_2 =
        manager.import_file("/tmp/tocctests/tocc_test_file_to_import_2",
                            "Title of the test file",
                            "/home/not_well_organized/test");
    // Checking if it's OK.
    REQUIRE(strcmp(test_file_2.get_title(), "Title of the test file") == 0);
    REQUIRE(strcmp(test_file_2.get_traditional_path(), "/home/not_well_organized/test") == 0);