开始设计

This commit is contained in:
2026-08-10 01:21:15 +08:00
commit e45398991f
228 changed files with 20827 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
#include "c_ByteRingBuffer.h"
#include <stdlib.h>
#include <stdio.h>
void test_log(const char* test_name) {
printf("[PASS] %s\n", test_name);
}
int main() {
printf("==================================================\n");
printf(" Starting c_ByteRingBuffer Unit Testing Suite\n");
printf("==================================================\n\n");
c_ByteRingBuffer_t rb;
// Set fixed byte size capacity to 4
c_err_t err = c_ByteRingBuffer_Init(&rb, 4);
assert(err == C_ERR_SUCCESS);
assert(c_ByteRingBuffer_IsEmpty(&rb) == C_TRUE);
test_log("1. Raw byte buffer initialization verified");
// ==========================================
// 2. Testing Single Byte Operations
// ==========================================
err = c_ByteRingBuffer_WriteByte(&rb, 0xAA); assert(err == C_ERR_SUCCESS);
err = c_ByteRingBuffer_WriteByte(&rb, 0xBB); assert(err == C_ERR_SUCCESS);
assert(c_ByteRingBuffer_GetSize(&rb) == 2);
uint8_t byte_out = 0;
err = c_ByteRingBuffer_ReadByte(&rb, &byte_out);
assert(err == C_ERR_SUCCESS);
assert(byte_out == 0xAA);
assert(c_ByteRingBuffer_GetSize(&rb) == 1);
test_log("2. Single byte discrete FIFO verified");
// Clear buffer out
c_ByteRingBuffer_ReadByte(&rb, &byte_out);
assert(c_ByteRingBuffer_IsEmpty(&rb) == C_TRUE);
// ==========================================
// 3. Testing Streaming Buffer Operations
// ==========================================
uint8_t stream_in[5] = {0x11, 0x22, 0x33, 0x44, 0x55};
// Total capacity is 4. Passing a length of 5 should stream up to max boundary
c_size_t written = c_ByteRingBuffer_WriteBuffer(&rb, stream_in, 5);
assert(written == 4);
assert(c_ByteRingBuffer_IsFull(&rb) == C_TRUE);
uint8_t stream_out[4] = {0};
c_size_t read = c_ByteRingBuffer_ReadBuffer(&rb, stream_out, 4);
assert(read == 4);
assert(stream_out[0] == 0x11);
assert(stream_out[3] == 0x44);
assert(c_ByteRingBuffer_IsEmpty(&rb) == C_TRUE);
test_log("3. Bulk string/buffer array streams chunk-read verified");
c_ByteRingBuffer_Destroy(&rb);
test_log("4. Clean resource teardown verified");
printf("\n==================================================\n");
printf(" Success! Byte RingBuffer tests passed!\n");
printf("==================================================\n");
return 0;
}