Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
100 lines (87 loc) · 2.71 KB

File metadata and controls

100 lines (87 loc) · 2.71 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <juce_gui_basics/juce_gui_basics.h>
#include <random>
#include "Utility/Config.h"
#include "Utility/OSUtils.h"
#include "Sidebar/Sidebar.h" // So we can read and clear the console
#include "Objects/ObjectBase.h" // So we can interact with object GUIs
#include "PluginEditor.h"
class PlugDataUnitTest : public UnitTest, public AsyncUpdater
{
protected:
PlugDataUnitTest(PluginEditor* editor, String const& name) : UnitTest(name), editor(editor)
{
}
virtual void perform() = 0;
void signalDone(bool result)
{
testResult = result;
testDone.signal();
}
// Generate a random float
float generateRandomFloat()
{
return rng.nextInt(100) / 10.0f;
}
pd::Atom generateIncorrectArg()
{
return generateRandomFloat() < 10.0f ? pd::Atom(generateRandomFloat()) : pd::Atom(generateRandomString(rng.nextInt() + 5));
}
t_symbol* generateRandomString(size_t length)
{
const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
std::string result;
for (size_t i = 0; i < length; ++i)
{
result += charset[rng.nextInt(sizeof(charset) - 2)];
}
return gensym(result.c_str());
}
// Generate a random pd::Atom based on type
SmallArray<pd::Atom> generateAtomForType(const std::string& type)
{
if (type == "<float>" || type == "<f>")
{
return {pd::Atom(generateRandomFloat())};
}
else if (type == "<float, float>" || type == "<f, f>")
{
// Make second float higher, in case it's a range
auto rand1 = generateRandomFloat();
return {pd::Atom(rand1), pd::Atom(rand1 + generateRandomFloat())};
}
else if (type == "<symbol>")
{
return {pd::Atom(generateRandomString(10))};
}
else if (type == "<int>")
{
return {pd::Atom(static_cast<int>(rand() % 12))}; // Random integer
}
else if (type == "<bool>")
{
return {pd::Atom(static_cast<int>(rand() % 2))}; // Random boolean (as 0 or 1)
}
else
{
// Default to a random float for unrecognized types
return {pd::Atom(generateRandomFloat())};
}
}
private:
void runTest() final
{
rng = getRandom();
triggerAsyncUpdate();
testDone.wait();
expect(testResult, "Test failed");
}
void handleAsyncUpdate() final
{
perform();
}
WaitableEvent testDone;
protected:
Random rng;
bool testResult;
PluginEditor* editor;
};
Morty Proxy This is a proxified and sanitized view of the page, visit original site.