Skip to content

Commit 1335216

Browse files
committed
Some tweaks
1 parent d488b26 commit 1335216

7 files changed

Lines changed: 133 additions & 185 deletions

test/base64_test.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -612,63 +612,63 @@ TEST(Utility, Base64DecodeErrors)
612612
{
613613
SCOPED_TRACE("invalid char in std");
614614
const char* invalid_std = "SGVs#G8="; // '#' is invalid
615-
auto written = decode_base64(output, sizeof(output), invalid_std, 8, false, true);
615+
auto written = decode_base64(output, sizeof(output), invalid_std, 8, false, true);
616616
EXPECT_EQ(written, 0u);
617617
}
618618

619619
// URL-safe chars in standard mode should fail
620620
{
621621
SCOPED_TRACE("url char in std mode");
622622
const char* url_in_std = "3q2-7w=="; // '-' is URL-safe, not standard
623-
auto written = decode_base64(output, sizeof(output), url_in_std, 8, false, true);
623+
auto written = decode_base64(output, sizeof(output), url_in_std, 8, false, true);
624624
EXPECT_EQ(written, 0u);
625625
}
626626

627627
// Standard chars in URL mode should fail
628628
{
629629
SCOPED_TRACE("std char in url mode");
630630
const char* std_in_url = "3q2+7w=="; // '+' is standard, not URL-safe
631-
auto written = decode_base64(output, sizeof(output), std_in_url, 8, true, true);
631+
auto written = decode_base64(output, sizeof(output), std_in_url, 8, true, true);
632632
EXPECT_EQ(written, 0u);
633633
}
634634

635635
// Padding when padding=false should fail
636636
{
637637
SCOPED_TRACE("padding when disabled");
638638
const char* with_padding = "AA==";
639-
auto written = decode_base64(output, sizeof(output), with_padding, 4, false, false);
639+
auto written = decode_base64(output, sizeof(output), with_padding, 4, false, false);
640640
EXPECT_EQ(written, 0u);
641641
}
642642

643643
// Incomplete group with padding=true should fail (expects '=' in input)
644644
{
645645
SCOPED_TRACE("incomplete group with padding=true");
646646
const char* incomplete = "AAA"; // 3 chars, needs '=' padding char when padding=true
647-
auto written = decode_base64(output, sizeof(output), incomplete, 3, false, true);
647+
auto written = decode_base64(output, sizeof(output), incomplete, 3, false, true);
648648
EXPECT_EQ(written, 0u);
649649
}
650650

651651
// Incomplete group with padding=false should succeed (auto-pad)
652652
{
653653
SCOPED_TRACE("incomplete group with padding=false");
654654
const char* incomplete = "AAA"; // 3 chars, will be auto-padded
655-
auto written = decode_base64(output, sizeof(output), incomplete, 3, false, false);
655+
auto written = decode_base64(output, sizeof(output), incomplete, 3, false, false);
656656
EXPECT_EQ(written, 2u);
657657
}
658658

659659
// NULL output buffer
660660
{
661661
SCOPED_TRACE("null output");
662662
const char* valid = "SGVsbG8=";
663-
auto written = decode_base64(nullptr, 128, valid, 8, false, true);
663+
auto written = decode_base64(nullptr, 128, valid, 8, false, true);
664664
EXPECT_EQ(written, 0u);
665665
}
666666

667667
// Zero output length
668668
{
669669
SCOPED_TRACE("zero output length");
670670
const char* valid = "SGVsbG8=";
671-
auto written = decode_base64(output, 0, valid, 8, false, true);
671+
auto written = decode_base64(output, 0, valid, 8, false, true);
672672
EXPECT_EQ(written, 0u);
673673
}
674674

@@ -683,15 +683,15 @@ TEST(Utility, Base64DecodeErrors)
683683
{
684684
SCOPED_TRACE("zero input length");
685685
const char* valid = "SGVsbG8=";
686-
auto written = decode_base64(output, sizeof(output), valid, 0, false, true);
686+
auto written = decode_base64(output, sizeof(output), valid, 0, false, true);
687687
EXPECT_EQ(written, 0u);
688688
}
689689

