@@ -86,6 +86,55 @@ TEST_F(FlashDriverTest, RequestWriteBlock)
86
86
87
87
auto task = flashDriver.pageWrite (address, std::span (TransmitData.data (), TransmitData.size ()));
88
88
CoroUtils::syncWait (task);
89
+ }
90
+
91
+ TEST_F (FlashDriverTest, RequestReadBlock)
92
+ {
93
+
94
+ EXPECT_CALL (getMockGpio (), setGpioLow ()).Times (1 );
95
+ EXPECT_CALL (getMockGpio (), setGpioHigh ()).Times (1 );
96
+
97
+ using TStream = std::array<std::uint8_t , 7 >;
98
+
99
+ auto ReceiveData{
100
+ TStream{0xEF , 0xFF , 0x18 , 0x19 , 0x20 , 0x21 , 0x22 }};
101
+
102
+ auto Dummy{TStream{}};
103
+
104
+ EXPECT_CALL (spiMockAccess (), receivedData)
105
+ .Times (1 )
106
+ .WillOnce (Return (std::span (
107
+ reinterpret_cast <const std::uint8_t *>(ReceiveData.data ()), ReceiveData.size ())));
108
+
109
+ constexpr std::uint32_t address{0x10'00 };
110
+
111
+ constexpr std::size_t ReadCommandLength = 4 ;
112
+ constexpr const std::array<std::uint8_t , ReadCommandLength> readCommand{
113
+ WindbondCommandSet::ReadData,
114
+ static_cast <std::uint8_t >((address & 0x00'FF'00'00 ) >> 16 ),
115
+ static_cast <std::uint8_t >((address & 0x00'00'FF'00 ) >> 8 ),
116
+ static_cast <std::uint8_t >(address & 0x00'00'00'FF )};
117
+
118
+ testing::Sequence sequence;
119
+
120
+ // https://gist.github.com/cppengineer/f1b6bc0f04ac7c29e963364f2c564a5e
121
+
122
+ const auto DummySpan = std::span<const std::uint8_t >(Dummy.data (), Dummy.size ());
123
+
124
+ const auto ReadDataSpan =
125
+ std::span<const std::uint8_t >(readCommand.data (), readCommand.size ());
126
+
127
+ EXPECT_CALL (spiMockAccess (), sentData)
128
+ .With (SpanChecker (ReadDataSpan))
129
+ .Times (1 )
130
+ .InSequence (sequence);
131
+ EXPECT_CALL (spiMockAccess (), sentData)
132
+ .With (SpanChecker (std::span (DummySpan.data (), DummySpan.size ())))
133
+ .Times (1 )
134
+ .InSequence (sequence);
135
+
136
+ auto task = flashDriver.requestReadBlock (address, ReceiveData.size ());
137
+ auto readSpan = CoroUtils::syncWait (task);
89
138
90
- // EXPECT_EQ(jedecId, fToJedecId(ExpectedStream ));
139
+ EXPECT_TRUE ( std::ranges::equal (readSpan, ReceiveData ));
91
140
}
0 commit comments