Skip to content

Commit f55b602

Browse files
committed
Defined some stubs as test doubles
1 parent 62d6f19 commit f55b602

File tree

13 files changed

+183
-31
lines changed

13 files changed

+183
-31
lines changed

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ build_flags =
3939
-fprofile-abs-path
4040
-O0
4141
-ggdb3
42-
-Itest/test_doubles
42+
-Itest/doubles
4343

4444
[env:esp32-s3-devkitc-1]
4545

test/doubles/FFat.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @file
3+
* @brief Fake for testing on native
4+
*/
5+
6+
#pragma once
7+
#include "esp_partition.h"
8+
#include <stddef.h>
9+
#include <stdint.h>
10+
11+
namespace fs
12+
{
13+
struct FS
14+
{
15+
bool begin(bool formatOnFail = false, const char *basePath = "/ffat", uint8_t maxOpenFiles = 10, const char *partitionLabel = (char *)FFAT_PARTITION_LABEL)
16+
{
17+
return true;
18+
}
19+
bool format(bool full_wipe = true, char *partitionLabel = (char *)FFAT_PARTITION_LABEL)
20+
{
21+
return true;
22+
}
23+
size_t totalBytes()
24+
{
25+
return 42;
26+
}
27+
size_t usedBytes()
28+
{
29+
return 42 / 2;
30+
}
31+
size_t freeBytes()
32+
{
33+
return totalBytes() - usedBytes();
34+
}
35+
void end()
36+
{
37+
}
38+
bool exists(const char *)
39+
{
40+
return true;
41+
}
42+
};
43+
} // namespace fs
44+
45+
extern fs::FS FFat;

test/doubles/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
\dir .
2+
\brief Package \ref test_doubles
3+
4+
\page test_doubles Test Doubles
5+
\brief Stubs, fakes, mocks, ... supporting unit testing.

test/doubles/USB.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @file
3+
* @brief Fake for testing on native
4+
*/
5+
6+
#pragma once
7+
#include <stdint.h>
8+
9+
typedef const char *esp_event_base_t;
10+
typedef void (*esp_event_handler_t)(void *, esp_event_base_t, int32_t, void *);
11+
12+
enum arduino_usb_event_t
13+
{
14+
ARDUINO_USB_STARTED_EVENT,
15+
ARDUINO_USB_STOPPED_EVENT,
16+
};
17+
18+
struct ESPUSB
19+
{
20+
bool begin()
21+
{
22+
return true;
23+
}
24+
25+
void onEvent(arduino_usb_event_t, esp_event_handler_t)
26+
{
27+
}
28+
};
29+
extern ESPUSB USB;

test/doubles/USBMSC.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file
3+
* @brief Fake for testing on native
4+
*/
5+
6+
#pragma once
7+
#include <stdint.h>
8+
9+
typedef bool (*msc_start_stop_cb)(uint8_t, bool, bool);
10+
typedef int32_t (*msc_read_cb)(uint32_t, uint32_t, void *, uint32_t);
11+
typedef int32_t (*msc_write_cb)(uint32_t, uint32_t, uint8_t *, uint32_t);
12+
13+
struct USBMSC
14+
{
15+
bool begin(uint32_t, uint16_t)
16+
{
17+
return true;
18+
}
19+
void end()
20+
{
21+
}
22+
void vendorID(const char *)
23+
{
24+
}
25+
void productID(const char *)
26+
{
27+
}
28+
void productRevision(const char *)
29+
{
30+
}
31+
void mediaPresent(bool)
32+
{
33+
}
34+
void onStartStop(msc_start_stop_cb);
35+
void onRead(msc_read_cb);
36+
void onWrite(msc_write_cb);
37+
};

test/doubles/esp32-hal-log.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @file
3+
* @brief Fake for testing on native
4+
*/
5+
6+
#pragma once
7+
8+
template <typename... T>
9+
inline void ESP_LOGD(const char *, const char *, T...)
10+
{
11+
}
12+
13+
template <typename... T>
14+
inline void ESP_LOGV(const char *, const char *, T...)
15+
{
16+
}
17+
18+
template <typename... T>
19+
inline void ESP_LOGI(const char *, const char *, T...)
20+
{
21+
}
22+
23+
template <typename... T>
24+
inline void ESP_LOGW(const char *, const char *, T...)
25+
{
26+
}
27+
28+
template <typename... T>
29+
void ESP_LOGE(const char *, const char *, T...)
30+
{
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@
44
*/
55

66
#pragma once
7+
8+
struct esp_err_t
9+
{
10+
};
11+
12+
inline void ESP_ERROR_CHECK(esp_err_t)
13+
{
14+
}

test/doubles/esp_partition.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @file
3+
* @brief Fake for testing on native
4+
*/
5+
6+
#pragma once
7+
#include "esp_err.h"
8+
#include <stddef.h>
9+
10+
struct esp_partition_t;
11+
12+
inline esp_err_t esp_partition_erase_range(const esp_partition_t *, size_t, size_t)
13+
{
14+
return {};
15+
}
16+
17+
inline esp_err_t esp_partition_read(const esp_partition_t *, size_t, void *, size_t)
18+
{
19+
return {};
20+
}
21+
22+
inline esp_err_t esp_partition_write(const esp_partition_t *, size_t, const void *, size_t)
23+
{
24+
return {};
25+
}
26+
27+
constexpr char FFAT_PARTITION_LABEL[] = "FFAT_PARTITION_LABEL";

test/test_doubles/FFat.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/test_doubles/USB.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)