Module: Pacct::Test
- Defined in:
- ext/pacct/pacct_c.c,
ext/pacct/pacct_c.c
Overview
Contains unit-testing methods
Only defined when RSpec is loaded
Class Method Summary collapse
-
.check_call(test) ⇒ Object
Unit testing code.
- .comp_t_to_ulong(val) ⇒ Object
- .read_failure ⇒ Object
-
.ulong_to_comp_t(val) ⇒ Object
To do: create unit test.
- .write_failure ⇒ Object
Class Method Details
.check_call(test) ⇒ Object
Unit testing code
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'ext/pacct/pacct_c.c', line 698
static VALUE test_check_call_macro(VALUE self, VALUE test) {
int i = NUM2INT(test);
switch(i) {
case 0:
CHECK_CALL(0, 0);
break;
case 1:
CHECK_CALL(1, 0);
break;
case 2:
CHECK_CALL(errno = 0, 1);
case 3:
CHECK_CALL(errno = ERANGE, 0);
default:
rb_raise(rb_eRangeError, "Unknown test code %i", i);
}
return Qnil;
}
|
.comp_t_to_ulong(val) ⇒ Object
752 753 754 755 756 |
# File 'ext/pacct/pacct_c.c', line 752
static VALUE test_comp_t_to_ulong(VALUE self, VALUE val) {
comp_t c = (comp_t)NUM2UINT(val);
unsigned long result = comp_t_to_ulong(c);
return ULONG2NUM(result);
}
|
.read_failure ⇒ Object
717 718 719 720 721 722 723 724 725 726 727 728 729 |
# File 'ext/pacct/pacct_c.c', line 717
static VALUE test_read_failure(VALUE self) {
PacctLog log;
//VALUE entry = pacct_entry_new(NULL);
const char* filename = "/dev/null";
log.num_entries = 0;
log.filename = malloc(strlen(filename) + 1);
ENSURE_ALLOCATED(log.filename);
strcpy(log.filename, filename);
log.file = fopen(log.filename, "r");
pacct_entry_new(&log);
return Qnil;
}
|
.ulong_to_comp_t(val) ⇒ Object
To do: create unit test.
746 747 748 749 750 |
# File 'ext/pacct/pacct_c.c', line 746
static VALUE test_ulong_to_comp_t(VALUE self, VALUE val) {
unsigned long l = (unsigned long)NUM2ULONG(val);
comp_t result = ulong_to_comp_t(l);
return INT2NUM(result);
}
|
.write_failure ⇒ Object
731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'ext/pacct/pacct_c.c', line 731
static VALUE test_write_failure(VALUE self) {
PacctLog* ptr;
VALUE log = Data_Make_Struct(cLog, PacctLog, 0, pacct_log_free, ptr);
VALUE entry = pacct_entry_new(NULL);
const char* filename = "spec/pacct_spec.rb";
ptr->num_entries = 0;
ptr->filename = malloc(strlen(filename) + 1);
ENSURE_ALLOCATED(ptr->filename);
strcpy(ptr->filename, filename);
ptr->file = fopen(ptr->filename, "r");
write_entry(log, entry);
return Qnil;
}
|