Skip to content

Commit f0d74b3

Browse files
ci: formatting
1 parent c753805 commit f0d74b3

File tree

9 files changed

+342
-335
lines changed

9 files changed

+342
-335
lines changed

packages/react-native-audio-api/common/cpp/test/src/FatFunctionTest.cpp

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include <gtest/gtest.h>
21
#include <audioapi/utils/FatFunction.hpp>
2+
#include <gtest/gtest.h>
33
#include <cstddef>
44
#include <memory>
5-
#include <utility>
65
#include <stdexcept>
76
#include <type_traits>
7+
#include <utility>
88

99
using namespace audioapi;
1010

@@ -24,20 +24,24 @@ class FatFunctionTest : public ::testing::Test {
2424
};
2525

2626
TEST(FatFunctionTest, BasicFunctionality) {
27-
FatFunction<64, IntOp> add = [](int a, int b) { return a + b; };
27+
FatFunction<64, IntOp> add = [](int a, int b) {
28+
return a + b;
29+
};
2830
EXPECT_EQ(add(2, 3), 5);
2931
// FatFunction contains both raw storage and function pointers.
3032
// The compiler may add tail padding so each instance still satisfies
3133
// alignof(std::max_align_t), especially when objects are placed in arrays.
3234
// We therefore compare against the aligned size, not just the raw field sum.
33-
constexpr size_t dataSize = 64 + sizeof(void*) * 3;
35+
constexpr size_t dataSize = 64 + sizeof(void *) * 3;
3436
constexpr size_t alignment = alignof(std::max_align_t);
3537
constexpr size_t expectedSize = ((dataSize + alignment - 1) / alignment) * alignment;
3638
EXPECT_EQ(sizeof(add), expectedSize);
3739
}
3840

