forked from rubinius/rubinius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_compiled_file.hpp
58 lines (44 loc) · 1.27 KB
/
test_compiled_file.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "vm/test/test.hpp"
#include "compiled_file.hpp"
#include "builtin/class.hpp"
#include "builtin/compiledmethod.hpp"
#include "builtin/lookuptable.hpp"
#include "builtin/staticscope.hpp"
#include "builtin/symbol.hpp"
#include <cxxtest/TestSuite.h>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace rubinius;
class TestCompiledFile : public CxxTest::TestSuite, public VMTest {
public:
void setUp() {
create();
}
void tearDown() {
destroy();
}
void test_load() {
std::istringstream stream;
stream.str("!RBIX\n1\n42\nt");
CompiledFile* cf = CompiledFile::load(stream);
TS_ASSERT_EQUALS(cf->magic, std::string("!RBIX"));
TS_ASSERT_EQUALS(cf->signature, 1ULL);
TS_ASSERT_EQUALS(cf->version, 42);
TS_ASSERT_EQUALS((long)stream.tellg(), 11);
}
void test_body() {
std::istringstream stream;
stream.str("!RBIX\n1\n42\nt");
CompiledFile* cf = CompiledFile::load(stream);
TS_ASSERT_EQUALS(cf->body(state), Qtrue);
}
void test_load_file() {
std::fstream stream("vm/test/fixture.rbc_");
TS_ASSERT(!!stream);
CompiledFile* cf = CompiledFile::load(stream);
TS_ASSERT_EQUALS(cf->magic, "!RBIX");
CompiledMethod* cm = try_as<CompiledMethod>(cf->body(state));
TS_ASSERT(cm);
}
};