Skip to content

Instantly share code, notes, and snippets.

@ambroff
Created January 2, 2020 21:42
Show Gist options
  • Save ambroff/6f08446bc2c62e2fb7ffa7ca128c9856 to your computer and use it in GitHub Desktop.
Save ambroff/6f08446bc2c62e2fb7ffa7ca128c9856 to your computer and use it in GitHub Desktop.
Testing BeOS
$ uname -a
BeOS trantor 5.0 1000009 BePC unknown
$ g++ test.cpp -o test -lbe
$ ./test
Running test 1
Running test 2
Running test 3
Running test 4
ERROR: 5 != -2147483643
ERROR: 1111556103 != 7
Running test 5
#include <iostream>
#include <string.h>
#include <DataIO.h>
template <typename A, typename B>
void assert_equal(const A& a, const B& b) {
if (a != b) {
std::cerr << "ERROR: " << a << " != " << b << std::endl;
}
}
int main()
{
char buf[10];
const char *writeBuf = "ABCDEF";
BMemoryIO mem(buf, 10);
ssize_t err;
off_t pos;
std::cout << "Running test 1" << std::endl;
memset(buf, 0, 10);
pos = mem.Position();
err = mem.Write(writeBuf, 7);
assert_equal(err, 7);
assert_equal(strcmp(writeBuf, buf), 0);
assert_equal(mem.Position(), pos + err);
std::cout << "Running test 2" << std::endl;
memset(buf, 0, 10);
pos = mem.Position();
err = mem.WriteAt(3, writeBuf, 2);
assert_equal(err, 2);
assert_equal(strncmp(buf + 3, writeBuf, 2), 0);
assert_equal(mem.Position(), pos);
std::cout << "Running test 3" << std::endl;
memset(buf, 0, 10);
pos = mem.Position();
err = mem.WriteAt(9, writeBuf, 5);
assert_equal(err, 1);
assert_equal(strncmp(buf + 9, writeBuf, 1), 0);
assert_equal(mem.Position(), pos);
std::cout << "Running test 4" << std::endl;
memset(buf, 0, 10);
pos = mem.Position();
err = mem.WriteAt(-10, writeBuf, 5);
assert_equal(err, B_BAD_VALUE);
assert_equal(mem.Position(), pos);
std::cout << "Running test 5" << std::endl;
memset(buf, 0, 10);
BMemoryIO read_only_mem(const_cast<const char*>(buf), 10);
pos = read_only_mem.Position();
err = read_only_mem.WriteAt(3, writeBuf, 2);
assert_equal(err, B_NOT_ALLOWED);
assert_equal(read_only_mem.Position(), pos);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment