示例#1
0
    void test_compare_bytes_out_of_bounds() {
        ByteArray* a = String::create(state, "xyZzy")->data();
        ByteArray* b = String::create(state, "xyzzy")->data();

        Integer* zero = Fixnum::from(0);
        Integer* neg = Fixnum::from(-1);

        TS_ASSERT_THROWS_ASSERT(a->compare_bytes(state, b, neg, zero), const RubyException &e,
                                TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
        TS_ASSERT_THROWS_ASSERT(a->compare_bytes(state, b, zero, neg), const RubyException &e,
                                TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
    }
示例#2
0
  void test_compare_bytes_out_of_bounds() {
    ByteArray* a = new_bytearray("xyZzy");
    ByteArray* b = new_bytearray("xyzzy");

    Fixnum* zero = Fixnum::from(0);
    Fixnum* neg = Fixnum::from(-1);

    TS_ASSERT_THROWS_ASSERT(a->compare_bytes(state, b, neg, zero), const RubyException &e,
        TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
    TS_ASSERT_THROWS_ASSERT(a->compare_bytes(state, b, zero, neg), const RubyException &e,
        TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
  }
示例#3
0
    void test_compare_bytes() {
        ByteArray* a = String::create(state, "xyZzyx")->data();
        ByteArray* b = String::create(state, "xyzzyx")->data();

        Integer* two = Fixnum::from(2);
        Integer* three = Fixnum::from(3);
        Integer* size = Fixnum::from(8);
        Integer* size1 = Fixnum::from(9);

        TS_ASSERT_EQUALS(a->size(state)->to_native(), 8);
        TS_ASSERT_EQUALS(b->size(state)->to_native(), 8);

        TS_ASSERT_EQUALS(a->compare_bytes(state, b, two, two), Fixnum::from(0));
        TS_ASSERT_EQUALS(a->compare_bytes(state, b, two, three), Fixnum::from(-1));
        TS_ASSERT_EQUALS(a->compare_bytes(state, b, three, two), Fixnum::from(1));
        TS_ASSERT_EQUALS(a->compare_bytes(state, b, three, three), Fixnum::from(-1));
        TS_ASSERT_EQUALS(a->compare_bytes(state, b, size, size), Fixnum::from(-1));
        TS_ASSERT_EQUALS(a->compare_bytes(state, b, size1, size1), Fixnum::from(-1));
    }
示例#4
0
  void test_compare_bytes() {
    ByteArray* a = new_bytearray("xyZzyx");
    ByteArray* b = new_bytearray("xyzzyx");

    Fixnum* two = Fixnum::from(2);
    Fixnum* three = Fixnum::from(3);
    Fixnum* size = Fixnum::from(8);
    Fixnum* size1 = Fixnum::from(9);

    TS_ASSERT_EQUALS(a->size(state)->to_native(), 8);
    TS_ASSERT_EQUALS(b->size(state)->to_native(), 8);

    TS_ASSERT_EQUALS(a->compare_bytes(state, b, two, two), Fixnum::from(0));
    TS_ASSERT_EQUALS(a->compare_bytes(state, b, two, three), Fixnum::from(-1));
    TS_ASSERT_EQUALS(a->compare_bytes(state, b, three, two), Fixnum::from(1));
    TS_ASSERT_EQUALS(a->compare_bytes(state, b, three, three), Fixnum::from(-1));
    TS_ASSERT_EQUALS(a->compare_bytes(state, b, size, size), Fixnum::from(-1));
    TS_ASSERT_EQUALS(a->compare_bytes(state, b, size1, size1), Fixnum::from(-1));
  }