690690
// Output buffer too small
691691
{
692692
SCOPED_TRACE("output buffer too small");
693693
const char* valid = "SGVsbG8="; // decodes to "Hello" (5 bytes)
694-
auto written = decode_base64(output, 3, valid, 8, false, true);
694+
auto written = decode_base64(output, 3, valid, 8, false, true);
695695
EXPECT_EQ(written, 0u);
696696
}
697697
}
@@ -701,7 +701,8 @@ TEST(Utility, Base64Roundtrip)
701701
SCOPED_TRACE("Base64Roundtrip");
702702

703703
// Test roundtrip: encode then decode should return original
704-
const uint8_t original[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
704+
const uint8_t original[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
705+
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
705706
char encoded[64]{};
706707
uint8_t decoded[64]{};
707708

@@ -786,9 +787,8 @@ TEST(Utility, Base64LineBreakPositions)
786787
for (uint32_t i = 0; i < len; ++i) {
787788
if (encoded[i] == '\n') {
788789
// Line break should occur exactly at line_len
789-
EXPECT_EQ(char_count, line_len)
790-
<< "Line break at wrong position. Expected after " << (int)line_len
791-
<< " chars, got after " << char_count << " at index " << i;
790+
EXPECT_EQ(char_count, line_len) << "Line break at wrong position. Expected after " << (int)line_len
791+
<< " chars, got after " << char_count << " at index " << i;
792792
char_count = 0;
793793
++line_count;
794794
} else {
@@ -812,7 +812,7 @@ TEST(Utility, Base64LineBreakPositions)
812812
SCOPED_TRACE("line_len=4");
813813
// 12 bytes input -> 16 base64 chars -> 4 lines of 4 chars with 3 newlines
814814
const uint8_t input[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B};
815-
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 4, false, true);
815+
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 4, false, true);
816816
EXPECT_GT(written, 0u);
817817

818818
// Expected: "AAEC\nAwQF\nBgcI\nCQoL" (16 chars + 3 newlines = 19)
@@ -831,7 +831,7 @@ TEST(Utility, Base64LineBreakPositions)
831831
SCOPED_TRACE("line_len=8");
832832
// 12 bytes input -> 16 base64 chars -> 2 lines of 8 chars with 1 newline
833833
const uint8_t input[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B};
834-
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 8, false, true);
834+
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 8, false, true);
835835
EXPECT_GT(written, 0u);
836836

837837
verify_linebreaks(output, written, 8);
@@ -848,7 +848,7 @@ TEST(Utility, Base64LineBreakPositions)
848848
SCOPED_TRACE("line_len=64 (PEM)");
849849
// 48 bytes input -> 64 base64 chars -> exactly 1 line, no newlines
850850
const uint8_t input[48] = {0};
851-
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 64, false, true);
851+
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 64, false, true);
852852
EXPECT_GT(written, 0u);
853853
EXPECT_EQ(written, 64u); // exactly 64 chars, no newline
854854

@@ -864,7 +864,7 @@ TEST(Utility, Base64LineBreakPositions)
864864
SCOPED_TRACE("line_len=64, overflow");
865865
// 49 bytes input -> 68 base64 chars (with padding) -> 1 line of 64 + 1 line of 4
866866
const uint8_t input[49] = {0};
867-
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 64, false, true);
867+
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 64, false, true);
868868
EXPECT_GT(written, 0u);
869869

870870
verify_linebreaks(output, written, 64);
@@ -881,7 +881,7 @@ TEST(Utility, Base64LineBreakPositions)
881881
SCOPED_TRACE("short input");
882882
// 3 bytes input -> 4 base64 chars -> no newlines needed
883883
const uint8_t input[] = {0x01, 0x02, 0x03};
884-
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 64, false, true);
884+
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 64, false, true);
885885
EXPECT_EQ(written, 4u);
886886

887887
uint32_t newline_count = 0;
@@ -896,7 +896,7 @@ TEST(Utility, Base64LineBreakPositions)
896896
SCOPED_TRACE("padding with linebreak");
897897
// 5 bytes -> 8 chars (with ==) -> with line_len=4: "AQID\nBAU=" (4+1+4=9)
898898
const uint8_t input[] = {0x01, 0x02, 0x03, 0x04, 0x05};
899-
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 4, false, true);
899+
auto written = encode_base64(output, sizeof(output), input, sizeof(input), 4, false, true);
900900
EXPECT_GT(written, 0u);
901901

