1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /***************************************************************************
3  *            resource_test.cc
4  *
5  *  Fri Nov 13 18:50:52 CET 2015
6  *  Copyright 2015 Bent Bisballe Nyeng
7  *  deva@aasimon.org
8  ****************************************************************************/
9 
10 /*
11  *  This file is part of DrumGizmo.
12  *
13  *  DrumGizmo is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU Lesser General Public License as published by
15  *  the Free Software Foundation; either version 3 of the License, or
16  *  (at your option) any later version.
17  *
18  *  DrumGizmo is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU Lesser General Public License for more details.
22  *
23  *  You should have received a copy of the GNU Lesser General Public License
24  *  along with DrumGizmo; if not, write to the Free Software
25  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
26  */
27 #include <uunit.h>
28 
29 #include "../plugingui/resource.h"
30 
31 #include "drumkit_creator.h"
32 
33 class ResourceTester
34 	: public GUI::Resource
35 {
36 public:
ResourceTester(const std::string & name)37 	ResourceTester(const std::string& name)
38 		: GUI::Resource(name)
39 	{}
40 
probeIsInternal()41 	bool probeIsInternal()
42 	{
43 		return isInternal;
44 	}
45 };
46 
47 class ResourceTest
48 	: public uUnit
49 {
50 public:
ResourceTest()51 	ResourceTest()
52 	{
53 		uUNIT_TEST(ResourceTest::externalReadTest);
54 		uUNIT_TEST(ResourceTest::internalReadTest);
55 		uUNIT_TEST(ResourceTest::failTest);
56 	}
57 
58 	DrumkitCreator drumkit_creator;
59 
externalReadTest()60 	void externalReadTest()
61 	{
62 		auto filename = drumkit_creator.create0000Wav("0000.wav");
63 
64 		ResourceTester rc(filename);
65 		uUNIT_ASSERT(!rc.probeIsInternal());
66 		uUNIT_ASSERT(rc.valid());
67 		uUNIT_ASSERT_EQUAL((size_t)46, rc.size());
68 	}
69 
internalReadTest()70 	void internalReadTest()
71 	{
72 		ResourceTester rc(":resources/bg.png");
73 		uUNIT_ASSERT(rc.probeIsInternal());
74 		uUNIT_ASSERT(rc.valid());
75 		uUNIT_ASSERT_EQUAL((size_t)1123, rc.size());
76 	}
77 
failTest()78 	void failTest()
79 	{
80 		{
81 			ResourceTester rc("/tmp/");
82 			uUNIT_ASSERT(!rc.valid());
83 		}
84 
85 		{
86 			ResourceTester rc("no_such_file");
87 			uUNIT_ASSERT(!rc.valid());
88 		}
89 
90 		{
91 			ResourceTester rc(":no_such_file");
92 			uUNIT_ASSERT(!rc.valid());
93 		}
94 	}
95 };
96 
97 // Registers the fixture into the 'registry'
98 static ResourceTest test;
99