3941
TEST(FatFunctionTest, MoveSemantics) {
40-
FatFunction<64, IntOp> add = [](int a, int b) { return a + b; };
42+
FatFunction<64, IntOp> add = [](int a, int b) {
43+
return a + b;
44+
};
4145
FatFunction<64, IntOp> movedAdd = std::move(add);
4246
EXPECT_EQ(movedAdd(4, 5), 9);
4347
EXPECT_THROW(add(1, 2), std::bad_function_call); // Original should be empty
@@ -46,25 +50,29 @@ TEST(FatFunctionTest, MoveSemantics) {
4650
TEST(FatFunctionTest, Release) {
4751
int destructorCalls = 0;
4852
struct Tracked {
49-
int* counter;
50-
explicit Tracked(int* c) : counter(c) {}
51-
int operator()(int a, int b) const { return a + b; }
52-
~Tracked() { (*counter)++; }
53+
int *counter;
54+
explicit Tracked(int *c) : counter(c) {}
55+
int operator()(int a, int b) const {
56+
return a + b;
57+
}
58+
~Tracked() {
59+
(*counter)++;
60+
}
5361
};
5462

5563
{
56-
FatFunction<64, IntOp> add = Tracked(&destructorCalls);
57-
// we comment this because compiler can optimize it and do not call destructor here
58-
// EXPECT_EQ(destructorCalls, 1); // Destructor called for the temporary Tracked object, but not for the one inside add
59-
destructorCalls = 0; // Reset counter after construction
60-
auto [storage, deleter] = add.release();
61-
EXPECT_GT(storage.size(), 0);
62-
EXPECT_NE(deleter, nullptr);
63-
64-
// We can call the deleter to clean up resources if needed
65-
if (deleter) {
66-
deleter(storage.data());
67-
}
64+
FatFunction<64, IntOp> add = Tracked(&destructorCalls);
65+
// we comment this because compiler can optimize it and do not call destructor here
66+
// EXPECT_EQ(destructorCalls, 1); // Destructor called for the temporary Tracked object, but not for the one inside add
67+
destructorCalls = 0; // Reset counter after construction
68+
auto [storage, deleter] = add.release();
69+
EXPECT_GT(storage.size(), 0);
70+
EXPECT_NE(deleter, nullptr);
71+
72+
// We can call the deleter to clean up resources if needed
73+
if (deleter) {
74+
deleter(storage.data());
75+
}
6876
} // FatFunction goes out of scope here, but it was released so it shouldn't destroy the object again
6977

7078
EXPECT_EQ(destructorCalls, 1); // Destructor should have been called exactly once from the deleter
@@ -76,12 +84,16 @@ TEST(FatFunctionTest, EmptyFunctionCall) {
7684
}
7785

7886
TEST(FatFunctionTest, SwapFunctions) {
79-
FatFunction<64, IntOp> add = [](int a, int b) { return a + b; };
80-
FatFunction<64, IntOp> multiply = [](int a, int b) { return a * b; };
87+
FatFunction<64, IntOp> add = [](int a, int b) {
88+
return a + b;
89+
};
90+
FatFunction<64, IntOp> multiply = [](int a, int b) {
91+
return a * b;
92+
};
8193

8294
std::swap(add, multiply);
8395

84-
EXPECT_EQ(add(2, 3), 6); // Now add should multiply
96+
EXPECT_EQ(add(2, 3), 6); // Now add should multiply
8597
EXPECT_EQ(multiply(2, 3), 5); // Now multiply should add
8698
}
8799

@@ -110,14 +122,18 @@ TEST(FatFunctionTest, TriviallyMoveableCallable) {
110122
}
111123

112124
TEST(FatFunctionTest, SmallerToLargerMove) {
113-
FatFunction<32, IntOp> smallFunc = [](int a, int b) { return a + b; };
125+
FatFunction<32, IntOp> smallFunc = [](int a, int b) {
126+
return a + b;
127+
};
114128
FatFunction<64, IntOp> largeFunc = std::move(smallFunc);
115129
EXPECT_EQ(largeFunc(2, 3), 5);
116130
EXPECT_THROW(smallFunc(1, 2), std::bad_function_call); // Original should be empty
117131
}
118132

119133
TEST(FatFunctionTest, LargerToSmallerMove) {
120-
FatFunction<64, IntOp> largeFunc = [](int a, int b) { return a * b; };
134+
FatFunction<64, IntOp> largeFunc = [](int a, int b) {
135+
return a * b;
136+
};
121137
// This should fail to compile because largeFunc exceeds the storage size of smallFunc
122138
bool isConstructible = std::is_constructible_v<FatFunction<32, IntOp>, decltype(largeFunc)>;
123139
EXPECT_FALSE(isConstructible);
@@ -128,21 +144,24 @@ TEST(FatFunctionTest, SmallerToLargerMoveWithNonTrivialMoveAndDestruct) {
128144
int moverCalled = 0;
129145

130146
struct NonTrivialCallable {
131-
int* dCounter;
132-
int* mCounter;
147+
int *dCounter;
148+
int *mCounter;
133149

134-
NonTrivialCallable(int* d, int* m) : dCounter(d), mCounter(m) {}
150+
NonTrivialCallable(int *d, int *m) : dCounter(d), mCounter(m) {}
135151

136152
int operator()(int a, int b) const {
137153
return a + b;
138154
}
139155
~NonTrivialCallable() {
140-
if (dCounter) (*dCounter)++;
156+
if (dCounter)
157+
(*dCounter)++;
141158
}
142-
NonTrivialCallable(NonTrivialCallable&& other) : dCounter(other.dCounter), mCounter(other.mCounter) {
143-
if (mCounter) (*mCounter)++;
159+
NonTrivialCallable(NonTrivialCallable &&other)
160+
: dCounter(other.dCounter), mCounter(other.mCounter) {
161+
if (mCounter)
162+
(*mCounter)++;
144163
}
145-
NonTrivialCallable(const NonTrivialCallable&) = delete; // Non-copyable
164+
NonTrivialCallable(const NonTrivialCallable &) = delete; // Non-copyable
146165
};
147166

148167
{
@@ -172,9 +191,9 @@ TEST(FatFunctionTest, MutableLambdaBasic) {
172191
counter++;
173192
return a + b + counter;
174193
};
175-
EXPECT_EQ(func(1, 2), 4); // 1 + 2 + 1
176-
EXPECT_EQ(func(1, 2), 5); // 1 + 2 + 2
177-
EXPECT_EQ(func(1, 2), 6); // 1 + 2 + 3
194+
EXPECT_EQ(func(1, 2), 4); // 1 + 2 + 1
195+
EXPECT_EQ(func(1, 2), 5); // 1 + 2 + 2
196+
EXPECT_EQ(func(1, 2), 6); // 1 + 2 + 3
178197
}
179198

180199
TEST(FatFunctionTest, MutableLambdaWithUniquePtr) {

packages/react-native-audio-api/common/cpp/test/src/graph/AudioGraphFuzzTest.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <gtest/gtest.h>
21
#include <audioapi/core/utils/graph/AudioGraph.hpp>
32
#include <audioapi/core/utils/graph/NodeHandle.hpp>
3+
#include <gtest/gtest.h>
44
#include "TestGraphUtils.h"
55

66
#include <algorithm>
@@ -52,8 +52,7 @@ class AudioGraphFuzzTest : public ::testing::TestWithParam<uint64_t> {
5252
// pickLive() will skip it because it checks orphaned status.
5353
}
5454

55-
void doAddEdge(std::shared_ptr<NodeHandle<MNode>> &from,
56-
std::shared_ptr<NodeHandle<MNode>> &to) {
55+
void doAddEdge(std::shared_ptr<NodeHandle<MNode>> &from, std::shared_ptr<NodeHandle<MNode>> &to) {
5756
auto fromIdx = from->index;
5857
auto toIdx = to->index;
5958
// Verify at point-of-add that this edge doesn't create a duplicate
@@ -68,8 +67,9 @@ class AudioGraphFuzzTest : public ::testing::TestWithParam<uint64_t> {
6867
graph.markDirty();
6968
}
7069

71-
void doRemoveEdge(std::shared_ptr<NodeHandle<MNode>> &from,
72-
std::shared_ptr<NodeHandle<MNode>> &to) {
70+
void doRemoveEdge(
71+
std::shared_ptr<NodeHandle<MNode>> &from,
72+
std::shared_ptr<NodeHandle<MNode>> &to) {
7373
// Same as what HostGraph's removeEdge event does
7474
graph.pool().remove(graph[to->index].input_head, from->index);
7575
graph.markDirty();
@@ -82,9 +82,8 @@ class AudioGraphFuzzTest : public ::testing::TestWithParam<uint64_t> {
8282
auto n = static_cast<uint32_t>(graph.size());
8383
for (uint32_t i = 0; i < n; i++) {
8484
for (auto inp : graph.pool().view(graph[i].input_head)) {
85-
ASSERT_LT(inp, n)
86-
<< "Node[" << i << "] (id=" << graph[i].test_node_identifier__
87-
<< ") has OOB input index " << inp << " (graph size=" << n << ")";
85+
ASSERT_LT(inp, n) << "Node[" << i << "] (id=" << graph[i].test_node_identifier__
86+
<< ") has OOB input index " << inp << " (graph size=" << n << ")";
8887
}
8988
}
9089
}
@@ -161,7 +160,8 @@ class AudioGraphFuzzTest : public ::testing::TestWithParam<uint64_t> {
161160
<< " orphaned=" << graph[i].orphaned << " inputs={";
162161
bool first = true;
163162
for (auto inp : graph.pool().view(graph[i].input_head)) {
164-
if (!first) std::cerr << ",";
163+
if (!first)
164+
std::cerr << ",";
165165
first = false;
166166
if (inp < n)
167167
std::cerr << inp << "(id=" << graph[inp].test_node_identifier__ << ")";
@@ -191,11 +191,11 @@ class AudioGraphFuzzTest : public ::testing::TestWithParam<uint64_t> {
191191
int pickLive() {
192192
std::vector<int> live;
193193
for (int i = 0; i < static_cast<int>(handles.size()); i++) {
194-
if (handles[i] && handles[i]->index < graph.size() &&
195-
!graph[handles[i]->index].orphaned)
194+
if (handles[i] && handles[i]->index < graph.size() && !graph[handles[i]->index].orphaned)
196195
live.push_back(i);
197196
}
198-
if (live.empty()) return -1;
197+
if (live.empty())
198+
return -1;
199199
return live[std::uniform_int_distribution<size_t>(0, live.size() - 1)(rng)];
200200
}
201201

@@ -206,7 +206,8 @@ class AudioGraphFuzzTest : public ::testing::TestWithParam<uint64_t> {
206206
// If adding fromIdx as input of toIdx, check if toIdx can reach fromIdx
207207
// through existing inputs (meaning fromIdx depends on toIdx already).
208208
auto n = static_cast<uint32_t>(graph.size());
209-
if (fromIdx == toIdx) return true;
209+
if (fromIdx == toIdx)
210+
return true;
210211

211212
std::vector<bool> visited(n, false);
212213
std::vector<uint32_t> stack;
@@ -217,7 +218,8 @@ class AudioGraphFuzzTest : public ::testing::TestWithParam<uint64_t> {
217218
auto cur = stack.back();
218219
stack.pop_back();
219220
for (auto inp : graph.pool().view(graph[cur].input_head)) {
220-
if (inp == toIdx) return true;
221+
if (inp == toIdx)
222+
return true;
221223
if (inp < n && !visited[inp]) {
222224
visited[inp] = true;
223225
stack.push_back(inp);
@@ -230,7 +232,8 @@ class AudioGraphFuzzTest : public ::testing::TestWithParam<uint64_t> {
230232
/// Check if edge already exists
231233
bool edgeExists(uint32_t fromIdx, uint32_t toIdx) {
232234
for (auto inp : graph.pool().view(graph[toIdx].input_head)) {
233-
if (inp == fromIdx) return true;
235+
if (inp == fromIdx)
236+
return true;
234237
}
235238
return false;
236239
}
@@ -289,7 +292,8 @@ TEST_P(AudioGraphFuzzTest, RandomOps) {
289292
}
290293
if (!inputVals.empty()) {
291294
// Pick a random input to remove
292-
auto inputIdx = inputVals[std::uniform_int_distribution<size_t>(0, inputVals.size() - 1)(rng)];
295+
auto inputIdx =
296+
inputVals[std::uniform_int_distribution<size_t>(0, inputVals.size() - 1)(rng)];
293297
// Find the handle with this index
294298
for (auto &h : handles) {
295299
if (h && h->index == inputIdx) {

packages/react-native-audio-api/common/cpp/test/src/graph/AudioGraphTest.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#include <gtest/gtest.h>
21
#include <audioapi/core/utils/graph/AudioGraph.hpp>
32
#include <audioapi/core/utils/graph/NodeHandle.hpp>
4-
#include "TestGraphUtils.h"
5-
#include <vector>
3+
#include <gtest/gtest.h>
64
#include <algorithm>
7-
#include <utility>
85
#include <memory>
6+
#include <utility>
7+
#include <vector>
8+
#include "TestGraphUtils.h"
99

1010
namespace audioapi::utils::graph {
1111

@@ -30,7 +30,9 @@ class AudioGraphTest : public ::testing::Test {
3030
}
3131

3232
/// @brief Adds N nodes with test identifiers 0..N-1 and returns their handles
33-
std::vector<std::shared_ptr<NodeHandle<MockNode>>> addNodes(size_t n, bool withAudioNode = false) {
33+
std::vector<std::shared_ptr<NodeHandle<MockNode>>> addNodes(
34+
size_t n,
35+
bool withAudioNode = false) {
3436
std::vector<std::shared_ptr<NodeHandle<MockNode>>> handles;
3537
handles.reserve(n);
3638
for (size_t i = 0; i < n; i++) {
@@ -55,7 +57,8 @@ class AudioGraphTest : public ::testing::Test {
5557
/// @brief Returns position of testId in the current order
5658
int posOf(size_t testId) {
5759
for (uint32_t i = 0; i < graph.size(); i++) {
58-
if (graph[i].test_node_identifier__ == testId) return static_cast<int>(i);
60+
if (graph[i].test_node_identifier__ == testId)
61+
return static_cast<int>(i);
5962
}
6063
return -1;
6164
}

packages/react-native-audio-api/common/cpp/test/src/graph/AudioThreadGuard.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "AudioThreadGuard.h"
22

3+
#include <sys/resource.h>
34
#include <cstdint>
45
#include <cstdlib>
56
#include <new>
6-
#include <sys/resource.h>
77

88
namespace audioapi::test {
99

@@ -30,17 +30,19 @@ size_t AudioThreadGuard::allocationViolations() {
3030
}
3131

3232
void AudioThreadGuard::recordAllocation() {
33-
if (g_armed) ++g_violations;
33+
if (g_armed)
34+
++g_violations;
3435
}
3536

3637
void AudioThreadGuard::recordDeallocation() {
37-
if (g_armed) ++g_violations;
38+
if (g_armed)
39+
++g_violations;
3840
}
3941

4042
// ── Context switches ──────────────────────────────────────────────────────
4143

4244
AudioThreadGuard::ContextSwitchSnapshot AudioThreadGuard::contextSwitches() {
43-
struct rusage usage {};
45+
struct rusage usage{};
4446
#if defined(__linux__)
4547
getrusage(RUSAGE_THREAD, &usage); // per-thread (Linux-only)
4648
#else
@@ -51,8 +53,7 @@ AudioThreadGuard::ContextSwitchSnapshot AudioThreadGuard::contextSwitches() {
5153

5254
// ── Scope ─────────────────────────────────────────────────────────────────
5355

54-
AudioThreadGuard::Scope::Scope()
55-
: startSnapshot_(contextSwitches()) {
56+
AudioThreadGuard::Scope::Scope() : startSnapshot_(contextSwitches()) {
5657
arm();
5758
}
5859

@@ -105,7 +106,8 @@ bool AudioThreadGuard::Scope::clean() const {
105106
void *allocate_with_thread_guard(std::size_t size) {
106107
audioapi::test::AudioThreadGuard::recordAllocation();
107108
void *p = std::malloc(size);
108-
if (!p) throw std::bad_alloc();
109+
if (!p)
110+
throw std::bad_alloc();
109111
return p;
110112
}
111113

0 commit comments

Comments
 (0)