902902
verify_linebreaks(output, written, 4);
@@ -916,15 +916,15 @@ TEST(Utility, Base64EncodeErrors)
916916
{
917917
SCOPED_TRACE("null output");
918918
const uint8_t input[] = {0x01, 0x02, 0x03};
919-
auto written = encode_base64(nullptr, 128, input, sizeof(input), 0, false, true);
919+
auto written = encode_base64(nullptr, 128, input, sizeof(input), 0, false, true);
920920
EXPECT_EQ(written, 0u);
921921
}
922922

923923
// Zero output length
924924
{
925925
SCOPED_TRACE("zero output length");
926926
const uint8_t input[] = {0x01, 0x02, 0x03};
927-
auto written = encode_base64(output, 0, input, sizeof(input), 0, false, true);
927+
auto written = encode_base64(output, 0, input, sizeof(input), 0, false, true);
928928
EXPECT_EQ(written, 0u);
929929
}
930930

@@ -939,7 +939,7 @@ TEST(Utility, Base64EncodeErrors)
939939
{
940940
SCOPED_TRACE("zero input length");
941941
const uint8_t input[] = {0x01, 0x02, 0x03};
942-
auto written = encode_base64(output, sizeof(output), input, 0, 0, false, true);
942+
auto written = encode_base64(output, sizeof(output), input, 0, 0, false, true);
943943
EXPECT_EQ(written, 0u);
944944
}
945945

@@ -1009,15 +1009,15 @@ TEST(Utility, Base64EncodeErrors)
10091009
{
10101010
SCOPED_TRACE("buffer too small for padding");
10111011
const uint8_t input[] = {0x01, 0x02}; // 2 bytes -> "AQI=" (4 chars with padding)
1012-
auto written = encode_base64(output, 4, input, sizeof(input), 0, false, true);
1012+
auto written = encode_base64(output, 4, input, sizeof(input), 0, false, true);
10131013
EXPECT_EQ(written, 0u); // needs 5 for null
10141014
}
10151015

10161016
// Without padding, shorter output
10171017
{
10181018
SCOPED_TRACE("without padding shorter");
10191019
const uint8_t input[] = {0x01, 0x02}; // 2 bytes -> "AQI" (3 chars without padding)
1020-
auto written = encode_base64(output, 4, input, sizeof(input), 0, false, false);
1020+
auto written = encode_base64(output, 4, input, sizeof(input), 0, false, false);
10211021
EXPECT_EQ(written, 3u);
10221022
EXPECT_STREQ(output, "AQI");
10231023
}
@@ -1026,7 +1026,7 @@ TEST(Utility, Base64EncodeErrors)
10261026
{
10271027
SCOPED_TRACE("large input buffer boundary");
10281028
const uint8_t input[48] = {0}; // 48 bytes -> 64 chars + null = 65 bytes needed
1029-
auto written = encode_base64(output, 64, input, sizeof(input), 0, false, true);
1029+
auto written = encode_base64(output, 64, input, sizeof(input), 0, false, true);
10301030
EXPECT_EQ(written, 0u); // needs 65
10311031

10321032
written = encode_base64(output, 65, input, sizeof(input), 0, false, true);

test/bit_segment_test.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
2+
* SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
33
*
44
* SPDX-License-Identifier: MIT
55
*/
@@ -62,7 +62,7 @@ TEST(BitSegment, Assignment)
6262
{
6363
BitSegment<4, uint8_t> seg(0x56);
6464
BitSegment<4, uint8_t>& ref = seg;
65-
seg = ref;
65+
seg = ref;
6666
EXPECT_EQ(seg.raw(), 0x56);
6767
}
6868
}
@@ -99,7 +99,7 @@ TEST(BitSegment, GetterSetter_uint8)
9999

