Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / src / core / juce_Initialisation.cpp
blob8696ba660481bc873d6a517f18776c23a20b49bf
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "juce_StandardHeader.h"
28 BEGIN_JUCE_NAMESPACE
30 #include "juce_PlatformUtilities.h"
31 #include "../utilities/juce_DeletedAtShutdown.h"
33 #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
34 #include "../events/juce_MessageManager.h"
35 #endif
37 //==============================================================================
38 #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
40 static bool juceInitialisedGUI = false;
42 JUCE_API void JUCE_CALLTYPE initialiseJuce_GUI()
44 if (! juceInitialisedGUI)
46 juceInitialisedGUI = true;
48 JUCE_AUTORELEASEPOOL
49 MessageManager::getInstance();
53 JUCE_API void JUCE_CALLTYPE shutdownJuce_GUI()
55 if (juceInitialisedGUI)
57 juceInitialisedGUI = false;
59 JUCE_AUTORELEASEPOOL
60 DeletedAtShutdown::deleteAll();
61 delete MessageManager::getInstance();
65 #endif
67 //==============================================================================
68 #if JUCE_UNIT_TESTS
70 #include "../utilities/juce_UnitTest.h"
71 #include "../memory/juce_Atomic.h"
73 class AtomicTests : public UnitTest
75 public:
76 AtomicTests() : UnitTest ("Atomics") {}
78 void runTest()
80 beginTest ("Misc");
82 char a1[7];
83 expect (numElementsInArray(a1) == 7);
84 int a2[3];
85 expect (numElementsInArray(a2) == 3);
87 expect (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
88 expect (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
89 expect (ByteOrder::swap ((uint64) literal64bit (0x1122334455667788)) == literal64bit (0x8877665544332211));
91 beginTest ("Atomic int");
92 AtomicTester <int>::testInteger (*this);
93 beginTest ("Atomic unsigned int");
94 AtomicTester <unsigned int>::testInteger (*this);
95 beginTest ("Atomic int32");
96 AtomicTester <int32>::testInteger (*this);
97 beginTest ("Atomic uint32");
98 AtomicTester <uint32>::testInteger (*this);
99 beginTest ("Atomic long");
100 AtomicTester <long>::testInteger (*this);
101 beginTest ("Atomic void*");
102 AtomicTester <void*>::testInteger (*this);
103 beginTest ("Atomic int*");
104 AtomicTester <int*>::testInteger (*this);
105 beginTest ("Atomic float");
106 AtomicTester <float>::testFloat (*this);
107 #if ! JUCE_64BIT_ATOMICS_UNAVAILABLE // 64-bit intrinsics aren't available on some old platforms
108 beginTest ("Atomic int64");
109 AtomicTester <int64>::testInteger (*this);
110 beginTest ("Atomic uint64");
111 AtomicTester <uint64>::testInteger (*this);
112 beginTest ("Atomic double");
113 AtomicTester <double>::testFloat (*this);
114 #endif
117 template <typename Type>
118 class AtomicTester
120 public:
121 AtomicTester() {}
123 static void testInteger (UnitTest& test)
125 Atomic<Type> a, b;
126 a.set ((Type) 10);
127 test.expect (a.value == (Type) 10);
128 test.expect (a.get() == (Type) 10);
129 a += (Type) 15;
130 test.expect (a.get() == (Type) 25);
131 a.memoryBarrier();
132 a -= (Type) 5;
133 test.expect (a.get() == (Type) 20);
134 test.expect (++a == (Type) 21);
135 ++a;
136 test.expect (--a == (Type) 21);
137 test.expect (a.get() == (Type) 21);
138 a.memoryBarrier();
140 testFloat (test);
143 static void testFloat (UnitTest& test)
145 Atomic<Type> a, b;
146 a = (Type) 21;
147 a.memoryBarrier();
149 /* These are some simple test cases to check the atomics - let me know
150 if any of these assertions fail on your system!
152 test.expect (a.get() == (Type) 21);
153 test.expect (a.compareAndSetValue ((Type) 100, (Type) 50) == (Type) 21);
154 test.expect (a.get() == (Type) 21);
155 test.expect (a.compareAndSetValue ((Type) 101, a.get()) == (Type) 21);
156 test.expect (a.get() == (Type) 101);
157 test.expect (! a.compareAndSetBool ((Type) 300, (Type) 200));
158 test.expect (a.get() == (Type) 101);
159 test.expect (a.compareAndSetBool ((Type) 200, a.get()));
160 test.expect (a.get() == (Type) 200);
162 test.expect (a.exchange ((Type) 300) == (Type) 200);
163 test.expect (a.get() == (Type) 300);
165 b = a;
166 test.expect (b.get() == a.get());
171 static AtomicTests atomicUnitTests;
173 #endif
175 END_JUCE_NAMESPACE