scsl/bufferTest.cc

60 lines
1.5 KiB
C++
Raw Permalink Normal View History

#include <cassert>
2023-10-09 17:24:40 +00:00
#include <iostream>
#include "Buffer.h"
2023-10-15 01:38:01 +00:00
using namespace scsl;
2023-10-09 17:24:40 +00:00
int
2023-10-09 20:23:03 +00:00
main(int argc, char *argv[])
2023-10-09 17:24:40 +00:00
{
(void) argc;
(void) argv;
2023-10-09 20:23:03 +00:00
Buffer buffer("hlo, world");
2023-10-10 11:22:04 +00:00
Buffer helloWorld("hello, world!");
Buffer goodbyeWorld("goodbye, world");
Buffer goodbyeCruelWorld("goodbye, cruel world");
2023-10-09 17:24:40 +00:00
2023-10-10 23:44:29 +00:00
std::cout << buffer << "\n";
2023-10-09 17:24:40 +00:00
buffer.Insert(1, (uint8_t *) "el", 2);
2023-10-09 19:45:19 +00:00
buffer.Append('!');
2023-10-10 11:22:04 +00:00
assert(buffer == helloWorld);
2023-10-09 17:24:40 +00:00
2023-10-10 23:44:29 +00:00
std::cout << buffer << "\n";
2023-10-09 19:45:19 +00:00
buffer.Remove(buffer.Length() - 1);
2023-10-10 23:44:29 +00:00
std::cout << buffer << "\n";
2023-10-09 19:45:19 +00:00
buffer.Remove(0, 5);
2023-10-10 23:44:29 +00:00
std::cout << buffer << "\n";
2023-10-09 19:45:19 +00:00
buffer.Insert(0, 'g');
2023-10-10 23:44:29 +00:00
std::cout << buffer << "\n";
buffer.Insert(1, (uint8_t *) "oodbye", 6);
2023-10-10 23:44:29 +00:00
std::cout << buffer << "\n";
2023-10-10 11:22:04 +00:00
assert(buffer == goodbyeWorld);
2023-10-10 02:59:21 +00:00
buffer.Insert(9, (uint8_t *)"cruel ", 6);
2023-10-10 23:44:29 +00:00
std::cout << buffer << "\n";
2023-10-10 02:59:21 +00:00
buffer.HexDump(std::cout);
2023-10-09 19:45:19 +00:00
buffer.Reclaim();
buffer.Append("and now for something completely different...");
2023-10-10 23:44:29 +00:00
std::cout << buffer.Contents() << "\n";
std::cout << "Length: " << buffer.Length() << ", capacity " << buffer.Capacity() << "\n";
buffer.Resize(128);
2023-10-10 23:44:29 +00:00
std::cout << "Length: " << buffer.Length() << ", capacity " << buffer.Capacity() << "\n";
buffer.Trim();
2023-10-10 23:44:29 +00:00
std::cout << "Length: " << buffer.Length() << ", capacity " << buffer.Capacity() << "\n";
2023-10-09 19:45:19 +00:00
Buffer buffer2("and now for something completely different...");
assert(buffer == buffer2);
buffer2.Remove(buffer2.Length()-3, 3);
2023-10-10 23:44:29 +00:00
std::cout << buffer << "\n";
assert(buffer != buffer2);
2023-10-09 20:16:05 +00:00
return 0;
2023-10-09 17:24:40 +00:00
}