Skip to content

Commit 2dd6045

Browse files
committed
fix: Replace FastbootUtil with FastbootDriver in tests
Update unit tests to use FastbootDriver instead of FastbootUtil across multiple test files. Added necessary using directives (FirmwareKit.Comm.Fastboot and subnamespaces Usb/Network) and updated static references (FastbootUtil.SparseMaxDownloadSize -> FastbootDriver.SparseMaxDownloadSize). Affects AospDriverTests, AospFastbootDriverTests, FastbootInfoTests, FastbootProtocolTests, TcpTransportTests, and UdpTransportTests.
1 parent 852344f commit 2dd6045

File tree

6 files changed

+53
-44
lines changed

6 files changed

+53
-44
lines changed

FirmwareKit.Comm.Fastboot.Tests/AospDriverTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text;
2+
using FirmwareKit.Comm.Fastboot;
23

34
namespace FirmwareKit.Comm.Fastboot.Tests
45
{
@@ -37,7 +38,7 @@ public void Test_Boot_Aosp()
3738
{
3839
// Ported from fastboot_driver_test.cpp: TEST_F(DriverTest, Boot)
3940
var transport = new MockTransport();
40-
var util = new FastbootUtil(transport);
41+
var util = new FastbootDriver(transport);
4142

4243
transport.EnqueueResponse("OKAY");
4344

@@ -52,7 +53,7 @@ public void Test_Continue_Aosp()
5253
{
5354
// Ported from fastboot_driver_test.cpp: TEST_F(DriverTest, Continue)
5455
var transport = new MockTransport();
55-
var util = new FastbootUtil(transport);
56+
var util = new FastbootDriver(transport);
5657

5758
transport.EnqueueResponse("OKAY");
5859

@@ -67,7 +68,7 @@ public void Test_Erase_Aosp()
6768
{
6869
// Ported from fastboot_driver_test.cpp: TEST_F(DriverTest, Erase)
6970
var transport = new MockTransport();
70-
var util = new FastbootUtil(transport);
71+
var util = new FastbootDriver(transport);
7172

7273
transport.EnqueueResponse("OKAY");
7374

@@ -82,7 +83,7 @@ public void Test_Flash_Aosp()
8283
{
8384
// Ported from fastboot_driver_test.cpp: TEST_F(DriverTest, Flash)
8485
var transport = new MockTransport();
85-
var util = new FastbootUtil(transport);
86+
var util = new FastbootDriver(transport);
8687

8788
transport.EnqueueResponse("OKAY");
8889

@@ -97,7 +98,7 @@ public void Test_GetVarAll_Aosp()
9798
{
9899
// Ported from fastboot_driver_test.cpp: TEST_F(DriverTest, GetVarAll)
99100
var transport = new MockTransport();
100-
var util = new FastbootUtil(transport);
101+
var util = new FastbootDriver(transport);
101102

102103
transport.EnqueueResponse("INFOversion:0.4");
103104
transport.EnqueueResponse("INFOslot-count:2");
@@ -115,7 +116,7 @@ public void Test_Reboot_Aosp()
115116
{
116117
// Ported from fastboot_driver_test.cpp: TEST_F(DriverTest, Reboot)
117118
var transport = new MockTransport();
118-
var util = new FastbootUtil(transport);
119+
var util = new FastbootDriver(transport);
119120

120121
transport.EnqueueResponse("OKAY");
121122

FirmwareKit.Comm.Fastboot.Tests/AospFastbootDriverTests.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text;
2+
using FirmwareKit.Comm.Fastboot;
23

34
namespace FirmwareKit.Comm.Fastboot.Tests
45
{
@@ -37,7 +38,7 @@ public void Test_GetVar_Aosp()
3738
{
3839
// Ported from: fastboot_driver_test.cpp -> TEST_F(DriverTest, GetVar)
3940
var transport = new MockTransport();
40-
var util = new FastbootUtil(transport);
41+
var util = new FastbootDriver(transport);
4142

4243
transport.EnqueueResponse("OKAY0.4");
4344

@@ -52,7 +53,7 @@ public void Test_InfoMessage_Aosp()
5253
{
5354
// Ported from: fastboot_driver_test.cpp -> TEST_F(DriverTest, InfoMessage)
5455
var transport = new MockTransport();
55-
var util = new FastbootUtil(transport);
56+
var util = new FastbootDriver(transport);
5657

5758
transport.EnqueueResponse("INFOthis is an info line");
5859
transport.EnqueueResponse("OKAY");
@@ -70,7 +71,7 @@ public void Test_TextMessage_Aosp()
7071
{
7172
// Ported from: fastboot_driver_test.cpp -> TEST_F(DriverTest, TextMessage)
7273
var transport = new MockTransport();
73-
var util = new FastbootUtil(transport);
74+
var util = new FastbootDriver(transport);
7475
string capturedText = "";
7576

7677
util.ReceivedFromDevice += (s, e) =>
@@ -104,7 +105,7 @@ public void Test_Download_Fail_Aosp()
104105
{
105106
// Logical check: If download command fails, should return FAIL immediately
106107
var transport = new MockTransport();
107-
var util = new FastbootUtil(transport);
108+
var util = new FastbootDriver(transport);
108109

109110
transport.EnqueueResponse("FAILdata too large");
110111

@@ -118,7 +119,7 @@ public void Test_Download_Fail_Aosp()
118119
public void Test_ConsecutiveInfoInSinglePacket()
119120
{
120121
var transport = new MockTransport();
121-
var util = new FastbootUtil(transport);
122+
var util = new FastbootDriver(transport);
122123

123124
// Single packet contains two INFO frames followed by OKAY
124125
transport.EnqueueResponse("INFOfirst lineINFOsecond lineOKAY");
@@ -135,7 +136,7 @@ public void Test_ConsecutiveInfoInSinglePacket()
135136
public void Test_InfoWithoutDelimiterFollowedByOkay()
136137
{
137138
var transport = new MockTransport();
138-
var util = new FastbootUtil(transport);
139+
var util = new FastbootDriver(transport);
139140

140141
// INFO payload without newline then OKAY immediately in same packet
141142
transport.EnqueueResponse("INFOpartial infoOKAY");
@@ -151,7 +152,7 @@ public void Test_InfoWithoutDelimiterFollowedByOkay()
151152
public void Test_MalformedDataLength()
152153
{
153154
var transport = new MockTransport();
154-
var util = new FastbootUtil(transport);
155+
var util = new FastbootDriver(transport);
155156

156157
// DATA followed by non-hex content should be treated as malformed
157158
transport.EnqueueResponse("DATAGARBAGE");

FirmwareKit.Comm.Fastboot.Tests/FastbootInfoTests.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Globalization;
22
using System.Text;
3+
using FirmwareKit.Comm.Fastboot;
34

45
namespace FirmwareKit.Comm.Fastboot.Tests
56
{
@@ -89,7 +90,7 @@ public void Dispose() { }
8990
[Fact]
9091
public void CheckFastbootInfoRequirements_CorrectVersions_ReturnsTrue()
9192
{
92-
var util = new FastbootUtil(new ScriptedTransport());
93+
var util = new FastbootDriver(new ScriptedTransport());
9394
string[] correctVersions = { "1", "2" };
9495

9596
foreach (string version in correctVersions)
@@ -101,7 +102,7 @@ public void CheckFastbootInfoRequirements_CorrectVersions_ReturnsTrue()
101102
[Fact]
102103
public void CheckFastbootInfoRequirements_BadVersions_ReturnsFalse()
103104
{
104-
var util = new FastbootUtil(new ScriptedTransport());
105+
var util = new FastbootDriver(new ScriptedTransport());
105106
string[] badVersions = { "", ".01", "x1", "1.0.1", "1.", "1.0 2.0", "100.00", "3", "17", "22" };
106107

107108
foreach (string version in badVersions)
@@ -113,7 +114,7 @@ public void CheckFastbootInfoRequirements_BadVersions_ReturnsFalse()
113114
[Fact]
114115
public void FlashFromInfo_UnknownCommand_Throws()
115116
{
116-
var util = new FastbootUtil(new ScriptedTransport());
117+
var util = new FastbootDriver(new ScriptedTransport());
117118
string info = "version 1\nunknown-cmd";
118119

119120
var ex = Assert.Throws<InvalidDataException>(() =>
@@ -129,7 +130,7 @@ public void FlashFromInfo_IfWipeFalse_SkipsEraseTask()
129130
{
130131
["getvar:has-slot:userdata"] = "OKAYno"
131132
});
132-
var util = new FastbootUtil(transport);
133+
var util = new FastbootDriver(transport);
133134

134135
string info = "version 1\nif-wipe erase userdata";
135136
util.FlashFromInfo(info, Path.GetTempPath(), wipe: false, slotOverride: "a", optimizeSuper: false);
@@ -144,7 +145,7 @@ public void FlashFromInfo_IfWipeTrue_ExecutesEraseTask()
144145
{
145146
["getvar:has-slot:userdata"] = "OKAYno"
146147
});
147-
var util = new FastbootUtil(transport);
148+
var util = new FastbootDriver(transport);
148149

149150
string info = "version 1\nif-wipe erase userdata";
150151
util.FlashFromInfo(info, Path.GetTempPath(), wipe: true, slotOverride: "a", optimizeSuper: false);
@@ -169,7 +170,7 @@ public void FlashFromInfo_SlotOther_FlashesToOtherSlot()
169170
["getvar:max-download-size"] = "OKAY0x100000",
170171
["flash:system_b"] = "OKAY"
171172
});
172-
var util = new FastbootUtil(transport);
173+
var util = new FastbootDriver(transport);
173174

174175
string info = "version 1\nflash --slot-other system system_other.img";
175176
util.FlashFromInfo(info, tempDir, wipe: false, slotOverride: "a", optimizeSuper: false);
@@ -187,7 +188,7 @@ public void FlashFromInfo_SlotOther_FlashesToOtherSlot()
187188
public void FlashFromInfo_RebootCommands_MappedCorrectly()
188189
{
189190
var transport = new ProtocolScriptTransport();
190-
var util = new FastbootUtil(transport);
191+
var util = new FastbootDriver(transport);
191192

192193
string info = "version 1\nreboot bootloader\nreboot";
193194
util.FlashFromInfo(info, Path.GetTempPath(), wipe: false, slotOverride: "a", optimizeSuper: false);
@@ -199,23 +200,23 @@ public void FlashFromInfo_RebootCommands_MappedCorrectly()
199200
[Fact]
200201
public void GetMaxDownloadSize_ClampsToSparseLimit()
201202
{
202-
int originalLimit = FastbootUtil.SparseMaxDownloadSize;
203+
int originalLimit = FastbootDriver.SparseMaxDownloadSize;
203204
try
204205
{
205-
FastbootUtil.SparseMaxDownloadSize = 1024 * 1024 * 1024;
206+
FastbootDriver.SparseMaxDownloadSize = 1024 * 1024 * 1024;
206207
var transport = new ProtocolScriptTransport(new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
207208
{
208209
["getvar:max-download-size"] = "OKAY0x80000000"
209210
});
210-
var util = new FastbootUtil(transport);
211+
var util = new FastbootDriver(transport);
211212

212213
long maxDownloadSize = util.GetMaxDownloadSize();
213214

214-
Assert.Equal(FastbootUtil.SparseMaxDownloadSize, maxDownloadSize);
215+
Assert.Equal(FastbootDriver.SparseMaxDownloadSize, maxDownloadSize);
215216
}
216217
finally
217218
{
218-
FastbootUtil.SparseMaxDownloadSize = originalLimit;
219+
FastbootDriver.SparseMaxDownloadSize = originalLimit;
219220
}
220221
}
221222

@@ -226,7 +227,7 @@ public void GetVar_FailureIsNotCached_AllowsRetrySuccess()
226227
int attempt = 0;
227228
string key = "max-download-size";
228229

229-
var util = new FastbootUtil(new DelegatingTransport(
230+
var util = new FastbootDriver(new DelegatingTransport(
230231
onWrite: (cmd) =>
231232
{
232233
if (cmd.Equals("getvar:" + key, StringComparison.OrdinalIgnoreCase))

0 commit comments

Comments
 (0)