100100
// Getter
101101
{
102-
BS seg(0xA5); // binary: 1010 0101
102+
BS seg(0xA5); // binary: 1010 0101
103103
EXPECT_EQ(seg.upper(), 0xAU); // upper 4 bits
104104
EXPECT_EQ(seg.lower(), 0x5U); // lower 4 bits
105105
EXPECT_EQ(seg.raw(), 0xA5);
@@ -194,17 +194,17 @@ TEST(BitSegment, AsymmetricBits)
194194
// 3 lower bits in uint8_t (5 upper bits)
195195
{
196196
using BS = BitSegment<3, uint8_t>;
197-
BS seg(0b11111111); // 0xFF
198-
EXPECT_EQ(seg.lower(), 0b111U); // 7
199-
EXPECT_EQ(seg.upper(), 0b11111U); // 31
197+
BS seg(0b11111111); // 0xFF
198+
EXPECT_EQ(seg.lower(), 0b111U); // 7
199+
EXPECT_EQ(seg.upper(), 0b11111U); // 31
200200
}
201201

202202
// 5 lower bits in uint8_t (3 upper bits)
203203
{
204204
using BS = BitSegment<5, uint8_t>;
205205
BS seg(0xFF);
206-
EXPECT_EQ(seg.lower(), 0b11111U); // 31
207-
EXPECT_EQ(seg.upper(), 0b111U); // 7
206+
EXPECT_EQ(seg.lower(), 0b11111U); // 31
207+
EXPECT_EQ(seg.upper(), 0b111U); // 7
208208
}
209209

210210
// 1 lower bit in uint8_t (7 upper bits)
@@ -233,9 +233,9 @@ TEST(BitSegment, SignedType)
233233
using BS = BitSegment<4, int8_t>;
234234

235235
// Check constants
236-
EXPECT_TRUE(BS::SIGNED);
237-
EXPECT_EQ(BS::LOWER_BITS, 4U);
238-
EXPECT_EQ(BS::UPPER_BITS, 3U); // 8 - 4 - 1(sign) = 3
236+
EXPECT_TRUE(+BS::SIGNED);
237+
EXPECT_EQ(+BS::LOWER_BITS, 4U);
238+
EXPECT_EQ(+BS::UPPER_BITS, 3U); // 8 - 4 - 1(sign) = 3
239239

240240
// Positive value
241241
{

test/compatibility_feature_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
2+
* SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
33
*
44
* SPDX-License-Identifier: MIT
55
*/
@@ -48,7 +48,7 @@ TEST(CompatibilityFeature, MicrosGreaterThanMillis)
4848
TEST(CompatibilityFeature, DelayApproximateTime)
4949
{
5050
// delay() should pause for approximately the specified time
51-
const unsigned long delay_ms = 50;
51+
const unsigned long delay_ms = 50;
5252
const unsigned long tolerance_ms = 20; // Allow 20ms tolerance
5353

5454
unsigned long start = millis();
@@ -64,7 +64,7 @@ TEST(CompatibilityFeature, DelayApproximateTime)
6464
TEST(CompatibilityFeature, DelayMicrosecondsApproximateTime)
6565
{
6666
// delayMicroseconds() should pause for approximately the specified time
67-
const unsigned int delay_us = 5000; // 5ms in microseconds
67+
const unsigned int delay_us = 5000; // 5ms in microseconds
6868
const unsigned long tolerance_us = 3000; // Allow 3ms tolerance
6969

7070
unsigned long start = micros();
@@ -100,8 +100,8 @@ TEST(CompatibilityFeature, DelayMicrosecondsZero)
100100
TEST(CompatibilityFeature, MultipleDelays)
101101
{
102102
// Multiple delays should accumulate
103-
const unsigned long delay_ms = 20;
104-
const int count = 3;
103+
const unsigned long delay_ms = 20;
104+
const int count = 3;
105105
const unsigned long tolerance_ms = 30;
106106

107107
unsigned long start = millis();
@@ -131,7 +131,7 @@ TEST(CompatibilityFeature, ConsistencyBetweenMillisAndMicros)
131131

132132
// us_diff should be approximately ms_diff * 1000 (with tolerance)
133133
unsigned long expected_us = ms_diff * 1000;
134-
unsigned long tolerance = 10000; // 10ms tolerance
134+
unsigned long tolerance = 10000; // 10ms tolerance
135135

136136
EXPECT_GE(us_diff + tolerance, expected_us);
137137
EXPECT_LE(us_diff, expected_us + tolerance);

0 commit comments

Comments
 (0)