From null+rcairo at clear-code.com Tue Sep 7 10:44:33 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Tue, 07 Sep 2010 14:44:33 +0000 Subject: [cairo-commit:00033] rcairo/rcairo [master] include Windows binary just for Windows build. Message-ID: <20100907144946.51BF7170E0C@taiyaki.ru> Kouhei Sutou 2010-09-07 14:44:33 +0000 (Tue, 07 Sep 2010) New Revision: c2a5837b3a16636e41e8f87a611bd86e807741d5 Log: include Windows binary just for Windows build. Modified files: Rakefile Modified: Rakefile (+9 -9) =================================================================== --- Rakefile 2010-08-28 23:32:38 +0000 (64d669a) +++ Rakefile 2010-09-07 14:44:33 +0000 (ba360f6) @@ -91,17 +91,17 @@ project.spec.dependencies.delete_if {|dependency| dependency.name == "hoe"} Rake::ExtensionTask.new("cairo", project.spec) do |ext| ext.cross_compile = true -end - -task :add_win32_binaries do - cairo_win32_dir = File.join("vendor", "local") - cairo_files = [] - Find.find(cairo_win32_dir) do |f| - cairo_files << f + ext.cross_compiling do |spec| + if /mingw|mswin/ =~ spec.platform.to_s + cairo_win32_dir = File.join("vendor", "local") + cairo_files = [] + Find.find(cairo_win32_dir) do |f| + cairo_files << f + end + spec.files += cairo_files + end end - project.spec.files += cairo_files end -task :cross => :add_win32_binaries # fix Hoe's incorrect guess. project.spec.executables.clear From null+rcairo at clear-code.com Sat Sep 11 02:17:19 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 06:17:19 +0000 Subject: [cairo-commit:00034] rcairo/rcairo [master] support cairo_pdf_version_t in cairo 1.10.0. Message-ID: <20100911061735.36D7B170521@taiyaki.ru> Kouhei Sutou 2010-09-11 06:17:19 +0000 (Sat, 11 Sep 2010) New Revision: e1c200522a8cedf2c6167d66b7cb6727ef3ff397 Log: support cairo_pdf_version_t in cairo 1.10.0. Modified files: ext/cairo/cairo.def ext/cairo/rb_cairo.h ext/cairo/rb_cairo_constants.c ext/cairo/rb_cairo_surface.c Modified: ext/cairo/cairo.def (+2 -0) =================================================================== --- ext/cairo/cairo.def 2010-09-07 14:44:33 +0000 (57d4f01) +++ ext/cairo/cairo.def 2010-09-11 06:17:19 +0000 (ec15612) @@ -52,6 +52,7 @@ EXPORTS rb_mCairo_Filter DATA rb_mCairo_SVGVersion DATA rb_mCairo_PSLevel DATA + rb_mCairo_PDFVersion DATA rb_mCairo_LCDFilter DATA rb_mCairo_Color DATA @@ -100,5 +101,6 @@ EXPORTS rb_cairo_filter_from_ruby_object rb_cairo_svg_version_from_ruby_object rb_cairo_ps_level_from_ruby_object + rb_cairo_pdf_version_from_ruby_object rb_cairo_text_cluster_flags_from_ruby_object rb_cairo_check_status Modified: ext/cairo/rb_cairo.h (+11 -0) =================================================================== --- ext/cairo/rb_cairo.h 2010-09-07 14:44:33 +0000 (d185a4d) +++ ext/cairo/rb_cairo.h 2010-09-11 06:17:19 +0000 (45e7532) @@ -124,6 +124,7 @@ RB_CAIRO_VAR VALUE rb_mCairo_Extend; RB_CAIRO_VAR VALUE rb_mCairo_Filter; RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion; RB_CAIRO_VAR VALUE rb_mCairo_PSLevel; +RB_CAIRO_VAR VALUE rb_mCairo_PDFVersion; RB_CAIRO_VAR VALUE rb_mCairo_LCDFilter; RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion; RB_CAIRO_VAR VALUE rb_mCairo_Color; @@ -233,6 +234,11 @@ VALUE rb_cairo_surface_to_ruby_object_with_destroy #define RVAL2CRPSLEVEL(obj) (rb_cairo_ps_level_from_ruby_object(obj)) # endif #endif +#ifdef CAIRO_HAS_PDF_SURFACE +# if CAIRO_CHECK_VERSION(1, 10, 0) +#define RVAL2CRPDFVERSION(obj) (rb_cairo_pdf_version_from_ruby_object(obj)) +# endif +#endif #if CAIRO_CHECK_VERSION(1, 7, 6) #define RVAL2CRTEXTCLUSTERFLAGS(obj) (rb_cairo_text_cluster_flags_from_ruby_object(obj)) #endif @@ -260,6 +266,11 @@ cairo_svg_version_t rb_cairo_svg_version_from_ruby_object (VALUE obj); cairo_ps_level_t rb_cairo_ps_level_from_ruby_object (VALUE obj); # endif #endif +#ifdef CAIRO_HAS_PDF_SURFACE +# if CAIRO_CHECK_VERSION(1, 10, 0) +cairo_pdf_version_t rb_cairo_pdf_version_from_ruby_object (VALUE obj); +# endif +#endif #if CAIRO_CHECK_VERSION(1, 7, 6) cairo_text_cluster_flags_t rb_cairo_text_cluster_flags_from_ruby_object (VALUE obj); #endif Modified: ext/cairo/rb_cairo_constants.c (+63 -1) =================================================================== --- ext/cairo/rb_cairo_constants.c 2010-09-07 14:44:33 +0000 (aae6e6d) +++ ext/cairo/rb_cairo_constants.c 2010-09-11 06:17:19 +0000 (846a14b) @@ -86,6 +86,9 @@ VALUE rb_mCairo_TextClusterFlag = Qnil; #define CAIRO_PS_LEVEL_MIN CAIRO_PS_LEVEL_2 #define CAIRO_PS_LEVEL_MAX CAIRO_PS_LEVEL_3 +#define CAIRO_PDF_VERSION_MIN CAIRO_PDF_VERSION_1_4 +#define CAIRO_PDF_VERSION_MAX CAIRO_PDF_VERSION_1_5 + #define CAIRO_TEXT_CLUSTER_FLAG_MIN 0 #define CAIRO_TEXT_CLUSTER_FLAG_MAX CAIRO_TEXT_CLUSTER_FLAG_BACKWARD @@ -135,7 +138,13 @@ DEFINE_RVAL2ENUM(svg_version, SVG_VERSION) #ifdef CAIRO_HAS_PS_SURFACE # if CAIRO_CHECK_VERSION(1, 5, 2) DEFINE_RVAL2ENUM(ps_level, PS_LEVEL) -#define PS_LEVEL_ENUM_DEFINED 1 +# endif +#endif + +#ifdef CAIRO_HAS_PDF_SURFACE +# if CAIRO_CHECK_VERSION(1, 10, 0) +DEFINE_RVAL2ENUM(pdf_version, PDF_VERSION) +#define PDF_VERSION_ENUM_DEFINED 1 # endif #endif @@ -236,6 +245,43 @@ cr_ps_level_to_string (int argc, VALUE *argv, VALUE self) # endif #endif +#ifdef CAIRO_HAS_PDF_SURFACE +# if CAIRO_CHECK_VERSION(1, 10, 0) +static VALUE +cr_pdf_get_versions (VALUE self) +{ + VALUE rb_versions; + const cairo_pdf_version_t *versions; + int i, n_versions; + + cairo_pdf_get_versions (&versions, &n_versions); + + rb_versions = rb_ary_new2 (n_versions); + for (i = 0; i < n_versions; i++) + { + rb_ary_push (rb_versions, INT2NUM (versions[i])); + } + + return rb_versions; +} + +static VALUE +cr_pdf_version_to_string (int argc, VALUE *argv, VALUE self) +{ + if (argc == 0) + { + return rb_call_super (argc, argv); + } + else + { + VALUE version; + rb_scan_args (argc, argv, "1", &version); + return rb_str_new2 (cairo_pdf_version_to_string (RVAL2CRPDFVERSION (version))); + } +} +# endif +#endif + void Init_cairo_constants (void) { @@ -468,6 +514,22 @@ Init_cairo_constants (void) # endif #endif +#ifdef CAIRO_HAS_PDF_SURFACE +# if CAIRO_CHECK_VERSION(1, 10, 0) + /* cairo_pdf_version_t */ + rb_mCairo_PDFVersion = rb_define_module_under (rb_mCairo, "PDFVersion"); + rb_define_const (rb_mCairo_PDFVersion, "VERSION_1_4", + INT2FIX (CAIRO_PDF_VERSION_1_4)); + rb_define_const (rb_mCairo_PDFVersion, "VERSION_1_5", + INT2FIX (CAIRO_PDF_VERSION_1_5)); + + rb_define_singleton_method (rb_mCairo_PDFVersion, "list", + cr_pdf_get_versions, 0); + rb_define_singleton_method (rb_mCairo_PDFVersion, "name", + cr_pdf_version_to_string, -1); +# endif +#endif + #if CAIRO_CHECK_VERSION(1, 7, 6) /* cairo_text_cluster_flags_t */ rb_mCairo_TextClusterFlag = Modified: ext/cairo/rb_cairo_surface.c (+15 -0) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-07 14:44:33 +0000 (e717589) +++ ext/cairo/rb_cairo_surface.c 2010-09-11 06:17:19 +0000 (cbfd20b) @@ -907,6 +907,16 @@ cr_ps_surface_set_eps (VALUE self, VALUE eps) /* PDF-surface functions */ DEFINE_SURFACE(pdf) DEFINE_SURFACE_SET_SIZE(pdf) + +# if CAIRO_CHECK_VERSION(1, 10, 0) +static VALUE +cr_pdf_surface_restrict_to_version (VALUE self, VALUE version) +{ + cairo_pdf_surface_restrict_to_version (_SELF, RVAL2CRPDFVERSION (version)); + cr_surface_check_status (_SELF); + return Qnil; +} +# endif #endif #ifdef CAIRO_HAS_SVG_SURFACE @@ -1307,6 +1317,11 @@ Init_cairo_surface (void) rb_define_method (rb_cCairo_PDFSurface, "set_size", cr_pdf_surface_set_size, -1); +# if CAIRO_CHECK_VERSION(1, 10, 0) + rb_define_method (rb_cCairo_PDFSurface, "restrict_to_version", + cr_pdf_surface_restrict_to_version, 1); +# endif + RB_CAIRO_DEF_SETTERS (rb_cCairo_PDFSurface); #endif From null+rcairo at clear-code.com Sat Sep 11 02:42:59 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 06:42:59 +0000 Subject: [cairo-commit:00035] rcairo/rcairo [master] support exceptions new in cairo 1.10. Message-ID: <20100911064310.C9F27170521@taiyaki.ru> Kouhei Sutou 2010-09-11 06:42:59 +0000 (Sat, 11 Sep 2010) New Revision: 1b626875e89347e1b2993e2766406f5cf19639c0 Log: support exceptions new in cairo 1.10. Modified files: ext/cairo/rb_cairo_exception.c Modified: ext/cairo/rb_cairo_exception.c (+83 -32) =================================================================== --- ext/cairo/rb_cairo_exception.c 2010-09-11 06:17:19 +0000 (83b20f7) +++ ext/cairo/rb_cairo_exception.c 2010-09-11 06:42:59 +0000 (ead926d) @@ -51,113 +51,136 @@ static VALUE rb_eCairo_InvalidClusters; static VALUE rb_eCairo_InvalidSlant; static VALUE rb_eCairo_InvalidWeight; #endif +#if CAIRO_CHECK_VERSION(1, 10, 0) +static VALUE rb_eCairo_InvalidSize; +static VALUE rb_eCairo_UserFontNotImplemented; +static VALUE rb_eCairo_DeviceTypeMismatch; +static VALUE rb_eCairo_DeviceError; +#endif void rb_cairo_check_status (cairo_status_t status) { const char *string = cairo_status_to_string (status); - + switch (status) { case CAIRO_STATUS_SUCCESS: break; case CAIRO_STATUS_NO_MEMORY: - rb_raise (rb_eNoMemError, string); + rb_raise (rb_eNoMemError, "%s", string); break; case CAIRO_STATUS_INVALID_RESTORE: - rb_raise (rb_eCairo_InvalidRestoreError, string); + rb_raise (rb_eCairo_InvalidRestoreError, "%s", string); break; case CAIRO_STATUS_INVALID_POP_GROUP: - rb_raise (rb_eCairo_InvalidPopGroupError, string); + rb_raise (rb_eCairo_InvalidPopGroupError, "%s", string); break; case CAIRO_STATUS_NO_CURRENT_POINT: - rb_raise (rb_eCairo_NoCurrentPointError, string); + rb_raise (rb_eCairo_NoCurrentPointError, "%s", string); break; case CAIRO_STATUS_INVALID_MATRIX: - rb_raise (rb_eCairo_InvalidMatrixError, string); + rb_raise (rb_eCairo_InvalidMatrixError, "%s", string); break; case CAIRO_STATUS_INVALID_STATUS: - rb_raise (rb_eCairo_InvalidStatusError, string); + rb_raise (rb_eCairo_InvalidStatusError, "%s", string); break; case CAIRO_STATUS_NULL_POINTER: - rb_raise (rb_eCairo_NullPointerError, string); + rb_raise (rb_eCairo_NullPointerError, "%s", string); break; case CAIRO_STATUS_INVALID_STRING: - rb_raise (rb_eCairo_InvalidStringError, string); + rb_raise (rb_eCairo_InvalidStringError, "%s", string); break; case CAIRO_STATUS_INVALID_PATH_DATA: - rb_raise (rb_eCairo_InvalidPathDataError, string); + rb_raise (rb_eCairo_InvalidPathDataError, "%s", string); break; case CAIRO_STATUS_READ_ERROR: - rb_raise (rb_eCairo_ReadError, string); + rb_raise (rb_eCairo_ReadError, "%s", string); break; case CAIRO_STATUS_WRITE_ERROR: - rb_raise (rb_eCairo_WriteError, string); + rb_raise (rb_eCairo_WriteError, "%s", string); break; case CAIRO_STATUS_SURFACE_FINISHED: - rb_raise (rb_eCairo_SurfaceFinishedError, string); + rb_raise (rb_eCairo_SurfaceFinishedError, "%s", string); break; case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: - rb_raise (rb_eCairo_SurfaceTypeMismatchError, string); + rb_raise (rb_eCairo_SurfaceTypeMismatchError, "%s", string); break; case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: - rb_raise (rb_eCairo_PatternTypeMismatchError, string); + rb_raise (rb_eCairo_PatternTypeMismatchError, "%s", string); break; case CAIRO_STATUS_INVALID_CONTENT: - rb_raise (rb_eCairo_InvalidContentError, string); + rb_raise (rb_eCairo_InvalidContentError, "%s", string); break; case CAIRO_STATUS_INVALID_FORMAT: - rb_raise (rb_eCairo_InvalidFormatError, string); + rb_raise (rb_eCairo_InvalidFormatError, "%s", string); break; case CAIRO_STATUS_INVALID_VISUAL: - rb_raise (rb_eCairo_InvalidVisualError, string); + rb_raise (rb_eCairo_InvalidVisualError, "%s", string); break; case CAIRO_STATUS_FILE_NOT_FOUND: - rb_raise (rb_eCairo_FileNotFoundError, string); + rb_raise (rb_eCairo_FileNotFoundError, "%s", string); break; case CAIRO_STATUS_INVALID_DASH: - rb_raise (rb_eCairo_InvalidDashError, string); + rb_raise (rb_eCairo_InvalidDashError, "%s", string); break; case CAIRO_STATUS_INVALID_DSC_COMMENT: - rb_raise (rb_eCairo_InvalidDscCommentError, string); + rb_raise (rb_eCairo_InvalidDscCommentError, "%s", string); break; #if CAIRO_CHECK_VERSION(1, 3, 0) case CAIRO_STATUS_INVALID_INDEX: - rb_raise (rb_eCairo_InvalidIndexError, string); + rb_raise (rb_eCairo_InvalidIndexError, "%s", string); break; case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: - rb_raise (rb_eCairo_ClipNotRepresentableError, string); + rb_raise (rb_eCairo_ClipNotRepresentableError, "%s", string); break; #endif #if CAIRO_CHECK_VERSION(1, 5, 6) case CAIRO_STATUS_TEMP_FILE_ERROR: - rb_raise (rb_eCairo_TempFileError, string); + rb_raise (rb_eCairo_TempFileError, "%s", string); break; case CAIRO_STATUS_INVALID_STRIDE: - rb_raise (rb_eCairo_InvalidStringError, string); + rb_raise (rb_eCairo_InvalidStringError, "%s", string); break; #endif #if CAIRO_CHECK_VERSION(1, 7, 2) case CAIRO_STATUS_FONT_TYPE_MISMATCH: - rb_raise (rb_eCairo_FontTypeMismatch, string); + rb_raise (rb_eCairo_FontTypeMismatch, "%s", string); break; case CAIRO_STATUS_USER_FONT_IMMUTABLE: - rb_raise (rb_eCairo_UserFontImmutable, string); + rb_raise (rb_eCairo_UserFontImmutable, "%s", string); break; case CAIRO_STATUS_USER_FONT_ERROR: - rb_raise (rb_eCairo_UserFontError, string); + rb_raise (rb_eCairo_UserFontError, "%s", string); break; case CAIRO_STATUS_NEGATIVE_COUNT: - rb_raise (rb_eCairo_NegativeCount, string); + rb_raise (rb_eCairo_NegativeCount, "%s", string); break; case CAIRO_STATUS_INVALID_CLUSTERS: - rb_raise (rb_eCairo_InvalidClusters, string); + rb_raise (rb_eCairo_InvalidClusters, "%s", string); break; case CAIRO_STATUS_INVALID_SLANT: - rb_raise (rb_eCairo_InvalidSlant, string); + rb_raise (rb_eCairo_InvalidSlant, "%s", string); break; case CAIRO_STATUS_INVALID_WEIGHT: - rb_raise (rb_eCairo_InvalidWeight, string); + rb_raise (rb_eCairo_InvalidWeight, "%s", string); + break; +#endif +#if CAIRO_CHECK_VERSION(1, 10, 0) + case CAIRO_STATUS_INVALID_SIZE: + rb_raise (rb_eCairo_InvalidSize, "%s", string); + break; + case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: + rb_raise (rb_eCairo_UserFontNotImplemented, "%s", string); + break; + case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: + rb_raise (rb_eCairo_DeviceTypeMismatch, "%s", string); + break; + case CAIRO_STATUS_DEVICE_ERROR: + rb_raise (rb_eCairo_DeviceError, "%s", string); + break; + case CAIRO_STATUS_LAST_STATUS: + rb_raise (rb_eArgError, "bug: %s: %d", string, status); break; #endif } @@ -236,6 +259,16 @@ rb_cairo__exception_to_status (VALUE exception) else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidWeight)) return CAIRO_STATUS_INVALID_WEIGHT; #endif +#if CAIRO_CHECK_VERSION(1, 10, 0) + else if (rb_cairo__is_kind_of (exception, rb_eCairo_InvalidSize)) + return CAIRO_STATUS_INVALID_SIZE; + else if (rb_cairo__is_kind_of (exception, rb_eCairo_UserFontNotImplemented)) + return CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED; + else if (rb_cairo__is_kind_of (exception, rb_eCairo_DeviceTypeMismatch)) + return CAIRO_STATUS_DEVICE_TYPE_MISMATCH; + else if (rb_cairo__is_kind_of (exception, rb_eCairo_DeviceError)) + return CAIRO_STATUS_DEVICE_ERROR; +#endif return -1; } @@ -351,4 +384,22 @@ Init_cairo_exception () rb_define_class_under (rb_mCairo, "InvalidWeight", rb_eArgError); #endif + +#if CAIRO_CHECK_VERSION(1, 10, 0) + rb_eCairo_InvalidSize = + rb_define_class_under (rb_mCairo, "InvalidSize", + rb_eArgError); + + rb_eCairo_UserFontNotImplemented = + rb_define_class_under (rb_mCairo, "UserFontNotImplemented", + rb_eCairo_Error); + + rb_eCairo_DeviceTypeMismatch = + rb_define_class_under (rb_mCairo, "DeviceTypeMismatch", + rb_eArgError); + + rb_eCairo_DeviceError = + rb_define_class_under (rb_mCairo, "DeviceError", + rb_eCairo_Error); +#endif } From null+rcairo at clear-code.com Sat Sep 11 02:46:35 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 06:46:35 +0000 Subject: [cairo-commit:00036] rcairo/rcairo [master] support operation new in cario 1.10. Message-ID: <20100911064646.0FD7C170521@taiyaki.ru> Kouhei Sutou 2010-09-11 06:46:35 +0000 (Sat, 11 Sep 2010) New Revision: 98b040f719322f162680f5abe8daf705f21f822d Log: support operation new in cario 1.10. Modified files: ext/cairo/rb_cairo_constants.c Modified: ext/cairo/rb_cairo_constants.c (+32 -0) =================================================================== --- ext/cairo/rb_cairo_constants.c 2010-09-11 06:42:59 +0000 (846a14b) +++ ext/cairo/rb_cairo_constants.c 2010-09-11 06:46:35 +0000 (aeea547) @@ -319,6 +319,38 @@ Init_cairo_constants (void) rb_define_const (rb_mCairo_Operator, "SATURATE", INT2FIX (CAIRO_OPERATOR_SATURATE)); +#if CAIRO_CHECK_VERSION(1, 10, 0) + rb_define_const (rb_mCairo_Operator, "MULTIPLY", + INT2FIX (CAIRO_OPERATOR_MULTIPLY)); + rb_define_const (rb_mCairo_Operator, "SCREEN", + INT2FIX (CAIRO_OPERATOR_SCREEN)); + rb_define_const (rb_mCairo_Operator, "OVERLAY", + INT2FIX (CAIRO_OPERATOR_OVERLAY)); + rb_define_const (rb_mCairo_Operator, "DARKEN", + INT2FIX (CAIRO_OPERATOR_DARKEN)); + rb_define_const (rb_mCairo_Operator, "LIGHTEN", + INT2FIX (CAIRO_OPERATOR_LIGHTEN)); + rb_define_const (rb_mCairo_Operator, "COLOR_DODGE", + INT2FIX (CAIRO_OPERATOR_COLOR_DODGE)); + rb_define_const (rb_mCairo_Operator, "COLOR_BURN", + INT2FIX (CAIRO_OPERATOR_COLOR_BURN)); + rb_define_const (rb_mCairo_Operator, "HARD_LIGHT", + INT2FIX (CAIRO_OPERATOR_HARD_LIGHT)); + rb_define_const (rb_mCairo_Operator, "SOFT_LIGHT", + INT2FIX (CAIRO_OPERATOR_SOFT_LIGHT)); + rb_define_const (rb_mCairo_Operator, "DIFFERENCE", + INT2FIX (CAIRO_OPERATOR_DIFFERENCE)); + rb_define_const (rb_mCairo_Operator, "EXCLUSION", + INT2FIX (CAIRO_OPERATOR_EXCLUSION)); + rb_define_const (rb_mCairo_Operator, "HSL_HUE", + INT2FIX (CAIRO_OPERATOR_HSL_HUE)); + rb_define_const (rb_mCairo_Operator, "HSL_SATURATION", + INT2FIX (CAIRO_OPERATOR_HSL_SATURATION)); + rb_define_const (rb_mCairo_Operator, "HSL_COLOR", + INT2FIX (CAIRO_OPERATOR_HSL_COLOR)); + rb_define_const (rb_mCairo_Operator, "HSL_LUMINOSITY", + INT2FIX (CAIRO_OPERATOR_HSL_LUMINOSITY)); +#endif /* cairo_antialias_t */ rb_mCairo_Antialias = rb_define_module_under (rb_mCairo, "Antialias"); From null+rcairo at clear-code.com Sat Sep 11 02:51:30 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 06:51:30 +0000 Subject: [cairo-commit:00037] rcairo/rcairo [master] support cairo_in_clip() new in cairo 1.10. Message-ID: <20100911065141.68D22170521@taiyaki.ru> Kouhei Sutou 2010-09-11 06:51:30 +0000 (Sat, 11 Sep 2010) New Revision: b1f479c2370f30fe5ba6c187e664b9fba4edc736 Log: support cairo_in_clip() new in cairo 1.10. Modified files: ext/cairo/rb_cairo_context.c Modified: ext/cairo/rb_cairo_context.c (+17 -0) =================================================================== --- ext/cairo/rb_cairo_context.c 2010-09-11 06:46:35 +0000 (d4e6721) +++ ext/cairo/rb_cairo_context.c 2010-09-11 06:51:30 +0000 (ff53986) @@ -5,6 +5,7 @@ * $Author: kou $ * $Date: 2008-09-26 13:52:08 $ * + * Copyright 2005-2010 Kouhei Sutou * Copyright 2005 ?yvind Kol?s * Copyright 2004-2005 MenTaLguY * @@ -983,6 +984,19 @@ cr_in_fill (VALUE self, VALUE x, VALUE y) return CBOOL2RVAL (cairo_in_fill (_SELF, NUM2DBL (x), NUM2DBL (y))); } +#if CAIRO_CHECK_VERSION(1, 10, 0) +static VALUE +cr_in_clip (VALUE self, VALUE x, VALUE y) +{ + if (rb_block_given_p ()) + { + cr_new_path (self); + rb_yield (self); + } + return CBOOL2RVAL (cairo_in_clip (_SELF, NUM2DBL (x), NUM2DBL (y))); +} +#endif + /* Rectangular extents */ static VALUE cr_stroke_extents (VALUE self) @@ -1615,6 +1629,9 @@ Init_cairo_context (void) /* Insideness testing */ rb_define_method (rb_cCairo_Context, "in_stroke?", cr_in_stroke, 2); rb_define_method (rb_cCairo_Context, "in_fill?", cr_in_fill, 2); +#if CAIRO_CHECK_VERSION(1, 10, 0) + rb_define_method (rb_cCairo_Context, "in_clip?", cr_in_clip, 2); +#endif /* Rectangular extents */ rb_define_method (rb_cCairo_Context, "stroke_extents", cr_stroke_extents, 0); From null+rcairo at clear-code.com Sat Sep 11 03:06:25 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 07:06:25 +0000 Subject: [cairo-commit:00038] rcairo/rcairo [master] support cairo_surface_create_for_rectangle() new in cairo 1.10. Message-ID: <20100911070638.1023C170521@taiyaki.ru> Kouhei Sutou 2010-09-11 07:06:25 +0000 (Sat, 11 Sep 2010) New Revision: 05300b5f2b19311f6be1f40daa1a8f663b4ce7d1 Log: support cairo_surface_create_for_rectangle() new in cairo 1.10. Modified files: ext/cairo/rb_cairo_surface.c Modified: ext/cairo/rb_cairo_surface.c (+35 -0) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-11 06:51:30 +0000 (cbfd20b) +++ ext/cairo/rb_cairo_surface.c 2010-09-11 07:06:25 +0000 (3f75e6f) @@ -434,6 +434,37 @@ cr_surface_create_similar (VALUE self, VALUE content, VALUE width, VALUE height) return CRSURFACE2RVAL_WITH_DESTROY (surface); } +#if CAIRO_CHECK_VERSION(1, 10, 0) +static VALUE +cr_surface_destroy_with_destroy_check (VALUE self) +{ + if (DATA_PTR (self)) + cr_surface_destroy (self); + return Qnil; +} + +static VALUE +cr_surface_create_sub_rectangle_surface (VALUE self, VALUE x, VALUE y, + VALUE width, VALUE height) +{ + VALUE rb_surface; + cairo_surface_t *surface; + + surface = cairo_surface_create_for_rectangle (RVAL2CRSURFACE (self), + NUM2DBL (x), + NUM2DBL (y), + NUM2DBL (width), + NUM2INT (height)); + cr_surface_check_status (surface); + rb_surface = CRSURFACE2RVAL_WITH_DESTROY (surface); + if (rb_block_given_p ()) + return rb_ensure (rb_yield, rb_surface, + cr_surface_destroy_with_destroy_check, rb_surface); + else + return rb_surface; +} +#endif + static VALUE cr_surface_get_content (VALUE self) { @@ -1225,6 +1256,10 @@ Init_cairo_surface (void) rb_define_method (rb_cCairo_Surface, "create_similar", cr_surface_create_similar, 3); +#if CAIRO_CHECK_VERSION(1, 10, 0) + rb_define_method (rb_cCairo_Surface, "sub_rectangle_surface", + cr_surface_create_sub_rectangle_surface, 4); +#endif rb_define_method (rb_cCairo_Surface, "destroy", cr_surface_destroy, 0); rb_define_method (rb_cCairo_Surface, "finish", cr_surface_finish, 0); rb_define_method (rb_cCairo_Surface, "content", cr_surface_get_content, 0); From null+rcairo at clear-code.com Sat Sep 11 03:30:35 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 07:30:35 +0000 Subject: [cairo-commit:00039] rcairo/rcairo [master] support script surface creation new in cairo 1.10. Message-ID: <20100911073145.26212170521@taiyaki.ru> Kouhei Sutou 2010-09-11 07:30:35 +0000 (Sat, 11 Sep 2010) New Revision: ea2669f281e136823a17438a98510861b00aed98 Log: support script surface creation new in cairo 1.10. Modified files: ext/cairo/cairo.def ext/cairo/rb_cairo.h ext/cairo/rb_cairo_surface.c Modified: ext/cairo/cairo.def (+2 -0) =================================================================== --- ext/cairo/cairo.def 2010-09-11 07:06:25 +0000 (ec15612) +++ ext/cairo/cairo.def 2010-09-11 07:30:35 +0000 (f7dae45) @@ -84,6 +84,8 @@ EXPORTS rb_cairo_surface_from_ruby_object rb_cairo_surface_to_ruby_object rb_cairo_surface_to_ruby_object_with_destroy + rb_cairo_device_from_ruby_object + rb_cairo_device_to_ruby_object rb_cairo_operator_from_ruby_object rb_cairo_antialias_from_ruby_object rb_cairo_fill_rule_from_ruby_object Modified: ext/cairo/rb_cairo.h (+17 -0) =================================================================== --- ext/cairo/rb_cairo.h 2010-09-11 07:06:25 +0000 (45e7532) +++ ext/cairo/rb_cairo.h 2010-09-11 07:30:35 +0000 (5b4fd0d) @@ -103,6 +103,16 @@ RB_CAIRO_VAR VALUE rb_cCairo_Win32PrintingSurface; #define rb_cCairo_WIN32Surface rb_cCairo_Win32Surface RB_CAIRO_VAR VALUE rb_cCairo_QuartzSurface; RB_CAIRO_VAR VALUE rb_cCairo_QuartzImageSurface; +RB_CAIRO_VAR VALUE rb_cCairo_ScriptSurface; +RB_CAIRO_VAR VALUE rb_cCairo_QtSurface; +RB_CAIRO_VAR VALUE rb_cCairo_RecordingSurface; +RB_CAIRO_VAR VALUE rb_cCairo_VGSurface; +RB_CAIRO_VAR VALUE rb_cCairo_GLSurface; +RB_CAIRO_VAR VALUE rb_cCairo_DRMSurface; +RB_CAIRO_VAR VALUE rb_cCairo_TeeSurface; +RB_CAIRO_VAR VALUE rb_cCairo_XMLSurface; +RB_CAIRO_VAR VALUE rb_cCairo_SkiaSurface; +RB_CAIRO_VAR VALUE rb_cCairo_SubSurface; RB_CAIRO_VAR VALUE rb_mCairo_Operator; RB_CAIRO_VAR VALUE rb_mCairo_Antialias; @@ -170,6 +180,9 @@ RB_CAIRO_VAR VALUE rb_cCairo_Paper; #define CRSURFACE2RVAL_WITH_DESTROY(surface) \ (rb_cairo_surface_to_ruby_object_with_destroy(surface)) +#define RVAL2CRDEVICE(obj) (rb_cairo_device_from_ruby_object(obj)) +#define CRDEVICE2RVAL(device) (rb_cairo_device_to_ruby_object(device)) + cairo_t *rb_cairo_context_from_ruby_object (VALUE obj); VALUE rb_cairo_context_to_ruby_object (cairo_t *cr); @@ -210,6 +223,10 @@ VALUE rb_cairo_surface_to_ruby_object (cairo_surface_t *s VALUE rb_cairo_surface_to_ruby_object_with_destroy (cairo_surface_t *surface); +#if CAIRO_CHECK_VERSION(1, 10, 0) +cairo_device_t *rb_cairo_device_from_ruby_object (VALUE obj); +VALUE rb_cairo_device_to_ruby_object (cairo_device_t *device); +#endif #define RVAL2CROPERATOR(obj) (rb_cairo_operator_from_ruby_object(obj)) #define RVAL2CRANTIALIAS(obj) (rb_cairo_antialias_from_ruby_object(obj)) Modified: ext/cairo/rb_cairo_surface.c (+120 -0) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-11 07:06:25 +0000 (3f75e6f) +++ ext/cairo/rb_cairo_surface.c 2010-09-11 07:30:35 +0000 (aa18962) @@ -5,6 +5,7 @@ * $Author: kou $ * $Date: 2008-11-01 14:23:14 $ * + * Copyright 2005-2010 Kouhei Sutou * Copyright 2005 ?yvind Kol?s * Copyright 2004-2005 MenTaLguY * @@ -52,6 +53,9 @@ enum ruby_value_type { # define HAS_CREATE_CR_CLOSURE_SURFACE 0 #endif +#ifdef CAIRO_HAS_SCRIPT_SURFACE +# include +#endif VALUE rb_cCairo_Surface; VALUE rb_cCairo_ImageSurface; @@ -62,6 +66,16 @@ VALUE rb_cCairo_Win32Surface = Qnil; VALUE rb_cCairo_Win32PrintingSurface = Qnil; VALUE rb_cCairo_QuartzSurface = Qnil; VALUE rb_cCairo_QuartzImageSurface = Qnil; +VALUE rb_cCairo_ScriptSurface = Qnil; +VALUE rb_cCairo_QtSurface = Qnil; +VALUE rb_cCairo_RecordingSurface = Qnil; +VALUE rb_cCairo_VGSurface = Qnil; +VALUE rb_cCairo_GLSurface = Qnil; +VALUE rb_cCairo_DRMSurface = Qnil; +VALUE rb_cCairo_TeeSurface = Qnil; +VALUE rb_cCairo_XMLSurface = Qnil; +VALUE rb_cCairo_SkiaSurface = Qnil; +VALUE rb_cCairo_SubSurface = Qnil; static ID cr_id_target; static ID cr_id_read; @@ -136,6 +150,38 @@ cr_surface_get_klass (cairo_surface_t *surface) klass = rb_cCairo_QuartzImageSurface; break; #endif +#if CAIRO_CHECK_VERSION(1, 10, 0) + case CAIRO_SURFACE_TYPE_SCRIPT: + klass = rb_cCairo_ScriptSurface; + break; + case CAIRO_SURFACE_TYPE_QT: + klass = rb_cCairo_QtSurface; + break; + case CAIRO_SURFACE_TYPE_RECORDING: + klass = rb_cCairo_RecordingSurface; + break; + case CAIRO_SURFACE_TYPE_VG: + klass = rb_cCairo_VGSurface; + break; + case CAIRO_SURFACE_TYPE_GL: + klass = rb_cCairo_GLSurface; + break; + case CAIRO_SURFACE_TYPE_DRM: + klass = rb_cCairo_DRMSurface; + break; + case CAIRO_SURFACE_TYPE_TEE: + klass = rb_cCairo_TeeSurface; + break; + case CAIRO_SURFACE_TYPE_XML: + klass = rb_cCairo_XMLSurface; + break; + case CAIRO_SURFACE_TYPE_SKIA: + klass = rb_cCairo_SkiaSurface; + break; + case CAIRO_SURFACE_TYPE_SUBSURFACE: + klass = rb_cCairo_SubSurface; + break; +#endif default: klass = rb_cCairo_Surface; break; @@ -1220,6 +1266,71 @@ cr_quartz_image_surface_get_image (VALUE self) # endif #endif +#ifdef CAIRO_HAS_SCRIPT_SURFACE +static VALUE +cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) +{ + cairo_device_t *script; + cairo_surface_t *surface = NULL, *target = NULL; + cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA; + VALUE arg1, arg2, arg3, arg4, rb_width = Qnil, rb_height = Qnil; + + rb_scan_args (argc, argv, "22", &arg1, &arg2, &arg3, &arg4); + + script = CRDEVICE2RVAL (arg1); + if (argc == 2) + { + target = RVAL2CRSURFACE (arg2); + } + else if (argc == 3) + { + rb_width = arg2; + rb_height = arg3; + } + else + { + switch (TYPE (arg1)) + { + case T_NIL: + break; + case T_STRING: + case T_SYMBOL: + case T_FIXNUM: + content = RVAL2CRCONTENT (arg1); + break; + default: + rb_raise (rb_eArgError, + "invalid argument (expect " + "(script, width, height), " + "(script, content, width, height), " + "(script, surface)): %s", + inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4))); + break; + } + + rb_width = arg3; + rb_height = arg4; + } + + if (target) + { + surface = cairo_script_surface_create_for_target (script, target); + } + else + { + surface = cairo_script_surface_create (script, content, + NUM2DBL (rb_width), + NUM2DBL (rb_height)); + } + + cr_surface_check_status (surface); + DATA_PTR (self) = surface; + if (rb_block_given_p ()) + yield_and_finish (self); + return Qnil; +} +#endif + static int cr_finish_all_guarded_surfaces_at_end_iter (VALUE key, VALUE value, VALUE data) { @@ -1416,6 +1527,15 @@ Init_cairo_surface (void) rb_define_method (rb_cCairo_QuartzImageSurface, "image", cr_quartz_image_surface_get_image, 0); # endif +#endif + +#ifdef CAIRO_HAS_SCRIPT_SURFACE + rb_cCairo_ScriptSurface = + rb_define_class_under (rb_mCairo, "ScriptSurface", rb_cCairo_ScriptSurface); + + rb_define_method (rb_cCairo_ScriptSurface, "initialize", + cr_script_surface_initialize, -1); + RB_CAIRO_DEF_SETTERS (rb_cCairo_ScriptSurface); #endif } From null+rcairo at clear-code.com Sat Sep 11 04:00:46 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 08:00:46 +0000 Subject: [cairo-commit:00040] rcairo/rcairo [master] start supporting cairo_device_t new in cairo 1.10. Message-ID: <20100911080056.35C6F170521@taiyaki.ru> Kouhei Sutou 2010-09-11 08:00:46 +0000 (Sat, 11 Sep 2010) New Revision: 049fd83dd877aacc2732baa1363d057401921e45 Log: start supporting cairo_device_t new in cairo 1.10. Added files: ext/cairo/rb_cairo_device.c Modified files: ext/cairo/rb_cairo.c ext/cairo/rb_cairo.h ext/cairo/rb_cairo_private.h Modified: ext/cairo/rb_cairo.c (+1 -0) =================================================================== --- ext/cairo/rb_cairo.c 2010-09-11 07:30:35 +0000 (dd596c3) +++ ext/cairo/rb_cairo.c 2010-09-11 08:00:46 +0000 (fbcf87e) @@ -91,6 +91,7 @@ Init_cairo () Init_cairo_context (); Init_cairo_path (); Init_cairo_matrix (); + Init_cairo_device (); Init_cairo_surface (); Init_cairo_exception (); Init_cairo_font (); Modified: ext/cairo/rb_cairo.h (+7 -0) =================================================================== --- ext/cairo/rb_cairo.h 2010-09-11 07:30:35 +0000 (5b4fd0d) +++ ext/cairo/rb_cairo.h 2010-09-11 08:00:46 +0000 (aac6d0e) @@ -113,6 +113,13 @@ RB_CAIRO_VAR VALUE rb_cCairo_TeeSurface; RB_CAIRO_VAR VALUE rb_cCairo_XMLSurface; RB_CAIRO_VAR VALUE rb_cCairo_SkiaSurface; RB_CAIRO_VAR VALUE rb_cCairo_SubSurface; +RB_CAIRO_VAR VALUE rb_cCairo_Device; +RB_CAIRO_VAR VALUE rb_cCairo_DRMDevice; +RB_CAIRO_VAR VALUE rb_cCairo_GLDevice; +RB_CAIRO_VAR VALUE rb_cCairo_ScriptDevice; +RB_CAIRO_VAR VALUE rb_cCairo_XCBDevice; +RB_CAIRO_VAR VALUE rb_cCairo_XlibtDevice; +RB_CAIRO_VAR VALUE rb_cCairo_XMLDevice; RB_CAIRO_VAR VALUE rb_mCairo_Operator; RB_CAIRO_VAR VALUE rb_mCairo_Antialias; Added: ext/cairo/rb_cairo_device.c (+249 -0) 100644 =================================================================== --- /dev/null +++ ext/cairo/rb_cairo_device.c 2010-09-11 08:00:46 +0000 (23cf96e) @@ -0,0 +1,249 @@ +/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */ +/* + * Ruby Cairo Binding + * + * Copyright 2010 Kouhei Sutou + * + * This file is made available under the same terms as Ruby + * + */ + +#include "rb_cairo.h" +#include "rb_cairo_private.h" + +#ifdef HAVE_RUBY_ST_H +# include +#else +# include +#endif + +#ifdef CAIRO_HAS_SCRIPT_SURFACE +# include +#endif + +VALUE rb_cCairo_Device = Qnil; +VALUE rb_cCairo_DRMDevice = Qnil; +VALUE rb_cCairo_GLDevice = Qnil; +VALUE rb_cCairo_ScriptDevice = Qnil; +VALUE rb_cCairo_XCBDevice = Qnil; +VALUE rb_cCairo_XlibDevice = Qnil; +VALUE rb_cCairo_XMLDevice = Qnil; + +static cairo_user_data_key_t cr_closure_key; +static cairo_user_data_key_t cr_object_holder_key; +static cairo_user_data_key_t cr_finished_key; + +#define _SELF (RVAL2CRDEVICE(self)) + +#if CAIRO_CHECK_VERSION(1, 10, 0) +static inline void +cr_device_check_status (cairo_device_t *device) +{ + rb_cairo_check_status (cairo_device_status (device)); +} + +static VALUE +cr_device_get_klass (cairo_device_t *device) +{ + VALUE klass; + cairo_device_type_t type; + + type = cairo_device_get_type (device); + switch (type) + { + case CAIRO_DEVICE_TYPE_DRM: + klass = rb_cCairo_DRMDevice; + break; + case CAIRO_DEVICE_TYPE_GL: + klass = rb_cCairo_GLDevice; + break; + case CAIRO_DEVICE_TYPE_SCRIPT: + klass = rb_cCairo_ScriptDevice; + break; + case CAIRO_DEVICE_TYPE_XCB: + klass = rb_cCairo_XCBDevice; + break; + case CAIRO_DEVICE_TYPE_XLIB: + klass = rb_cCairo_XlibDevice; + break; + case CAIRO_DEVICE_TYPE_XML: + klass = rb_cCairo_XMLDevice; + break; + default: + klass = rb_cCairo_Device; + break; + } + + if (NIL_P (klass)) + rb_raise (rb_eArgError, "unknown device type: %d", type); + + return klass; +} + +/* constructor/de-constructor */ +cairo_device_t * +rb_cairo_device_from_ruby_object (VALUE obj) +{ + cairo_device_t *device; + if (!rb_cairo__is_kind_of (obj, rb_cCairo_Device)) + { + rb_raise (rb_eTypeError, "not a cairo device"); + } + Data_Get_Struct (obj, cairo_device_t, device); + if (!device) + rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER); + return device; +} + +static rb_cairo__object_holder_t * +cr_object_holder_new (VALUE object) +{ + return rb_cairo__object_holder_new (rb_cCairo_Device, object); +} + +static void +cr_object_holder_free (void *ptr) +{ + rb_cairo__object_holder_free (rb_cCairo_Device, ptr); +} + +static void +cr_device_free (void *ptr) +{ + cairo_device_t *device = ptr; + + if (device) + cairo_device_destroy (device); +} + +VALUE +rb_cairo_device_to_ruby_object (cairo_device_t *device) +{ + if (device) + { + VALUE klass; + klass = cr_device_get_klass (device); + cairo_device_reference (device); + return Data_Wrap_Struct (klass, NULL, cr_device_free, device); + } + else + { + return Qnil; + } +} + +VALUE +rb_cairo_device_to_ruby_object_with_destroy (cairo_device_t *device) +{ + VALUE rb_device; + + rb_device = rb_cairo_device_to_ruby_object (device); + if (device) + cairo_device_destroy (device); + + return rb_device; +} + +static VALUE +cr_device_allocate (VALUE klass) +{ + return Data_Wrap_Struct (klass, NULL, cr_device_free, NULL); +} + +/* Backend device manipulation */ +static VALUE +cr_device_destroy (VALUE self) +{ + cairo_device_t *device; + + device = _SELF; + cairo_device_destroy (device); + DATA_PTR (self) = NULL; + + return self; +} + +static VALUE +cr_device_finish (VALUE self) +{ + cairo_device_t *device; + /* cr_io_callback_closure_t *closure; */ + + device = _SELF; + /* closure = cairo_device_get_user_data (device, &cr_closure_key); */ + + cairo_device_finish (device); + cairo_device_set_user_data (device, &cr_finished_key, (void *)CR_TRUE, NULL); + cairo_device_set_user_data (device, &cr_object_holder_key, NULL, NULL); + + /* if (closure && !NIL_P (closure->error)) */ + /* rb_exc_raise (closure->error); */ + cr_device_check_status (device); + + return self; +} + +static VALUE +cr_device_flush (VALUE self) +{ + cairo_device_flush (_SELF); + cr_device_check_status (_SELF); + return self; +} + +static VALUE +cr_device_release (VALUE self) +{ + cairo_device_release (_SELF); + cr_device_check_status (_SELF); + return self; +} + +static VALUE +cr_device_acquire (VALUE self) +{ + cairo_device_acquire (_SELF); + cr_device_check_status (_SELF); + if (rb_block_given_p ()) + return rb_ensure (rb_yield, self, cr_device_release, self); + else + return self; +} +#endif + +static int +cr_finish_all_guarded_devices_at_end_iter (VALUE key, VALUE value, VALUE data) +{ + cr_device_finish (key); + return ST_CONTINUE; +} + +static void +cr_finish_all_guarded_devices_at_end (VALUE data) +{ + rb_hash_foreach (rb_cairo__gc_guarded_objects (rb_cCairo_Device), + cr_finish_all_guarded_devices_at_end_iter, + Qnil); +} + +void +Init_cairo_device (void) +{ +#ifdef CAIRO_CHECK_VERSION(1, 10, 0) + rb_cCairo_Device = + rb_define_class_under (rb_mCairo, "Device", rb_cObject); + rb_define_alloc_func (rb_cCairo_Device, cr_device_allocate); + + rb_cairo__initialize_gc_guard_holder_class (rb_cCairo_Device); + rb_set_end_proc(cr_finish_all_guarded_devices_at_end, Qnil); + + + rb_define_method (rb_cCairo_Device, "destroy", cr_device_destroy, 0); + rb_define_method (rb_cCairo_Device, "finish", cr_device_finish, 0); + rb_define_method (rb_cCairo_Device, "flush", cr_device_flush, 0); + rb_define_method (rb_cCairo_Device, "acquire", cr_device_acquire, 0); + rb_define_method (rb_cCairo_Device, "release", cr_device_release, 0); + + RB_CAIRO_DEF_SETTERS (rb_cCairo_Device); +#endif +} Modified: ext/cairo/rb_cairo_private.h (+1 -0) =================================================================== --- ext/cairo/rb_cairo_private.h 2010-09-11 07:30:35 +0000 (dbd77df) +++ ext/cairo/rb_cairo_private.h 2010-09-11 08:00:46 +0000 (4c0d304) @@ -49,6 +49,7 @@ extern void Init_cairo_constants (void); extern void Init_cairo_context (void); extern void Init_cairo_path (void); extern void Init_cairo_matrix (void); +extern void Init_cairo_device (void); extern void Init_cairo_surface (void); extern void Init_cairo_quartz_surface (void); extern void Init_cairo_exception (void); From null+rcairo at clear-code.com Sat Sep 11 04:09:39 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 08:09:39 +0000 Subject: [cairo-commit:00041] rcairo/rcairo [master] add missing variables to .def. Message-ID: <20100911080950.36A38170521@taiyaki.ru> Kouhei Sutou 2010-09-11 08:09:39 +0000 (Sat, 11 Sep 2010) New Revision: d364271696dc9252286bc409be7b509f3b0bd84a Log: add missing variables to .def. Modified files: ext/cairo/cairo.def Modified: ext/cairo/cairo.def (+17 -0) =================================================================== --- ext/cairo/cairo.def 2010-09-11 08:00:46 +0000 (f7dae45) +++ ext/cairo/cairo.def 2010-09-11 08:09:39 +0000 (dfcbcb0) @@ -34,6 +34,23 @@ EXPORTS rb_cCairo_Win32PrintingSurface DATA rb_cCairo_QuartzSurface DATA rb_cCairo_QuartzImageSurface DATA + rb_cCairo_ScriptSurface DATA + rb_cCairo_QtSurface DATA + rb_cCairo_RecordingSurface DATA + rb_cCairo_VGSurface DATA + rb_cCairo_GLSurface DATA + rb_cCairo_DRMSurface DATA + rb_cCairo_TeeSurface DATA + rb_cCairo_XMLSurface DATA + rb_cCairo_SkiaSurface DATA + rb_cCairo_SubSurface DATA + rb_cCairo_Device DATA + rb_cCairo_DRMDevice DATA + rb_cCairo_GLDevice DATA + rb_cCairo_ScriptDevice DATA + rb_cCairo_XCBDevice DATA + rb_cCairo_XlibtDevice DATA + rb_cCairo_XMLDevice DATA rb_mCairo_Operator DATA rb_mCairo_Antialias DATA From null+rcairo at clear-code.com Sat Sep 11 06:49:06 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 10:49:06 +0000 Subject: [cairo-commit:00042] rcairo/rcairo [master] add missing PDFVersion variable. Message-ID: <20100911104950.842B8278001@taiyaki.ru> Kouhei Sutou 2010-09-11 10:49:06 +0000 (Sat, 11 Sep 2010) New Revision: e72456826c538413b132145508696dd82cb552be Log: add missing PDFVersion variable. Modified files: ext/cairo/rb_cairo_constants.c Modified: ext/cairo/rb_cairo_constants.c (+1 -0) =================================================================== --- ext/cairo/rb_cairo_constants.c 2010-09-11 10:41:36 +0000 (aeea547) +++ ext/cairo/rb_cairo_constants.c 2010-09-11 10:49:06 +0000 (093ca44) @@ -34,6 +34,7 @@ VALUE rb_mCairo_Filter; VALUE rb_mCairo_SVGVersion = Qnil; VALUE rb_mCairo_PSLevel = Qnil; VALUE rb_mCairo_TextClusterFlag = Qnil; +VALUE rb_mCairo_PDFVersion = Qnil; #define CAIRO_OPERATOR_MIN CAIRO_OPERATOR_CLEAR #define CAIRO_OPERATOR_MAX CAIRO_OPERATOR_SATURATE From null+rcairo at clear-code.com Sat Sep 11 06:41:36 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 10:41:36 +0000 Subject: [cairo-commit:00043] rcairo/rcairo [master] use pkg-config package instead of bundled pkg-config. Message-ID: <20100911104950.76012170521@taiyaki.ru> Kouhei Sutou 2010-09-11 10:41:36 +0000 (Sat, 11 Sep 2010) New Revision: 95aa3b4a4e15625d5b3bfe2d72b9ede5ca133d6f Log: use pkg-config package instead of bundled pkg-config. Removed files: pkg-config.rb test/test_pkg_config.rb Modified files: Rakefile ext/cairo/extconf.rb test/run-test.rb Modified: Rakefile (+1 -0) =================================================================== --- Rakefile 2010-09-11 08:09:39 +0000 (ba360f6) +++ Rakefile 2010-09-11 10:41:36 +0000 (5185239) @@ -78,6 +78,7 @@ project = Hoe.spec('cairo') do |project| :require_paths => ['lib'], :has_rdoc => false, } + project.extra_deps << ['pkg-config', '>= 0'] platform = ENV["FORCE_PLATFORM"] project.spec_extras[:platform] = platform if platform news = File.join(base_dir, "NEWS") Modified: ext/cairo/extconf.rb (+6 -4) =================================================================== --- ext/cairo/extconf.rb 2010-09-11 08:09:39 +0000 (37e8b8e) +++ ext/cairo/extconf.rb 2010-09-11 10:41:36 +0000 (89321e9) @@ -6,10 +6,12 @@ require 'English' require 'mkmf' require 'fileutils' -base_dir = (Pathname(__FILE__).dirname + ".." + "..").expand_path -$LOAD_PATH.unshift(base_dir.to_s) - -require 'pkg-config' +begin + require 'pkg-config' +rescue LoadError + require 'rubygems' + require 'pkg-config' +end checking_for(checking_message("GCC")) do if macro_defined?("__GNUC__", "") Deleted: pkg-config.rb (+0 -313) 100644 =================================================================== --- pkg-config.rb 2010-09-11 08:09:39 +0000 (587245c) +++ /dev/null @@ -1,313 +0,0 @@ -# Copyright 2008-2009 Kouhei Sutou -# This file is made available under the same terms as Ruby. - -require "rbconfig" - -require 'mkmf' -require 'shellwords' -require 'English' -require 'pathname' - -class PackageConfig - attr_accessor :msvc_syntax - def initialize(name, path=nil, msvc_syntax=false) - @name = name - @path = path || ENV["PKG_CONFIG_PATH"] - @path = [@path, guess_default_path].compact.join(separator) - @msvc_syntax = msvc_syntax - @variables = @declarations = nil - override_variables = with_config("override-variables", "") - @override_variables = parse_override_variables(override_variables) - end - - def exist? - not pc.nil? - end - - def requires - parse_requires(declaration("Requires")) - end - - def requires_private - parse_requires(declaration("Requires.private")) - end - - def cflags - path_flags, other_flags = collect_cflags - (other_flags + path_flags).join(" ") - end - - def cflags_only_I - collect_cflags[0].join(" ") - end - - def libs - path_flags, other_flags = collect_libs - (other_flags + path_flags).join(" ") - end - - def libs_only_l - collect_libs[1].find_all do |arg| - if @msvc_syntax - /\.lib\z/ =~ arg - else - /\A-l/ =~ arg - end - end.join(" ") - end - - def version - declaration("Version") - end - - def variable(name) - parse_pc if @variables.nil? - expand_value(@override_variables[name] || @variables[name]) - end - - def declaration(name) - parse_pc if @declarations.nil? - expand_value(@declarations[name]) - end - - private - def pc - @path.split(separator).each do |path| - pc_name = File.join(path, "#{@name}.pc") - return pc_name if File.exist?(pc_name) - end - return nil - end - - def separator - File.expand_path(".").index(":") ? ";" : ":" - end - - def collect_cflags - all_cflags = (requires_private + requires.reverse).collect do |package| - self.class.new(package, @path, @msvc_syntax).cflags - end - all_cflags = [declaration("Cflags")] + all_cflags - all_cflags = all_cflags.join(" ").gsub(/-I /, '-I').split.uniq - path_flags, other_flags = all_cflags.partition {|flag| /\A-I/ =~ flag} - path_flags = path_flags.reject do |flag| - flag == "-I/usr/include" - end - if @msvc_syntax - path_flags = path_flags.collect do |flag| - flag.gsub(/\A-I/, "/I") - end - end - [path_flags, other_flags] - end - - def collect_libs - all_libs = requires.collect do |package| - self.class.new(package, @path, @msvc_syntax).libs - end - all_libs = [declaration("Libs")] + all_libs - all_libs = all_libs.join(" ").gsub(/-([Ll]) /, '\1').split.uniq - path_flags, other_flags = all_libs.partition {|flag| /\A-L/ =~ flag} - path_flags = path_flags.reject do |flag| - /\A-L\/usr\/lib(?:64)?\z/ =~ flag - end - if @msvc_syntax - path_flags = path_flags.collect do |flag| - flag.gsub(/\A-L/, "/libpath:") - end - other_flags = other_flags.collect do |flag| - if /\A-l/ =~ flag - "#{$POSTMATCH}.lib" - else - flag - end - end - end - [path_flags, other_flags] - end - - IDENTIFIER_RE = /[\w\d_.]+/ - def parse_pc - raise ".pc for #{@name} doesn't exist." unless exist? - @variables = {} - @declarations = {} - File.open(pc) do |input| - input.each_line do |line| - line = line.gsub(/#.*/, '').strip - next if line.empty? - case line - when /^(#{IDENTIFIER_RE})=/ - @variables[$1] = $POSTMATCH.strip - when /^(#{IDENTIFIER_RE}):/ - @declarations[$1] = $POSTMATCH.strip - end - end - end - end - - def parse_requires(requires) - return [] if requires.nil? - requires_without_version = requires.gsub(/[<>]?=\s*[\d.]+\s*/, '') - requires_without_version.split(/[,\s]+/) - end - - def parse_override_variables(override_variables) - variables = {} - override_variables.split(",").each do |variable| - name, value = variable.split("=", 2) - variables[name] = value - end - variables - end - - def expand_value(value) - return nil if value.nil? - value.gsub(/\$\{(#{IDENTIFIER_RE})\}/) do - variable($1) - end - end - - def search_pkg_config_from_path(pkg_config) - (ENV["PATH"] || "").split(separator).each do |path| - try_pkg_config = Pathname(path) + pkg_config - return try_pkg_config if try_pkg_config.exist? - end - nil - end - - def search_pkg_config_by_dln_find_exe(pkg_config) - begin - require "dl/import" - rescue LoadError - return nil - end - dln = Module.new - dln.module_eval do - if DL.const_defined?(:Importer) - extend DL::Importer - else - extend DL::Importable - end - begin - dlload RbConfig::CONFIG["LIBRUBY"] - rescue RuntimeError - return nil if $!.message == "unknown error" - return nil if /: image not found\z/ =~ $!.message - raise - rescue DL::DLError - return nil - end - extern "const char *dln_find_exe(const char *, const char *)" - end - path = dln.dln_find_exe(pkg_config.to_s, nil) - if path.size.zero? - nil - else - Pathname(path.to_s) - end - end - - def guess_default_path - default_path = ["/usr/local/lib64/pkgconfig", - "/usr/local/lib/pkgconfig", - "/usr/local/libdata/pkgconfig", - "/opt/local/lib/pkgconfig", - "/usr/lib64/pkgconfig", - "/usr/lib/pkgconfig", - "/usr/X11/lib/pkgconfig/", - "/usr/share/pkgconfig"].join(separator) - libdir = ENV["PKG_CONFIG_LIBDIR"] - default_path = [libdir, default_path].join(separator) if libdir - - pkg_config = with_config("pkg-config", ENV["PKG_CONFIG"] || "pkg-config") - pkg_config = Pathname.new(pkg_config) - unless pkg_config.absolute? - found_pkg_config = search_pkg_config_from_path(pkg_config) - pkg_config = found_pkg_config if found_pkg_config - end - unless pkg_config.absolute? - found_pkg_config = search_pkg_config_by_dln_find_exe(pkg_config) - pkg_config = found_pkg_config if found_pkg_config - end - - return default_path unless pkg_config.absolute? - [(pkg_config.parent.parent + "lib" + "pkgconfig").to_s, - (pkg_config.parent.parent + "libdata" + "pkgconfig").to_s, - default_path].join(separator) - end -end - -module PKGConfig - module_function - def msvc? - /mswin32/.match(RUBY_PLATFORM) and /^cl\b/.match(Config::CONFIG['CC']) - end - - def package_config(package) - PackageConfig.new(package, nil, msvc?) - end - - def exist?(pkg) - package_config(pkg).exist? - end - - def libs(pkg) - package_config(pkg).libs - end - - def libs_only_l(pkg) - package_config(pkg).libs_only_l - end - - def cflags(pkg) - package_config(pkg).cflags - end - - def cflags_only_I(pkg) - package_config(pkg).cflags_only_I - end - - def modversion(pkg) - package_config(pkg).version - end - - def check_version?(pkg, major = 0, minor = 0, micro = 0) - return false unless exist?(pkg) - ver = modversion(pkg).split(".").collect{|item| item.to_i} - (0..2).each {|i| ver[i] = 0 unless ver[i]} - - (ver[0] > major || - (ver[0] == major && ver[1] > minor) || - (ver[0] == major && ver[1] == minor && - ver[2] >= micro)) - end - - def have_package(pkg, major = nil, minor = 0, micro = 0) - if major.nil? - STDOUT.print("checking for #{pkg}... ") - else - STDOUT.print("checking for #{pkg} version (>= #{major}.#{minor}.#{micro})... ") - end - major ||= 0 - STDOUT.flush - if check_version?(pkg, major, minor, micro) - STDOUT.print "yes\n" - libraries = libs_only_l(pkg) - dldflags = libs(pkg) - dldflags = (Shellwords.shellwords(dldflags) - - Shellwords.shellwords(libraries)) - dldflags = dldflags.map {|s| /\s/ =~ s ? "\"#{s}\"" : s }.join(' ') - $libs += ' ' + libraries - if /mswin32/ =~ RUBY_PLATFORM - $DLDFLAGS += ' ' + dldflags - else - $LDFLAGS += ' ' + dldflags - end - $CFLAGS += ' ' + cflags(pkg) - true - else - STDOUT.print "no\n" - false - end - end -end Modified: test/run-test.rb (+3 -1) =================================================================== --- test/run-test.rb 2010-09-11 08:09:39 +0000 (ae9606c) +++ test/run-test.rb 2010-09-11 10:41:36 +0000 (92058da) @@ -7,7 +7,9 @@ lib_dir = File.join(base_dir, "lib") test_dir = File.join(base_dir, "test") if system("which make > /dev/null") - system("cd #{base_dir.dump} && make > /dev/null") or exit(1) + Dir.chdir(base_dir) do + system("make > /dev/null") or exit(1) + end end $LOAD_PATH.unshift(test_unit_dir) Deleted: test/test_pkg_config.rb (+0 -123) 100644 =================================================================== --- test/test_pkg_config.rb 2010-09-11 08:09:39 +0000 (21b9b1f) +++ /dev/null @@ -1,123 +0,0 @@ -require 'pkg-config' - -class PkgConfigTest < Test::Unit::TestCase - def setup - @cairo = PackageConfig.new("cairo") - @cairo_png = PackageConfig.new("cairo-png") - end - - def test_exist? - assert(system('pkg-config --exists cairo')) - assert(@cairo.exist?) - - assert(system('pkg-config --exists cairo-png')) - assert(@cairo_png.exist?) - end - - def test_cflags - assert_pkg_config("cairo", ["--cflags"], @cairo.cflags) - assert_pkg_config("cairo-png", ["--cflags"], @cairo_png.cflags) - end - - def test_cflags_only_I - assert_pkg_config("cairo", ["--cflags-only-I"], @cairo.cflags_only_I) - assert_pkg_config("cairo-png", ["--cflags-only-I"], @cairo_png.cflags_only_I) - end - - def test_libs - assert_pkg_config("cairo", ["--libs"], @cairo.libs) - assert_pkg_config("cairo-png", ["--libs"], @cairo_png.libs) - - @cairo.msvc_syntax = true - result = pkg_config("cairo", "--libs") - msvc_result = result.gsub(/-lcairo\b/, "cairo.lib") - assert_not_equal(msvc_result, result) - assert_equal(msvc_result, @cairo.libs) - end - - def test_libs_only_l - assert_pkg_config("cairo", ["--libs-only-l"], @cairo.libs_only_l) - assert_pkg_config("cairo-png", ["--libs-only-l"], @cairo_png.libs_only_l) - - @cairo_png.msvc_syntax = true - result = pkg_config("cairo-png", "--libs-only-l") - msvc_result = result.gsub(/-l(cairo|png12)\b/, '\1.lib') - assert_not_equal(msvc_result, result) - assert_equal(msvc_result, @cairo_png.libs_only_l) - end - - def test_requires - assert_equal([], @cairo.requires) - end - - def test_requires_private - assert_equal(["freetype2", "fontconfig", "libpng12", - "xcb", "xcb-render", "xcb-renderutil", - "xrender", "x11", "pixman-1"], - @cairo.requires_private) - end - - def test_version - assert_pkg_config("cairo", ["--modversion"], @cairo.version) - end - - def test_parse_override_variables - assert_override_variables({}, nil) - assert_override_variables({"prefix" => "c:\\\\gtk-dev"}, - "prefix=c:\\\\gtk-dev") - assert_override_variables({ - "prefix" => "c:\\\\gtk-dev", - "includdir" => "d:\\\\gtk\\include" - }, - ["prefix=c:\\\\gtk-dev", - "includdir=d:\\\\gtk\\include"].join(",")) - end - - def test_override_variables - overridden_prefix = "c:\\\\gtk-dev" - original_prefix = @cairo.variable("prefix") - assert_not_equal(overridden_prefix, original_prefix) - with_override_variables("prefix=#{overridden_prefix}") do - cairo = PackageConfig.new("cairo") - assert_equal(overridden_prefix, cairo.variable("prefix")) - end - end - - private - def pkg_config(package, *args) - args = args.collect {|arg| arg.dump}.join(' ') - `pkg-config #{args} #{package}`.strip - end - - def assert_pkg_config(package, pkg_config_args, actual) - result = pkg_config(package, *pkg_config_args) - result = nil if result.empty? - assert_equal(result, actual) - end - - def assert_override_variables(expected, override_variables) - with_override_variables(override_variables) do - cairo = PackageConfig.new("cairo") - assert_equal(expected, cairo.instance_variable_get("@override_variables")) - end - end - - def with_override_variables(override_variables) - if override_variables.nil? - args = {} - else - args = {"--with-override-variables" => override_variables} - end - configure_args(args) do - yield - end - end - - def configure_args(args) - original_configure_args = $configure_args - $configure_args = $configure_args.merge(args) - yield - ensure - $configure_args = original_configure_args - end -end From null+rcairo at clear-code.com Sat Sep 11 06:49:35 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 10:49:35 +0000 Subject: [cairo-commit:00044] rcairo/rcairo [master] support cairo_surface_get_device() new in cairo 1.10. Message-ID: <20100911104950.9408F278002@taiyaki.ru> Kouhei Sutou 2010-09-11 10:49:35 +0000 (Sat, 11 Sep 2010) New Revision: b45a38a4256db086d93c621468fe0e806b40281a Log: support cairo_surface_get_device() new in cairo 1.10. Modified files: ext/cairo/rb_cairo_surface.c Modified: ext/cairo/rb_cairo_surface.c (+10 -2) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-11 10:49:06 +0000 (aa18962) +++ ext/cairo/rb_cairo_surface.c 2010-09-11 10:49:35 +0000 (35a5c45) @@ -509,6 +509,12 @@ cr_surface_create_sub_rectangle_surface (VALUE self, VALUE x, VALUE y, else return rb_surface; } + +static VALUE +cr_surface_get_device (VALUE self) +{ + return CRDEVICE2RVAL (cairo_surface_get_device (_SELF)); +} #endif static VALUE @@ -1277,7 +1283,7 @@ cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) rb_scan_args (argc, argv, "22", &arg1, &arg2, &arg3, &arg4); - script = CRDEVICE2RVAL (arg1); + script = RVAL2CRDEVICE (arg1); if (argc == 2) { target = RVAL2CRSURFACE (arg2); @@ -1370,6 +1376,8 @@ Init_cairo_surface (void) #if CAIRO_CHECK_VERSION(1, 10, 0) rb_define_method (rb_cCairo_Surface, "sub_rectangle_surface", cr_surface_create_sub_rectangle_surface, 4); + rb_define_method (rb_cCairo_Surface, "device", + cr_surface_get_device, 0); #endif rb_define_method (rb_cCairo_Surface, "destroy", cr_surface_destroy, 0); rb_define_method (rb_cCairo_Surface, "finish", cr_surface_finish, 0); @@ -1531,7 +1539,7 @@ Init_cairo_surface (void) #ifdef CAIRO_HAS_SCRIPT_SURFACE rb_cCairo_ScriptSurface = - rb_define_class_under (rb_mCairo, "ScriptSurface", rb_cCairo_ScriptSurface); + rb_define_class_under (rb_mCairo, "ScriptSurface", rb_cCairo_Surface); rb_define_method (rb_cCairo_ScriptSurface, "initialize", cr_script_surface_initialize, -1); From null+rcairo at clear-code.com Sat Sep 11 06:50:45 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 10:50:45 +0000 Subject: [cairo-commit:00045] rcairo/rcairo [master] use common inspect function. Message-ID: <20100911113730.E9B79170521@taiyaki.ru> Kouhei Sutou 2010-09-11 10:50:45 +0000 (Sat, 11 Sep 2010) New Revision: cb82fb59b8f665f458363087c7c5e480f40b5454 Log: use common inspect function. Modified files: ext/cairo/rb_cairo_surface.c Modified: ext/cairo/rb_cairo_surface.c (+4 -14) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-11 10:49:35 +0000 (35a5c45) +++ ext/cairo/rb_cairo_surface.c 2010-09-11 10:50:45 +0000 (bfa7a4b) @@ -80,7 +80,6 @@ VALUE rb_cCairo_SubSurface = Qnil; static ID cr_id_target; static ID cr_id_read; static ID cr_id_write; -static ID cr_id_inspect; static ID cr_id_parse; static ID cr_id_size; static ID cr_id_set_unit; @@ -193,14 +192,6 @@ cr_surface_get_klass (cairo_surface_t *surface) return klass; } -static char * -inspect (VALUE object) -{ - VALUE inspected; - inspected = rb_funcall (object, cr_id_inspect, 0); - return StringValueCStr(inspected); -} - /* read/write callback */ typedef struct cr_io_callback_closure { VALUE target; @@ -611,7 +602,7 @@ cr_surface_mark_dirty (int argc, VALUE *argv, VALUE self) rb_raise (rb_eArgError, "invalid argument (expect () or (x, y, width, height)): %s", - inspect (args)); + rb_cairo__inspect (args)); } cr_surface_check_status (_SELF); @@ -775,7 +766,7 @@ cr_image_surface_initialize (int argc, VALUE *argv, VALUE self) "(width, height) or " "(format, width, height) or " "(data, format, width, height, stride)): %s", - inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4))); + rb_cairo__inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4))); cr_surface_check_status (surface); DATA_PTR (self) = surface; @@ -1204,7 +1195,7 @@ cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self) "(width, height), " "(format, width, height) or " "(cg_context, width, height)): %s", - inspect (rb_ary_new3 (3, arg1, arg2, arg3))); + rb_cairo__inspect (rb_ary_new3 (3, arg1, arg2, arg3))); break; } @@ -1310,7 +1301,7 @@ cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) "(script, width, height), " "(script, content, width, height), " "(script, surface)): %s", - inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4))); + rb_cairo__inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4))); break; } @@ -1358,7 +1349,6 @@ Init_cairo_surface (void) cr_id_target = rb_intern ("target"); cr_id_read = rb_intern ("read"); cr_id_write = rb_intern ("write"); - cr_id_inspect = rb_intern ("inspect"); cr_id_parse = rb_intern ("parse"); cr_id_size = rb_intern ("size"); cr_id_set_unit = rb_intern ("unit="); From null+rcairo at clear-code.com Sat Sep 11 07:10:18 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 11:10:18 +0000 Subject: [cairo-commit:00046] rcairo/rcairo [master] split IO functions. Message-ID: <20100911113731.01AC11705CA@taiyaki.ru> Kouhei Sutou 2010-09-11 11:10:18 +0000 (Sat, 11 Sep 2010) New Revision: 3354742c14acbdd9ac135ef79d2d478ab6b3026d Log: split IO functions. Added files: ext/cairo/rb_cairo_io.c ext/cairo/rb_cairo_io.h Modified files: ext/cairo/rb_cairo.c ext/cairo/rb_cairo_private.h ext/cairo/rb_cairo_surface.c Modified: ext/cairo/rb_cairo.c (+1 -0) =================================================================== --- ext/cairo/rb_cairo.c 2010-09-11 10:50:45 +0000 (fbcf87e) +++ ext/cairo/rb_cairo.c 2010-09-11 11:10:18 +0000 (e268f95) @@ -86,6 +86,7 @@ Init_cairo () rb_cCairo_Paper = rb_const_get (rb_mCairo, rb_intern ("Paper")); Init_cairo_private (); + Init_cairo_io (); Init_cairo_constants (); Init_cairo_context (); Added: ext/cairo/rb_cairo_io.c (+164 -0) 100644 =================================================================== --- /dev/null +++ ext/cairo/rb_cairo_io.c 2010-09-11 11:10:18 +0000 (2efcb60) @@ -0,0 +1,164 @@ +/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */ +/* + * Ruby Cairo Binding + * + * Copyright 2005-2010 Kouhei Sutou + * + * This file is made available under the same terms as Ruby + * + */ + +#include "rb_cairo.h" +#include "rb_cairo_private.h" +#include "rb_cairo_io.h" + +ID rb_cairo__io_id_read; +ID rb_cairo__io_id_write; + +/* read/write callback */ +rb_cairo__io_callback_closure_t * +rb_cairo__io_closure_new (VALUE target) +{ + rb_cairo__io_callback_closure_t *closure; + closure = ALLOC (rb_cairo__io_callback_closure_t); + + closure->target = target; + closure->error = Qnil; + + return closure; +} + +void +rb_cairo__io_closure_destroy (rb_cairo__io_callback_closure_t *closure) +{ + xfree (closure); +} + +void +rb_cairo__io_closure_free (void *closure) +{ + rb_cairo__io_closure_destroy ((rb_cairo__io_callback_closure_t *) closure); +} + +static VALUE +rb_cairo__io_func_rescue (VALUE io_closure) +{ + rb_cairo__io_callback_closure_t *closure; + closure = (rb_cairo__io_callback_closure_t *)io_closure; + closure->error = RB_ERRINFO; + return Qnil; +} + +static VALUE +rb_cairo__io_func_invoke (VALUE user_data) +{ + rb_cairo__io_invoke_data_t *data; + + data = (rb_cairo__io_invoke_data_t *)user_data; + return rb_rescue2 (data->func, data->data, + rb_cairo__io_func_rescue, data->data, rb_eException, + (VALUE)0); +} + +/* write callback */ +static VALUE +rb_cairo__io_write_func_invoke (VALUE write_closure) +{ + VALUE output, data; + long written_bytes; + rb_cairo__io_callback_closure_t *closure; + unsigned int length; + + closure = (rb_cairo__io_callback_closure_t *)write_closure; + + output = closure->target; + data = rb_str_new ((const char *)closure->data, closure->length); + + length = RSTRING_LEN (data); + while (length != 0) + { + VALUE rb_written_bytes = rb_funcall (output, + rb_cairo__io_id_write, 1, data); + written_bytes = NUM2LONG (rb_written_bytes); + data = rb_str_substr (data, written_bytes, + RSTRING_LEN (data) - written_bytes); + length -= written_bytes; + } + + return Qnil; +} + +cairo_status_t +rb_cairo__io_write_func (void *write_closure, + const unsigned char *data, unsigned int length) +{ + rb_cairo__io_callback_closure_t *closure; + rb_cairo__io_invoke_data_t invoke_data; + + closure = (rb_cairo__io_callback_closure_t *)write_closure; + closure->data = (unsigned char *)data; + closure->length = length; + + invoke_data.func = rb_cairo__io_write_func_invoke; + invoke_data.data = (VALUE)closure; + rb_cairo__invoke_callback (rb_cairo__io_func_invoke, (VALUE)&invoke_data); + + if (NIL_P (closure->error)) + return CAIRO_STATUS_SUCCESS; + else + return CAIRO_STATUS_WRITE_ERROR; +} + +/* read callback */ +static VALUE +rb_cairo__io_read_func_invoke (VALUE read_closure) +{ + VALUE input, result; + rb_cairo__io_callback_closure_t *closure; + unsigned int length, rest; + + closure = (rb_cairo__io_callback_closure_t *)read_closure; + input = closure->target; + length = closure->length; + + result = rb_str_new2 (""); + + for (rest = length; rest != 0; rest = length - RSTRING_LEN (result)) + { + rb_str_concat (result, + rb_funcall (input, + rb_cairo__io_id_read, 1, INT2NUM (rest))); + } + + memcpy ((void *)closure->data, (const void *)StringValuePtr (result), length); + + return Qnil; +} + +cairo_status_t +rb_cairo__io_read_func (void *read_closure, + unsigned char *data, unsigned int length) +{ + rb_cairo__io_callback_closure_t *closure; + rb_cairo__io_invoke_data_t invoke_data; + + closure = (rb_cairo__io_callback_closure_t *)read_closure; + closure->data = data; + closure->length = length; + + invoke_data.func = rb_cairo__io_read_func_invoke; + invoke_data.data = (VALUE)closure; + rb_cairo__invoke_callback (rb_cairo__io_func_invoke, (VALUE)&invoke_data); + + if (NIL_P (closure->error)) + return CAIRO_STATUS_SUCCESS; + else + return CAIRO_STATUS_READ_ERROR; +} + +void +Init_cairo_io (void) +{ + rb_cairo__io_id_read = rb_intern ("read"); + rb_cairo__io_id_write = rb_intern ("write"); +} Added: ext/cairo/rb_cairo_io.h (+43 -0) 100644 =================================================================== --- /dev/null +++ ext/cairo/rb_cairo_io.h 2010-09-11 11:10:18 +0000 (5b44c34) @@ -0,0 +1,43 @@ +/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */ +/* + * Ruby Cairo Binding + * + * Copyright 2005-2010 Kouhei Sutou + * + * This file is made available under the same terms as Ruby + * +*/ + +#ifndef RB_CAIRO_IO_H +#define RB_CAIRO_IO_H + +#include + +typedef struct rb_cairo__io_callback_closure { + VALUE target; + VALUE error; + unsigned char *data; + unsigned int length; +} rb_cairo__io_callback_closure_t; + +typedef struct rb_cairo__io_invoke_data { + cr_callback_func_t func; + VALUE data; +} rb_cairo__io_invoke_data_t; + +RB_CAIRO_VAR ID rb_cairo__io_id_read; +RB_CAIRO_VAR ID rb_cairo__io_id_write; + +rb_cairo__io_callback_closure_t * + rb_cairo__io_closure_new (VALUE target); +void rb_cairo__io_closure_destroy (rb_cairo__io_callback_closure_t *closure); +void rb_cairo__io_closure_free (void *closure); +cairo_status_t rb_cairo__io_write_func (void *write_closure, + const unsigned char *data, + unsigned int length); +cairo_status_t rb_cairo__io_read_func (void *read_closure, + unsigned char *data, + unsigned int length); + + +#endif Modified: ext/cairo/rb_cairo_private.h (+1 -0) =================================================================== --- ext/cairo/rb_cairo_private.h 2010-09-11 10:50:45 +0000 (4c0d304) +++ ext/cairo/rb_cairo_private.h 2010-09-11 11:10:18 +0000 (25938f4) @@ -44,6 +44,7 @@ #endif extern void Init_cairo_private (void); +extern void Init_cairo_io (void); extern void Init_cairo_constants (void); extern void Init_cairo_context (void); Modified: ext/cairo/rb_cairo_surface.c (+17 -178) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-11 10:50:45 +0000 (bfa7a4b) +++ ext/cairo/rb_cairo_surface.c 2010-09-11 11:10:18 +0000 (7631b0b) @@ -15,6 +15,7 @@ #include "rb_cairo.h" #include "rb_cairo_private.h" +#include "rb_cairo_io.h" #ifdef HAVE_RUBY_ST_H # include @@ -45,14 +46,6 @@ enum ruby_value_type { # define T_DATA RUBY_T_DATA #endif -#if defined(CAIRO_HAS_PS_SURFACE) || \ - defined(CAIRO_HAS_PDF_SURFACE) || \ - defined(CAIRO_HAS_SVG_SURFACE) -# define HAS_CREATE_CR_CLOSURE_SURFACE 1 -#else -# define HAS_CREATE_CR_CLOSURE_SURFACE 0 -#endif - #ifdef CAIRO_HAS_SCRIPT_SURFACE # include #endif @@ -78,8 +71,6 @@ VALUE rb_cCairo_SkiaSurface = Qnil; VALUE rb_cCairo_SubSurface = Qnil; static ID cr_id_target; -static ID cr_id_read; -static ID cr_id_write; static ID cr_id_parse; static ID cr_id_size; static ID cr_id_set_unit; @@ -192,158 +183,6 @@ cr_surface_get_klass (cairo_surface_t *surface) return klass; } -/* read/write callback */ -typedef struct cr_io_callback_closure { - VALUE target; - VALUE error; - unsigned char *data; - unsigned int length; -} cr_io_callback_closure_t; - -typedef struct cr_invoke_data { - cr_callback_func_t func; - VALUE data; -} cr_invoke_data_t; - -#if HAS_CREATE_CR_CLOSURE_SURFACE -static cr_io_callback_closure_t * -cr_closure_new (VALUE target) -{ - cr_io_callback_closure_t *closure; - closure = ALLOC (cr_io_callback_closure_t); - - closure->target = target; - closure->error = Qnil; - - return closure; -} - -static void -cr_closure_destroy (cr_io_callback_closure_t *closure) -{ - xfree (closure); -} - -static void -cr_closure_free (void *closure) -{ - cr_closure_destroy ((cr_io_callback_closure_t *) closure); -} -#endif - -static VALUE -cr_surface_io_func_rescue (VALUE io_closure) -{ - cr_io_callback_closure_t *closure; - closure = (cr_io_callback_closure_t *)io_closure; - closure->error = RB_ERRINFO; - return Qnil; -} - -static VALUE -cr_surface_invoke_io_func (VALUE user_data) -{ - cr_invoke_data_t *data; - - data = (cr_invoke_data_t *)user_data; - return rb_rescue2 (data->func, data->data, - cr_surface_io_func_rescue, data->data, rb_eException, - (VALUE)0); -} - -/* write callback */ -static VALUE -cr_surface_write_func_invoke (VALUE write_closure) -{ - VALUE output, data; - long written_bytes; - cr_io_callback_closure_t *closure; - unsigned int length; - - closure = (cr_io_callback_closure_t *)write_closure; - - output = closure->target; - data = rb_str_new ((const char *)closure->data, closure->length); - - length = RSTRING_LEN (data); - while (length != 0) - { - VALUE rb_written_bytes = rb_funcall (output, cr_id_write, 1, data); - written_bytes = NUM2LONG (rb_written_bytes); - data = rb_str_substr (data, written_bytes, - RSTRING_LEN (data) - written_bytes); - length -= written_bytes; - } - - return Qnil; -} - -static cairo_status_t -cr_surface_write_func (void *write_closure, - const unsigned char *data, unsigned int length) -{ - cr_io_callback_closure_t *closure; - cr_invoke_data_t invoke_data; - - closure = (cr_io_callback_closure_t *)write_closure; - closure->data = (unsigned char *)data; - closure->length = length; - - invoke_data.func = cr_surface_write_func_invoke; - invoke_data.data = (VALUE)closure; - rb_cairo__invoke_callback (cr_surface_invoke_io_func, (VALUE)&invoke_data); - - if (NIL_P (closure->error)) - return CAIRO_STATUS_SUCCESS; - else - return CAIRO_STATUS_WRITE_ERROR; -} - -/* read callback */ -static VALUE -cr_surface_read_func_invoke (VALUE read_closure) -{ - VALUE input, result; - cr_io_callback_closure_t *closure; - unsigned int length, rest; - - closure = (cr_io_callback_closure_t *)read_closure; - input = closure->target; - length = closure->length; - - result = rb_str_new2 (""); - - for (rest = length; rest != 0; rest = length - RSTRING_LEN (result)) - { - rb_str_concat (result, rb_funcall (input, cr_id_read, 1, INT2NUM (rest))); - } - - memcpy ((void *)closure->data, (const void *)StringValuePtr (result), length); - - return Qnil; -} - -static cairo_status_t -cr_surface_read_func (void *read_closure, - unsigned char *data, unsigned int length) -{ - cr_io_callback_closure_t *closure; - cr_invoke_data_t invoke_data; - - closure = (cr_io_callback_closure_t *)read_closure; - closure->data = data; - closure->length = length; - - invoke_data.func = cr_surface_read_func_invoke; - invoke_data.data = (VALUE)closure; - rb_cairo__invoke_callback (cr_surface_invoke_io_func, (VALUE)&invoke_data); - - if (NIL_P (closure->error)) - return CAIRO_STATUS_SUCCESS; - else - return CAIRO_STATUS_READ_ERROR; -} - /* constructor/de-constructor */ cairo_surface_t * rb_cairo_surface_from_ruby_object (VALUE obj) @@ -431,7 +270,7 @@ static VALUE cr_surface_finish (VALUE self) { cairo_surface_t *surface; - cr_io_callback_closure_t *closure; + rb_cairo__io_callback_closure_t *closure; surface = _SELF; closure = cairo_surface_get_user_data (surface, &cr_closure_key); @@ -520,12 +359,13 @@ static VALUE cr_surface_write_to_png_stream (VALUE self, VALUE target) { cairo_status_t status; - cr_io_callback_closure_t closure; + rb_cairo__io_callback_closure_t closure; closure.target = target; closure.error = Qnil; - status = cairo_surface_write_to_png_stream (_SELF, cr_surface_write_func, + status = cairo_surface_write_to_png_stream (_SELF, + rb_cairo__io_write_func, (void *)&closure); if (!NIL_P (closure.error)) rb_exc_raise (closure.error); @@ -546,7 +386,7 @@ cr_surface_write_to_png (VALUE self, VALUE filename) static VALUE cr_surface_write_to_png_generic (VALUE self, VALUE target) { - if (rb_respond_to (target, cr_id_write)) + if (rb_respond_to (target, rb_cairo__io_id_write)) return cr_surface_write_to_png_stream (self, target); else return cr_surface_write_to_png (self, target); @@ -681,17 +521,17 @@ cr_surface_show_page (VALUE self) static cairo_surface_t * cr_image_surface_create_from_png_stream (VALUE target) { - cr_io_callback_closure_t closure; + rb_cairo__io_callback_closure_t closure; cairo_surface_t *surface; closure.target = target; closure.error = Qnil; - surface = cairo_image_surface_create_from_png_stream (cr_surface_read_func, + surface = cairo_image_surface_create_from_png_stream (rb_cairo__io_read_func, (void *)&closure); if (!NIL_P (closure.error)) rb_exc_raise (closure.error); - + return surface; } @@ -707,7 +547,7 @@ cr_image_surface_create_from_png_generic (VALUE klass, VALUE target) VALUE rb_surface; cairo_surface_t *surface; - if (rb_respond_to (target, cr_id_read)) + if (rb_respond_to (target, rb_cairo__io_id_read)) surface = cr_image_surface_create_from_png_stream (target); else surface = cr_image_surface_create_from_png (target); @@ -846,27 +686,28 @@ cr_ ## type ## _surface_initialize (int argc, VALUE *argv, VALUE self) \ width_in_points = NUM2DBL (rb_width_in_points); \ height_in_points = NUM2DBL (rb_height_in_points); \ \ - if (rb_respond_to (target, cr_id_write)) \ + if (rb_respond_to (target, rb_cairo__io_id_write)) \ { \ - cr_io_callback_closure_t *closure; \ + rb_cairo__io_callback_closure_t *closure; \ \ - closure = cr_closure_new (target); \ + closure = rb_cairo__io_closure_new (target); \ surface = \ cairo_ ## type ## _surface_create_for_stream ( \ - cr_surface_write_func, \ + rb_cairo__io_write_func, \ (void *) closure, \ width_in_points, \ height_in_points); \ \ if (cairo_surface_status (surface)) \ { \ - cr_closure_destroy (closure); \ + rb_cairo__io_closure_destroy (closure); \ } \ else \ { \ rb_ivar_set (self, cr_id_target, target); \ cairo_surface_set_user_data (surface, &cr_closure_key, \ - closure, cr_closure_free); \ + closure, \ + rb_cairo__io_closure_free); \ cairo_surface_set_user_data (surface, &cr_object_holder_key, \ cr_object_holder_new(self), \ cr_object_holder_free); \ @@ -1347,8 +1188,6 @@ void Init_cairo_surface (void) { cr_id_target = rb_intern ("target"); - cr_id_read = rb_intern ("read"); - cr_id_write = rb_intern ("write"); cr_id_parse = rb_intern ("parse"); cr_id_size = rb_intern ("size"); cr_id_set_unit = rb_intern ("unit="); From null+rcairo at clear-code.com Sat Sep 11 07:37:11 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 11:37:11 +0000 Subject: [cairo-commit:00047] rcairo/rcairo [master] start supporting ScriptDevice. Message-ID: <20100911113731.0E762170F52@taiyaki.ru> Kouhei Sutou 2010-09-11 11:37:11 +0000 (Sat, 11 Sep 2010) New Revision: 5ea65ffa56546c55efd8c3c6cef3521cb99b3e04 Log: start supporting ScriptDevice. Added files: test/test_device.rb Modified files: ext/cairo/rb_cairo_device.c ext/cairo/rb_cairo_io.c ext/cairo/rb_cairo_io.h ext/cairo/rb_cairo_surface.c Modified: ext/cairo/rb_cairo_device.c (+71 -6) =================================================================== --- ext/cairo/rb_cairo_device.c 2010-09-11 11:10:18 +0000 (23cf96e) +++ ext/cairo/rb_cairo_device.c 2010-09-11 11:37:11 +0000 (46205d1) @@ -10,6 +10,7 @@ #include "rb_cairo.h" #include "rb_cairo_private.h" +#include "rb_cairo_io.h" #ifdef HAVE_RUBY_ST_H # include @@ -167,17 +168,17 @@ static VALUE cr_device_finish (VALUE self) { cairo_device_t *device; - /* cr_io_callback_closure_t *closure; */ + rb_cairo__io_callback_closure_t *closure; device = _SELF; - /* closure = cairo_device_get_user_data (device, &cr_closure_key); */ + closure = cairo_device_get_user_data (device, &cr_closure_key); cairo_device_finish (device); cairo_device_set_user_data (device, &cr_finished_key, (void *)CR_TRUE, NULL); cairo_device_set_user_data (device, &cr_object_holder_key, NULL, NULL); - /* if (closure && !NIL_P (closure->error)) */ - /* rb_exc_raise (closure->error); */ + if (closure && !NIL_P (closure->error)) + rb_exc_raise (closure->error); cr_device_check_status (device); return self; @@ -209,7 +210,6 @@ cr_device_acquire (VALUE self) else return self; } -#endif static int cr_finish_all_guarded_devices_at_end_iter (VALUE key, VALUE value, VALUE data) @@ -226,10 +226,64 @@ cr_finish_all_guarded_devices_at_end (VALUE data) Qnil); } +static void +yield_and_finish (VALUE self) +{ + cairo_device_t *device; + + rb_yield (self); + + device = _SELF; + if (!cairo_device_get_user_data (device, &cr_finished_key)) + cr_device_finish (self); +} + +# ifdef CAIRO_HAS_SCRIPT_SURFACE +static VALUE +cr_script_device_initialize (VALUE self, VALUE file_name_or_output) +{ + cairo_device_t *device; + + if (rb_respond_to (file_name_or_output, rb_cairo__io_id_write)) + { + rb_cairo__io_callback_closure_t *closure; + + closure = rb_cairo__io_closure_new (file_name_or_output); + device = cairo_script_create_for_stream (rb_cairo__io_write_func, + (void *)closure); + if (cairo_device_status (device)) + { + rb_cairo__io_closure_destroy (closure); + } + else + { + cairo_device_set_user_data (device, &cr_closure_key, + closure, rb_cairo__io_closure_free); + cairo_device_set_user_data (device, &cr_object_holder_key, + cr_object_holder_new (self), + cr_object_holder_free); + } + } + else + { + device = cairo_script_create (StringValueCStr (file_name_or_output)); + } + + cr_device_check_status (device); + DATA_PTR (self) = device; + if (rb_block_given_p ()) + yield_and_finish (self); + return Qnil; +} + +# endif + +#endif + void Init_cairo_device (void) { -#ifdef CAIRO_CHECK_VERSION(1, 10, 0) +#if CAIRO_CHECK_VERSION(1, 10, 0) rb_cCairo_Device = rb_define_class_under (rb_mCairo, "Device", rb_cObject); rb_define_alloc_func (rb_cCairo_Device, cr_device_allocate); @@ -245,5 +299,16 @@ Init_cairo_device (void) rb_define_method (rb_cCairo_Device, "release", cr_device_release, 0); RB_CAIRO_DEF_SETTERS (rb_cCairo_Device); + +# ifdef CAIRO_HAS_SCRIPT_SURFACE + rb_cCairo_ScriptDevice = + rb_define_class_under (rb_mCairo, "ScriptDevice", rb_cCairo_Device); + + rb_define_method (rb_cCairo_ScriptDevice, "initialize", + cr_script_device_initialize, 1); + + RB_CAIRO_DEF_SETTERS (rb_cCairo_ScriptDevice); +# endif + #endif } Modified: ext/cairo/rb_cairo_io.c (+2 -0) =================================================================== --- ext/cairo/rb_cairo_io.c 2010-09-11 11:10:18 +0000 (2efcb60) +++ ext/cairo/rb_cairo_io.c 2010-09-11 11:37:11 +0000 (31c905e) @@ -14,6 +14,7 @@ ID rb_cairo__io_id_read; ID rb_cairo__io_id_write; +ID rb_cairo__io_id_output; /* read/write callback */ rb_cairo__io_callback_closure_t * @@ -161,4 +162,5 @@ Init_cairo_io (void) { rb_cairo__io_id_read = rb_intern ("read"); rb_cairo__io_id_write = rb_intern ("write"); + rb_cairo__io_id_output = rb_intern ("output"); } Modified: ext/cairo/rb_cairo_io.h (+1 -0) =================================================================== --- ext/cairo/rb_cairo_io.h 2010-09-11 11:10:18 +0000 (5b44c34) +++ ext/cairo/rb_cairo_io.h 2010-09-11 11:37:11 +0000 (e5df784) @@ -27,6 +27,7 @@ typedef struct rb_cairo__io_invoke_data { RB_CAIRO_VAR ID rb_cairo__io_id_read; RB_CAIRO_VAR ID rb_cairo__io_id_write; +RB_CAIRO_VAR ID rb_cairo__io_id_output; rb_cairo__io_callback_closure_t * rb_cairo__io_closure_new (VALUE target); Modified: ext/cairo/rb_cairo_surface.c (+2 -4) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-11 11:10:18 +0000 (7631b0b) +++ ext/cairo/rb_cairo_surface.c 2010-09-11 11:37:11 +0000 (e3fdba0) @@ -70,7 +70,6 @@ VALUE rb_cCairo_XMLSurface = Qnil; VALUE rb_cCairo_SkiaSurface = Qnil; VALUE rb_cCairo_SubSurface = Qnil; -static ID cr_id_target; static ID cr_id_parse; static ID cr_id_size; static ID cr_id_set_unit; @@ -704,12 +703,12 @@ cr_ ## type ## _surface_initialize (int argc, VALUE *argv, VALUE self) \ } \ else \ { \ - rb_ivar_set (self, cr_id_target, target); \ + rb_ivar_set (self, rb_cairo__io_id_output, target); \ cairo_surface_set_user_data (surface, &cr_closure_key, \ closure, \ rb_cairo__io_closure_free); \ cairo_surface_set_user_data (surface, &cr_object_holder_key, \ - cr_object_holder_new(self), \ + cr_object_holder_new (self), \ cr_object_holder_free); \ } \ } \ @@ -1187,7 +1186,6 @@ cr_finish_all_guarded_surfaces_at_end (VALUE data) void Init_cairo_surface (void) { - cr_id_target = rb_intern ("target"); cr_id_parse = rb_intern ("parse"); cr_id_size = rb_intern ("size"); cr_id_set_unit = rb_intern ("unit="); Added: test/test_device.rb (+23 -0) 100644 =================================================================== --- /dev/null +++ test/test_device.rb 2010-09-11 11:37:11 +0000 (92d6b4f) @@ -0,0 +1,23 @@ +require 'cairo' +require 'stringio' + +class DeviceTest < Test::Unit::TestCase + include CairoTestUtils + + def test_new + output = StringIO.new + device = Cairo::ScriptDevice.new(output) + assert_equal("%!CairoScript\n", output.string) + device.finish + assert_equal("%!CairoScript\n", output.string) + end + + def test_new_with_block + output = StringIO.new + string = nil + Cairo::ScriptDevice.new(output) do |device| + string = output.string + end + assert_equal("%!CairoScript\n", string) + end +end From null+rcairo at clear-code.com Sat Sep 11 07:46:27 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 11:46:27 +0000 Subject: [cairo-commit:00048] rcairo/rcairo [master] add a test for Surface#device. Message-ID: <20100911114637.0EF0F1705CA@taiyaki.ru> Kouhei Sutou 2010-09-11 11:46:27 +0000 (Sat, 11 Sep 2010) New Revision: 530afab63e02574ce0dab879fc2ab8f4f57ce9a8 Log: add a test for Surface#device. Modified files: test/test_surface.rb Modified: test/test_surface.rb (+8 -0) =================================================================== --- test/test_surface.rb 2010-09-11 11:44:52 +0000 (94bffe2) +++ test/test_surface.rb 2010-09-11 11:46:27 +0000 (4862bf4) @@ -38,4 +38,12 @@ class SurfaceTest < Test::Unit::TestCase surface.set_fallback_resolution(95, 95) assert_equal([95.0, 95.0], surface.fallback_resolution) end + + def test_device + only_device("Script") + + device = Cairo::ScriptDevice.new(StringIO.new) + surface = Cairo::ScriptSurface.new(device, 100, 100) + assert_equal(Cairo::ScriptDevice, surface.device.class) + end end From null+rcairo at clear-code.com Sat Sep 11 07:44:52 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 11:44:52 +0000 Subject: [cairo-commit:00049] rcairo/rcairo [master] support cairo_script_write_comment() new in cairo 1.10. Message-ID: <20100911114637.05880170521@taiyaki.ru> Kouhei Sutou 2010-09-11 11:44:52 +0000 (Sat, 11 Sep 2010) New Revision: c679692893bd5a718af6c3ebb7fa37af9af494f5 Log: support cairo_script_write_comment() new in cairo 1.10. Added files: test/test_script_device.rb Removed files: test/test_device.rb Modified files: ext/cairo/rb_cairo_device.c test/cairo-test-utils.rb Modified: ext/cairo/rb_cairo_device.c (+15 -0) =================================================================== --- ext/cairo/rb_cairo_device.c 2010-09-11 11:37:11 +0000 (46205d1) +++ ext/cairo/rb_cairo_device.c 2010-09-11 11:44:52 +0000 (db1b244) @@ -276,6 +276,18 @@ cr_script_device_initialize (VALUE self, VALUE file_name_or_output) return Qnil; } +static VALUE +cr_script_device_write_comment (VALUE self, VALUE comment) +{ + cairo_device_t *device; + + device = _SELF; + cairo_script_write_comment (device, + StringValuePtr (comment), + RSTRING_LEN (comment)); + cr_device_check_status (device); + return Qnil; +} # endif #endif @@ -307,6 +319,9 @@ Init_cairo_device (void) rb_define_method (rb_cCairo_ScriptDevice, "initialize", cr_script_device_initialize, 1); + rb_define_method (rb_cCairo_ScriptDevice, "write_comment", + cr_script_device_write_comment, 1); + RB_CAIRO_DEF_SETTERS (rb_cCairo_ScriptDevice); # endif Modified: test/cairo-test-utils.rb (+7 -0) =================================================================== --- test/cairo-test-utils.rb 2010-09-11 11:37:11 +0000 (659a621) +++ test/cairo-test-utils.rb 2010-09-11 11:44:52 +0000 (cc446f8) @@ -15,4 +15,11 @@ module CairoTestUtils def win32? /cygwin|mingw|mswin32|bccwin32/.match(RUBY_PLATFORM) ? true : false end + + def only_device(name) + device_class = "#{name}Device" + unless Cairo.const_defined?(device_class) + omit("Only for #{device_class} device available") + end + end end Deleted: test/test_device.rb (+0 -23) 100644 =================================================================== --- test/test_device.rb 2010-09-11 11:37:11 +0000 (92d6b4f) +++ /dev/null @@ -1,23 +0,0 @@ -require 'cairo' -require 'stringio' - -class DeviceTest < Test::Unit::TestCase - include CairoTestUtils - - def test_new - output = StringIO.new - device = Cairo::ScriptDevice.new(output) - assert_equal("%!CairoScript\n", output.string) - device.finish - assert_equal("%!CairoScript\n", output.string) - end - - def test_new_with_block - output = StringIO.new - string = nil - Cairo::ScriptDevice.new(output) do |device| - string = output.string - end - assert_equal("%!CairoScript\n", string) - end -end Added: test/test_script_device.rb (+37 -0) 100644 =================================================================== --- /dev/null +++ test/test_script_device.rb 2010-09-11 11:44:52 +0000 (bd78669) @@ -0,0 +1,37 @@ +require 'cairo' +require 'stringio' + +class ScriptDeviceTest < Test::Unit::TestCase + include CairoTestUtils + + def setup + only_device("Script") + end + + def test_new + output = StringIO.new + device = Cairo::ScriptDevice.new(output) + assert_equal("%!CairoScript\n", output.string) + device.finish + assert_equal("%!CairoScript\n", output.string) + end + + def test_new_with_block + output = StringIO.new + string = nil + Cairo::ScriptDevice.new(output) do |device| + string = output.string + end + assert_equal("%!CairoScript\n", string) + end + + def test_write_comment + output = StringIO.new + Cairo::ScriptDevice.new(output) do |device| + device.write_comment("Hello!") + end + assert_equal("%!CairoScript\n" + + "% Hello!\n", + output.string) + end +end From null+rcairo at clear-code.com Sat Sep 11 07:53:14 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 11:53:14 +0000 Subject: [cairo-commit:00050] rcairo/rcairo [master] support cairo_script_mode_t new in cairo 1.10. Message-ID: <20100911115323.34ED6170521@taiyaki.ru> Kouhei Sutou 2010-09-11 11:53:14 +0000 (Sat, 11 Sep 2010) New Revision: d631854edf5839cb2b3df7863f4aeb9c137feaf5 Log: support cairo_script_mode_t new in cairo 1.10. Modified files: ext/cairo/cairo.def ext/cairo/rb_cairo.h ext/cairo/rb_cairo_constants.c ext/cairo/rb_cairo_device.c ext/cairo/rb_cairo_surface.c Modified: ext/cairo/cairo.def (+2 -1) =================================================================== --- ext/cairo/cairo.def 2010-09-11 11:46:27 +0000 (dfcbcb0) +++ ext/cairo/cairo.def 2010-09-11 11:53:14 +0000 (bfd20d6) @@ -70,7 +70,8 @@ EXPORTS rb_mCairo_SVGVersion DATA rb_mCairo_PSLevel DATA rb_mCairo_PDFVersion DATA - rb_mCairo_LCDFilter DATA + rb_cCairo_TextClusterFlag DATA + rb_cCairo_ScriptMode DATA rb_mCairo_Color DATA rb_cCairo_Color_Base DATA Modified: ext/cairo/rb_cairo.h (+12 -1) =================================================================== --- ext/cairo/rb_cairo.h 2010-09-11 11:46:27 +0000 (aac6d0e) +++ ext/cairo/rb_cairo.h 2010-09-11 11:53:14 +0000 (667b2d3) @@ -31,6 +31,10 @@ # include #endif +#ifdef CAIRO_HAS_SCRIPT_SURFACE +# include +#endif + #define CAIRO_CHECK_VERSION(major, minor, micro) \ (CAIRO_VERSION_MAJOR > (major) || \ (CAIRO_VERSION_MAJOR == (major) && CAIRO_VERSION_MINOR > (minor)) || \ @@ -142,8 +146,9 @@ RB_CAIRO_VAR VALUE rb_mCairo_Filter; RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion; RB_CAIRO_VAR VALUE rb_mCairo_PSLevel; RB_CAIRO_VAR VALUE rb_mCairo_PDFVersion; -RB_CAIRO_VAR VALUE rb_mCairo_LCDFilter; RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion; +RB_CAIRO_VAR VALUE rb_mCairo_TextClusterFlag; +RB_CAIRO_VAR VALUE rb_mCairo_ScriptMode; RB_CAIRO_VAR VALUE rb_mCairo_Color; RB_CAIRO_VAR VALUE rb_cCairo_Color_Base; RB_CAIRO_VAR VALUE rb_cCairo_Paper; @@ -266,6 +271,9 @@ VALUE rb_cairo_device_to_ruby_object (cairo_device_t *de #if CAIRO_CHECK_VERSION(1, 7, 6) #define RVAL2CRTEXTCLUSTERFLAGS(obj) (rb_cairo_text_cluster_flags_from_ruby_object(obj)) #endif +#ifdef CAIRO_HAS_SCRIPT_SURFACE +#define RVAL2CRSCRIPTMODE(obj) (rb_cairo_script_mode_from_ruby_object(obj)) +#endif cairo_operator_t rb_cairo_operator_from_ruby_object (VALUE obj); cairo_antialias_t rb_cairo_antialias_from_ruby_object (VALUE obj); @@ -298,6 +306,9 @@ cairo_pdf_version_t rb_cairo_pdf_version_from_ruby_object (VALUE obj); #if CAIRO_CHECK_VERSION(1, 7, 6) cairo_text_cluster_flags_t rb_cairo_text_cluster_flags_from_ruby_object (VALUE obj); #endif +#ifdef CAIRO_HAS_SCRIPT_SURFACE +cairo_script_mode_t rb_cairo_script_mode_from_ruby_object (VALUE obj); +#endif void rb_cairo_check_status (cairo_status_t status); Modified: ext/cairo/rb_cairo_constants.c (+17 -0) =================================================================== --- ext/cairo/rb_cairo_constants.c 2010-09-11 11:46:27 +0000 (093ca44) +++ ext/cairo/rb_cairo_constants.c 2010-09-11 11:53:14 +0000 (1e3c78c) @@ -35,6 +35,7 @@ VALUE rb_mCairo_SVGVersion = Qnil; VALUE rb_mCairo_PSLevel = Qnil; VALUE rb_mCairo_TextClusterFlag = Qnil; VALUE rb_mCairo_PDFVersion = Qnil; +VALUE rb_mCairo_ScriptMode = Qnil; #define CAIRO_OPERATOR_MIN CAIRO_OPERATOR_CLEAR #define CAIRO_OPERATOR_MAX CAIRO_OPERATOR_SATURATE @@ -93,6 +94,9 @@ VALUE rb_mCairo_PDFVersion = Qnil; #define CAIRO_TEXT_CLUSTER_FLAG_MIN 0 #define CAIRO_TEXT_CLUSTER_FLAG_MAX CAIRO_TEXT_CLUSTER_FLAG_BACKWARD +#define CAIRO_SCRIPT_MODE_MIN CAIRO_SCRIPT_MODE_BINARY +#define CAIRO_SCRIPT_MODE_MAX CAIRO_SCRIPT_MODE_ASCII + #define DEFINE_RVAL2ENUM(name, const_name) \ cairo_ ## name ## _t \ rb_cairo_ ## name ## _from_ruby_object (VALUE rb_ ## name) \ @@ -153,6 +157,10 @@ DEFINE_RVAL2ENUM(pdf_version, PDF_VERSION) DEFINE_RVAL2ENUM(text_cluster_flags, TEXT_CLUSTER_FLAG) #endif +#ifdef CAIRO_HAS_SCRIPT_SURFACE +DEFINE_RVAL2ENUM(script_mode, SCRIPT_MODE) +#endif + #if defined(RB_CAIRO_PLATFORM_WIN32) && !defined(PS_LEVEL_ENUM_DEFINED) void rb_cairo_ps_level_from_ruby_object (VALUE rb_ps_level) @@ -570,4 +578,13 @@ Init_cairo_constants (void) rb_define_const (rb_mCairo_TextClusterFlag, "BACKWARD", INT2FIX (CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)); #endif + +#ifdef CAIRO_HAS_SCRIPT_SURFACE + /* cairo_script_mode_t */ + rb_mCairo_ScriptMode = rb_define_module_under (rb_mCairo, "ScriptMode"); + rb_define_const (rb_mCairo_ScriptMode, "BINARY", + INT2FIX (CAIRO_SCRIPT_MODE_BINARY)); + rb_define_const (rb_mCairo_ScriptMode, "ASCII", + INT2FIX (CAIRO_SCRIPT_MODE_ASCII)); +#endif } Modified: ext/cairo/rb_cairo_device.c (+0 -4) =================================================================== --- ext/cairo/rb_cairo_device.c 2010-09-11 11:46:27 +0000 (db1b244) +++ ext/cairo/rb_cairo_device.c 2010-09-11 11:53:14 +0000 (79ae24a) @@ -18,10 +18,6 @@ # include #endif -#ifdef CAIRO_HAS_SCRIPT_SURFACE -# include -#endif - VALUE rb_cCairo_Device = Qnil; VALUE rb_cCairo_DRMDevice = Qnil; VALUE rb_cCairo_GLDevice = Qnil; Modified: ext/cairo/rb_cairo_surface.c (+0 -4) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-11 11:46:27 +0000 (e3fdba0) +++ ext/cairo/rb_cairo_surface.c 2010-09-11 11:53:14 +0000 (25be19c) @@ -46,10 +46,6 @@ enum ruby_value_type { # define T_DATA RUBY_T_DATA #endif -#ifdef CAIRO_HAS_SCRIPT_SURFACE -# include -#endif - VALUE rb_cCairo_Surface; VALUE rb_cCairo_ImageSurface; VALUE rb_cCairo_PDFSurface = Qnil; From null+rcairo at clear-code.com Sat Sep 11 07:56:17 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 11:56:17 +0000 Subject: [cairo-commit:00051] rcairo/rcairo [master] support cairo_script_mode_t accessor new in cairo 1.10. Message-ID: <20100911115640.12883170521@taiyaki.ru> Kouhei Sutou 2010-09-11 11:56:17 +0000 (Sat, 11 Sep 2010) New Revision: f179ddad59046a9e293d773d3053da1df818e038 Log: support cairo_script_mode_t accessor new in cairo 1.10. Modified files: ext/cairo/rb_cairo_device.c test/test_script_device.rb Modified: ext/cairo/rb_cairo_device.c (+22 -0) =================================================================== --- ext/cairo/rb_cairo_device.c 2010-09-11 11:53:14 +0000 (79ae24a) +++ ext/cairo/rb_cairo_device.c 2010-09-11 11:56:17 +0000 (05c8aec) @@ -284,6 +284,23 @@ cr_script_device_write_comment (VALUE self, VALUE comment) cr_device_check_status (device); return Qnil; } + +static VALUE +cr_script_device_set_mode (VALUE self, VALUE mode) +{ + cairo_device_t *device; + + device = _SELF; + cairo_script_set_mode (device, RVAL2CRSCRIPTMODE (mode)); + cr_device_check_status (device); + return Qnil; +} + +static VALUE +cr_script_device_get_mode (VALUE self) +{ + return INT2NUM (cairo_script_get_mode (_SELF)); +} # endif #endif @@ -318,6 +335,11 @@ Init_cairo_device (void) rb_define_method (rb_cCairo_ScriptDevice, "write_comment", cr_script_device_write_comment, 1); + rb_define_method (rb_cCairo_ScriptDevice, "set_mode", + cr_script_device_set_mode, 1); + rb_define_method (rb_cCairo_ScriptDevice, "mode", + cr_script_device_get_mode, 0); + RB_CAIRO_DEF_SETTERS (rb_cCairo_ScriptDevice); # endif Modified: test/test_script_device.rb (+9 -0) =================================================================== --- test/test_script_device.rb 2010-09-11 11:53:14 +0000 (bd78669) +++ test/test_script_device.rb 2010-09-11 11:56:17 +0000 (086f867) @@ -34,4 +34,13 @@ class ScriptDeviceTest < Test::Unit::TestCase "% Hello!\n", output.string) end + + def test_mode + output = StringIO.new + Cairo::ScriptDevice.new(output) do |device| + assert_equal(Cairo::ScriptMode::ASCII, device.mode) + device.mode = Cairo::ScriptMode::BINARY + assert_equal(Cairo::ScriptMode::BINARY, device.mode) + end + end end From null+rcairo at clear-code.com Sat Sep 11 08:06:05 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 12:06:05 +0000 Subject: [cairo-commit:00052] rcairo/rcairo [master] support cairo_script_from_recording_surface() new in cairo 1.10. Message-ID: <20100911120615.72465170521@taiyaki.ru> Kouhei Sutou 2010-09-11 12:06:05 +0000 (Sat, 11 Sep 2010) New Revision: 85f8a093d8d731505bc12329c3c043f18c48670a Log: support cairo_script_from_recording_surface() new in cairo 1.10. Modified files: ext/cairo/rb_cairo_device.c Modified: ext/cairo/rb_cairo_device.c (+15 -0) =================================================================== --- ext/cairo/rb_cairo_device.c 2010-09-11 11:56:17 +0000 (05c8aec) +++ ext/cairo/rb_cairo_device.c 2010-09-11 12:06:05 +0000 (f998fb5) @@ -301,6 +301,18 @@ cr_script_device_get_mode (VALUE self) { return INT2NUM (cairo_script_get_mode (_SELF)); } + +static VALUE +cr_script_device_reply (VALUE self, VALUE recording_surface) +{ + cairo_device_t *device; + + device = _SELF; + cairo_script_from_recording_surface (device, + RVAL2CRSURFACE (recording_surface)); + cr_device_check_status (device); + return Qnil; +} # endif #endif @@ -340,6 +352,9 @@ Init_cairo_device (void) rb_define_method (rb_cCairo_ScriptDevice, "mode", cr_script_device_get_mode, 0); + rb_define_method (rb_cCairo_ScriptDevice, "reply", + cr_script_device_reply, 1); + RB_CAIRO_DEF_SETTERS (rb_cCairo_ScriptDevice); # endif From null+rcairo at clear-code.com Sat Sep 11 08:24:21 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 12:24:21 +0000 Subject: [cairo-commit:00053] rcairo/rcairo [master] support cairo_surface_{get, set}_mime_data() new in cairo 1.10. Message-ID: <20100911122433.6CFC5278001@taiyaki.ru> Kouhei Sutou 2010-09-11 12:24:21 +0000 (Sat, 11 Sep 2010) New Revision: d6c106584f5bfa5b51b640a007717d5c959f0e7a Log: support cairo_surface_{get,set}_mime_data() new in cairo 1.10. Modified files: ext/cairo/cairo.def ext/cairo/rb_cairo.h ext/cairo/rb_cairo_constants.c ext/cairo/rb_cairo_surface.c test/test_surface.rb Modified: ext/cairo/cairo.def (+1 -0) =================================================================== --- ext/cairo/cairo.def 2010-09-11 12:06:05 +0000 (bfd20d6) +++ ext/cairo/cairo.def 2010-09-11 12:24:21 +0000 (9e2bbbb) @@ -72,6 +72,7 @@ EXPORTS rb_mCairo_PDFVersion DATA rb_cCairo_TextClusterFlag DATA rb_cCairo_ScriptMode DATA + rb_cCairo_MimeType DATA rb_mCairo_Color DATA rb_cCairo_Color_Base DATA Modified: ext/cairo/rb_cairo.h (+1 -0) =================================================================== --- ext/cairo/rb_cairo.h 2010-09-11 12:06:05 +0000 (667b2d3) +++ ext/cairo/rb_cairo.h 2010-09-11 12:24:21 +0000 (14b900f) @@ -149,6 +149,7 @@ RB_CAIRO_VAR VALUE rb_mCairo_PDFVersion; RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion; RB_CAIRO_VAR VALUE rb_mCairo_TextClusterFlag; RB_CAIRO_VAR VALUE rb_mCairo_ScriptMode; +RB_CAIRO_VAR VALUE rb_mCairo_MimeType; RB_CAIRO_VAR VALUE rb_mCairo_Color; RB_CAIRO_VAR VALUE rb_cCairo_Color_Base; RB_CAIRO_VAR VALUE rb_cCairo_Paper; Modified: ext/cairo/rb_cairo_constants.c (+14 -0) =================================================================== --- ext/cairo/rb_cairo_constants.c 2010-09-11 12:06:05 +0000 (1e3c78c) +++ ext/cairo/rb_cairo_constants.c 2010-09-11 12:24:21 +0000 (6484144) @@ -36,6 +36,7 @@ VALUE rb_mCairo_PSLevel = Qnil; VALUE rb_mCairo_TextClusterFlag = Qnil; VALUE rb_mCairo_PDFVersion = Qnil; VALUE rb_mCairo_ScriptMode = Qnil; +VALUE rb_mCairo_MimeType = Qnil; #define CAIRO_OPERATOR_MIN CAIRO_OPERATOR_CLEAR #define CAIRO_OPERATOR_MAX CAIRO_OPERATOR_SATURATE @@ -587,4 +588,17 @@ Init_cairo_constants (void) rb_define_const (rb_mCairo_ScriptMode, "ASCII", INT2FIX (CAIRO_SCRIPT_MODE_ASCII)); #endif + +#if CAIRO_CHECK_VERSION(1, 10, 0) + rb_mCairo_MimeType = rb_define_module_under (rb_mCairo, "MimeType"); + + rb_define_const (rb_mCairo_MimeType, "JPEG", + rb_str_new2 (CAIRO_MIME_TYPE_JPEG)); + rb_define_const (rb_mCairo_MimeType, "PNG", + rb_str_new2 (CAIRO_MIME_TYPE_PNG)); + rb_define_const (rb_mCairo_MimeType, "JP2", + rb_str_new2 (CAIRO_MIME_TYPE_JP2)); + rb_define_const (rb_mCairo_MimeType, "URI", + rb_str_new2 (CAIRO_MIME_TYPE_URI)); +#endif } Modified: ext/cairo/rb_cairo_surface.c (+57 -0) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-11 12:06:05 +0000 (25be19c) +++ ext/cairo/rb_cairo_surface.c 2010-09-11 12:24:21 +0000 (be4d833) @@ -388,6 +388,56 @@ cr_surface_write_to_png_generic (VALUE self, VALUE target) } #endif +#if CAIRO_CHECK_VERSION(1, 10, 0) +static VALUE +cr_surface_get_mime_data (VALUE self, VALUE mime_type) +{ + cairo_surface_t *surface; + const unsigned char *data; + unsigned long length; + + surface = _SELF; + cairo_surface_get_mime_data (surface, StringValueCStr (mime_type), + &data, &length); + if (data) + return rb_str_new ((const char *)data, length); + else + return Qnil; +} + +static VALUE +cr_surface_set_mime_data (VALUE self, VALUE rb_mime_type, VALUE rb_data) +{ + cairo_status_t status; + cairo_surface_t *surface; + const char *mime_type; + + surface = _SELF; + mime_type = StringValueCStr (rb_mime_type); + if (NIL_P (rb_data)) + { + status = cairo_surface_set_mime_data (surface, mime_type, + NULL, 0, NULL, NULL); + } + else + { + const char *raw_data; + unsigned char *data; + unsigned long length; + + raw_data = StringValuePtr (rb_data); + length = RSTRING_LEN (rb_data); + data = xmalloc (length); + memcpy (data, raw_data, length); + status = cairo_surface_set_mime_data (surface, mime_type, + data, length, + xfree, data); + } + rb_cairo_check_status (status); + return Qnil; +} +#endif + static VALUE cr_surface_get_font_options (VALUE self) { @@ -1206,6 +1256,13 @@ Init_cairo_surface (void) rb_define_method (rb_cCairo_Surface, "finish", cr_surface_finish, 0); rb_define_method (rb_cCairo_Surface, "content", cr_surface_get_content, 0); +#if CAIRO_CHECK_VERSION(1, 10, 0) + rb_define_method (rb_cCairo_Surface, "get_mime_data", + cr_surface_get_mime_data, 1); + rb_define_method (rb_cCairo_Surface, "set_mime_data", + cr_surface_set_mime_data, 2); +#endif + rb_define_method (rb_cCairo_Surface, "font_options", cr_surface_get_font_options, 0); rb_define_method (rb_cCairo_Surface, "flush", cr_surface_flush, 0); Modified: test/test_surface.rb (+10 -0) =================================================================== --- test/test_surface.rb 2010-09-11 12:06:05 +0000 (4862bf4) +++ test/test_surface.rb 2010-09-11 12:24:21 +0000 (2a29d9c) @@ -46,4 +46,14 @@ class SurfaceTest < Test::Unit::TestCase surface = Cairo::ScriptSurface.new(device, 100, 100) assert_equal(Cairo::ScriptDevice, surface.device.class) end + + def test_mime_data + only_cairo_version(1, 10, 0) + + output = StringIO.new + surface = Cairo::PDFSurface.new(output, 100, 100) + surface.set_mime_data(Cairo::MimeType::URI, "http://cairo.rubyforge.org/") + assert_equal("http://cairo.rubyforge.org/", + surface.get_mime_data(Cairo::MimeType::URI)) + end end From null+rcairo at clear-code.com Sat Sep 11 10:25:35 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 14:25:35 +0000 Subject: [cairo-commit:00054] rcairo/rcairo [master] enable CAIRO_FORMAT_RGB16_565 re-enabled in cairo 1.10. Message-ID: <20100911142546.175E8170521@taiyaki.ru> Kouhei Sutou 2010-09-11 14:25:35 +0000 (Sat, 11 Sep 2010) New Revision: 7cc3658ad2b016cd99d27cc94ddcde56bfd0bd69 Log: enable CAIRO_FORMAT_RGB16_565 re-enabled in cairo 1.10. Modified files: ext/cairo/rb_cairo_constants.c Modified: ext/cairo/rb_cairo_constants.c (+6 -3) =================================================================== --- ext/cairo/rb_cairo_constants.c 2010-09-11 12:24:21 +0000 (6484144) +++ ext/cairo/rb_cairo_constants.c 2010-09-11 14:25:35 +0000 (3eb8f06) @@ -5,6 +5,7 @@ * $Author: kou $ * $Date: 2008-09-19 12:56:27 $ * + * Copyright 2005-2010 Kouhei Sutou * Copyright 2005 ?yvind Kol?s * Copyright 2004-2005 MenTaLguY * @@ -75,7 +76,7 @@ VALUE rb_mCairo_MimeType = Qnil; #define CAIRO_CONTENT_MAX CAIRO_CONTENT_COLOR_ALPHA #define CAIRO_FORMAT_MIN CAIRO_FORMAT_ARGB32 -#define CAIRO_FORMAT_MAX CAIRO_FORMAT_A1 +#define CAIRO_FORMAT_MAX CAIRO_FORMAT_RGB16_565 #define CAIRO_EXTEND_MIN CAIRO_EXTEND_NONE #define CAIRO_EXTEND_MAX CAIRO_EXTEND_REFLECT @@ -482,6 +483,10 @@ Init_cairo_constants (void) /* cairo_format_t */ rb_mCairo_Format = rb_define_module_under (rb_mCairo, "Format"); +#if CAIRO_CHECK_VERSION(1, 10, 0) + rb_define_const (rb_mCairo_Format, "INVALID", + INT2FIX (CAIRO_FORMAT_INVALID)); +#endif rb_define_const (rb_mCairo_Format, "ARGB32", INT2FIX (CAIRO_FORMAT_ARGB32)); rb_define_const (rb_mCairo_Format, "RGB24", @@ -490,10 +495,8 @@ Init_cairo_constants (void) INT2FIX (CAIRO_FORMAT_A8)); rb_define_const (rb_mCairo_Format, "A1", INT2FIX (CAIRO_FORMAT_A1)); -#if !CAIRO_CHECK_VERSION(1, 3, 0) rb_define_const (rb_mCairo_Format, "RGB16_565", INT2FIX (CAIRO_FORMAT_RGB16_565)); -#endif #if CAIRO_CHECK_VERSION(1, 5, 8) rb_define_singleton_method (rb_mCairo_Format, "stride_for_width", From null+rcairo at clear-code.com Sat Sep 11 11:02:15 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sat, 11 Sep 2010 15:02:15 +0000 Subject: [cairo-commit:00055] rcairo/rcairo [master] support RecordingSurface new in cairo 1.10. Message-ID: <20100911150224.3D597170521@taiyaki.ru> Kouhei Sutou 2010-09-11 15:02:15 +0000 (Sat, 11 Sep 2010) New Revision: b9c3b72cda454c6f8a3ffe4786e0785da6e59217 Log: support RecordingSurface new in cairo 1.10. Added files: test/test_recording_surface.rb Modified files: ext/cairo/rb_cairo_surface.c test/cairo-test-utils.rb Modified: ext/cairo/rb_cairo_surface.c (+93 -0) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-11 14:25:35 +0000 (be4d833) +++ ext/cairo/rb_cairo_surface.c 2010-09-11 15:02:15 +0000 (0a48510) @@ -701,6 +701,87 @@ cr_image_surface_get_stride (VALUE self) return INT2NUM (cairo_image_surface_get_stride (_SELF)); } +#ifdef CAIRO_HAS_RECORDING_SURFACE +/* Recording-surface functions */ +static VALUE +cr_recording_surface_initialize (int argc, VALUE *argv, VALUE self) +{ + VALUE arg1, arg2, arg3, arg4, arg5; + cairo_surface_t *surface; + cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA; + cairo_rectangle_t extents; + const char *error_message = + "invalid argument (expect " + "(x, y, width, height), " + "([x, y, width, height])," + "(content, x, y, width, height) or " + "(content, [x, y, width, height])): %s"; + + rb_scan_args (argc, argv, "14", &arg1, &arg2, &arg3, &arg4, &arg5); + if (argc == 1 || argc == 2) + { + VALUE rb_extents; + + if (argc == 1) + { + rb_extents = arg1; + } + else + { + content = RVAL2CRCONTENT (arg1); + rb_extents = arg2; + } + rb_extents = rb_check_array_type (rb_extents); + if (RARRAY_LEN (rb_extents) != 4) + rb_raise (rb_eArgError, error_message, rb_cairo__inspect (arg1)); + extents.x = NUM2DBL (RARRAY_PTR (rb_extents)[0]); + extents.y = NUM2DBL (RARRAY_PTR (rb_extents)[1]); + extents.width = NUM2DBL (RARRAY_PTR (rb_extents)[2]); + extents.height = NUM2DBL (RARRAY_PTR (rb_extents)[3]); + } + else if (argc == 4) + { + extents.x = NUM2DBL (arg1); + extents.y = NUM2DBL (arg2); + extents.width = NUM2DBL (arg3); + extents.height = NUM2DBL (arg4); + } + else if (argc == 5) + { + content = RVAL2CRCONTENT (arg1); + extents.x = NUM2DBL (arg2); + extents.y = NUM2DBL (arg3); + extents.width = NUM2DBL (arg4); + extents.height = NUM2DBL (arg5); + } + else + { + rb_raise (rb_eArgError, error_message, + rb_cairo__inspect (rb_ary_new4 (argc, argv))); + } + + surface = cairo_recording_surface_create (content, &extents); + cr_surface_check_status (surface); + DATA_PTR (self) = surface; + if (rb_block_given_p ()) + yield_and_finish (self); + return Qnil; +} + +static VALUE +cr_recording_surface_get_ink_extents (VALUE self) +{ + cairo_surface_t *surface; + double x, y, width, height; + + surface = _SELF; + cairo_recording_surface_ink_extents (surface, &x, &y, &width, &height); + cr_surface_check_status (surface); + return rb_ary_new3 (4, + rb_float_new (x), rb_float_new (y), + rb_float_new (width), rb_float_new (height)); +} +#endif /* Printing surfaces */ #define DEFINE_SURFACE(type) \ @@ -1314,6 +1395,18 @@ Init_cairo_surface (void) rb_define_method (rb_cCairo_ImageSurface, "stride", cr_image_surface_get_stride, 0); +#ifdef CAIRO_HAS_RECORDING_SURFACE + /* Recording-surface */ + rb_cCairo_RecordingSurface = + rb_define_class_under (rb_mCairo, "RecordingSurface", rb_cCairo_Surface); + + rb_define_method (rb_cCairo_RecordingSurface, "initialize", + cr_recording_surface_initialize, -1); + + rb_define_method (rb_cCairo_RecordingSurface, "ink_extents", + cr_recording_surface_get_ink_extents, 0); +#endif + #define INIT_SURFACE(type, name) \ rb_cCairo_ ## name ## Surface = \ rb_define_class_under (rb_mCairo, # name "Surface", \ Modified: test/cairo-test-utils.rb (+7 -0) =================================================================== --- test/cairo-test-utils.rb 2010-09-11 14:25:35 +0000 (cc446f8) +++ test/cairo-test-utils.rb 2010-09-11 15:02:15 +0000 (2d95dbc) @@ -22,4 +22,11 @@ module CairoTestUtils omit("Only for #{device_class} device available") end end + + def only_surface(name) + surface_class = "#{name}Surface" + unless Cairo.const_defined?(surface_class) + omit("Only for #{surface_class} surface available") + end + end end Added: test/test_recording_surface.rb (+21 -0) 100644 =================================================================== --- /dev/null +++ test/test_recording_surface.rb 2010-09-11 15:02:15 +0000 (2da4ce2) @@ -0,0 +1,21 @@ +require 'cairo' +require 'stringio' + +class RecordingSurfaceTest < Test::Unit::TestCase + include CairoTestUtils + + def setup + only_surface("Recording") + end + + def test_new + surface = Cairo::RecordingSurface.new(10, 20, 300, 400) + assert_equal([0.0, 0.0, 0.0, 0.0], surface.ink_extents) + Cairo::Context.new(surface) do |context| + context.move_to(15, 30) + context.line_to(80, 100) + context.stroke + end + assert_equal([10.0, 20.0, 99.0, 109.0], surface.ink_extents) + end +end From null+rcairo at clear-code.com Sat Sep 11 21:27:57 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 01:27:57 +0000 Subject: [cairo-commit:00056] rcairo/rcairo [master] support XMLDevice new in cairo 1.10. Message-ID: <20100912012811.BB36A170521@taiyaki.ru> Kouhei Sutou 2010-09-12 01:27:57 +0000 (Sun, 12 Sep 2010) New Revision: 8b127cd4b8df616d82712bfc92b77579b9a2404d Log: support XMLDevice new in cairo 1.10. Added files: test/test_xml_device.rb Modified files: ext/cairo/rb_cairo_device.c test/cairo-test-utils.rb Modified: ext/cairo/rb_cairo_device.c (+77 -36) =================================================================== --- ext/cairo/rb_cairo_device.c 2010-09-11 15:02:15 +0000 (f998fb5) +++ ext/cairo/rb_cairo_device.c 2010-09-12 01:27:57 +0000 (69c3384) @@ -18,6 +18,10 @@ # include #endif +#ifdef CAIRO_HAS_XML_SURFACE +# include +#endif + VALUE rb_cCairo_Device = Qnil; VALUE rb_cCairo_DRMDevice = Qnil; VALUE rb_cCairo_GLDevice = Qnil; @@ -234,44 +238,52 @@ yield_and_finish (VALUE self) cr_device_finish (self); } -# ifdef CAIRO_HAS_SCRIPT_SURFACE -static VALUE -cr_script_device_initialize (VALUE self, VALUE file_name_or_output) -{ - cairo_device_t *device; - - if (rb_respond_to (file_name_or_output, rb_cairo__io_id_write)) - { - rb_cairo__io_callback_closure_t *closure; - - closure = rb_cairo__io_closure_new (file_name_or_output); - device = cairo_script_create_for_stream (rb_cairo__io_write_func, - (void *)closure); - if (cairo_device_status (device)) - { - rb_cairo__io_closure_destroy (closure); - } - else - { - cairo_device_set_user_data (device, &cr_closure_key, - closure, rb_cairo__io_closure_free); - cairo_device_set_user_data (device, &cr_object_holder_key, - cr_object_holder_new (self), - cr_object_holder_free); - } - } - else - { - device = cairo_script_create (StringValueCStr (file_name_or_output)); - } - - cr_device_check_status (device); - DATA_PTR (self) = device; - if (rb_block_given_p ()) - yield_and_finish (self); - return Qnil; +#define DEFINE_OUTPUT_INITIALIZE(type) \ +static VALUE \ +cr_ ## type ## _device_initialize (VALUE self, \ + VALUE file_name_or_output) \ +{ \ + cairo_device_t *device; \ + \ + if (rb_respond_to (file_name_or_output, rb_cairo__io_id_write)) \ + { \ + rb_cairo__io_callback_closure_t *closure; \ + \ + closure = rb_cairo__io_closure_new (file_name_or_output); \ + device = \ + cairo_ ## type ## _create_for_stream (rb_cairo__io_write_func, \ + (void *)closure); \ + if (cairo_device_status (device)) \ + { \ + rb_cairo__io_closure_destroy (closure); \ + } \ + else \ + { \ + cairo_device_set_user_data (device, &cr_closure_key, \ + closure, \ + rb_cairo__io_closure_free); \ + cairo_device_set_user_data (device, &cr_object_holder_key, \ + cr_object_holder_new (self), \ + cr_object_holder_free); \ + } \ + } \ + else \ + { \ + const char *file_name; \ + file_name = StringValueCStr (file_name_or_output); \ + device = cairo_ ## type ## _create (file_name); \ + } \ + \ + cr_device_check_status (device); \ + DATA_PTR (self) = device; \ + if (rb_block_given_p ()) \ + yield_and_finish (self); \ + return Qnil; \ } +# ifdef CAIRO_HAS_SCRIPT_SURFACE +DEFINE_OUTPUT_INITIALIZE(script) + static VALUE cr_script_device_write_comment (VALUE self, VALUE comment) { @@ -315,6 +327,22 @@ cr_script_device_reply (VALUE self, VALUE recording_surface) } # endif +# ifdef CAIRO_HAS_XML_SURFACE +DEFINE_OUTPUT_INITIALIZE(xml) + +static VALUE +cr_xml_device_reply (VALUE self, VALUE recording_surface) +{ + cairo_device_t *device; + + device = _SELF; + cairo_xml_for_recording_surface (device, + RVAL2CRSURFACE (recording_surface)); + cr_device_check_status (device); + return Qnil; +} +# endif + #endif void @@ -358,5 +386,18 @@ Init_cairo_device (void) RB_CAIRO_DEF_SETTERS (rb_cCairo_ScriptDevice); # endif +# ifdef CAIRO_HAS_XML_SURFACE + rb_cCairo_XMLDevice = + rb_define_class_under (rb_mCairo, "XMLDevice", rb_cCairo_Device); + + rb_define_method (rb_cCairo_XMLDevice, "initialize", + cr_xml_device_initialize, 1); + + rb_define_method (rb_cCairo_XMLDevice, "reply", + cr_xml_device_reply, 1); + + RB_CAIRO_DEF_SETTERS (rb_cCairo_XMLDevice); +# endif + #endif } Modified: test/cairo-test-utils.rb (+1 -0) =================================================================== --- test/cairo-test-utils.rb 2010-09-11 15:02:15 +0000 (2d95dbc) +++ test/cairo-test-utils.rb 2010-09-12 01:27:57 +0000 (6df73c9) @@ -1,4 +1,5 @@ require 'cairo' +require 'stringio' module CairoTestUtils private Added: test/test_xml_device.rb (+22 -0) 100644 =================================================================== --- /dev/null +++ test/test_xml_device.rb 2010-09-12 01:27:57 +0000 (a3612cc) @@ -0,0 +1,22 @@ +class XMLDeviceTest < Test::Unit::TestCase + include CairoTestUtils + + def setup + only_device("XML") + end + + def test_new + output = StringIO.new + device = Cairo::XMLDevice.new(output) + assert_equal("", output.string) + end + + def test_new_with_block + output = StringIO.new + string = nil + Cairo::XMLDevice.new(output) do |device| + string = output.string + end + assert_equal("", string) + end +end From null+rcairo at clear-code.com Sat Sep 11 21:41:05 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 01:41:05 +0000 Subject: [cairo-commit:00057] rcairo/rcairo [master] support XMLSurface new in cairo 1.10. Message-ID: <20100912014115.B2548170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 01:41:05 +0000 (Sun, 12 Sep 2010) New Revision: 0214a2e68c53005ff961f58070db05f2383e20fa Log: support XMLSurface new in cairo 1.10. Added files: test/test_xml_surface.rb Modified files: ext/cairo/rb_cairo_surface.c Modified: ext/cairo/rb_cairo_surface.c (+69 -2) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-12 01:27:57 +0000 (0a48510) +++ ext/cairo/rb_cairo_surface.c 2010-09-12 01:41:05 +0000 (32e95e2) @@ -46,6 +46,10 @@ enum ruby_value_type { # define T_DATA RUBY_T_DATA #endif +#ifdef CAIRO_HAS_XML_SURFACE +# include +#endif + VALUE rb_cCairo_Surface; VALUE rb_cCairo_ImageSurface; VALUE rb_cCairo_PDFSurface = Qnil; @@ -1266,9 +1270,9 @@ cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) rb_raise (rb_eArgError, "invalid argument (expect " "(script, width, height), " - "(script, content, width, height), " + "(script, content, width, height) or " "(script, surface)): %s", - rb_cairo__inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4))); + rb_cairo__inspect (rb_ary_new4 (argc, argv))); break; } @@ -1295,6 +1299,59 @@ cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) } #endif +#ifdef CAIRO_HAS_XML_SURFACE +static VALUE +cr_xml_surface_initialize (int argc, VALUE *argv, VALUE self) +{ + cairo_device_t *script; + cairo_surface_t *surface = NULL; + cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA; + VALUE arg1, arg2, arg3, arg4, rb_width = Qnil, rb_height = Qnil; + + rb_scan_args (argc, argv, "22", &arg1, &arg2, &arg3, &arg4); + + script = RVAL2CRDEVICE (arg1); + if (argc == 3) + { + rb_width = arg2; + rb_height = arg3; + } + else + { + switch (TYPE (arg1)) + { + case T_NIL: + break; + case T_STRING: + case T_SYMBOL: + case T_FIXNUM: + content = RVAL2CRCONTENT (arg1); + break; + default: + rb_raise (rb_eArgError, + "invalid argument (expect " + "(script, width, height) or " + "(script, content, width, height)): %s", + rb_cairo__inspect (rb_ary_new4 (argc, argv))); + break; + } + + rb_width = arg3; + rb_height = arg4; + } + + surface = cairo_xml_surface_create (script, content, + NUM2DBL (rb_width), + NUM2DBL (rb_height)); + + cr_surface_check_status (surface); + DATA_PTR (self) = surface; + if (rb_block_given_p ()) + yield_and_finish (self); + return Qnil; +} +#endif + static int cr_finish_all_guarded_surfaces_at_end_iter (VALUE key, VALUE value, VALUE data) { @@ -1519,4 +1576,14 @@ Init_cairo_surface (void) RB_CAIRO_DEF_SETTERS (rb_cCairo_ScriptSurface); #endif + +#ifdef CAIRO_HAS_XML_SURFACE + rb_cCairo_XMLSurface = + rb_define_class_under (rb_mCairo, "XMLSurface", rb_cCairo_Surface); + + rb_define_method (rb_cCairo_XMLSurface, "initialize", + cr_xml_surface_initialize, -1); + + RB_CAIRO_DEF_SETTERS (rb_cCairo_XMLSurface); +#endif } Added: test/test_xml_surface.rb (+32 -0) 100644 =================================================================== --- /dev/null +++ test/test_xml_surface.rb 2010-09-12 01:41:05 +0000 (9eec1aa) @@ -0,0 +1,32 @@ +class XMLSurfaceTest < Test::Unit::TestCase + include CairoTestUtils + + def setup + only_surface("XML") + end + + def test_new + output = StringIO.new + device = Cairo::XMLDevice.new(output) + surface = Cairo::XMLSurface.new(device, 100, 200) + Cairo::Context.new(surface) do |context| + context.move_to(15, 30) + context.line_to(80, 100) + context.stroke + end + assert_equal(<<-EOX, output.string) + + OVER + 2 + 10 + LINE_CAP_BUTT + LINE_JOIN_MITER + + 0 0 0 1 + + 15 30 m 80 100 l 0.1 + ANTIALIAS_DEFAULT + +EOX + end +end From null+rcairo at clear-code.com Sat Sep 11 21:42:40 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 01:42:40 +0000 Subject: [cairo-commit:00058] rcairo/rcairo [master] split ScriptSurface test. Message-ID: <20100912014249.4EE30170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 01:42:40 +0000 (Sun, 12 Sep 2010) New Revision: 447c5f90367fafacaaf1832a1cefb713845d5d78 Log: split ScriptSurface test. Added files: test/test_script_surface.rb Modified files: test/test_recording_surface.rb test/test_surface.rb Modified: test/test_recording_surface.rb (+0 -3) =================================================================== --- test/test_recording_surface.rb 2010-09-12 01:41:05 +0000 (2da4ce2) +++ test/test_recording_surface.rb 2010-09-12 01:42:40 +0000 (7d9b1c1) @@ -1,6 +1,3 @@ -require 'cairo' -require 'stringio' - class RecordingSurfaceTest < Test::Unit::TestCase include CairoTestUtils Added: test/test_script_surface.rb (+13 -0) 100644 =================================================================== --- /dev/null +++ test/test_script_surface.rb 2010-09-12 01:42:40 +0000 (1f43548) @@ -0,0 +1,13 @@ +class ScriptSurfaceTest < Test::Unit::TestCase + include CairoTestUtils + + def setup + only_surface("Script") + end + + def test_device + device = Cairo::ScriptDevice.new(StringIO.new) + surface = Cairo::ScriptSurface.new(device, 100, 100) + assert_equal(Cairo::ScriptDevice, surface.device.class) + end +end Modified: test/test_surface.rb (+0 -8) =================================================================== --- test/test_surface.rb 2010-09-12 01:41:05 +0000 (2a29d9c) +++ test/test_surface.rb 2010-09-12 01:42:40 +0000 (d9957da) @@ -39,14 +39,6 @@ class SurfaceTest < Test::Unit::TestCase assert_equal([95.0, 95.0], surface.fallback_resolution) end - def test_device - only_device("Script") - - device = Cairo::ScriptDevice.new(StringIO.new) - surface = Cairo::ScriptSurface.new(device, 100, 100) - assert_equal(Cairo::ScriptDevice, surface.device.class) - end - def test_mime_data only_cairo_version(1, 10, 0) From null+rcairo at clear-code.com Sat Sep 11 22:04:22 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 02:04:22 +0000 Subject: [cairo-commit:00059] rcairo/rcairo [master] support TeeSurface new in cairo 1.10. Message-ID: <20100912020430.5DE62170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 02:04:22 +0000 (Sun, 12 Sep 2010) New Revision: 47d10661b80fdddfffb4d6600480e226d4dc803c Log: support TeeSurface new in cairo 1.10. Added files: test/test_tee_surface.rb Modified files: ext/cairo/rb_cairo_surface.c Modified: ext/cairo/rb_cairo_surface.c (+95 -0) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-12 01:42:40 +0000 (32e95e2) +++ ext/cairo/rb_cairo_surface.c 2010-09-12 02:04:22 +0000 (b2ce0fd) @@ -50,6 +50,10 @@ enum ruby_value_type { # include #endif +#ifdef CAIRO_HAS_TEE_SURFACE +# include +#endif + VALUE rb_cCairo_Surface; VALUE rb_cCairo_ImageSurface; VALUE rb_cCairo_PDFSurface = Qnil; @@ -1352,6 +1356,78 @@ cr_xml_surface_initialize (int argc, VALUE *argv, VALUE self) } #endif +#ifdef CAIRO_HAS_TEE_SURFACE +static VALUE +cr_tee_surface_initialize (VALUE self, VALUE master) +{ + cairo_surface_t *surface = NULL; + + surface = cairo_tee_surface_create (RVAL2CRSURFACE (master)); + cr_surface_check_status (surface); + DATA_PTR (self) = surface; + if (rb_block_given_p ()) + yield_and_finish (self); + return Qnil; +} + +static VALUE +cr_tee_surface_add (VALUE self, VALUE target) +{ + cairo_surface_t *surface = NULL; + + surface = _SELF; + cairo_tee_surface_add (surface, RVAL2CRSURFACE (target)); + cr_surface_check_status (surface); + return Qnil; +} + +static VALUE +cr_tee_surface_shift_operator (VALUE self, VALUE target) +{ + cr_tee_surface_add (self, target); + return self; +} + +static VALUE +cr_tee_surface_remove (VALUE self, VALUE target_or_index) +{ + cairo_surface_t *surface = NULL, *target; + + surface = _SELF; + if (rb_cairo__is_kind_of (target_or_index, rb_cCairo_Surface)) + { + target = RVAL2CRSURFACE (target_or_index); + } + else + { + VALUE index; + + index = rb_check_to_integer (target_or_index, "to_int"); + if (NIL_P (index)) + rb_raise (rb_eArgError, + "invalid argument (expect (surface) or (index)): %s", + rb_cairo__inspect (target_or_index)); + target = cairo_tee_surface_index (surface, NUM2INT (index)); + } + cairo_tee_surface_remove (surface, target); + cr_surface_check_status (surface); + return Qnil; +} + +static VALUE +cr_tee_surface_array_reference (VALUE self, VALUE index) +{ + cairo_surface_t *surface = NULL, *target; + + surface = _SELF; + index = rb_Integer (index); + target = cairo_tee_surface_index (surface, NUM2INT (index)); + cr_surface_check_status (surface); + cr_surface_check_status (target); + return CRSURFACE2RVAL (target); +} +#endif + static int cr_finish_all_guarded_surfaces_at_end_iter (VALUE key, VALUE value, VALUE data) { @@ -1586,4 +1662,23 @@ Init_cairo_surface (void) RB_CAIRO_DEF_SETTERS (rb_cCairo_XMLSurface); #endif + +#ifdef CAIRO_HAS_TEE_SURFACE + rb_cCairo_TeeSurface = + rb_define_class_under (rb_mCairo, "TeeSurface", rb_cCairo_Surface); + + rb_define_method (rb_cCairo_TeeSurface, "initialize", + cr_tee_surface_initialize, 1); + + rb_define_method (rb_cCairo_TeeSurface, "add", + cr_tee_surface_add, 1); + rb_define_method (rb_cCairo_TeeSurface, "<<", + cr_tee_surface_shift_operator, 1); + rb_define_method (rb_cCairo_TeeSurface, "remove", + cr_tee_surface_remove, 1); + rb_define_method (rb_cCairo_TeeSurface, "[]", + cr_tee_surface_array_reference, 1); + + RB_CAIRO_DEF_SETTERS (rb_cCairo_TeeSurface); +#endif } Added: test/test_tee_surface.rb (+32 -0) 100644 =================================================================== --- /dev/null +++ test/test_tee_surface.rb 2010-09-12 02:04:22 +0000 (f5e958b) @@ -0,0 +1,32 @@ +class TeeSurfaceTest < Test::Unit::TestCase + include CairoTestUtils + + def setup + only_surface("Tee") + only_surface("Script") + end + + def test_new + output1 = StringIO.new + device1 = Cairo::ScriptDevice.new(output1) + surface1 = Cairo::ScriptSurface.new(device1, 100, 200) + output2 = StringIO.new + device2 = Cairo::ScriptDevice.new(output2) + surface2 = Cairo::ScriptSurface.new(device2, 100, 200) + + surface = Cairo::TeeSurface.new(surface1) + surface << surface2 + Cairo::Context.new(surface) do |context| + context.move_to(15, 30) + context.line_to(80, 100) + context.stroke + end + assert_equal(<<-EOS, output1.string) +%!CairoScript +<< /content //COLOR_ALPHA /width 100 /height 200 >> surface context +n 15 30 m 80 100 l +stroke+ +EOS + assert_equal(output1.string, output2.string) + end +end From null+rcairo at clear-code.com Sat Sep 11 22:36:27 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 02:36:27 +0000 Subject: [cairo-commit:00060] rcairo/rcairo [master] support GLSurface new in cairo 1.10. Message-ID: <20100912023637.8A8B5170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 02:36:27 +0000 (Sun, 12 Sep 2010) New Revision: 1a223c76b2d7732558796363a169506861523662 Log: support GLSurface new in cairo 1.10. Modified files: ext/cairo/cairo.def ext/cairo/rb_cairo.h ext/cairo/rb_cairo_surface.c Modified: ext/cairo/cairo.def (+1 -0) =================================================================== --- ext/cairo/cairo.def 2010-09-12 02:04:22 +0000 (9e2bbbb) +++ ext/cairo/cairo.def 2010-09-12 02:36:27 +0000 (422ed7c) @@ -39,6 +39,7 @@ EXPORTS rb_cCairo_RecordingSurface DATA rb_cCairo_VGSurface DATA rb_cCairo_GLSurface DATA + rb_cCairo_GLTextureSurface DATA rb_cCairo_DRMSurface DATA rb_cCairo_TeeSurface DATA rb_cCairo_XMLSurface DATA Modified: ext/cairo/rb_cairo.h (+1 -0) =================================================================== --- ext/cairo/rb_cairo.h 2010-09-12 02:04:22 +0000 (14b900f) +++ ext/cairo/rb_cairo.h 2010-09-12 02:36:27 +0000 (a35d469) @@ -112,6 +112,7 @@ RB_CAIRO_VAR VALUE rb_cCairo_QtSurface; RB_CAIRO_VAR VALUE rb_cCairo_RecordingSurface; RB_CAIRO_VAR VALUE rb_cCairo_VGSurface; RB_CAIRO_VAR VALUE rb_cCairo_GLSurface; +RB_CAIRO_VAR VALUE rb_cCairo_GLTextureSurface; RB_CAIRO_VAR VALUE rb_cCairo_DRMSurface; RB_CAIRO_VAR VALUE rb_cCairo_TeeSurface; RB_CAIRO_VAR VALUE rb_cCairo_XMLSurface; Modified: ext/cairo/rb_cairo_surface.c (+169 -12) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-12 02:04:22 +0000 (b2ce0fd) +++ ext/cairo/rb_cairo_surface.c 2010-09-12 02:36:27 +0000 (f8e2f4e) @@ -54,6 +54,10 @@ enum ruby_value_type { # include #endif +#ifdef CAIRO_HAS_GL_SURFACE +# include +#endif + VALUE rb_cCairo_Surface; VALUE rb_cCairo_ImageSurface; VALUE rb_cCairo_PDFSurface = Qnil; @@ -68,6 +72,7 @@ VALUE rb_cCairo_QtSurface = Qnil; VALUE rb_cCairo_RecordingSurface = Qnil; VALUE rb_cCairo_VGSurface = Qnil; VALUE rb_cCairo_GLSurface = Qnil; +VALUE rb_cCairo_GLTextureSurface = Qnil; VALUE rb_cCairo_DRMSurface = Qnil; VALUE rb_cCairo_TeeSurface = Qnil; VALUE rb_cCairo_XMLSurface = Qnil; @@ -1242,14 +1247,14 @@ cr_quartz_image_surface_get_image (VALUE self) static VALUE cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) { - cairo_device_t *script; + cairo_device_t *device; cairo_surface_t *surface = NULL, *target = NULL; cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA; VALUE arg1, arg2, arg3, arg4, rb_width = Qnil, rb_height = Qnil; rb_scan_args (argc, argv, "22", &arg1, &arg2, &arg3, &arg4); - script = RVAL2CRDEVICE (arg1); + device = RVAL2CRDEVICE (arg1); if (argc == 2) { target = RVAL2CRSURFACE (arg2); @@ -1273,9 +1278,9 @@ cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) default: rb_raise (rb_eArgError, "invalid argument (expect " - "(script, width, height), " - "(script, content, width, height) or " - "(script, surface)): %s", + "(device, width, height), " + "(device, content, width, height) or " + "(device, surface)): %s", rb_cairo__inspect (rb_ary_new4 (argc, argv))); break; } @@ -1286,11 +1291,11 @@ cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) if (target) { - surface = cairo_script_surface_create_for_target (script, target); + surface = cairo_script_surface_create_for_target (device, target); } else { - surface = cairo_script_surface_create (script, content, + surface = cairo_script_surface_create (device, content, NUM2DBL (rb_width), NUM2DBL (rb_height)); } @@ -1307,14 +1312,14 @@ cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) static VALUE cr_xml_surface_initialize (int argc, VALUE *argv, VALUE self) { - cairo_device_t *script; + cairo_device_t *device; cairo_surface_t *surface = NULL; cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA; VALUE arg1, arg2, arg3, arg4, rb_width = Qnil, rb_height = Qnil; rb_scan_args (argc, argv, "22", &arg1, &arg2, &arg3, &arg4); - script = RVAL2CRDEVICE (arg1); + device = RVAL2CRDEVICE (arg1); if (argc == 3) { rb_width = arg2; @@ -1334,8 +1339,8 @@ cr_xml_surface_initialize (int argc, VALUE *argv, VALUE self) default: rb_raise (rb_eArgError, "invalid argument (expect " - "(script, width, height) or " - "(script, content, width, height)): %s", + "(device, width, height) or " + "(device, content, width, height)): %s", rb_cairo__inspect (rb_ary_new4 (argc, argv))); break; } @@ -1344,7 +1349,7 @@ cr_xml_surface_initialize (int argc, VALUE *argv, VALUE self) rb_height = arg4; } - surface = cairo_xml_surface_create (script, content, + surface = cairo_xml_surface_create (device, content, NUM2DBL (rb_width), NUM2DBL (rb_height)); @@ -1428,6 +1433,131 @@ cr_tee_surface_array_reference (VALUE self, VALUE index) } #endif +#ifdef CAIRO_HAS_GL_SURFACE +static VALUE +cr_gl_surface_initialize (int argc, VALUE *argv, VALUE self) +{ + cairo_surface_t *surface; + cairo_device_t *device; + int width, height; + cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA; + VALUE rb_device, rb_width, rb_height, rb_content; + + rb_scan_args (argc, argv, "31", + &rb_device, &rb_width, &rb_height, &rb_content); + + device = RVAL2CRDEVICE (rb_device); + width = NUM2INT (rb_width); + height = NUM2INT (rb_height); + switch (TYPE (rb_content)) + { + case T_NIL: + break; + case T_STRING: + case T_SYMBOL: + case T_FIXNUM: + content = RVAL2CRCONTENT (rb_content); + break; + default: + rb_raise (rb_eArgError, + "invalid argument (expect " + "(device, width, height) or " + "(device, width, height, content)): %s", + rb_cairo__inspect (rb_ary_new4 (argc, argv))); + break; + } + + surface = cairo_gl_surface_create (device, content, width, height); + + cr_surface_check_status (surface); + DATA_PTR (self) = surface; + if (rb_block_given_p ()) + yield_and_finish (self); + return Qnil; +} + +static VALUE +cr_gl_texture_surface_initialize (int argc, VALUE *argv, VALUE self) +{ + cairo_surface_t *surface; + cairo_device_t *device; + unsigned int texture; + int width, height; + cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA; + VALUE rb_device, rb_texture, rb_width, rb_height, rb_content; + + rb_scan_args (argc, argv, "41", + &rb_device, &rb_texture, &rb_width, &rb_height, &rb_content); + + device = RVAL2CRDEVICE (rb_device); + texture = NUM2UINT (rb_texture); + width = NUM2INT (rb_width); + height = NUM2INT (rb_height); + switch (TYPE (rb_content)) + { + case T_NIL: + break; + case T_STRING: + case T_SYMBOL: + case T_FIXNUM: + content = RVAL2CRCONTENT (rb_content); + break; + default: + rb_raise (rb_eArgError, + "invalid argument (expect " + "(device, texture, width, height) or " + "(device, texture, width, height, content)): %s", + rb_cairo__inspect (rb_ary_new4 (argc, argv))); + break; + } + + surface = cairo_gl_surface_create_for_texture (device, content, + texture, + width, + height); + + cr_surface_check_status (surface); + DATA_PTR (self) = surface; + if (rb_block_given_p ()) + yield_and_finish (self); + return Qnil; +} + +static VALUE +cr_gl_surface_set_size (VALUE self, VALUE width, VALUE height) +{ + cairo_surface_t *surface = NULL; + + surface = _SELF; + cairo_gl_surface_set_size (surface, NUM2INT (width), NUM2INT (height)); + cr_surface_check_status (surface); + return Qnil; +} + +static VALUE +cr_gl_surface_get_width (VALUE self) +{ + return INT2NUM (cairo_gl_surface_get_width (_SELF)); +} + +static VALUE +cr_gl_surface_get_height (VALUE self) +{ + return INT2NUM (cairo_gl_surface_get_height (_SELF)); +} + +static VALUE +cr_gl_surface_swap_buffers (VALUE self) +{ + cairo_surface_t *surface = NULL; + + surface = _SELF; + cairo_gl_surface_swapbuffers (surface); + cr_surface_check_status (surface); + return Qnil; +} +#endif + static int cr_finish_all_guarded_surfaces_at_end_iter (VALUE key, VALUE value, VALUE data) { @@ -1681,4 +1811,31 @@ Init_cairo_surface (void) RB_CAIRO_DEF_SETTERS (rb_cCairo_TeeSurface); #endif + +#ifdef CAIRO_HAS_GL_SURFACE + rb_cCairo_GLSurface = + rb_define_class_under (rb_mCairo, "GLSurface", rb_cCairo_Surface); + + rb_define_method (rb_cCairo_GLSurface, "initialize", + cr_gl_surface_initialize, 1); + + rb_define_method (rb_cCairo_GLSurface, "set_size", + cr_gl_surface_set_size, 2); + rb_define_method (rb_cCairo_GLSurface, "width", + cr_gl_surface_get_width, 0); + rb_define_method (rb_cCairo_GLSurface, "height", + cr_gl_surface_get_height, 0); + rb_define_method (rb_cCairo_GLSurface, "swap_buffers", + cr_gl_surface_swap_buffers, 0); + + RB_CAIRO_DEF_SETTERS (rb_cCairo_GLSurface); + + rb_cCairo_GLTextureSurface = + rb_define_class_under (rb_mCairo, "GLTextureSurface", rb_cCairo_GLSurface); + + rb_define_method (rb_cCairo_GLTextureSurface, "initialize", + cr_gl_texture_surface_initialize, 1); + + RB_CAIRO_DEF_SETTERS (rb_cCairo_GLTextureSurface); +#endif } From null+rcairo at clear-code.com Sat Sep 11 22:47:03 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 02:47:03 +0000 Subject: [cairo-commit:00061] rcairo/rcairo [master] improve content argument position. Message-ID: <20100912024713.4B35C170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 02:47:03 +0000 (Sun, 12 Sep 2010) New Revision: ba60f7602ed5bd8009ac19bf27734a06792e0b44 Log: improve content argument position. Modified files: ext/cairo/rb_cairo_surface.c Modified: ext/cairo/rb_cairo_surface.c (+42 -75) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-12 02:36:27 +0000 (f8e2f4e) +++ ext/cairo/rb_cairo_surface.c 2010-09-12 02:47:03 +0000 (012427a) @@ -727,45 +727,32 @@ cr_recording_surface_initialize (int argc, VALUE *argv, VALUE self) "invalid argument (expect " "(x, y, width, height), " "([x, y, width, height])," - "(content, x, y, width, height) or " - "(content, [x, y, width, height])): %s"; + "(x, y, width, height, content) or " + "([x, y, width, height], content)): %s"; rb_scan_args (argc, argv, "14", &arg1, &arg2, &arg3, &arg4, &arg5); if (argc == 1 || argc == 2) { VALUE rb_extents; - if (argc == 1) - { - rb_extents = arg1; - } - else - { - content = RVAL2CRCONTENT (arg1); - rb_extents = arg2; - } - rb_extents = rb_check_array_type (rb_extents); + rb_extents = rb_check_array_type (arg1); if (RARRAY_LEN (rb_extents) != 4) rb_raise (rb_eArgError, error_message, rb_cairo__inspect (arg1)); extents.x = NUM2DBL (RARRAY_PTR (rb_extents)[0]); extents.y = NUM2DBL (RARRAY_PTR (rb_extents)[1]); extents.width = NUM2DBL (RARRAY_PTR (rb_extents)[2]); extents.height = NUM2DBL (RARRAY_PTR (rb_extents)[3]); + if (!NIL_P (arg2)) + content = RVAL2CRCONTENT (arg2); } - else if (argc == 4) + else if (argc == 4 || argc == 5) { extents.x = NUM2DBL (arg1); extents.y = NUM2DBL (arg2); extents.width = NUM2DBL (arg3); extents.height = NUM2DBL (arg4); - } - else if (argc == 5) - { - content = RVAL2CRCONTENT (arg1); - extents.x = NUM2DBL (arg2); - extents.y = NUM2DBL (arg3); - extents.width = NUM2DBL (arg4); - extents.height = NUM2DBL (arg5); + if (!NIL_P (arg5)) + content = RVAL2CRCONTENT (arg5); } else { @@ -1247,10 +1234,11 @@ cr_quartz_image_surface_get_image (VALUE self) static VALUE cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) { - cairo_device_t *device; cairo_surface_t *surface = NULL, *target = NULL; + cairo_device_t *device; + double width = 0.0, height = 0.0; cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA; - VALUE arg1, arg2, arg3, arg4, rb_width = Qnil, rb_height = Qnil; + VALUE arg1, arg2, arg3, arg4; rb_scan_args (argc, argv, "22", &arg1, &arg2, &arg3, &arg4); @@ -1259,46 +1247,34 @@ cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) { target = RVAL2CRSURFACE (arg2); } - else if (argc == 3) - { - rb_width = arg2; - rb_height = arg3; - } else { - switch (TYPE (arg1)) + width = NUM2DBL (arg2); + height = NUM2DBL (arg3); + switch (TYPE (arg4)) { case T_NIL: break; case T_STRING: case T_SYMBOL: case T_FIXNUM: - content = RVAL2CRCONTENT (arg1); + content = RVAL2CRCONTENT (arg4); break; default: rb_raise (rb_eArgError, "invalid argument (expect " "(device, width, height), " - "(device, content, width, height) or " + "(device, width, height, content) or " "(device, surface)): %s", rb_cairo__inspect (rb_ary_new4 (argc, argv))); break; } - - rb_width = arg3; - rb_height = arg4; } if (target) - { - surface = cairo_script_surface_create_for_target (device, target); - } + surface = cairo_script_surface_create_for_target (device, target); else - { - surface = cairo_script_surface_create (device, content, - NUM2DBL (rb_width), - NUM2DBL (rb_height)); - } + surface = cairo_script_surface_create (device, content, width, height); cr_surface_check_status (surface); DATA_PTR (self) = surface; @@ -1312,46 +1288,37 @@ cr_script_surface_initialize (int argc, VALUE *argv, VALUE self) static VALUE cr_xml_surface_initialize (int argc, VALUE *argv, VALUE self) { + cairo_surface_t *surface; cairo_device_t *device; - cairo_surface_t *surface = NULL; + double width, height; cairo_content_t content = CAIRO_CONTENT_COLOR_ALPHA; - VALUE arg1, arg2, arg3, arg4, rb_width = Qnil, rb_height = Qnil; + VALUE rb_device, rb_width, rb_height, rb_content; - rb_scan_args (argc, argv, "22", &arg1, &arg2, &arg3, &arg4); + rb_scan_args (argc, argv, "31", + &rb_device, &rb_width, &rb_height, &rb_content); - device = RVAL2CRDEVICE (arg1); - if (argc == 3) - { - rb_width = arg2; - rb_height = arg3; - } - else + device = RVAL2CRDEVICE (rb_device); + width = NUM2DBL (rb_width); + height = NUM2DBL (rb_height); + switch (TYPE (rb_content)) { - switch (TYPE (arg1)) - { - case T_NIL: - break; - case T_STRING: - case T_SYMBOL: - case T_FIXNUM: - content = RVAL2CRCONTENT (arg1); - break; - default: - rb_raise (rb_eArgError, - "invalid argument (expect " - "(device, width, height) or " - "(device, content, width, height)): %s", - rb_cairo__inspect (rb_ary_new4 (argc, argv))); - break; - } - - rb_width = arg3; - rb_height = arg4; + case T_NIL: + break; + case T_STRING: + case T_SYMBOL: + case T_FIXNUM: + content = RVAL2CRCONTENT (rb_content); + break; + default: + rb_raise (rb_eArgError, + "invalid argument (expect " + "(device, width, height) or " + "(device, width, height, content)): %s", + rb_cairo__inspect (rb_ary_new4 (argc, argv))); + break; } - surface = cairo_xml_surface_create (device, content, - NUM2DBL (rb_width), - NUM2DBL (rb_height)); + surface = cairo_xml_surface_create (device, content, width, height); cr_surface_check_status (surface); DATA_PTR (self) = surface; From null+rcairo at clear-code.com Sat Sep 11 22:50:47 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 02:50:47 +0000 Subject: [cairo-commit:00062] rcairo/rcairo [master] make create_similar's content omittable. Message-ID: <20100912025057.1F1F2170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 02:50:47 +0000 (Sun, 12 Sep 2010) New Revision: 25ad97084b5a8a372640d23d0bd16c9eab7fdf54 Log: make create_similar's content omittable. Modified files: ext/cairo/rb_cairo_surface.c Modified: ext/cairo/rb_cairo_surface.c (+26 -8) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-12 02:47:03 +0000 (012427a) +++ ext/cairo/rb_cairo_surface.c 2010-09-12 02:50:47 +0000 (816b8a7) @@ -307,15 +307,33 @@ yield_and_finish (VALUE self) } static VALUE -cr_surface_create_similar (VALUE self, VALUE content, VALUE width, VALUE height) +cr_surface_create_similar (int argc, VALUE *argv, VALUE self) { - cairo_surface_t *surface; + cairo_surface_t *surface, *similar_surface; + cairo_content_t content; + int width, height; + VALUE arg1, arg2, arg3; - surface = cairo_surface_create_similar (RVAL2CRSURFACE (self), - RVAL2CRCONTENT (content), - NUM2INT (width), NUM2INT (height)); - cr_surface_check_status (surface); - return CRSURFACE2RVAL_WITH_DESTROY (surface); + rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3); + + surface = _SELF; + if (argc == 2) + { + content = cairo_surface_get_content (surface); + width = NUM2INT (arg1); + height = NUM2INT (arg2); + } + else + { + content = RVAL2CRCONTENT (arg1); + width = NUM2INT (arg2); + height = NUM2INT (arg3); + } + + similar_surface = cairo_surface_create_similar (surface, content, + width, height); + cr_surface_check_status (similar_surface); + return CRSURFACE2RVAL_WITH_DESTROY (similar_surface); } #if CAIRO_CHECK_VERSION(1, 10, 0) @@ -1556,7 +1574,7 @@ Init_cairo_surface (void) rb_define_method (rb_cCairo_Surface, "create_similar", - cr_surface_create_similar, 3); + cr_surface_create_similar, -1); #if CAIRO_CHECK_VERSION(1, 10, 0) rb_define_method (rb_cCairo_Surface, "sub_rectangle_surface", cr_surface_create_sub_rectangle_surface, 4); From null+rcairo at clear-code.com Sat Sep 11 23:03:44 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 03:03:44 +0000 Subject: [cairo-commit:00063] rcairo/rcairo [master] use xfree() instead of free(). Message-ID: <20100912035907.408B4170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 03:03:44 +0000 (Sun, 12 Sep 2010) New Revision: af70d5b98dbe5d48e9ecac715e27ac367e881a26 Log: use xfree() instead of free(). Modified files: ext/cairo/rb_cairo_matrix.c Modified: ext/cairo/rb_cairo_matrix.c (+1 -1) =================================================================== --- ext/cairo/rb_cairo_matrix.c 2010-09-12 02:50:47 +0000 (b258e89) +++ ext/cairo/rb_cairo_matrix.c 2010-09-12 03:03:44 +0000 (25ee44e) @@ -40,7 +40,7 @@ cr_matrix_free (void *ptr) { if (ptr) { - free ((cairo_matrix_t *) ptr); + xfree ((cairo_matrix_t *) ptr); } } From null+rcairo at clear-code.com Sat Sep 11 23:58:54 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 03:58:54 +0000 Subject: [cairo-commit:00064] rcairo/rcairo [master] support Region new in cairo 1.10. Message-ID: <20100912035907.770C6170F61@taiyaki.ru> Kouhei Sutou 2010-09-12 03:58:54 +0000 (Sun, 12 Sep 2010) New Revision: 7147acd7ef83726c94de92f5bdd8ec4eb81f3886 Log: support Region new in cairo 1.10. Added files: ext/cairo/rb_cairo_region.c test/test_region.rb Modified files: ext/cairo/cairo.def ext/cairo/rb_cairo.c ext/cairo/rb_cairo.h ext/cairo/rb_cairo_constants.c ext/cairo/rb_cairo_private.h Modified: ext/cairo/cairo.def (+3 -0) =================================================================== --- ext/cairo/cairo.def 2010-09-12 03:48:18 +0000 (422ed7c) +++ ext/cairo/cairo.def 2010-09-12 03:58:54 +0000 (0173eeb) @@ -9,6 +9,7 @@ EXPORTS rb_cCairo_PathCurveTo DATA rb_cCairo_PathClosePath DATA rb_cCairo_Matrix DATA + rb_cCairo_Region DATA rb_cCairo_Pattern DATA rb_cCairo_SolidPattern DATA rb_cCairo_SurfacePattern DATA @@ -85,6 +86,8 @@ EXPORTS rb_cairo_path_to_ruby_object rb_cairo_matrix_from_ruby_object rb_cairo_matrix_to_ruby_object + rb_cairo_region_from_ruby_object + rb_cairo_region_to_ruby_object rb_cairo_pattern_from_ruby_object rb_cairo_pattern_to_ruby_object rb_cairo_font_face_from_ruby_object Modified: ext/cairo/rb_cairo.c (+1 -0) =================================================================== --- ext/cairo/rb_cairo.c 2010-09-12 03:48:18 +0000 (e268f95) +++ ext/cairo/rb_cairo.c 2010-09-12 03:58:54 +0000 (fd058de) @@ -92,6 +92,7 @@ Init_cairo () Init_cairo_context (); Init_cairo_path (); Init_cairo_matrix (); + Init_cairo_region (); Init_cairo_device (); Init_cairo_surface (); Init_cairo_exception (); Modified: ext/cairo/rb_cairo.h (+16 -0) =================================================================== --- ext/cairo/rb_cairo.h 2010-09-12 03:48:18 +0000 (a35d469) +++ ext/cairo/rb_cairo.h 2010-09-12 03:58:54 +0000 (e772f65) @@ -81,6 +81,7 @@ RB_CAIRO_VAR VALUE rb_cCairo_PathLineTo; RB_CAIRO_VAR VALUE rb_cCairo_PathCurveTo; RB_CAIRO_VAR VALUE rb_cCairo_PathClosePath; RB_CAIRO_VAR VALUE rb_cCairo_Matrix; +RB_CAIRO_VAR VALUE rb_cCairo_Region; RB_CAIRO_VAR VALUE rb_cCairo_Pattern; RB_CAIRO_VAR VALUE rb_cCairo_SolidPattern; RB_CAIRO_VAR VALUE rb_cCairo_SurfacePattern; @@ -151,6 +152,7 @@ RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion; RB_CAIRO_VAR VALUE rb_mCairo_TextClusterFlag; RB_CAIRO_VAR VALUE rb_mCairo_ScriptMode; RB_CAIRO_VAR VALUE rb_mCairo_MimeType; +RB_CAIRO_VAR VALUE rb_mCairo_RegionOverlap; RB_CAIRO_VAR VALUE rb_mCairo_Color; RB_CAIRO_VAR VALUE rb_cCairo_Color_Base; RB_CAIRO_VAR VALUE rb_cCairo_Paper; @@ -165,6 +167,9 @@ RB_CAIRO_VAR VALUE rb_cCairo_Paper; #define RVAL2CRMATRIX(obj) (rb_cairo_matrix_from_ruby_object(obj)) #define CRMATRIX2RVAL(matrix) (rb_cairo_matrix_to_ruby_object(matrix)) +#define RVAL2CRREGION(obj) (rb_cairo_region_from_ruby_object(obj)) +#define CRREGION2RVAL(region) (rb_cairo_region_to_ruby_object(region)) + #define RVAL2CRPATTERN(obj) (rb_cairo_pattern_from_ruby_object(obj)) #define CRPATTERN2RVAL(pattern) (rb_cairo_pattern_to_ruby_object(pattern)) @@ -206,6 +211,11 @@ VALUE rb_cairo_path_to_ruby_object (cairo_path_t *path cairo_matrix_t *rb_cairo_matrix_from_ruby_object (VALUE obj); VALUE rb_cairo_matrix_to_ruby_object (cairo_matrix_t *matrix); +#if CAIRO_CHECK_VERSION(1, 10, 0) +cairo_region_t *rb_cairo_region_from_ruby_object (VALUE obj); +VALUE rb_cairo_region_to_ruby_object (cairo_region_t *region); +#endif + cairo_pattern_t *rb_cairo_pattern_from_ruby_object (VALUE obj); VALUE rb_cairo_pattern_to_ruby_object (cairo_pattern_t *pat); @@ -276,6 +286,9 @@ VALUE rb_cairo_device_to_ruby_object (cairo_device_t *de #ifdef CAIRO_HAS_SCRIPT_SURFACE #define RVAL2CRSCRIPTMODE(obj) (rb_cairo_script_mode_from_ruby_object(obj)) #endif +#if CAIRO_CHECK_VERSION(1, 10, 0) +#define RVAL2CRREGIONOVERLAP(obj) (rb_cairo_region_overalap_from_ruby_object(obj)) +#endif cairo_operator_t rb_cairo_operator_from_ruby_object (VALUE obj); cairo_antialias_t rb_cairo_antialias_from_ruby_object (VALUE obj); @@ -311,6 +324,9 @@ cairo_text_cluster_flags_t rb_cairo_text_cluster_flags_from_ruby_object (VALUE o #ifdef CAIRO_HAS_SCRIPT_SURFACE cairo_script_mode_t rb_cairo_script_mode_from_ruby_object (VALUE obj); #endif +#if CAIRO_CHECK_VERSION(1, 10, 0) +cairo_region_overlap_t rb_cairo_region_overlap_from_ruby_object(VALUE obj); +#endif void rb_cairo_check_status (cairo_status_t status); Modified: ext/cairo/rb_cairo_constants.c (+17 -0) =================================================================== --- ext/cairo/rb_cairo_constants.c 2010-09-12 03:48:18 +0000 (3eb8f06) +++ ext/cairo/rb_cairo_constants.c 2010-09-12 03:58:54 +0000 (b63d286) @@ -38,6 +38,7 @@ VALUE rb_mCairo_TextClusterFlag = Qnil; VALUE rb_mCairo_PDFVersion = Qnil; VALUE rb_mCairo_ScriptMode = Qnil; VALUE rb_mCairo_MimeType = Qnil; +VALUE rb_mCairo_RegionOverlap = Qnil; #define CAIRO_OPERATOR_MIN CAIRO_OPERATOR_CLEAR #define CAIRO_OPERATOR_MAX CAIRO_OPERATOR_SATURATE @@ -99,6 +100,9 @@ VALUE rb_mCairo_MimeType = Qnil; #define CAIRO_SCRIPT_MODE_MIN CAIRO_SCRIPT_MODE_BINARY #define CAIRO_SCRIPT_MODE_MAX CAIRO_SCRIPT_MODE_ASCII +#define CAIRO_REGION_OVERLAP_MIN CAIRO_REGION_OVERLAP_IN +#define CAIRO_REGION_OVERLAP_MAX CAIRO_REGION_OVERLAP_PART + #define DEFINE_RVAL2ENUM(name, const_name) \ cairo_ ## name ## _t \ rb_cairo_ ## name ## _from_ruby_object (VALUE rb_ ## name) \ @@ -163,6 +167,10 @@ DEFINE_RVAL2ENUM(text_cluster_flags, TEXT_CLUSTER_FLAG) DEFINE_RVAL2ENUM(script_mode, SCRIPT_MODE) #endif +#if CAIRO_CHECK_VERSION(1, 10, 0) +DEFINE_RVAL2ENUM(region_overlap, REGION_OVERLAP) +#endif + #if defined(RB_CAIRO_PLATFORM_WIN32) && !defined(PS_LEVEL_ENUM_DEFINED) void rb_cairo_ps_level_from_ruby_object (VALUE rb_ps_level) @@ -603,5 +611,14 @@ Init_cairo_constants (void) rb_str_new2 (CAIRO_MIME_TYPE_JP2)); rb_define_const (rb_mCairo_MimeType, "URI", rb_str_new2 (CAIRO_MIME_TYPE_URI)); + + rb_mCairo_RegionOverlap = rb_define_module_under (rb_mCairo, "RegionOverlap"); + + rb_define_const (rb_mCairo_RegionOverlap, "IN", + INT2FIX (CAIRO_REGION_OVERLAP_IN)); + rb_define_const (rb_mCairo_RegionOverlap, "OUT", + INT2FIX (CAIRO_REGION_OVERLAP_OUT)); + rb_define_const (rb_mCairo_RegionOverlap, "PART", + INT2FIX (CAIRO_REGION_OVERLAP_PART)); #endif } Modified: ext/cairo/rb_cairo_private.h (+1 -0) =================================================================== --- ext/cairo/rb_cairo_private.h 2010-09-12 03:48:18 +0000 (25938f4) +++ ext/cairo/rb_cairo_private.h 2010-09-12 03:58:54 +0000 (3b9754a) @@ -50,6 +50,7 @@ extern void Init_cairo_constants (void); extern void Init_cairo_context (void); extern void Init_cairo_path (void); extern void Init_cairo_matrix (void); +extern void Init_cairo_region (void); extern void Init_cairo_device (void); extern void Init_cairo_surface (void); extern void Init_cairo_quartz_surface (void); Added: ext/cairo/rb_cairo_region.c (+385 -0) 100644 =================================================================== --- /dev/null +++ ext/cairo/rb_cairo_region.c 2010-09-12 03:58:54 +0000 (de3d3af) @@ -0,0 +1,385 @@ +/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */ +/* + * Ruby Cairo Binding + * + * Copyright 2010 Kouhei Sutou + * + * This file is made available under the same terms as Ruby + * + */ + + +#include "rb_cairo.h" +#include "rb_cairo_private.h" + +VALUE rb_cCairo_Region = Qnil; + +#if CAIRO_CHECK_VERSION(1, 10, 0) + +#define _SELF (RVAL2CRREGION(self)) + +static inline void +cr_region_check_status (cairo_region_t *region) +{ + rb_cairo_check_status (cairo_region_status (region)); +} + +cairo_region_t * +rb_cairo_region_from_ruby_object (VALUE obj) +{ + cairo_region_t *region; + if (!rb_cairo__is_kind_of (obj, rb_cCairo_Region)) + { + rb_raise (rb_eTypeError, "not a cairo region"); + } + Data_Get_Struct (obj, cairo_region_t, region); + return region; +} + +static void +cr_region_free (void *ptr) +{ + if (ptr) + { + cairo_region_destroy ((cairo_region_t *) ptr); + } +} + +VALUE +rb_cairo_region_to_ruby_object (cairo_region_t *region) +{ + if (region) + { + cairo_region_reference (region); + return Data_Wrap_Struct (rb_cCairo_Region, NULL, cr_region_free, region); + } + else + { + return Qnil; + } +} + +static VALUE +cr_region_allocate (VALUE klass) +{ + return Data_Wrap_Struct (klass, NULL, cr_region_free, NULL); +} + +static VALUE +cr_region_initialize (int argc, VALUE *argv, VALUE self) +{ + cairo_region_t *region; + + if (argc == 0) + { + region = cairo_region_create (); + } + else + { + int i; + cairo_rectangle_int_t *rectangles; + + rectangles = ALLOCA_N (cairo_rectangle_int_t, argc); + for (i = 0; i < argc; i++) + { + VALUE rb_rectangle; + + rb_rectangle = rb_check_array_type (argv[i]); + if (RARRAY_LEN (rb_rectangle) != 4) + rb_raise (rb_eArgError, + "invalid argument (expect " + "() or ([x, y, width, height], ...): %s", + rb_cairo__inspect (rb_ary_new4 (argc, argv))); + rectangles[i].x = NUM2INT (RARRAY_PTR (rb_rectangle)[0]); + rectangles[i].y = NUM2INT (RARRAY_PTR (rb_rectangle)[1]); + rectangles[i].width = NUM2INT (RARRAY_PTR (rb_rectangle)[2]); + rectangles[i].height = NUM2INT (RARRAY_PTR (rb_rectangle)[3]); + } + region = cairo_region_create_rectangles (rectangles, argc); + } + cr_region_check_status (region); + DATA_PTR (self) = region; + return Qnil; +} + +static VALUE +cr_region_dup (VALUE self) +{ + cairo_region_t *copied_region; + VALUE rb_copied_region; + + copied_region = cairo_region_copy (_SELF); + cr_region_check_status (copied_region); + rb_copied_region = CRREGION2RVAL (copied_region); + cairo_region_destroy (copied_region); + return rb_copied_region; +} + +static VALUE +cr_region_equal (VALUE self, VALUE other) +{ + cairo_region_t *region, *other_region; + + if (!rb_cairo__is_kind_of (other, rb_cCairo_Region)) + return Qfalse; + + region = _SELF; + other_region = RVAL2CRREGION (other); + return CBOOL2RVAL (cairo_region_equal (region, other_region)); +} + +static VALUE +cr_region_get_extents (VALUE self) +{ + cairo_region_t *region; + cairo_rectangle_int_t extents; + + region = _SELF; + cairo_region_get_extents (region, &extents); + cr_region_check_status (region); + return rb_ary_new3 (4, + INT2NUM (extents.x), INT2NUM (extents.y), + INT2NUM (extents.width), INT2NUM (extents.height)); +} + +static VALUE +cr_region_num_rectangles (VALUE self) +{ + cairo_region_t *region; + int num_rectangles; + + region = _SELF; + num_rectangles = cairo_region_num_rectangles (region); + cr_region_check_status (region); + return INT2NUM (num_rectangles); +} + +static VALUE +cr_region_get_rectangle (VALUE self, VALUE index) +{ + cairo_region_t *region; + cairo_rectangle_int_t extents; + + region = _SELF; + cairo_region_get_rectangle (region, NUM2INT (index), &extents); + cr_region_check_status (region); + return rb_ary_new3 (4, + INT2NUM (extents.x), INT2NUM (extents.y), + INT2NUM (extents.width), INT2NUM (extents.height)); +} + +static VALUE +cr_region_is_empty (VALUE self) +{ + return CBOOL2RVAL (cairo_region_is_empty (_SELF)); +} + +static VALUE +cr_region_containts_rectangle (int argc, VALUE *argv, VALUE self) +{ + cairo_region_t *region; + cairo_rectangle_int_t rectangle; + cairo_region_overlap_t overlap; + VALUE arg1, arg2, arg3, arg4; + const char *error_message = + "invalid argument (expect " + "(x, y, width, height) or ([x, y, width, height])): %s"; + + rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4); + + region = _SELF; + if (argc == 1) + { + VALUE rb_rectangle; + + rb_rectangle = rb_check_array_type (arg1); + if (RARRAY_LEN (rb_rectangle) != 4) + rb_raise (rb_eArgError, error_message, + rb_cairo__inspect (rb_ary_new4 (argc, argv))); + rectangle.x = NUM2INT (RARRAY_PTR (rb_rectangle)[0]); + rectangle.y = NUM2INT (RARRAY_PTR (rb_rectangle)[1]); + rectangle.width = NUM2INT (RARRAY_PTR (rb_rectangle)[2]); + rectangle.height = NUM2INT (RARRAY_PTR (rb_rectangle)[3]); + } + else if (argc == 4) + { + rectangle.x = NUM2INT (arg1); + rectangle.y = NUM2INT (arg2); + rectangle.width = NUM2INT (arg3); + rectangle.height = NUM2INT (arg4); + } + else + { + rb_raise (rb_eArgError, error_message, + rb_cairo__inspect (rb_ary_new4 (argc, argv))); + } + + overlap = cairo_region_contains_rectangle (region, &rectangle); + cr_region_check_status (region); + return INT2NUM (overlap); +} + +static VALUE +cr_region_containts_point (int argc, VALUE *argv, VALUE self) +{ + cairo_region_t *region; + int x, y; + VALUE arg1, arg2; + const char *error_message = + "invalid argument (expect " + "(x, y) or ([x, y])): %s"; + + rb_scan_args (argc, argv, "11", &arg1, &arg2); + + region = _SELF; + if (argc == 1) + { + VALUE point; + + point = rb_check_array_type (arg1); + if (RARRAY_LEN (point) != 4) + rb_raise (rb_eArgError, error_message, + rb_cairo__inspect (rb_ary_new4 (argc, argv))); + x = NUM2INT (RARRAY_PTR (point)[0]); + y = NUM2INT (RARRAY_PTR (point)[1]); + } + else + { + x = NUM2INT (arg1); + y = NUM2INT (arg2); + } + return CBOOL2RVAL (cairo_region_contains_point (region, x, y)); +} + +static VALUE +cr_region_translate (int argc, VALUE *argv, VALUE self) +{ + cairo_region_t *region; + int x, y; + VALUE arg1, arg2; + const char *error_message = + "invalid argument (expect " + "(x, y) or ([x, y])): %s"; + + rb_scan_args (argc, argv, "11", &arg1, &arg2); + + region = _SELF; + if (argc == 1) + { + VALUE point; + + point = rb_check_array_type (arg1); + if (RARRAY_LEN (point) != 4) + rb_raise (rb_eArgError, error_message, + rb_cairo__inspect (rb_ary_new4 (argc, argv))); + x = NUM2INT (RARRAY_PTR (point)[0]); + y = NUM2INT (RARRAY_PTR (point)[1]); + } + else + { + x = NUM2INT (arg1); + y = NUM2INT (arg2); + } + + cairo_region_translate (region, x, y); + cr_region_check_status (region); + return Qnil; +} + +#define DEFINE_OPERATOR(type) \ +static VALUE \ +cr_region_ ## type (int argc, VALUE *argv, VALUE self) \ +{ \ + cairo_status_t status; \ + cairo_region_t *region, *other = NULL; \ + cairo_rectangle_int_t rectangle; \ + VALUE arg1, arg2, arg3, arg4; \ + const char *error_message = \ + "invalid argument (expect " \ + "(region), (x, y, width, height) or ([x, y, width, height])): %s"; \ + \ + rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4); \ + \ + region = _SELF; \ + if (argc == 1) \ + { \ + if (rb_cairo__is_kind_of (arg1, rb_cCairo_Region)) \ + { \ + other = RVAL2CRREGION (arg1); \ + } \ + else \ + { \ + VALUE rb_rectangle; \ + \ + rb_rectangle = rb_check_array_type (arg1); \ + if (RARRAY_LEN (rb_rectangle) != 4) \ + rb_raise (rb_eArgError, error_message, \ + rb_cairo__inspect (rb_ary_new4 (argc, argv))); \ + rectangle.x = NUM2INT (RARRAY_PTR (rb_rectangle)[0]); \ + rectangle.y = NUM2INT (RARRAY_PTR (rb_rectangle)[1]); \ + rectangle.width = NUM2INT (RARRAY_PTR (rb_rectangle)[2]); \ + rectangle.height = NUM2INT (RARRAY_PTR (rb_rectangle)[3]); \ + } \ + } \ + else if (argc == 4) \ + { \ + rectangle.x = NUM2INT (arg1); \ + rectangle.y = NUM2INT (arg2); \ + rectangle.width = NUM2INT (arg3); \ + rectangle.height = NUM2INT (arg4); \ + } \ + else \ + { \ + rb_raise (rb_eArgError, error_message, \ + rb_cairo__inspect (rb_ary_new4 (argc, argv))); \ + } \ + \ + if (other) \ + status = cairo_region_ ## type (region, other); \ + else \ + status = cairo_region_ ## type ## _rectangle (region, &rectangle); \ + rb_cairo_check_status (status); \ + cr_region_check_status (region); \ + return Qnil; \ +} + +DEFINE_OPERATOR(subtract) +DEFINE_OPERATOR(intersect) +DEFINE_OPERATOR(union) +DEFINE_OPERATOR(xor) +#endif + +void +Init_cairo_region (void) +{ +#if CAIRO_CHECK_VERSION(1, 10, 0) + rb_cCairo_Region = + rb_define_class_under (rb_mCairo, "Region", rb_cObject); + + rb_define_alloc_func (rb_cCairo_Region, cr_region_allocate); + + rb_define_method (rb_cCairo_Region, "initialize", cr_region_initialize, -1); + + rb_define_method (rb_cCairo_Region, "dup", cr_region_dup, 0); + rb_define_method (rb_cCairo_Region, "==", cr_region_equal, 1); + + rb_define_method (rb_cCairo_Region, "extents", cr_region_get_extents, 0); + rb_define_method (rb_cCairo_Region, "num_rectangles", + cr_region_num_rectangles, 0); + rb_define_method (rb_cCairo_Region, "[]", + cr_region_get_rectangle, 1); + rb_define_method (rb_cCairo_Region, "empty?", cr_region_is_empty, 0); + rb_define_method (rb_cCairo_Region, "contains_rectangle", + cr_region_containts_rectangle, -1); + rb_define_method (rb_cCairo_Region, "contains_point?", + cr_region_containts_point, -1); + + rb_define_method (rb_cCairo_Region, "translate!", cr_region_translate, -1); + rb_define_method (rb_cCairo_Region, "subtract!", cr_region_subtract, -1); + rb_define_method (rb_cCairo_Region, "intersect!", cr_region_intersect, -1); + rb_define_method (rb_cCairo_Region, "union!", cr_region_union, -1); + rb_define_method (rb_cCairo_Region, "xor!", cr_region_xor, -1); + + RB_CAIRO_DEF_SETTERS (rb_cCairo_Region); +#endif +} Added: test/test_region.rb (+102 -0) 100644 =================================================================== --- /dev/null +++ test/test_region.rb 2010-09-12 03:58:54 +0000 (f7b4dd2) @@ -0,0 +1,102 @@ +class RegionTest < Test::Unit::TestCase + include CairoTestUtils + + def setup + only_cairo_version(1, 10, 0) + end + + def test_new_empty + region = Cairo::Region.new + assert_predicate(region, :empty?) + end + + def test_new_rectangle + region = Cairo::Region.new([0, 0, 10, 10]) + assert_not_predicate(region, :empty?) + end + + def test_num_rectangles + region = Cairo::Region.new + assert_equal(0, region.num_rectangles) + end + + def test_get_rectangle + region = Cairo::Region.new([0, 0, 10, 10]) + assert_equal([0, 0, 10, 10], region[0]) + end + + def test_dup + region = Cairo::Region.new([0, 0, 10, 10]) + region.dup.subtract!([5, 5, 5, 5]) + assert_equal([0, 0, 10, 10], region.extents) + end + + def test_equal + assert_equal(Cairo::Region.new([0, 0, 10, 10]), + Cairo::Region.new([0, 0, 10, 10])) + assert_not_equal(Cairo::Region.new([0, 0, 10, 10]), + Cairo::Region.new([0, 0, 100, 100])) + end + + def test_extents + region = Cairo::Region.new + assert_equal([0, 0, 0, 0], region.extents) + region.union!([0, 0, 10, 10]) + assert_equal([0, 0, 10, 10], region.extents) + end + + def test_contains_rectangle + region = Cairo::Region.new([0, 0, 10, 10]) + assert_equal(Cairo::RegionOverlap::IN, + region.contains_rectangle([2, 2, 2, 2])) + assert_equal(Cairo::RegionOverlap::OUT, + region.contains_rectangle([10, 10, 1, 1])) + assert_equal(Cairo::RegionOverlap::PART, + region.contains_rectangle([2, 2, 10, 10])) + end + + def test_contains_point + region = Cairo::Region.new([0, 0, 10, 10]) + assert_equal(true, region.contains_point?(5, 5)) + assert_equal(false, region.contains_point?(10, 10)) + end + + def test_translate + region = Cairo::Region.new([0, 0, 10, 10]) + assert_equal(true, region.contains_point?(5, 5)) + region.translate!(6, 6) + assert_equal(false, region.contains_point?(5, 5)) + end + + def test_subtract + region = Cairo::Region.new([0, 0, 10, 10]) + assert_equal(true, region.contains_point?(5, 5)) + region.subtract!([5, 5, 2, 2]) + assert_equal(false, region.contains_point?(5, 5)) + end + + def test_intersect + region = Cairo::Region.new([0, 0, 10, 10]) + assert_equal(true, region.contains_point?(5, 5)) + assert_equal(true, region.contains_point?(7, 7)) + region.intersect!([5, 5, 2, 2]) + assert_equal(true, region.contains_point?(5, 5)) + assert_equal(false, region.contains_point?(7, 7)) + end + + def test_union + region = Cairo::Region.new([0, 0, 4, 4]) + assert_equal(false, region.contains_point?(5, 5)) + region.union!([5, 5, 5, 5]) + assert_equal(true, region.contains_point?(5, 5)) + end + + def test_xor + region = Cairo::Region.new([0, 0, 5, 5]) + assert_equal(true, region.contains_point?(4, 4)) + assert_equal(false, region.contains_point?(7, 7)) + region.xor!([3, 3, 5, 5]) + assert_equal(false, region.contains_point?(4, 4)) + assert_equal(true, region.contains_point?(7, 7)) + end +end From null+rcairo at clear-code.com Sat Sep 11 23:48:18 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 03:48:18 +0000 Subject: [cairo-commit:00065] rcairo/rcairo [master] use test-unit gem. Message-ID: <20100912035907.4D2FA170F31@taiyaki.ru> Kouhei Sutou 2010-09-12 03:48:18 +0000 (Sun, 12 Sep 2010) New Revision: 4144355655a12ad4671b13600de0f78159b5f69a Log: use test-unit gem. Removed files: test-unit/History.txt test-unit/Manifest.txt test-unit/README.txt test-unit/Rakefile test-unit/bin/testrb test-unit/lib/test/unit.rb test-unit/lib/test/unit/assertionfailederror.rb test-unit/lib/test/unit/assertions.rb test-unit/lib/test/unit/attribute.rb test-unit/lib/test/unit/autorunner.rb test-unit/lib/test/unit/collector.rb test-unit/lib/test/unit/collector/descendant.rb test-unit/lib/test/unit/collector/dir.rb test-unit/lib/test/unit/collector/load.rb test-unit/lib/test/unit/collector/objectspace.rb test-unit/lib/test/unit/color.rb test-unit/lib/test/unit/diff.rb test-unit/lib/test/unit/error.rb test-unit/lib/test/unit/exceptionhandler.rb test-unit/lib/test/unit/failure.rb test-unit/lib/test/unit/fixture.rb test-unit/lib/test/unit/notification.rb test-unit/lib/test/unit/omission.rb test-unit/lib/test/unit/pending.rb test-unit/lib/test/unit/priority.rb test-unit/lib/test/unit/runner/console.rb test-unit/lib/test/unit/runner/emacs.rb test-unit/lib/test/unit/testcase.rb test-unit/lib/test/unit/testresult.rb test-unit/lib/test/unit/testsuite.rb test-unit/lib/test/unit/ui/console/outputlevel.rb test-unit/lib/test/unit/ui/console/testrunner.rb test-unit/lib/test/unit/ui/emacs/testrunner.rb test-unit/lib/test/unit/ui/testrunner.rb test-unit/lib/test/unit/ui/testrunnermediator.rb test-unit/lib/test/unit/ui/testrunnerutilities.rb test-unit/lib/test/unit/util/backtracefilter.rb test-unit/lib/test/unit/util/observable.rb test-unit/lib/test/unit/util/procwrapper.rb test-unit/lib/test/unit/version.rb test-unit/sample/adder.rb test-unit/sample/subtracter.rb test-unit/sample/tc_adder.rb test-unit/sample/tc_subtracter.rb test-unit/sample/ts_examples.rb test-unit/test/collector/test_descendant.rb test-unit/test/collector/test_dir.rb test-unit/test/collector/test_load.rb test-unit/test/collector/test_objectspace.rb test-unit/test/run-test.rb test-unit/test/test_assertions.rb test-unit/test/test_attribute.rb test-unit/test/test_color.rb test-unit/test/test_diff.rb test-unit/test/test_emacs_runner.rb test-unit/test/test_error.rb test-unit/test/test_failure.rb test-unit/test/test_fixture.rb test-unit/test/test_notification.rb test-unit/test/test_omission.rb test-unit/test/test_pending.rb test-unit/test/test_priority.rb test-unit/test/test_testcase.rb test-unit/test/test_testresult.rb test-unit/test/test_testsuite.rb test-unit/test/testunit_test_util.rb test-unit/test/ui/test_testrunmediator.rb test-unit/test/util/test_backtracefilter.rb test-unit/test/util/test_observable.rb test-unit/test/util/test_procwrapper.rb Modified files: test/run-test.rb Deleted: test-unit/History.txt (+0 -32) 100644 =================================================================== --- test-unit/History.txt 2010-09-12 03:03:44 +0000 (a142f78) +++ /dev/null @@ -1,32 +0,0 @@ -=== 2.0.0 / 2008-06-18 - -* 15 major enhancements - - * support startup/shutdown. (test case level setup/teardown) - * support multiple setup/teardown. - * support pending. - * support omission. - * support notification. - * support colorize. - * support diff. - * support test attribute. - * add assert_boolean. - * add assert_true. - * add assert_false. - * add --priority-mode option. - * don't use ObjectSpace to collect test cases. - * make more customizable. (additional options, exception handling and so on) - * improve Emacs integration. - -* 4 major changes - - * remove GTK+1 support. - * split GTK+ runner as another gem. - * split FOX runner as another gem. - * split Tk runner as another gem. - -=== 1.2.3 / 2008-02-25 - -* 1 major enhancement - - * Birthday (as a gem)! Deleted: test-unit/Manifest.txt (+0 -70) 100644 =================================================================== --- test-unit/Manifest.txt 2010-09-12 03:03:44 +0000 (9d0f112) +++ /dev/null @@ -1,70 +0,0 @@ -History.txt -Manifest.txt -README.txt -Rakefile -bin/testrb -lib/test/unit.rb -lib/test/unit/assertionfailederror.rb -lib/test/unit/assertions.rb -lib/test/unit/attribute.rb -lib/test/unit/autorunner.rb -lib/test/unit/collector.rb -lib/test/unit/collector/descendant.rb -lib/test/unit/collector/dir.rb -lib/test/unit/collector/load.rb -lib/test/unit/collector/objectspace.rb -lib/test/unit/color.rb -lib/test/unit/diff.rb -lib/test/unit/error.rb -lib/test/unit/exceptionhandler.rb -lib/test/unit/failure.rb -lib/test/unit/fixture.rb -lib/test/unit/notification.rb -lib/test/unit/omission.rb -lib/test/unit/pending.rb -lib/test/unit/priority.rb -lib/test/unit/runner/console.rb -lib/test/unit/runner/emacs.rb -lib/test/unit/testcase.rb -lib/test/unit/testresult.rb -lib/test/unit/testsuite.rb -lib/test/unit/ui/console/outputlevel.rb -lib/test/unit/ui/console/testrunner.rb -lib/test/unit/ui/emacs/testrunner.rb -lib/test/unit/ui/testrunner.rb -lib/test/unit/ui/testrunnermediator.rb -lib/test/unit/ui/testrunnerutilities.rb -lib/test/unit/util/backtracefilter.rb -lib/test/unit/util/observable.rb -lib/test/unit/util/procwrapper.rb -lib/test/unit/version.rb -sample/adder.rb -sample/subtracter.rb -sample/tc_adder.rb -sample/tc_subtracter.rb -sample/ts_examples.rb -test/collector/test_descendant.rb -test/collector/test_dir.rb -test/collector/test_load.rb -test/collector/test_objectspace.rb -test/run-test.rb -test/test_assertions.rb -test/test_attribute.rb -test/test_color.rb -test/test_diff.rb -test/test_emacs_runner.rb -test/test_error.rb -test/test_failure.rb -test/test_fixture.rb -test/test_notification.rb -test/test_omission.rb -test/test_pending.rb -test/test_priority.rb -test/test_testcase.rb -test/test_testresult.rb -test/test_testsuite.rb -test/testunit_test_util.rb -test/ui/test_testrunmediator.rb -test/util/test_backtracefilter.rb -test/util/test_observable.rb -test/util/test_procwrapper.rb Deleted: test-unit/README.txt (+0 -32) 100644 =================================================================== --- test-unit/README.txt 2010-09-12 03:03:44 +0000 (2b58f1f) +++ /dev/null @@ -1,32 +0,0 @@ -= Test::Unit (Classic) - -* http://rubyforge.org/projects/test-unit/ - -== DESCRIPTION: - -Test::Unit (Classic) - Nathaniel Talbott's originial test-unit, -externalized from the ruby project as a gem (for tool developers). - -== FEATURES/PROBLEMS: - -* Test::Unit 1.2.3 is the original Test::Unit, taken - straight from the ruby distribution. It is being - distributed as a gem to allow tool builders to use it as a - stand-alone package. (The test framework in ruby is going - to radically change very soon). - -* DO NOT INSTALL THIS GEM unless you're active state or some other - development tool provider! You don't need it. - -* Test::Unit 2.0.0 or later are extended versions of the - original Test::Unit (== Tset::Unit 1.2.3). - -== INSTALL: - -* sudo gem install test-unit - -== LICENSE: - -(The Ruby License) - -This software is distributed under the same terms as ruby. Deleted: test-unit/Rakefile (+0 -30) 100644 =================================================================== --- test-unit/Rakefile 2010-09-12 03:03:44 +0000 (2408ca6) +++ /dev/null @@ -1,30 +0,0 @@ -# -*- ruby -*- - -require 'rubygems' -require 'hoe' -require './lib/test/unit/version.rb' - -version = Test::Unit::VERSION -ENV["VERSION"] = version -Hoe.new('test-unit', version) do |p| - p.developer('Kouhei Sutou', 'kou at cozmixng.org') - p.developer('Ryan Davis', 'ryand-ruby at zenspider.com') - - # Ex-Parrot: - # p.developer('Nathaniel Talbott', 'nathaniel at talbott.ws') -end - -task :check_manifest => :clean_test_result - -task :clean_test_result do - test_results = Dir.glob("**/.test-result") - sh("rm", "-rf", *test_results) unless test_results.empty? -end - -task :tag do - message = "Released Test::Unit #{version}!" - base = "svn+ssh://#{ENV['USER']}@rubyforge.org/var/svn/test-unit/" - sh 'svn', 'copy', '-m', message, "#{base}trunk", "#{base}tags/#{version}" -end - -# vim: syntax=Ruby Deleted: test-unit/bin/testrb (+0 -5) 100755 =================================================================== --- test-unit/bin/testrb 2010-09-12 03:03:44 +0000 (ff49cb5) +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env ruby -require 'test/unit' -(r = Test::Unit::AutoRunner.new(true)).process_args(ARGV) or - abort r.options.banner + " tests..." -exit r.run Deleted: test-unit/lib/test/unit.rb (+0 -280) 100644 =================================================================== --- test-unit/lib/test/unit.rb 2010-09-12 03:03:44 +0000 (b71f644) +++ /dev/null @@ -1,280 +0,0 @@ -require 'test/unit/testcase' -require 'test/unit/autorunner' - -module Test # :nodoc: - # - # = Test::Unit - Ruby Unit Testing Framework - # - # == Introduction - # - # Unit testing is making waves all over the place, largely due to the - # fact that it is a core practice of XP. While XP is great, unit testing - # has been around for a long time and has always been a good idea. One - # of the keys to good unit testing, though, is not just writing tests, - # but having tests. What's the difference? Well, if you just _write_ a - # test and throw it away, you have no guarantee that something won't - # change later which breaks your code. If, on the other hand, you _have_ - # tests (obviously you have to write them first), and run them as often - # as possible, you slowly build up a wall of things that cannot break - # without you immediately knowing about it. This is when unit testing - # hits its peak usefulness. - # - # Enter Test::Unit, a framework for unit testing in Ruby, helping you to - # design, debug and evaluate your code by making it easy to write and - # have tests for it. - # - # - # == Notes - # - # Test::Unit has grown out of and superceded Lapidary. - # - # - # == Feedback - # - # I like (and do my best to practice) XP, so I value early releases, - # user feedback, and clean, simple, expressive code. There is always - # room for improvement in everything I do, and Test::Unit is no - # exception. Please, let me know what you think of Test::Unit as it - # stands, and what you'd like to see expanded/changed/improved/etc. If - # you find a bug, let me know ASAP; one good way to let me know what the - # bug is is to submit a new test that catches it :-) Also, I'd love to - # hear about any successes you have with Test::Unit, and any - # documentation you might add will be greatly appreciated. My contact - # info is below. - # - # - # == Contact Information - # - # A lot of discussion happens about Ruby in general on the ruby-talk - # mailing list (http://www.ruby-lang.org/en/ml.html), and you can ask - # any questions you might have there. I monitor the list, as do many - # other helpful Rubyists, and you're sure to get a quick answer. Of - # course, you're also welcome to email me (Nathaniel Talbott) directly - # at mailto:testunit at talbott.ws, and I'll do my best to help you out. - # - # - # == Credits - # - # I'd like to thank... - # - # Matz, for a great language! - # - # Masaki Suketa, for his work on RubyUnit, which filled a vital need in - # the Ruby world for a very long time. I'm also grateful for his help in - # polishing Test::Unit and getting the RubyUnit compatibility layer - # right. His graciousness in allowing Test::Unit to supercede RubyUnit - # continues to be a challenge to me to be more willing to defer my own - # rights. - # - # Ken McKinlay, for his interest and work on unit testing, and for his - # willingness to dialog about it. He was also a great help in pointing - # out some of the holes in the RubyUnit compatibility layer. - # - # Dave Thomas, for the original idea that led to the extremely simple - # "require 'test/unit'", plus his code to improve it even more by - # allowing the selection of tests from the command-line. Also, without - # RDoc, the documentation for Test::Unit would stink a lot more than it - # does now. - # - # Everyone who's helped out with bug reports, feature ideas, - # encouragement to continue, etc. It's a real privilege to be a part of - # the Ruby community. - # - # The guys at RoleModel Software, for putting up with me repeating, "But - # this would be so much easier in Ruby!" whenever we're coding in Java. - # - # My Creator, for giving me life, and giving it more abundantly. - # - # - # == License - # - # Test::Unit is copyright (c) 2000-2003 Nathaniel Talbott. It is free - # software, and is distributed under the Ruby license. See the COPYING - # file in the standard Ruby distribution for details. - # - # - # == Warranty - # - # This software is provided "as is" and without any express or - # implied warranties, including, without limitation, the implied - # warranties of merchantibility and fitness for a particular - # purpose. - # - # - # == Author - # - # Nathaniel Talbott. - # Copyright (c) 2000-2003, Nathaniel Talbott - # - # ---- - # - # = Usage - # - # The general idea behind unit testing is that you write a _test_ - # _method_ that makes certain _assertions_ about your code, working - # against a _test_ _fixture_. A bunch of these _test_ _methods_ are - # bundled up into a _test_ _suite_ and can be run any time the - # developer wants. The results of a run are gathered in a _test_ - # _result_ and displayed to the user through some UI. So, lets break - # this down and see how Test::Unit provides each of these necessary - # pieces. - # - # - # == Assertions - # - # These are the heart of the framework. Think of an assertion as a - # statement of expected outcome, i.e. "I assert that x should be equal - # to y". If, when the assertion is executed, it turns out to be - # correct, nothing happens, and life is good. If, on the other hand, - # your assertion turns out to be false, an error is propagated with - # pertinent information so that you can go back and make your - # assertion succeed, and, once again, life is good. For an explanation - # of the current assertions, see Test::Unit::Assertions. - # - # - # == Test Method & Test Fixture - # - # Obviously, these assertions have to be called within a context that - # knows about them and can do something meaningful with their - # pass/fail value. Also, it's handy to collect a bunch of related - # tests, each test represented by a method, into a common test class - # that knows how to run them. The tests will be in a separate class - # from the code they're testing for a couple of reasons. First of all, - # it allows your code to stay uncluttered with test code, making it - # easier to maintain. Second, it allows the tests to be stripped out - # for deployment, since they're really there for you, the developer, - # and your users don't need them. Third, and most importantly, it - # allows you to set up a common test fixture for your tests to run - # against. - # - # What's a test fixture? Well, tests do not live in a vacuum; rather, - # they're run against the code they are testing. Often, a collection - # of tests will run against a common set of data, also called a - # fixture. If they're all bundled into the same test class, they can - # all share the setting up and tearing down of that data, eliminating - # unnecessary duplication and making it much easier to add related - # tests. - # - # Test::Unit::TestCase wraps up a collection of test methods together - # and allows you to easily set up and tear down the same test fixture - # for each test. This is done by overriding #setup and/or #teardown, - # which will be called before and after each test method that is - # run. The TestCase also knows how to collect the results of your - # assertions into a Test::Unit::TestResult, which can then be reported - # back to you... but I'm getting ahead of myself. To write a test, - # follow these steps: - # - # * Make sure Test::Unit is in your library path. - # * require 'test/unit' in your test script. - # * Create a class that subclasses Test::Unit::TestCase. - # * Add a method that begins with "test" to your class. - # * Make assertions in your test method. - # * Optionally define #setup and/or #teardown to set up and/or tear - # down your common test fixture. - # * You can now run your test as you would any other Ruby - # script... try it and see! - # - # A really simple test might look like this (#setup and #teardown are - # commented out to indicate that they are completely optional): - # - # require 'test/unit' - # - # class TC_MyTest < Test::Unit::TestCase - # # def setup - # # end - # - # # def teardown - # # end - # - # def test_fail - # assert(false, 'Assertion was false.') - # end - # end - # - # - # == Test Runners - # - # So, now you have this great test class, but you still need a way to - # run it and view any failures that occur during the run. This is - # where Test::Unit::UI::Console::TestRunner (and others, such as - # Test::Unit::UI::GTK::TestRunner) comes into play. The console test - # runner is automatically invoked for you if you require 'test/unit' - # and simply run the file. To use another runner, or to manually - # invoke a runner, simply call its run class method and pass in an - # object that responds to the suite message with a - # Test::Unit::TestSuite. This can be as simple as passing in your - # TestCase class (which has a class suite method). It might look - # something like this: - # - # require 'test/unit/ui/console/testrunner' - # Test::Unit::UI::Console::TestRunner.run(TC_MyTest) - # - # - # == Test Suite - # - # As more and more unit tests accumulate for a given project, it - # becomes a real drag running them one at a time, and it also - # introduces the potential to overlook a failing test because you - # forget to run it. Suddenly it becomes very handy that the - # TestRunners can take any object that returns a Test::Unit::TestSuite - # in response to a suite method. The TestSuite can, in turn, contain - # other TestSuites or individual tests (typically created by a - # TestCase). In other words, you can easily wrap up a group of - # TestCases and TestSuites like this: - # - # require 'test/unit/testsuite' - # require 'tc_myfirsttests' - # require 'tc_moretestsbyme' - # require 'ts_anothersetoftests' - # - # class TS_MyTests - # def self.suite - # suite = Test::Unit::TestSuite.new - # suite << TC_MyFirstTests.suite - # suite << TC_MoreTestsByMe.suite - # suite << TS_AnotherSetOfTests.suite - # return suite - # end - # end - # Test::Unit::UI::Console::TestRunner.run(TS_MyTests) - # - # Now, this is a bit cumbersome, so Test::Unit does a little bit more - # for you, by wrapping these up automatically when you require - # 'test/unit'. What does this mean? It means you could write the above - # test case like this instead: - # - # require 'test/unit' - # require 'tc_myfirsttests' - # require 'tc_moretestsbyme' - # require 'ts_anothersetoftests' - # - # Test::Unit is smart enough to find all the test cases existing in - # the ObjectSpace and wrap them up into a suite for you. It then runs - # the dynamic suite using the console TestRunner. - # - # - # == Questions? - # - # I'd really like to get feedback from all levels of Ruby - # practitioners about typos, grammatical errors, unclear statements, - # missing points, etc., in this document (or any other). - # - - module Unit - # If set to false Test::Unit will not automatically run at exit. - def self.run=(flag) - @run = flag - end - - # Automatically run tests at exit? - def self.run? - @run ||= false - end - end -end - -at_exit do - unless $! || Test::Unit.run? - exit Test::Unit::AutoRunner.run - end -end Deleted: test-unit/lib/test/unit/assertionfailederror.rb (+0 -14) 100644 =================================================================== --- test-unit/lib/test/unit/assertionfailederror.rb 2010-09-12 03:03:44 +0000 (a21e4b5) +++ /dev/null @@ -1,14 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -module Test - module Unit - - # Thrown by Test::Unit::Assertions when an assertion fails. - class AssertionFailedError < StandardError - end - end -end Deleted: test-unit/lib/test/unit/assertions.rb (+0 -722) 100644 =================================================================== --- test-unit/lib/test/unit/assertions.rb 2010-09-12 03:03:44 +0000 (635d36a) +++ /dev/null @@ -1,722 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/assertionfailederror' -require 'test/unit/util/backtracefilter' -require 'test/unit/diff' - -module Test - module Unit - - ## - # Test::Unit::Assertions contains the standard Test::Unit assertions. - # Assertions is included in Test::Unit::TestCase. - # - # To include it in your own code and use its functionality, you simply - # need to rescue Test::Unit::AssertionFailedError. Additionally you may - # override add_assertion to get notified whenever an assertion is made. - # - # Notes: - # * The message to each assertion, if given, will be propagated with the - # failure. - # * It is easy to add your own assertions based on assert_block(). - # - # = Example Custom Assertion - # - # def deny(boolean, message = nil) - # message = build_message message, ' is not false or nil.', boolean - # assert_block message do - # not boolean - # end - # end - - module Assertions - - ## - # The assertion upon which all other assertions are based. Passes if the - # block yields true. - # - # Example: - # assert_block "Couldn't do the thing" do - # do_the_thing - # end - - public - def assert_block(message="assert_block failed.") # :yields: - _wrap_assertion do - if (! yield) - raise AssertionFailedError.new(message.to_s) - end - end - end - - ## - # Asserts that +boolean+ is not false or nil. - # - # Example: - # assert [1, 2].include?(5) - - public - def assert(boolean, message=nil) - _wrap_assertion do - assert_block("assert should not be called with a block.") { !block_given? } - assert_block(build_message(message, " is not true.", boolean)) { boolean } - end - end - - ## - # Passes if +expected+ == +actual. - # - # Note that the ordering of arguments is important, since a helpful - # error message is generated when this one fails that tells you the - # values of expected and actual. - # - # Example: - # assert_equal 'MY STRING', 'my string'.upcase - - public - def assert_equal(expected, actual, message=nil) - diff = AssertionMessage.delayed_literal do - if !expected.is_a?(String) or !actual.is_a?(String) - expected = AssertionMessage.convert(expected) - actual = AssertionMessage.convert(actual) - end - diff = Diff.readable(expected, actual) - if /^[-+]/ !~ diff - diff = "" - elsif /^[ ?]/ =~ diff or /(?:.*\n){2,}/ =~ diff - diff = "\n\ndiff:\n#{diff}" - else - diff = "" - end - diff - end - full_message = build_message(message, < expected but was -.? -EOT - assert_block(full_message) { expected == actual } - end - - private - def _check_exception_class(args) # :nodoc: - args.partition do |klass| - next if klass.instance_of?(Module) - assert(Exception >= klass, "Should expect a class of exception, #{klass}") - true - end - end - - private - def _expected_exception?(actual_exception, exceptions, modules) # :nodoc: - exceptions.include?(actual_exception.class) or - modules.any? {|mod| actual_exception.is_a?(mod)} - end - - ## - # Passes if the block raises one of the given exceptions. - # - # Example: - # assert_raise RuntimeError, LoadError do - # raise 'Boom!!!' - # end - - public - def assert_raise(*args) - _wrap_assertion do - if Module === args.last - message = "" - else - message = args.pop - end - exceptions, modules = _check_exception_class(args) - expected = args.size == 1 ? args.first : args - actual_exception = nil - full_message = build_message(message, " exception expected but none was thrown.", expected) - assert_block(full_message) do - begin - yield - rescue Exception => actual_exception - break - end - false - end - full_message = build_message(message, " exception expected but was\n?", expected, actual_exception) - assert_block(full_message) {_expected_exception?(actual_exception, exceptions, modules)} - actual_exception - end - end - - ## - # Alias of assert_raise. - # - # Will be deprecated in 1.9, and removed in 2.0. - - public - def assert_raises(*args, &block) - assert_raise(*args, &block) - end - - ## - # Passes if +object+ .instance_of? +klass+ - # - # Example: - # assert_instance_of String, 'foo' - - public - def assert_instance_of(klass, object, message="") - _wrap_assertion do - assert_equal(Class, klass.class, "assert_instance_of takes a Class as its first argument") - full_message = build_message(message, < expected to be an instance of - but was -. -EOT - assert_block(full_message){object.instance_of?(klass)} - end - end - - ## - # Passes if +object+ is nil. - # - # Example: - # assert_nil [1, 2].uniq! - - public - def assert_nil(object, message="") - full_message = build_message(message, < expected to be nil. -EOT - assert_block(full_message) { object.nil? } - end - - ## - # Passes if +object+ .kind_of? +klass+ - # - # Example: - # assert_kind_of Object, 'foo' - - public - def assert_kind_of(klass, object, message="") - _wrap_assertion do - assert(klass.kind_of?(Module), "The first parameter to assert_kind_of should be a kind_of Module.") - full_message = build_message(message, "\nexpected to be kind_of\\?\n but was\n.", object, klass, object.class) - assert_block(full_message){object.kind_of?(klass)} - end - end - - ## - # Passes if +object+ .respond_to? +method+ - # - # Example: - # assert_respond_to 'bugbear', :slice - - public - def assert_respond_to(object, method, message="") - _wrap_assertion do - full_message = build_message(nil, "\ngiven as the method name argument to #assert_respond_to must be a Symbol or #respond_to\\?(:to_str).", method) - - assert_block(full_message) do - method.kind_of?(Symbol) || method.respond_to?(:to_str) - end - full_message = build_message(message, < -of type -expected to respond_to\\?. -EOT - assert_block(full_message) { object.respond_to?(method) } - end - end - - ## - # Passes if +string+ =~ +pattern+. - # - # Example: - # assert_match(/\d+/, 'five, 6, seven') - - public - def assert_match(pattern, string, message="") - _wrap_assertion do - pattern = case(pattern) - when String - Regexp.new(Regexp.escape(pattern)) - else - pattern - end - full_message = build_message(message, " expected to be =~\n.", string, pattern) - assert_block(full_message) { string =~ pattern } - end - end - - ## - # Passes if +actual+ .equal? +expected+ (i.e. they are the same - # instance). - # - # Example: - # o = Object.new - # assert_same o, o - - public - def assert_same(expected, actual, message="") - full_message = build_message(message, < -with id expected to be equal\\? to - -with id . -EOT - assert_block(full_message) { actual.equal?(expected) } - end - - ## - # Compares the +object1+ with +object2+ using +operator+. - # - # Passes if object1.__send__(operator, object2) is true. - # - # Example: - # assert_operator 5, :>=, 4 - - public - def assert_operator(object1, operator, object2, message="") - _wrap_assertion do - full_message = build_message(nil, "\ngiven as the operator for #assert_operator must be a Symbol or #respond_to\\?(:to_str).", operator) - assert_block(full_message){operator.kind_of?(Symbol) || operator.respond_to?(:to_str)} - full_message = build_message(message, < expected to be -? -. -EOT - assert_block(full_message) { object1.__send__(operator, object2) } - end - end - - ## - # Passes if block does not raise an exception. - # - # Example: - # assert_nothing_raised do - # [1, 2].uniq - # end - - public - def assert_nothing_raised(*args) - _wrap_assertion do - if Module === args.last - message = "" - else - message = args.pop - end - exceptions, modules = _check_exception_class(args) - begin - yield - rescue Exception => e - if ((args.empty? && !e.instance_of?(AssertionFailedError)) || - _expected_exception?(e, exceptions, modules)) - assert_block(build_message(message, "Exception raised:\n?", e)){false} - else - raise - end - end - nil - end - end - - ## - # Flunk always fails. - # - # Example: - # flunk 'Not done testing yet.' - - public - def flunk(message="Flunked") - assert_block(build_message(message)){false} - end - - ## - # Passes if ! +actual+ .equal? +expected+ - # - # Example: - # assert_not_same Object.new, Object.new - - public - def assert_not_same(expected, actual, message="") - full_message = build_message(message, < -with id expected to not be equal\\? to - -with id . -EOT - assert_block(full_message) { !actual.equal?(expected) } - end - - ## - # Passes if +expected+ != +actual+ - # - # Example: - # assert_not_equal 'some string', 5 - - public - def assert_not_equal(expected, actual, message="") - full_message = build_message(message, " expected to be != to\n.", expected, actual) - assert_block(full_message) { expected != actual } - end - - ## - # Passes if ! +object+ .nil? - # - # Example: - # assert_not_nil '1 two 3'.sub!(/two/, '2') - - public - def assert_not_nil(object, message="") - full_message = build_message(message, " expected to not be nil.", object) - assert_block(full_message){!object.nil?} - end - - ## - # Passes if +regexp+ !~ +string+ - # - # Example: - # assert_no_match(/two/, 'one 2 three') - - public - def assert_no_match(regexp, string, message="") - _wrap_assertion do - assert_instance_of(Regexp, regexp, "The first argument to assert_no_match should be a Regexp.") - full_message = build_message(message, " expected to not match\n.", regexp, string) - assert_block(full_message) { regexp !~ string } - end - end - - UncaughtThrow = { - NameError => /^uncaught throw \`(.+)\'$/, - ArgumentError => /^uncaught throw (.+)$/, - ThreadError => /^uncaught throw \`(.+)\' in thread / - } #` - - ## - # Passes if the block throws +expected_object+ - # - # Example: - # assert_throws :done do - # throw :done - # end - - public - def assert_throws(expected_object, message="", &proc) - _wrap_assertion do - begin - catch([]) {} - rescue TypeError - assert_instance_of(Symbol, expected_object, - "assert_throws expects the symbol that should be thrown for its first argument") - end - assert_block("Should have passed a block to assert_throws.") do - block_given? - end - caught = true - begin - catch(expected_object) do - proc.call - caught = false - end - full_message = build_message(message, - " should have been thrown.", - expected_object) - assert_block(full_message) {caught} - rescue NameError, ArgumentError, ThreadError => error - raise unless UncaughtThrow[error.class] =~ error.message - tag = $1 - tag = tag[1..-1].intern if tag[0, 1] == ":" - full_message = build_message(message, - " expected to be thrown but\n" + - " was thrown.", - expected_object, tag) - flunk(full_message) - end - end - end - - ## - # Passes if block does not throw anything. - # - # Example: - # assert_nothing_thrown do - # [1, 2].uniq - # end - - public - def assert_nothing_thrown(message="", &proc) - _wrap_assertion do - assert(block_given?, "Should have passed a block to assert_nothing_thrown") - begin - proc.call - rescue NameError, ArgumentError, ThreadError => error - raise unless UncaughtThrow[error.class] =~ error.message - tag = $1 - tag = tag[1..-1].intern if tag[0, 1] == ":" - full_message = build_message(message, - " was thrown when nothing was expected", - tag) - flunk(full_message) - end - assert(true, "Expected nothing to be thrown") - end - end - - ## - # Passes if +expected_float+ and +actual_float+ are equal - # within +delta+ tolerance. - # - # Example: - # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001 - - public - def assert_in_delta(expected_float, actual_float, delta, message="") - _wrap_assertion do - {expected_float => "first float", actual_float => "second float", delta => "delta"}.each do |float, name| - assert_respond_to(float, :to_f, "The arguments must respond to to_f; the #{name} did not") - end - assert_operator(delta, :>=, 0.0, "The delta should not be negative") - full_message = build_message(message, < and - expected to be within - of each other. -EOT - assert_block(full_message) { (expected_float.to_f - actual_float.to_f).abs <= delta.to_f } - end - end - - ## - # Passes if the method send returns a true value. - # - # +send_array+ is composed of: - # * A receiver - # * A method - # * Arguments to the method - # - # Example: - # assert_send [[1, 2], :include?, 4] - - public - def assert_send(send_array, message="") - _wrap_assertion do - assert_instance_of(Array, send_array, "assert_send requires an array of send information") - assert(send_array.size >= 2, "assert_send requires at least a receiver and a message name") - full_message = build_message(message, < expected to respond to - with a true value. -EOT - assert_block(full_message) { send_array[0].__send__(send_array[1], *send_array[2..-1]) } - end - end - - ## - # Passes if +actual+ is a boolean value. - # - # Example: - # assert_boolean(true) # -> pass - # assert_boolean(nil) # -> fail - def assert_boolean(actual, message=nil) - _wrap_assertion do - assert_block(build_message(message, - " or expected but was\n", - actual)) do - [true, false].include?(actual) - end - end - end - - ## - # Passes if +actual+ is true. - # - # Example: - # assert_true(true) # -> pass - # assert_true(:true) # -> fail - def assert_true(actual, message=nil) - _wrap_assertion do - assert_block(build_message(message, - " expected but was\n", - actual)) do - actual == true - end - end - end - - ## - # Passes if +actual+ is false. - # - # Example: - # assert_false(false) # -> pass - # assert_false(nil) # -> fail - def assert_false(actual, message=nil) - _wrap_assertion do - assert_block(build_message(message, - " expected but was\n", - actual)) do - actual == false - end - end - end - - ## - # Builds a failure message. +head+ is added before the +template+ and - # +arguments+ replaces the '?'s positionally in the template. - - public - def build_message(head, template=nil, *arguments) - template &&= template.chomp - return AssertionMessage.new(head, template, arguments) - end - - private - def _wrap_assertion - @_assertion_wrapped ||= false - unless (@_assertion_wrapped) - @_assertion_wrapped = true - begin - add_assertion - return yield - ensure - @_assertion_wrapped = false - end - else - return yield - end - end - - ## - # Called whenever an assertion is made. Define this in classes that - # include Test::Unit::Assertions to record assertion counts. - - private - def add_assertion - end - - ## - # Select whether or not to use the pretty-printer. If this option is set - # to false before any assertions are made, pp.rb will not be required. - - public - def self.use_pp=(value) - AssertionMessage.use_pp = value - end - - # :stopdoc: - - class AssertionMessage - @use_pp = true - class << self - attr_accessor :use_pp - - def literal(value) - Literal.new(value) - end - - def delayed_literal(&block) - DelayedLiteral.new(block) - end - - def convert(object) - case object - when Exception - < -Message: <#{convert(object.message)}> ----Backtrace--- -#{Util::BacktraceFilter.filter_backtrace(object.backtrace).join("\n")} ---------------- -EOM - else - if use_pp - begin - require 'pp' unless defined?(PP) - return PP.pp(object, '').chomp - rescue LoadError - self.use_pp = false - end - end - object.inspect - end - end - end - - class Literal - def initialize(value) - @value = value - end - - def inspect - @value.to_s - end - end - - class DelayedLiteral - def initialize(value) - @value = value - end - - def inspect - @value.call.to_s - end - end - - class Template - def self.create(string) - parts = (string ? string.scan(/(?=[^\\])\?|(?:\\\?|[^\?])+/m) : []) - self.new(parts) - end - - attr_reader :count - - def initialize(parts) - @parts = parts - @count = parts.find_all{|e| e == '?'}.size - end - - def result(parameters) - raise "The number of parameters does not match the number of substitutions." if(parameters.size != count) - params = parameters.dup - @parts.collect{|e| e == '?' ? params.shift : e.gsub(/\\\?/m, '?')}.join('') - end - end - - include Util::BacktraceFilter - - def initialize(head, template_string, parameters) - @head = head - @template_string = template_string - @parameters = parameters - end - - def convert(object) - self.class.convert(object) - end - - def template - @template ||= Template.create(@template_string) - end - - def add_period(string) - (string =~ /\.\Z/ ? string : string + '.') - end - - def to_s - message_parts = [] - if (@head) - head = @head.to_s - unless(head.empty?) - message_parts << add_period(head) - end - end - tail = template.result(@parameters.collect{|e| convert(e)}) - message_parts << tail unless(tail.empty?) - message_parts.join("\n") - end - end - - # :startdoc: - - end - end -end Deleted: test-unit/lib/test/unit/attribute.rb (+0 -125) 100644 =================================================================== --- test-unit/lib/test/unit/attribute.rb 2010-09-12 03:03:44 +0000 (35e362f) +++ /dev/null @@ -1,125 +0,0 @@ -module Test - module Unit - module Attribute - class << self - def included(base) - base.extend(BaseClassMethods) - base.extend(ClassMethods) - end - end - - module BaseClassMethods - def attributes_table - {} - end - end - - module ClassMethods - def method_added(name) - super - return unless defined?(@current_attributes) - - attributes = {} - kept_attributes = {} - @current_attributes.each do |attribute_name, attribute| - attributes[attribute_name] = attribute[:value] - kept_attributes[attribute_name] = attribute if attribute[:keep] - end - set_attributes(name, attributes) - @current_attributes = kept_attributes - end - - def attribute(name, value, options={}, *method_names) - unless options.is_a?(Hash) - method_names << options - options = {} - end - @current_attributes ||= {} - if method_names.empty? - @current_attributes[name] = options.merge(:value => value) - else - method_names.each do |method_name| - set_attributes(method_name, {name => value}) - end - end - end - - def attributes_table - @attributes_table ||= {} - super.merge(@attributes_table) - end - - def set_attributes(method_name, new_attributes) - return if new_attributes.empty? - method_name = normalize_method_name(method_name) - @attributes_table ||= {} - @attributes_table[method_name] ||= {} - current_attributes = @attributes_table[method_name] - new_attributes.each do |key, value| - key = normalize_attribute_name(key) - observers = attribute_observers(key) || [] - observers.each do |observer| - observer.call(self, - key, - (attributes(method_name) || {})[key], - value, - method_name) - end - current_attributes[key] = value - end - end - - def attributes(method_name) - method_name = normalize_method_name(method_name) - attributes = attributes_table[method_name] - ancestors[1..-1].each do |ancestor| - if ancestor.is_a?(Class) and ancestor < Test::Unit::Attribute - parent_attributes = ancestor.attributes(method_name) - if attributes - attributes = (parent_attributes || {}).merge(attributes) - else - attributes = parent_attributes - end - break - end - end - attributes - end - - def get_attribute(method_name, attribute_name) - attribute_name = normalize_attribute_name(attribute_name) - (attributes(method_name) || {})[attribute_name] - end - - @@attribute_observers = {} - def register_attribute_observer(attribute_name, observer=Proc.new) - attribute_name = normalize_attribute_name(attribute_name) - @@attribute_observers[attribute_name] ||= [] - @@attribute_observers[attribute_name] << observer - end - - def attribute_observers(attribute_name) - attribute_name = normalize_attribute_name(attribute_name) - @@attribute_observers[attribute_name] - end - - private - def normalize_attribute_name(name) - name.to_s - end - - def normalize_method_name(name) - name.to_s - end - end - - def attributes - self.class.attributes(@method_name) || {} - end - - def [](name) - self.class.get_attribute(@method_name, name) - end - end - end -end Deleted: test-unit/lib/test/unit/autorunner.rb (+0 -254) 100644 =================================================================== --- test-unit/lib/test/unit/autorunner.rb 2010-09-12 03:03:44 +0000 (974f444) +++ /dev/null @@ -1,254 +0,0 @@ -require 'test/unit' -require 'optparse' - -module Test - module Unit - class AutoRunner - RUNNERS = {} - COLLECTORS = {} - ADDITIONAL_OPTIONS = [] - - class << self - def register_runner(id, runner_builder=Proc.new) - RUNNERS[id] = runner_builder - end - - def register_collector(id, collector_builder=Proc.new) - COLLECTORS[id] = collector_builder - end - - def setup_option(option_builder=Proc.new) - ADDITIONAL_OPTIONS << option_builder - end - end - - def self.run(force_standalone=false, default_dir=nil, argv=ARGV, &block) - r = new(force_standalone || standalone?, &block) - r.base = default_dir - r.process_args(argv) - r.run - end - - def self.standalone? - return false unless("-e" == $0) - ObjectSpace.each_object(Class) do |klass| - return false if(klass < TestCase) - end - true - end - - register_collector(:descendant) do |auto_runner| - require 'test/unit/collector/descendant' - collector = Collector::Descendant.new - collector.filter = auto_runner.filters - collector.collect($0.sub(/\.rb\Z/, '')) - end - - register_collector(:load) do |auto_runner| - require 'test/unit/collector/load' - collector = Collector::Load.new - collector.patterns.concat(auto_runner.pattern) if auto_runner.pattern - collector.excludes.concat(auto_runner.exclude) if auto_runner.exclude - collector.base = auto_runner.base - collector.filter = auto_runner.filters - collector.collect(*auto_runner.to_run) - end - - # deprecated - register_collector(:object_space) do |auto_runner| - require 'test/unit/collector/objectspace' - c = Collector::ObjectSpace.new - c.filter = auto_runner.filters - c.collect($0.sub(/\.rb\Z/, '')) - end - - # deprecated - register_collector(:dir) do |auto_runner| - require 'test/unit/collector/dir' - c = Collector::Dir.new - c.filter = auto_runner.filters - c.pattern.concat(auto_runner.pattern) if auto_runner.pattern - c.exclude.concat(auto_runner.exclude) if auto_runner.exclude - c.base = auto_runner.base - $:.push(auto_runner.base) if auto_runner.base - c.collect(*(auto_runner.to_run.empty? ? ['.'] : auto_runner.to_run)) - end - - attr_reader :suite, :runner_options - attr_accessor :filters, :to_run, :pattern, :exclude, :base, :workdir - attr_writer :runner, :collector - - def initialize(standalone) - Unit.run = true - @standalone = standalone - @runner = default_runner - @collector = default_collector - @filters = [] - @to_run = [] - @runner_options = {} - @workdir = nil - yield(self) if block_given? - end - - def process_args(args = ARGV) - begin - options.order!(args) {|arg| @to_run << arg} - rescue OptionParser::ParseError => e - puts e - puts options - $! = nil - abort - else - @filters << proc{false} unless(@filters.empty?) - end - not @to_run.empty? - end - - def options - @options ||= OptionParser.new do |o| - o.banner = "Test::Unit automatic runner." - o.banner << "\nUsage: #{$0} [options] [-- untouched arguments]" - - o.on - o.on('-r', '--runner=RUNNER', RUNNERS, - "Use the given RUNNER.", - "(" + keyword_display(RUNNERS) + ")") do |r| - @runner = r - end - - if(@standalone) - o.on('-b', '--basedir=DIR', "Base directory of test suites.") do |b| - @base = b - end - - o.on('-w', '--workdir=DIR', "Working directory to run tests.") do |w| - @workdir = w - end - - o.on('-a', '--add=TORUN', Array, - "Add TORUN to the list of things to run;", - "can be a file or a directory.") do |a| - @to_run.concat(a) - end - - @pattern = [] - o.on('-p', '--pattern=PATTERN', Regexp, - "Match files to collect against PATTERN.") do |e| - @pattern << e - end - - @exclude = [] - o.on('-x', '--exclude=PATTERN', Regexp, - "Ignore files to collect against PATTERN.") do |e| - @exclude << e - end - end - - o.on('-n', '--name=NAME', String, - "Runs tests matching NAME.", - "(patterns may be used).") do |n| - n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) - case n - when Regexp - @filters << proc{|t| n =~ t.method_name ? true : nil} - else - @filters << proc{|t| n == t.method_name ? true : nil} - end - end - - o.on('-t', '--testcase=TESTCASE', String, - "Runs tests in TestCases matching TESTCASE.", - "(patterns may be used).") do |n| - n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) - case n - when Regexp - @filters << proc{|t| n =~ t.class.name ? true : nil} - else - @filters << proc{|t| n == t.class.name ? true : nil} - end - end - - priority_filter = Proc.new do |test| - if @filters.size > 2 - nil - else - Priority::Checker.new(test).need_to_run? or nil - end - end - o.on("--[no-]priority-mode", - "Runs some tests based on their priority.") do |priority_mode| - if priority_mode - @filters |= [priority_filter] - else - @filters -= [priority_filter] - end - end - - o.on('-I', "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]", - "Appends directory list to $LOAD_PATH.") do |dirs| - $LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR)) - end - - ADDITIONAL_OPTIONS.each do |option_builder| - option_builder.call(self, o) - end - - o.on('--', - "Stop processing options so that the", - "remaining options will be passed to the", - "test."){o.terminate} - - o.on('-h', '--help', 'Display this help.'){puts o; exit} - - o.on_tail - o.on_tail('Deprecated options:') - - o.on_tail('--console', 'Console runner (use --runner).') do - warn("Deprecated option (--console).") - @runner = RUNNERS[:console] - end - - if RUNNERS[:fox] - o.on_tail('--fox', 'Fox runner (use --runner).') do - warn("Deprecated option (--fox).") - @runner = RUNNERS[:fox] - end - end - - o.on_tail - end - end - - def keyword_display(array) - list = array.collect {|e, *| e.to_s} - Array === array or list.sort! - list.collect {|e| e.sub(/^(.)([A-Za-z]+)(?=\w*$)/, '\\1[\\2]')}.join(", ") - end - - def run - suite = @collector[self] - return false if suite.nil? - runner = @runner[self] - return false if runner.nil? - Dir.chdir(@workdir) if @workdir - runner.run(suite, @runner_options).passed? - end - - private - def default_runner - if ENV["EMACS"] == "t" - RUNNERS[:emacs] - else - RUNNERS[:console] - end - end - - def default_collector - COLLECTORS[@standalone ? :load : :descendant] - end - end - end -end - -require 'test/unit/runner/console' -require 'test/unit/runner/emacs' Deleted: test-unit/lib/test/unit/collector.rb (+0 -43) 100644 =================================================================== --- test-unit/lib/test/unit/collector.rb 2010-09-12 03:03:44 +0000 (9e9e654) +++ /dev/null @@ -1,43 +0,0 @@ -module Test - module Unit - module Collector - def initialize - @filters = [] - end - - def filter=(filters) - @filters = case(filters) - when Proc - [filters] - when Array - filters - end - end - - def add_suite(destination, suite) - to_delete = suite.tests.find_all{|t| !include?(t)} - to_delete.each{|t| suite.delete(t)} - destination << suite unless(suite.size == 0) - end - - def include?(test) - return true if(@filters.empty?) - @filters.each do |filter| - result = filter[test] - if(result.nil?) - next - elsif(!result) - return false - else - return true - end - end - true - end - - def sort(suites) - suites.sort_by{|s| s.name} - end - end - end -end Deleted: test-unit/lib/test/unit/collector/descendant.rb (+0 -23) 100644 =================================================================== --- test-unit/lib/test/unit/collector/descendant.rb 2010-09-12 03:03:44 +0000 (3ecad00) +++ /dev/null @@ -1,23 +0,0 @@ -require 'test/unit/collector' - -module Test - module Unit - module Collector - class Descendant - include Collector - - NAME = 'collected from the subclasses of TestCase' - - def collect(name=NAME) - suite = TestSuite.new(name) - sub_suites = [] - TestCase::DESCENDANTS.each do |descendant_test_case| - add_suite(sub_suites, descendant_test_case.suite) - end - sort(sub_suites).each {|s| suite << s} - suite - end - end - end - end -end Deleted: test-unit/lib/test/unit/collector/dir.rb (+0 -108) 100644 =================================================================== --- test-unit/lib/test/unit/collector/dir.rb 2010-09-12 03:03:44 +0000 (896008a) +++ /dev/null @@ -1,108 +0,0 @@ -require 'test/unit/testsuite' -require 'test/unit/collector' - -module Test - module Unit - module Collector - class Dir - include Collector - - attr_reader :pattern, :exclude - attr_accessor :base - - def initialize(dir=::Dir, file=::File, object_space=::ObjectSpace, req=nil) - super() - @dir = dir - @file = file - @object_space = object_space - @req = req - @pattern = [/\btest_.*\.rb\Z/m] - @exclude = [] - @base = nil - end - - def collect(*from) - basedir = @base - $:.push(basedir) if basedir - if(from.empty?) - recursive_collect('.', find_test_cases) - elsif(from.size == 1) - recursive_collect(from.first, find_test_cases) - else - suites = [] - from.each do |f| - suite = recursive_collect(f, find_test_cases) - suites << suite unless(suite.tests.empty?) - end - suite = TestSuite.new("[#{from.join(', ')}]") - sort(suites).each{|s| suite << s} - suite - end - ensure - $:.delete_at($:.rindex(basedir)) if basedir - end - - def find_test_cases(ignore=[]) - cases = [] - @object_space.each_object(Class) do |c| - cases << c if(c < TestCase && !ignore.include?(c)) - end - ignore.concat(cases) - cases - end - - def recursive_collect(name, already_gathered) - sub_suites = [] - path = realdir(name) - if @file.directory?(path) - dir_name = name unless name == '.' - @dir.entries(path).each do |e| - next if(e == '.' || e == '..') - e_name = dir_name ? @file.join(dir_name, e) : e - if @file.directory?(realdir(e_name)) - next if /\A(?:CVS|\.svn)\z/ =~ e - sub_suite = recursive_collect(e_name, already_gathered) - sub_suites << sub_suite unless(sub_suite.empty?) - else - next if /~\z/ =~ e_name or /\A\.\#/ =~ e - if @pattern and !@pattern.empty? - next unless @pattern.any? {|pat| pat =~ e_name} - end - if @exclude and !@exclude.empty? - next if @exclude.any? {|pat| pat =~ e_name} - end - collect_file(e_name, sub_suites, already_gathered) - end - end - else - collect_file(name, sub_suites, already_gathered) - end - suite = TestSuite.new(@file.basename(name)) - sort(sub_suites).each{|s| suite << s} - suite - end - - def collect_file(name, suites, already_gathered) - dir = @file.dirname(@file.expand_path(name, @base)) - $:.unshift(dir) - if(@req) - @req.require(name) - else - require(name) - end - find_test_cases(already_gathered).each{|t| add_suite(suites, t.suite)} - ensure - $:.delete_at($:.rindex(dir)) if(dir) - end - - def realdir(path) - if @base - @file.join(@base, path) - else - path - end - end - end - end - end -end Deleted: test-unit/lib/test/unit/collector/load.rb (+0 -135) 100644 =================================================================== --- test-unit/lib/test/unit/collector/load.rb 2010-09-12 03:03:44 +0000 (3d07bc0) +++ /dev/null @@ -1,135 +0,0 @@ -require 'pathname' - -require 'test/unit/testsuite' -require 'test/unit/collector' - -module Test - module Unit - module Collector - class Load - include Collector - - attr_reader :patterns, :excludes, :base - - def initialize - super - @system_excludes = [/~\z/, /\A\.\#/] - @system_directory_excludes = [/\A(?:CVS|\.svn)\z/] - @patterns = [/\Atest_.+\.rb\z/m] - @excludes = [] - @base = nil - end - - def base=(base) - base = Pathname(base) unless base.nil? - @base = base - end - - def collect(*froms) - add_load_path(@base) do - froms = ["."] if froms.empty? - test_suites = froms.collect do |from| - test_suite = collect_recursive(from, find_test_cases) - test_suite = nil if test_suite.tests.empty? - test_suite - end.compact - - if test_suites.size > 1 - test_suite = TestSuite.new("[#{froms.join(', ')}]") - sort(test_suites).each do |sub_test_suite| - test_suite << sub_test_suite - end - test_suite - else - test_suites.first - end - end - end - - def find_test_cases(ignore=[]) - test_cases = [] - TestCase::DESCENDANTS.each do |test_case| - test_cases << test_case unless ignore.include?(test_case) - end - ignore.concat(test_cases) - test_cases - end - - private - def collect_recursive(name, already_gathered) - sub_test_suites = [] - - path = resolve_path(name) - if path.directory? - directories, files = path.children.partition do |child| - child.directory? - end - - files.each do |child| - next if excluded_file?(child.basename.to_s) - collect_file(child, sub_test_suites, already_gathered) - end - - directories.each do |child| - next if excluded_directory?(child.basename.to_s) - sub_test_suite = collect_recursive(child, already_gathered) - sub_test_suites << sub_test_suite unless sub_test_suite.empty? - end - else - collect_file(path, sub_test_suites, already_gathered) - end - - test_suite = TestSuite.new(path.basename.to_s) - sort(sub_test_suites).each do |sub_test_suite| - test_suite << sub_test_suite - end - test_suite - end - - def collect_file(path, test_suites, already_gathered) - add_load_path(path.expand_path.dirname) do - require(path.to_s) - find_test_cases(already_gathered).each do |test_case| - add_suite(test_suites, test_case.suite) - end - end - end - - def resolve_path(path) - if @base - @base + path - else - Pathname(path) - end - end - - def add_load_path(path) - $LOAD_PATH.push(path.to_s) if path - yield - ensure - $LOAD_PATH.delete_at($LOAD_PATH.rindex(path.to_s)) if path - end - - def excluded_directory?(base) - @system_directory_excludes.any? {|pattern| pattern =~ base} - end - - def excluded_file?(base) - return true if @system_excludes.any? {|pattern| pattern =~ base} - - patterns = @patterns || [] - unless patterns.empty? - return true unless patterns.any? {|pattern| pattern =~ base} - end - - excludes = @excludes || [] - unless excludes.empty? - return true if excludes.any? {|pattern| pattern =~ base} - end - - false - end - end - end - end -end Deleted: test-unit/lib/test/unit/collector/objectspace.rb (+0 -34) 100644 =================================================================== --- test-unit/lib/test/unit/collector/objectspace.rb 2010-09-12 03:03:44 +0000 (d1127a9) +++ /dev/null @@ -1,34 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/collector' - -module Test - module Unit - module Collector - class ObjectSpace - include Collector - - NAME = 'collected from the ObjectSpace' - - def initialize(source=::ObjectSpace) - super() - @source = source - end - - def collect(name=NAME) - suite = TestSuite.new(name) - sub_suites = [] - @source.each_object(Class) do |klass| - if(Test::Unit::TestCase > klass) - add_suite(sub_suites, klass.suite) - end - end - sort(sub_suites).each{|s| suite << s} - suite - end - end - end - end -end Deleted: test-unit/lib/test/unit/color.rb (+0 -61) 100644 =================================================================== --- test-unit/lib/test/unit/color.rb 2010-09-12 03:03:44 +0000 (435676f) +++ /dev/null @@ -1,61 +0,0 @@ -module Test - module Unit - class Color - NAMES = ["black", "red", "green", "yellow", - "blue", "magenta", "cyan", "white"] - def initialize(name, options={}) - @name = name - @foreground = options[:foreground] - @foreground = true if @foreground.nil? - @intensity = options[:intensity] - @bold = options[:bold] - @italic = options[:italic] - @underline = options[:underline] - end - - def sequence - sequence = [] - if @name == "none" - elsif @name == "reset" - sequence << "0" - else - foreground_parameter = @foreground ? 3 : 4 - foreground_parameter += 6 if @intensity - sequence << "#{foreground_parameter}#{NAMES.index(@name)}" - end - sequence << "1" if @bold - sequence << "3" if @italic - sequence << "4" if @underline - sequence - end - - def escape_sequence - "\e[#{sequence.join(';')}m" - end - - def +(other) - MixColor.new([self, other]) - end - end - - class MixColor - def initialize(colors) - @colors = colors - end - - def sequence - @colors.inject([]) do |result, color| - result + color.sequence - end - end - - def escape_sequence - "\e[#{sequence.join(';')}m" - end - - def +(other) - self.class.new([self, other]) - end - end - end -end Deleted: test-unit/lib/test/unit/diff.rb (+0 -524) 100644 =================================================================== --- test-unit/lib/test/unit/diff.rb 2010-09-12 03:03:44 +0000 (7e5e747) +++ /dev/null @@ -1,524 +0,0 @@ -# port of Python's difflib. - -module Test - module Unit - module Diff - class SequenceMatcher - def initialize(from, to, &junk_predicate) - @from = from - @to = to - @junk_predicate = junk_predicate - update_to_indexes - end - - def longest_match(from_start, from_end, to_start, to_end) - best_info = find_best_match_position(from_start, from_end, - to_start, to_end) - unless @junks.empty? - args = [from_start, from_end, to_start, to_end] - best_info = adjust_best_info_with_junk_predicate(false, best_info, - *args) - best_info = adjust_best_info_with_junk_predicate(true, best_info, - *args) - end - - best_info - end - - def blocks - @blocks ||= compute_blocks - end - - def operations - @operations ||= compute_operations - end - - def grouped_operations(context_size=nil) - context_size ||= 3 - _operations = operations - _operations = [[:equal, 0, 0, 0, 0]] if _operations.empty? - expand_edge_equal_operations!(_operations, context_size) - - group_window = context_size * 2 - groups = [] - group = [] - _operations.each do |tag, from_start, from_end, to_start, to_end| - if tag == :equal and from_end - from_start > group_window - group << [tag, - from_start, - [from_end, from_start + context_size].min, - to_start, - [to_end, to_start + context_size].min] - groups << group - group = [] - from_start = [from_start, from_end - context_size].max - to_start = [to_start, to_end - context_size].max - end - group << [tag, from_start, from_end, to_start, to_end] - end - groups << group unless group.empty? - groups - end - - def ratio - @ratio ||= compute_ratio - end - - private - def update_to_indexes - @to_indexes = {} - @junks = {} - if @to.is_a?(String) - each = " "[0].is_a?(Integer) ? :each_byte : :each_char - else - each = :each - end - i = 0 - @to.send(each) do |item| - @to_indexes[item] ||= [] - @to_indexes[item] << i - i += 1 - end - - return if @junk_predicate.nil? - @to_indexes = @to_indexes.reject do |key, value| - junk = @junk_predicate.call(key) - @junks[key] = true if junk - junk - end - end - - def find_best_match_position(from_start, from_end, to_start, to_end) - best_from, best_to, best_size = from_start, to_start, 0 - sizes = {} - from_start.upto(from_end) do |from_index| - _sizes = {} - (@to_indexes[@from[from_index]] || []).each do |to_index| - next if to_index < to_start - break if to_index > to_end - size = _sizes[to_index] = (sizes[to_index - 1] || 0) + 1 - if size > best_size - best_from = from_index - size + 1 - best_to = to_index - size + 1 - best_size = size - end - end - sizes = _sizes - end - [best_from, best_to, best_size] - end - - def adjust_best_info_with_junk_predicate(should_junk, best_info, - from_start, from_end, - to_start, to_end) - best_from, best_to, best_size = best_info - while best_from > from_start and best_to > to_start and - (should_junk ? - @junks.has_key?(@to[best_to - 1]) : - !@junks.has_key?(@to[best_to - 1])) and - @from[best_from - 1] == @to[best_to - 1] - best_from -= 1 - best_to -= 1 - best_size += 1 - end - - while best_from + best_size < from_end and - best_to + best_size < to_end and - (should_junk ? - @junks.has_key?(@to[best_to + best_size]) : - !@junks.has_key?(@to[best_to + best_size])) and - @from[best_from + best_size] == @to[best_to + best_size] - best_size += 1 - end - - [best_from, best_to, best_size] - end - - def matches - @matches ||= compute_matches - end - - def compute_matches - matches = [] - queue = [[0, @from.size, 0, @to.size]] - until queue.empty? - from_start, from_end, to_start, to_end = queue.pop - match = longest_match(from_start, from_end - 1, to_start, to_end - 1) - match_from_index, match_to_index, size = match - unless size.zero? - if from_start < match_from_index and - to_start < match_to_index - queue.push([from_start, match_from_index, - to_start, match_to_index]) - end - matches << match - if match_from_index + size < from_end and - match_to_index + size < to_end - queue.push([match_from_index + size, from_end, - match_to_index + size, to_end]) - end - end - end - matches.sort_by do |(from_index, to_index, match_size)| - from_index - end - end - - def compute_blocks - blocks = [] - current_from_index = current_to_index = current_size = 0 - matches.each do |from_index, to_index, size| - if current_from_index + current_size == from_index and - current_to_index + current_size == to_index - current_size += size - else - unless current_size.zero? - blocks << [current_from_index, current_to_index, current_size] - end - current_from_index = from_index - current_to_index = to_index - current_size = size - end - end - unless current_size.zero? - blocks << [current_from_index, current_to_index, current_size] - end - - blocks << [@from.size, @to.size, 0] - blocks - end - - def compute_operations - from_index = to_index = 0 - operations = [] - blocks.each do |match_from_index, match_to_index, size| - tag = determine_tag(from_index, to_index, - match_from_index, match_to_index) - if tag != :equal - operations << [tag, - from_index, match_from_index, - to_index, match_to_index] - end - - from_index, to_index = match_from_index + size, match_to_index + size - if size > 0 - operations << [:equal, - match_from_index, from_index, - match_to_index, to_index] - end - end - operations - end - - def compute_ratio - matches = blocks.inject(0) {|result, block| result + block[-1]} - length = @from.length + @to.length - if length.zero? - 1.0 - else - 2.0 * matches / length - end - end - - def determine_tag(from_index, to_index, - match_from_index, match_to_index) - if from_index < match_from_index and to_index < match_to_index - :replace - elsif from_index < match_from_index - :delete - elsif to_index < match_to_index - :insert - else - :equal - end - end - - def expand_edge_equal_operations!(_operations, context_size) - tag, from_start, from_end, to_start, to_end = _operations[0] - if tag == :equal - _operations[0] = [tag, - [from_start, from_end - context_size].max, - from_end, - [to_start, to_end - context_size].max, - to_end] - end - - tag, from_start, from_end, to_start, to_end = _operations[-1] - if tag == :equal - _operations[-1] = [tag, - from_start, - [from_end, from_start + context_size].min, - to_start, - [to_end, to_start + context_size].min] - end - end - end - - class Differ - def initialize(from, to) - @from = from - @to = to - end - - private - def tag(mark, contents) - contents.collect {|content| "#{mark}#{content}"} - end - end - - class ReadableDiffer < Differ - def diff(options={}) - result = [] - matcher = SequenceMatcher.new(@from, @to) - matcher.operations.each do |args| - tag, from_start, from_end, to_start, to_end = args - case tag - when :replace - result.concat(diff_lines(from_start, from_end, to_start, to_end)) - when :delete - result.concat(tag_deleted(@from[from_start...from_end])) - when :insert - result.concat(tag_inserted(@to[to_start...to_end])) - when :equal - result.concat(tag_equal(@from[from_start...from_end])) - else - raise "unknown tag: #{tag}" - end - end - result - end - - private - def tag_deleted(contents) - tag("- ", contents) - end - - def tag_inserted(contents) - tag("+ ", contents) - end - - def tag_equal(contents) - tag(" ", contents) - end - - def tag_difference(contents) - tag("? ", contents) - end - - def find_diff_line_info(from_start, from_end, to_start, to_end) - best_ratio = 0.74 - from_equal_index = to_equal_index = nil - from_best_index = to_best_index = nil - - to_start.upto(to_end - 1) do |to_index| - from_start.upto(from_end - 1) do |from_index| - if @from[from_index] == @to[to_index] - from_equal_index ||= from_index - to_equal_index ||= to_index - next - end - - matcher = SequenceMatcher.new(@from[from_index], @to[to_index], - &method(:space_character?)) - if matcher.ratio > best_ratio - best_ratio = matcher.ratio - from_best_index = from_index - to_best_index = to_index - end - end - end - - [best_ratio, - from_equal_index, to_equal_index, - from_best_index, to_best_index] - end - - def diff_lines(from_start, from_end, to_start, to_end) - cut_off = 0.75 - - info = find_diff_line_info(from_start, from_end, to_start, to_end) - best_ratio, from_equal_index, to_equal_index, *info = info - from_best_index, to_best_index = info - - if best_ratio < cut_off - if from_equal_index.nil? - tagged_from = tag_deleted(@from[from_start...from_end]) - tagged_to = tag_inserted(@to[to_start...to_end]) - if to_end - to_start < from_end - from_start - return tagged_to + tagged_from - else - return tagged_from + tagged_to - end - end - from_best_index = from_equal_index - to_best_index = to_equal_index - best_ratio = 1.0 - end - - _diff_lines(from_start, from_best_index, to_start, to_best_index) + - diff_line(@from[from_best_index], @to[to_best_index]) + - _diff_lines(from_best_index + 1, from_end, to_best_index + 1, to_end) - end - - def _diff_lines(from_start, from_end, to_start, to_end) - if from_start < from_end - if to_start < to_end - diff_lines(from_start, from_end, to_start, to_end) - else - tag_deleted(@from[from_start...from_end]) - end - else - tag_inserted(@to[to_start...to_end]) - end - end - - def diff_line(from_line, to_line) - from_tags = "" - to_tags = "" - matcher = SequenceMatcher.new(from_line, to_line, - &method(:space_character?)) - operations = matcher.operations - operations.each do |tag, from_start, from_end, to_start, to_end| - from_length = from_end - from_start - to_length = to_end - to_start - case tag - when :replace - from_tags << "^" * from_length - to_tags << "^" * to_length - when :delete - from_tags << "-" * from_length - when :insert - to_tags << "+" * to_length - when :equal - from_tags << " " * from_length - to_tags << " " * to_length - else - raise "unknown tag: #{tag}" - end - end - format_diff_point(from_line, to_line, from_tags, to_tags) - end - - def format_diff_point(from_line, to_line, from_tags, to_tags) - common = [n_leading_characters(from_line, ?\t), - n_leading_characters(to_line, ?\t)].min - common = [common, - n_leading_characters(from_tags[0, common], " "[0])].min - from_tags = from_tags[common..-1].rstrip - to_tags = to_tags[common..-1].rstrip - - result = tag_deleted([from_line]) - unless from_tags.empty? - result.concat(tag_difference(["#{"\t" * common}#{from_tags}"])) - end - result.concat(tag_inserted([to_line])) - unless to_tags.empty? - result.concat(tag_difference(["#{"\t" * common}#{to_tags}"])) - end - result - end - - def n_leading_characters(string, character) - n = 0 - while string[n] == character - n += 1 - end - n - end - - def space_character?(character) - [" "[0], "\t"[0]].include?(character) - end - end - - class UnifiedDiffer < Differ - def diff(options={}) - groups = SequenceMatcher.new(@from, @to).grouped_operations - return [] if groups.empty? - return [] if same_content?(groups) - - show_context = options[:show_context] - show_context = true if show_context.nil? - result = ["--- #{options[:from_label]}".rstrip, - "+++ #{options[:to_label]}".rstrip] - groups.each do |operations| - result << format_summary(operations, show_context) - operations.each do |args| - operation_tag, from_start, from_end, to_start, to_end = args - case operation_tag - when :replace - result.concat(tag("-", @from[from_start...from_end])) - result.concat(tag("+", @to[to_start...to_end])) - when :delete - result.concat(tag("-", @from[from_start...from_end])) - when :insert - result.concat(tag("+", @to[to_start...to_end])) - when :equal - result.concat(tag(" ", @from[from_start...from_end])) - end - end - end - result - end - - private - def same_content?(groups) - return false if groups.size != 1 - group = groups[0] - return false if group.size != 1 - tag, from_start, from_end, to_start, to_end = group[0] - - tag == :equal and [from_start, from_end] == [to_start, to_end] - end - - def format_summary(operations, show_context) - _, first_from_start, _, first_to_start, _ = operations[0] - _, _, last_from_end, _, last_to_end = operations[-1] - summary = "@@ -%d,%d +%d,%d @@" % [first_from_start + 1, - last_from_end - first_from_start, - first_to_start + 1, - last_to_end - first_to_start,] - if show_context - interesting_line = find_interesting_line(first_from_start, - first_to_start, - :define_line?) - summary << " #{interesting_line}" if interesting_line - end - summary - end - - def find_interesting_line(from_start, to_start, predicate) - from_index = from_start - to_index = to_start - while from_index >= 0 or to_index >= 0 - [@from[from_index], @to[to_index]].each do |line| - return line if line and send(predicate, line) - end - - from_index -= 1 - to_index -= 1 - end - nil - end - - def define_line?(line) - /\A(?:[_a-zA-Z$]|\s*(?:class|module|def)\b)/ =~ line - end - end - - module_function - def readable(from, to, options={}) - diff(ReadableDiffer, from, to, options) - end - - def unified(from, to, options={}) - diff(UnifiedDiffer, from, to, options) - end - - def diff(differ_class, from, to, options={}) - differ = differ_class.new(from.split(/\r?\n/), to.split(/\r?\n/)) - differ.diff(options).join("\n") - end - end - end -end Deleted: test-unit/lib/test/unit/error.rb (+0 -124) 100644 =================================================================== --- test-unit/lib/test/unit/error.rb 2010-09-12 03:03:44 +0000 (33844dd) +++ /dev/null @@ -1,124 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/util/backtracefilter' - -module Test - module Unit - - # Encapsulates an error in a test. Created by - # Test::Unit::TestCase when it rescues an exception thrown - # during the processing of a test. - class Error - include Util::BacktraceFilter - - attr_reader(:test_name, :exception) - - SINGLE_CHARACTER = 'E' - LABEL = "Error" - - # Creates a new Error with the given test_name and - # exception. - def initialize(test_name, exception) - @test_name = test_name - @exception = exception - end - - # Returns a single character representation of an error. - def single_character_display - SINGLE_CHARACTER - end - - def label - LABEL - end - - # Returns the message associated with the error. - def message - "#{@exception.class.name}: #{@exception.message}" - end - - # Returns a brief version of the error description. - def short_display - "#@test_name: #{message.split("\n")[0]}" - end - - # Returns a verbose version of the error description. - def long_display - backtrace_display = backtrace.join("\n ") - "#{label}:\n#@test_name:\n#{message}\n #{backtrace_display}" - end - - def backtrace - filter_backtrace(@exception.backtrace) - end - - # Overridden to return long_display. - def to_s - long_display - end - end - - module ErrorHandler - class << self - def included(base) - base.exception_handler(:handle_all_exception) - end - end - - PASS_THROUGH_EXCEPTIONS = [NoMemoryError, SignalException, Interrupt, - SystemExit] - private - def handle_all_exception(exception) - case exception - when *PASS_THROUGH_EXCEPTIONS - false - else - problem_occurred - add_error(exception) - true - end - end - - def add_error(exception) - current_result.add_error(Error.new(name, exception)) - end - end - - module TestResultErrorSupport - attr_reader :errors - - # Records a Test::Unit::Error. - def add_error(error) - @errors << error - notify_fault(error) - notify_changed - end - - # Returns the number of errors this TestResult has - # recorded. - def error_count - @errors.size - end - - def error_occurred? - not @errors.empty? - end - - private - def initialize_containers - super - @errors = [] - @summary_generators << :error_summary - @problem_checkers << :error_occurred? - end - - def error_summary - "#{error_count} errors" - end - end - end -end Deleted: test-unit/lib/test/unit/exceptionhandler.rb (+0 -39) 100644 =================================================================== --- test-unit/lib/test/unit/exceptionhandler.rb 2010-09-12 03:03:44 +0000 (8f21318) +++ /dev/null @@ -1,39 +0,0 @@ -module Test - module Unit - module ExceptionHandler - @@exception_handlers = [] - class << self - def exception_handlers - @@exception_handlers - end - - def included(base) - base.extend(ClassMethods) - - observer = Proc.new do |test_case, _, _, value, method_name| - if value - @@exception_handlers.unshift(method_name) - else - @@exception_handlers -= [method_name] - end - end - base.register_attribute_observer(:exception_handler, &observer) - end - end - - module ClassMethods - def exception_handlers - ExceptionHandler.exception_handlers - end - - def exception_handler(*method_names) - attribute(:exception_handler, true, *method_names) - end - - def unregister_exception_handler(*method_names) - attribute(:exception_handler, false, *method_names) - end - end - end - end -end Deleted: test-unit/lib/test/unit/failure.rb (+0 -110) 100644 =================================================================== --- test-unit/lib/test/unit/failure.rb 2010-09-12 03:03:44 +0000 (ccd71c2) +++ /dev/null @@ -1,110 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -module Test - module Unit - - # Encapsulates a test failure. Created by Test::Unit::TestCase - # when an assertion fails. - class Failure - attr_reader :test_name, :location, :message - - SINGLE_CHARACTER = 'F' - LABEL = "Failure" - - # Creates a new Failure with the given location and - # message. - def initialize(test_name, location, message) - @test_name = test_name - @location = location - @message = message - end - - # Returns a single character representation of a failure. - def single_character_display - SINGLE_CHARACTER - end - - def label - LABEL - end - - # Returns a brief version of the error description. - def short_display - "#@test_name: #{@message.split("\n")[0]}" - end - - # Returns a verbose version of the error description. - def long_display - if location.size == 1 - location_display = location[0].sub(/\A(.+:\d+).*/, ' [\\1]') - else - location_display = "\n [#{location.join("\n ")}]" - end - "#{label}:\n#@test_name#{location_display}:\n#@message" - end - - # Overridden to return long_display. - def to_s - long_display - end - end - - module FailureHandler - class << self - def included(base) - base.exception_handler(:handle_assertion_failed_error) - end - end - - private - def handle_assertion_failed_error(exception) - return false unless exception.is_a?(AssertionFailedError) - problem_occurred - add_failure(exception.message, exception.backtrace) - true - end - - def add_failure(message, backtrace) - failure = Failure.new(name, filter_backtrace(backtrace), message) - current_result.add_failure(failure) - end - end - - module TestResultFailureSupport - attr_reader :failures - - # Records a Test::Unit::Failure. - def add_failure(failure) - @failures << failure - notify_fault(failure) - notify_changed - end - - # Returns the number of failures this TestResult has - # recorded. - def failure_count - @failures.size - end - - def failure_occurred? - not @failures.empty? - end - - private - def initialize_containers - super - @failures = [] - @summary_generators << :failure_summary - @problem_checkers << :failure_occurred? - end - - def failure_summary - "#{failure_count} failures" - end - end - end -end Deleted: test-unit/lib/test/unit/fixture.rb (+0 -185) 100644 =================================================================== --- test-unit/lib/test/unit/fixture.rb 2010-09-12 03:03:44 +0000 (f031026) +++ /dev/null @@ -1,185 +0,0 @@ -module Test - module Unit - module Fixture - class << self - def included(base) - base.extend(ClassMethods) - - [:setup, :teardown].each do |fixture| - observer = Proc.new do |test_case, _, _, value, method_name| - if value.nil? - test_case.send("unregister_#{fixture}_method", method_name) - else - test_case.send("register_#{fixture}_method", method_name, - value) - end - end - base.register_attribute_observer(fixture, &observer) - end - end - end - - module ClassMethods - def setup(*method_names) - register_fixture(:setup, *method_names) - end - - def unregister_setup(*method_names) - unregister_fixture(:setup, *method_names) - end - - def teardown(*method_names) - register_fixture(:teardown, *method_names) - end - - def unregister_teardown(*method_names) - unregister_fixture(:teardown, *method_names) - end - - def register_setup_method(method_name, options) - register_fixture_method(:setup, method_name, options, :after, :append) - end - - def unregister_setup_method(method_name) - unregister_fixture_method(:setup, method_name) - end - - def register_teardown_method(method_name, options) - register_fixture_method(:teardown, method_name, options, - :before, :prepend) - end - - def unregister_teardown_method(method_name) - unregister_fixture_method(:teardown, method_name) - end - - def before_setup_methods - collect_fixture_methods(:setup, :before) - end - - def after_setup_methods - collect_fixture_methods(:setup, :after) - end - - def before_teardown_methods - collect_fixture_methods(:teardown, :before) - end - - def after_teardown_methods - collect_fixture_methods(:teardown, :after) - end - - private - def register_fixture(fixture, *method_names) - options = {} - options = method_names.pop if method_names.last.is_a?(Hash) - attribute(fixture, options, *method_names) - end - - def unregister_fixture(fixture, *method_names) - attribute(fixture, nil, *method_names) - end - - def valid_register_fixture_options?(options) - return true if options.empty? - return false if options.size > 1 - - key = options.keys.first - [:before, :after].include?(key) and - [:prepend, :append].include?(options[key]) - end - - def add_fixture_method_name(how, variable_name, method_name) - unless self.instance_variable_defined?(variable_name) - self.instance_variable_set(variable_name, []) - end - methods = self.instance_variable_get(variable_name) - - if how == :prepend - methods = [method_name] | methods - else - methods = methods | [method_name] - end - self.instance_variable_set(variable_name, methods) - end - - def registered_methods_variable_name(fixture, order) - "@#{order}_#{fixture}_methods" - end - - def unregistered_methods_variable_name(fixture) - "@unregistered_#{fixture}_methods" - end - - def register_fixture_method(fixture, method_name, options, - default_order, default_how) - unless valid_register_fixture_options?(options) - message = "must be {:before => :prepend}, " + - "{:before => :append}, {:after => :prepend} or " + - "{:after => :append}: #{options.inspect}" - raise ArgumentError, message - end - - if options.empty? - order, how = default_order, default_how - else - order, how = options.to_a.first - end - variable_name = registered_methods_variable_name(fixture, order) - add_fixture_method_name(how, variable_name, method_name) - end - - def unregister_fixture_method(fixture, method_name) - variable_name = unregistered_methods_variable_name(fixture) - add_fixture_method_name(:append, variable_name, method_name) - end - - def collect_fixture_methods(fixture, order) - methods_variable = registered_methods_variable_name(fixture, order) - unregistered_methods_variable = - unregistered_methods_variable_name(fixture) - - base_index = ancestors.index(Fixture) - interested_ancestors = ancestors[0, base_index].reverse - interested_ancestors.inject([]) do |result, ancestor| - if ancestor.is_a?(Class) - ancestor.class_eval do - methods = [] - unregistered_methods = [] - if instance_variable_defined?(methods_variable) - methods = instance_variable_get(methods_variable) - end - if instance_variable_defined?(unregistered_methods_variable) - unregistered_methods = - instance_variable_get(unregistered_methods_variable) - end - (result | methods) - unregistered_methods - end - else - result - end - end - end - end - - private - def run_fixture(fixture) - [ - self.class.send("before_#{fixture}_methods"), - fixture, - self.class.send("after_#{fixture}_methods") - ].flatten.each do |method_name| - send(method_name) if respond_to?(method_name, true) - end - end - - def run_setup - run_fixture(:setup) - end - - def run_teardown - run_fixture(:teardown) - end - end - end -end Deleted: test-unit/lib/test/unit/notification.rb (+0 -125) 100644 =================================================================== --- test-unit/lib/test/unit/notification.rb 2010-09-12 03:03:44 +0000 (48ba3f6) +++ /dev/null @@ -1,125 +0,0 @@ -require 'test/unit/util/backtracefilter' - -module Test - module Unit - class Notification - include Util::BacktraceFilter - attr_reader :test_name, :location, :message - - SINGLE_CHARACTER = 'N' - LABEL = "Notification" - - # Creates a new Notification with the given location and - # message. - def initialize(test_name, location, message) - @test_name = test_name - @location = location - @message = message - end - - # Returns a single character representation of a notification. - def single_character_display - SINGLE_CHARACTER - end - - def label - LABEL - end - - # Returns a brief version of the error description. - def short_display - "#{@test_name}: #{@message.split("\n")[0]}" - end - - # Returns a verbose version of the error description. - def long_display - backtrace = filter_backtrace(location).join("\n") - "#{label}: #{@message}\n#{@test_name}\n#{backtrace}" - end - - # Overridden to return long_display. - def to_s - long_display - end - end - - class NotifiedError < StandardError - end - - - module TestCaseNotificationSupport - class << self - def included(base) - base.class_eval do - include NotificationHandler - end - end - end - - # Notify some information. - # - # Example: - # def test_notification - # notify("I'm here!") - # # Reached here - # notify("Special!") if special_case? - # # Reached here too - # end - def notify(message, &block) - notification = Notification.new(name, filter_backtrace(caller), message) - add_notification(notification) - end - - private - def add_notification(notification) - current_result.add_notification(notification) - end - end - - module NotificationHandler - class << self - def included(base) - base.exception_handler(:handle_Notified_error) - end - end - - private - def handle_Notified_error(exception) - return false unless exception.is_a?(NotifiedError) - notification = Notification.new(name, - filter_backtrace(exception.backtrace), - exception.message) - add_notification(notification) - true - end - end - - module TestResultNotificationSupport - attr_reader :notifications - - # Records a Test::Unit::Notification. - def add_notification(notification) - @notifications << notification - notify_fault(notification) - notify_changed - end - - # Returns the number of notifications this TestResult has - # recorded. - def notification_count - @notifications.size - end - - private - def initialize_containers - super - @notifications = [] - @summary_generators << :notification_summary - end - - def notification_summary - "#{notification_count} notifications" - end - end - end -end Deleted: test-unit/lib/test/unit/omission.rb (+0 -143) 100644 =================================================================== --- test-unit/lib/test/unit/omission.rb 2010-09-12 03:03:44 +0000 (e2187ba) +++ /dev/null @@ -1,143 +0,0 @@ -require 'test/unit/util/backtracefilter' - -module Test - module Unit - class Omission - include Util::BacktraceFilter - attr_reader :test_name, :location, :message - - SINGLE_CHARACTER = 'O' - LABEL = "Omission" - - # Creates a new Omission with the given location and - # message. - def initialize(test_name, location, message) - @test_name = test_name - @location = location - @message = message - end - - # Returns a single character representation of a omission. - def single_character_display - SINGLE_CHARACTER - end - - def label - LABEL - end - - # Returns a brief version of the error description. - def short_display - "#{@test_name}: #{@message.split("\n")[0]}" - end - - # Returns a verbose version of the error description. - def long_display - backtrace = filter_backtrace(location).join("\n") - "#{label}: #{@message}\n#{@test_name}\n#{backtrace}" - end - - # Overridden to return long_display. - def to_s - long_display - end - end - - class OmittedError < StandardError - end - - - module TestCaseOmissionSupport - class << self - def included(base) - base.class_eval do - include OmissionHandler - end - end - end - - # Omit the test of part of the test. - # - # Example: - # def test_omission - # omit - # # Not reached here - # end - # - # def test_omission_with_here - # omit do - # # Not ran here - # end - # # Reached here - # end - def omit(message=nil, &block) - message ||= "omitted." - if block_given? - omission = Omission.new(name, filter_backtrace(caller), message) - add_omission(omission) - else - raise OmittedError.new(message) - end - end - - def omit_if(condition, *args, &block) - omit(*args, &block) if condition - end - - def omit_unless(condition, *args, &block) - omit(*args, &block) unless condition - end - - private - def add_omission(omission) - current_result.add_omission(omission) - end - end - - module OmissionHandler - class << self - def included(base) - base.exception_handler(:handle_omitted_error) - end - end - - private - def handle_omitted_error(exception) - return false unless exception.is_a?(OmittedError) - omission = Omission.new(name, - filter_backtrace(exception.backtrace), - exception.message) - add_omission(omission) - true - end - end - - module TestResultOmissionSupport - attr_reader :omissions - - # Records a Test::Unit::Omission. - def add_omission(omission) - @omissions << omission - notify_fault(omission) - notify_changed - end - - # Returns the number of omissions this TestResult has - # recorded. - def omission_count - @omissions.size - end - - private - def initialize_containers - super - @omissions = [] - @summary_generators << :omission_summary - end - - def omission_summary - "#{omission_count} omissions" - end - end - end -end Deleted: test-unit/lib/test/unit/pending.rb (+0 -146) 100644 =================================================================== --- test-unit/lib/test/unit/pending.rb 2010-09-12 03:03:44 +0000 (bfc5ac0) +++ /dev/null @@ -1,146 +0,0 @@ -require 'test/unit/util/backtracefilter' - -module Test - module Unit - class Pending - include Util::BacktraceFilter - attr_reader :test_name, :location, :message - - SINGLE_CHARACTER = 'P' - LABEL = "Pending" - - # Creates a new Pending with the given location and - # message. - def initialize(test_name, location, message) - @test_name = test_name - @location = location - @message = message - end - - # Returns a single character representation of a pending. - def single_character_display - SINGLE_CHARACTER - end - - def label - LABEL - end - - # Returns a brief version of the error description. - def short_display - "#{@test_name}: #{@message.split("\n")[0]}" - end - - # Returns a verbose version of the error description. - def long_display - backtrace = filter_backtrace(location).join("\n") - "#{label}: #{@message}\n#{@test_name}\n#{backtrace}" - end - - # Overridden to return long_display. - def to_s - long_display - end - end - - class PendedError < StandardError - end - - - module TestCasePendingSupport - class << self - def included(base) - base.class_eval do - include PendingHandler - end - end - end - - # Marks the test or part of the test is pending. - # - # Example: - # def test_pending - # pend - # # Not reached here - # end - # - # def test_pending_with_here - # pend do - # # Ran here - # # Fails if the block doesn't raise any error. - # # Because it means the block is passed unexpectedly. - # end - # # Reached here - # end - def pend(message=nil, &block) - message ||= "pended." - if block_given? - pending = nil - begin - yield - rescue Exception - pending = Pending.new(name, filter_backtrace(caller), message) - add_pending(pending) - end - unless pending - flunk("Pending block should not be passed: #{message}") - end - else - raise PendedError.new(message) - end - end - - private - def add_pending(pending) - problem_occurred - current_result.add_pending(pending) - end - end - - module PendingHandler - class << self - def included(base) - base.exception_handler(:handle_pended_error) - end - end - - private - def handle_pended_error(exception) - return false unless exception.is_a?(PendedError) - pending = Pending.new(name, - filter_backtrace(exception.backtrace), - exception.message) - add_pending(pending) - true - end - end - - module TestResultPendingSupport - attr_reader :pendings - - # Records a Test::Unit::Pending. - def add_pending(pending) - @pendings << pending - notify_fault(pending) - notify_changed - end - - # Returns the number of pendings this TestResult has - # recorded. - def pending_count - @pendings.size - end - - private - def initialize_containers - super - @pendings = [] - @summary_generators << :pending_summary - end - - def pending_summary - "#{pending_count} pendings" - end - end - end -end Deleted: test-unit/lib/test/unit/priority.rb (+0 -146) 100644 =================================================================== --- test-unit/lib/test/unit/priority.rb 2010-09-12 03:03:44 +0000 (f3b24b0) +++ /dev/null @@ -1,146 +0,0 @@ -require "fileutils" -require "tmpdir" - -module Test - module Unit - module Priority - class << self - def included(base) - base.extend(ClassMethods) - - base.class_eval do - setup :priority_setup, :before => :prepend - teardown :priority_teardown, :after => :append - end - end - end - - class Checker - class << self - def have_priority?(name) - singleton_class = (class << self; self; end) - singleton_class.method_defined?(priority_check_method_name(name)) - end - - def need_to_run?(test) - priority = test[:priority] || :normal - if have_priority?(priority) - send(priority_check_method_name(priority), test) - else - true - end - end - - def run_priority_must?(test) - true - end - - def run_priority_important?(test) - rand > 0.1 - end - - def run_priority_high?(test) - rand > 0.3 - end - - def run_priority_normal?(test) - rand > 0.5 - end - - def run_priority_low?(test) - rand > 0.75 - end - - def run_priority_never?(test) - false - end - - private - def priority_check_method_name(priority_name) - "run_priority_#{priority_name}?" - end - end - - attr_reader :test - def initialize(test) - @test = test - end - - def setup - FileUtils.rm_f(passed_file) - end - - def teardown - if @test.send(:passed?) - FileUtils.touch(passed_file) - else - FileUtils.rm_f(passed_file) - end - end - - def need_to_run? - !previous_test_success? or self.class.need_to_run?(@test) - end - - private - def previous_test_success? - File.exist?(passed_file) - end - - def result_dir - components = [".test-result", - @test.class.name || "AnonymousTestCase", - @test.method_name.to_s] - parent_directories = [File.dirname($0), Dir.pwd] - if Process.respond_to?(:uid) - parent_directories << File.join(Dir.tmpdir, Process.uid.to_s) - end - parent_directories.each do |parent_directory| - dir = File.expand_path(File.join(parent_directory, *components)) - begin - FileUtils.mkdir_p(dir) - return dir - rescue Errno::EACCES - end - end - - raise Errno::EACCES, parent_directories.join(", ") - end - - def passed_file - File.join(result_dir, "passed") - end - - def escaped_method_name - @method_name.to_s.gsub(/[!?=]$/) do |matched| - case matched - when "!" - ".destructive" - when "?" - ".predicate" - when "=" - ".equal" - end - end - end - end - - module ClassMethods - def priority(name, *tests) - unless Checker.have_priority?(name) - raise ArgumentError, "unknown priority: #{name}" - end - attribute(:priority, name, {:keep => true}, *tests) - end - end - - def priority_setup - Checker.new(self).setup - end - - def priority_teardown - Checker.new(self).teardown - end - end - end -end Deleted: test-unit/lib/test/unit/runner/console.rb (+0 -46) 100644 =================================================================== --- test-unit/lib/test/unit/runner/console.rb 2010-09-12 03:03:44 +0000 (c3f3d53) +++ /dev/null @@ -1,46 +0,0 @@ -module Test - module Unit - AutoRunner.register_runner(:console) do |auto_runner| - require 'test/unit/ui/console/testrunner' - Test::Unit::UI::Console::TestRunner - end - - AutoRunner.setup_option do |auto_runner, opts| - require 'test/unit/ui/console/outputlevel' - - output_levels = [ - [:silent, UI::Console::OutputLevel::SILENT], - [:progress, UI::Console::OutputLevel::PROGRESS_ONLY], - [:normal, UI::Console::OutputLevel::NORMAL], - [:verbose, UI::Console::OutputLevel::VERBOSE], - ] - opts.on('-v', '--verbose=[LEVEL]', output_levels, - "Set the output level (default is verbose).", - "(#{auto_runner.keyword_display(output_levels)})") do |level| - level ||= output_levels.assoc(:verbose)[1] - auto_runner.runner_options[:output_level] = level - end - - use_color_options = [ - [:auto, :auto], - ["-", false], - ["no", false], - ["false", false], - ["+", true], - ["yes", true], - ["true", true], - ] - opts.on("--[no-]use-color=[auto]", use_color_options, - "Use color output", - "(default is auto") do |use_color| - case use_color - when nil - use_color = true - when :auto - use_color = nil - end - auto_runner.runner_options[:use_color] = use_color - end - end - end -end Deleted: test-unit/lib/test/unit/runner/emacs.rb (+0 -8) 100644 =================================================================== --- test-unit/lib/test/unit/runner/emacs.rb 2010-09-12 03:03:44 +0000 (c254657) +++ /dev/null @@ -1,8 +0,0 @@ -module Test - module Unit - AutoRunner.register_runner(:emacs) do |auto_runner| - require 'test/unit/ui/emacs/testrunner' - Test::Unit::UI::Emacs::TestRunner - end - end -end Deleted: test-unit/lib/test/unit/testcase.rb (+0 -281) 100644 =================================================================== --- test-unit/lib/test/unit/testcase.rb 2010-09-12 03:03:44 +0000 (134f4f9) +++ /dev/null @@ -1,281 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/attribute' -require 'test/unit/fixture' -require 'test/unit/exceptionhandler' -require 'test/unit/assertions' -require 'test/unit/failure' -require 'test/unit/error' -require 'test/unit/pending' -require 'test/unit/omission' -require 'test/unit/notification' -require 'test/unit/priority' -require 'test/unit/testsuite' -require 'test/unit/assertionfailederror' -require 'test/unit/util/backtracefilter' - -module Test - module Unit - - # Ties everything together. If you subclass and add your own - # test methods, it takes care of making them into tests and - # wrapping those tests into a suite. It also does the - # nitty-gritty of actually running an individual test and - # collecting its results into a Test::Unit::TestResult object. - # - # You can run two hooks before/after a TestCase run. - # - # Example: - # class TestMyClass < Test::Unit::TestCase - # class << self - # def startup - # ... - # end - # - # def shutdown - # ... - # end - # end - # - # def setup - # ... - # end - # - # def teardown - # ... - # end - # - # def test_my_method1 - # ... - # end - # - # def test_my_method2 - # ... - # end - # end - # - # Here is a call order: - # * startup - # * setup - # * test_my_method1 - # * teardown - # * setup - # * test_my_method2 - # * teardown - # * shutdown - class TestCase - include Attribute - include Fixture - include ExceptionHandler - include ErrorHandler - include FailureHandler - include TestCasePendingSupport - include TestCaseOmissionSupport - include TestCaseNotificationSupport - include Priority - include Assertions - include Util::BacktraceFilter - - STARTED = name + "::STARTED" - FINISHED = name + "::FINISHED" - - DESCENDANTS = [] - - class << self - def inherited(sub_class) - DESCENDANTS << sub_class - end - - # Rolls up all of the test* methods in the fixture into - # one suite, creating a new instance of the fixture for - # each method. - def suite - method_names = public_instance_methods(true).collect {|name| name.to_s} - tests = method_names.delete_if {|method_name| method_name !~ /^test./} - suite = TestSuite.new(name, self) - tests.sort.each do |test| - catch(:invalid_test) do - suite << new(test) - end - end - if suite.empty? - catch(:invalid_test) do - suite << new("default_test") - end - end - suite - end - end - - attr_reader :method_name - - # Creates a new instance of the fixture for running the - # test represented by test_method_name. - def initialize(test_method_name) - throw :invalid_test unless respond_to?(test_method_name) - throw :invalid_test if method(test_method_name).arity > 0 - @method_name = test_method_name - @test_passed = true - @interrupted = false - end - - # Runs the individual test method represented by this - # instance of the fixture, collecting statistics, failures - # and errors in result. - def run(result) - begin - @_result = result - yield(STARTED, name) - begin - run_setup - run_test - rescue Exception - @interrupted = true - raise unless handle_exception($!) - ensure - begin - run_teardown - rescue Exception - raise unless handle_exception($!) - end - end - result.add_run - yield(FINISHED, name) - ensure - @_result = nil - end - end - - # Called before every test method runs. Can be used - # to set up fixture information. - # - # You can add additional setup tasks by the following - # code: - # class TestMyClass < Test::Unit::TestCase - # def setup - # ... - # end - # - # setup - # def my_setup1 - # ... - # end - # - # setup - # def my_setup2 - # ... - # end - # - # def test_my_class - # ... - # end - # end - # - # Here is a call order: - # * setup - # * my_setup1 - # * my_setup2 - # * test_my_class - def setup - end - - # Called after every test method runs. Can be used to tear - # down fixture information. - # - # You can add additional teardown tasks by the following - # code: - # class TestMyClass < Test::Unit::TestCase - # def teardown - # ... - # end - # - # teardown - # def my_teardown1 - # ... - # end - # - # teardown - # def my_teardown2 - # ... - # end - # - # def test_my_class - # ... - # end - # end - # - # Here is a call order: - # * test_my_class - # * my_teardown2 - # * my_teardown1 - # * teardown - def teardown - end - - def default_test - flunk("No tests were specified") - end - - def size - 1 - end - - # Returns a human-readable name for the specific test that - # this instance of TestCase represents. - def name - "#{@method_name}(#{self.class.name})" - end - - # Overridden to return #name. - def to_s - name - end - - # It's handy to be able to compare TestCase instances. - def ==(other) - return false unless(other.kind_of?(self.class)) - return false unless(@method_name == other.method_name) - self.class == other.class - end - - def interrupted? - @interrupted - end - - private - def current_result - @_result - end - - def run_test - __send__(@method_name) - end - - def handle_exception(exception) - self.class.exception_handlers.each do |handler| - return true if send(handler, exception) - end - false - end - - # Returns whether this individual test passed or - # not. Primarily for use in teardown so that artifacts - # can be left behind if the test fails. - def passed? - @test_passed - end - - def problem_occurred - @test_passed = false - end - - def add_assertion - current_result.add_assertion - end - end - end -end Deleted: test-unit/lib/test/unit/testresult.rb (+0 -89) 100644 =================================================================== --- test-unit/lib/test/unit/testresult.rb 2010-09-12 03:03:44 +0000 (1af27a0) +++ /dev/null @@ -1,89 +0,0 @@ -#-- -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/util/observable' -require 'test/unit/failure' -require 'test/unit/error' -require 'test/unit/omission' -require 'test/unit/pending' -require 'test/unit/notification' - -module Test - module Unit - module NullResultContainerInitializer - private - def initialize_containers - end - end - - # Collects Test::Unit::Failure and Test::Unit::Error so that - # they can be displayed to the user. To this end, observers - # can be added to it, allowing the dynamic updating of, say, a - # UI. - class TestResult - include Util::Observable - include NullResultContainerInitializer - include TestResultFailureSupport - include TestResultErrorSupport - include TestResultPendingSupport - include TestResultOmissionSupport - include TestResultNotificationSupport - - CHANGED = "CHANGED" - FAULT = "FAULT" - - attr_reader :run_count, :assertion_count, :faults - - # Constructs a new, empty TestResult. - def initialize - @run_count, @assertion_count = 0, 0 - @summary_generators = [] - @problem_checkers = [] - @faults = [] - initialize_containers - end - - # Records a test run. - def add_run - @run_count += 1 - notify_changed - end - - # Records an individual assertion. - def add_assertion - @assertion_count += 1 - notify_changed - end - - # Returns a string contain the recorded runs, assertions, - # failures and errors in this TestResult. - def summary - ["#{run_count} tests", - "#{assertion_count} assertions", - *@summary_generators.collect {|generator| send(generator)}].join(", ") - end - - def to_s - summary - end - - # Returns whether or not this TestResult represents - # successful completion. - def passed? - @problem_checkers.all? {|checker| not send(checker)} - end - - private - def notify_changed - notify_listeners(CHANGED, self) - end - - def notify_fault(fault) - @faults << fault - notify_listeners(FAULT, fault) - end - end - end -end Deleted: test-unit/lib/test/unit/testsuite.rb (+0 -110) 100644 =================================================================== --- test-unit/lib/test/unit/testsuite.rb 2010-09-12 03:03:44 +0000 (02a2ec3) +++ /dev/null @@ -1,110 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/error' - -module Test - module Unit - - # A collection of tests which can be #run. - # - # Note: It is easy to confuse a TestSuite instance with - # something that has a static suite method; I know because _I_ - # have trouble keeping them straight. Think of something that - # has a suite method as simply providing a way to get a - # meaningful TestSuite instance. - class TestSuite - attr_reader :name, :tests - - STARTED = name + "::STARTED" - FINISHED = name + "::FINISHED" - - # Creates a new TestSuite with the given name. - def initialize(name="Unnamed TestSuite", test_case=nil) - @name = name - @tests = [] - @test_case = test_case - end - - # Runs the tests and/or suites contained in this - # TestSuite. - def run(result, &progress_block) - yield(STARTED, name) - run_startup(result) - @tests.each do |test| - test.run(result, &progress_block) - end - run_shutdown(result) - yield(FINISHED, name) - end - - # Adds the test to the suite. - def <<(test) - @tests << test - self - end - - def delete(test) - @tests.delete(test) - end - - # Retuns the rolled up number of tests in this suite; - # i.e. if the suite contains other suites, it counts the - # tests within those suites, not the suites themselves. - def size - total_size = 0 - @tests.each { |test| total_size += test.size } - total_size - end - - def empty? - tests.empty? - end - - # Overridden to return the name given the suite at - # creation. - def to_s - @name - end - - # It's handy to be able to compare TestSuite instances. - def ==(other) - return false unless(other.kind_of?(self.class)) - return false unless(@name == other.name) - @tests == other.tests - end - - private - def run_startup(result) - return if @test_case.nil? or !@test_case.respond_to?(:startup) - begin - @test_case.startup - rescue Exception - raise unless handle_exception($!, result) - end - end - - def run_shutdown(result) - return if @test_case.nil? or !@test_case.respond_to?(:shutdown) - begin - @test_case.shutdown - rescue Exception - raise unless handle_exception($!, result) - end - end - - def handle_exception(exception, result) - case exception - when *ErrorHandler::PASS_THROUGH_EXCEPTIONS - false - else - result.add_error(Error.new(@test_case.name, exception)) - true - end - end - end - end -end Deleted: test-unit/lib/test/unit/ui/console/outputlevel.rb (+0 -14) 100644 =================================================================== --- test-unit/lib/test/unit/ui/console/outputlevel.rb 2010-09-12 03:03:44 +0000 (67e5d9b) +++ /dev/null @@ -1,14 +0,0 @@ -module Test - module Unit - module UI - module Console - module OutputLevel - SILENT = 0 - PROGRESS_ONLY = 1 - NORMAL = 2 - VERBOSE = 3 - end - end - end - end -end Deleted: test-unit/lib/test/unit/ui/console/testrunner.rb (+0 -195) 100644 =================================================================== --- test-unit/lib/test/unit/ui/console/testrunner.rb 2010-09-12 03:03:44 +0000 (271a58d) +++ /dev/null @@ -1,195 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/color' -require 'test/unit/ui/testrunner' -require 'test/unit/ui/testrunnermediator' -require 'test/unit/ui/console/outputlevel' - -module Test - module Unit - module UI - module Console - - # Runs a Test::Unit::TestSuite on the console. - class TestRunner < UI::TestRunner - include OutputLevel - - COLOR_SCHEMES = { - :default => { - "success" => Color.new("green", :bold => true), - "failure" => Color.new("red", :bold => true), - "pending" => Color.new("magenta", :bold => true), - "omission" => Color.new("blue", :bold => true), - "notification" => Color.new("cyan", :bold => true), - "error" => Color.new("yellow", :bold => true), - }, - } - - # Creates a new TestRunner for running the passed - # suite. If quiet_mode is true, the output while - # running is limited to progress dots, errors and - # failures, and the final result. io specifies - # where runner output should go to; defaults to - # STDOUT. - def initialize(suite, options={}) - super - @output_level = @options[:output_level] || NORMAL - @output = @options[:output] || STDOUT - @use_color = @options[:use_color] - @use_color = guess_color_availability if @use_color.nil? - @color_scheme = COLOR_SCHEMES[:default] - @reset_color = Color.new("reset") - @already_outputted = false - @faults = [] - end - - # Begins the test run. - def start - setup_mediator - attach_to_mediator - return start_mediator - end - - private - def setup_mediator - @mediator = create_mediator(@suite) - output_setup_end - end - - def output_setup_end - suite_name = @suite.to_s - suite_name = @suite.name if @suite.kind_of?(Module) - output("Loaded suite #{suite_name}") - end - - def create_mediator(suite) - return TestRunnerMediator.new(suite) - end - - def attach_to_mediator - @mediator.add_listener(TestResult::FAULT, &method(:add_fault)) - @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started)) - @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished)) - @mediator.add_listener(TestCase::STARTED, &method(:test_started)) - @mediator.add_listener(TestCase::FINISHED, &method(:test_finished)) - end - - def start_mediator - return @mediator.run_suite - end - - def add_fault(fault) - @faults << fault - output_single(fault.single_character_display, - fault_color(fault), - PROGRESS_ONLY) - @already_outputted = true - end - - def started(result) - @result = result - output_started - end - - def output_started - output("Started") - end - - def finished(elapsed_time) - nl if output?(NORMAL) and !output?(VERBOSE) - nl - output("Finished in #{elapsed_time} seconds.") - @faults.each_with_index do |fault, index| - nl - output_single("%3d) " % (index + 1)) - label, detail = format_fault(fault).split(/\r?\n/, 2) - output(label, fault_color(fault)) - output(detail) - end - nl - output(@result, result_color) - end - - def format_fault(fault) - fault.long_display - end - - def test_started(name) - output_single(name + ": ", nil, VERBOSE) - end - - def test_finished(name) - unless @already_outputted - output_single(".", @color_scheme["success"], PROGRESS_ONLY) - end - nl(VERBOSE) - @already_outputted = false - end - - def nl(level=NORMAL) - output("", nil, level) - end - - def output(something, color=nil, level=NORMAL) - return unless output?(level) - output_single(something, color, level) - @output.puts - end - - def output_single(something, color=nil, level=NORMAL) - return unless output?(level) - if @use_color and color - something = "%s%s%s" % [color.escape_sequence, - something, - @reset_color.escape_sequence] - end - @output.write(something) - @output.flush - end - - def output?(level) - level <= @output_level - end - - def fault_color(fault) - @color_scheme[fault.class.name.split(/::/).last.downcase] - end - - def result_color - if @result.passed? - if @result.pending_count > 0 - @color_scheme["pending"] - elsif @result.omission_count > 0 - @color_scheme["omission"] - elsif @result.notification_count > 0 - @color_scheme["notification"] - else - @color_scheme["success"] - end - elsif @result.error_count > 0 - @color_scheme["error"] - elsif @result.failure_count > 0 - @color_scheme["failure"] - end - end - - def guess_color_availability - return false unless @output.tty? - term = ENV["TERM"] - return true if term and (/term\z/ =~ term or term == "screen") - return true if ENV["EMACS"] == "t" - false - end - end - end - end - end -end - -if __FILE__ == $0 - Test::Unit::UI::Console::TestRunner.start_command_line_test -end Deleted: test-unit/lib/test/unit/ui/emacs/testrunner.rb (+0 -49) 100644 =================================================================== --- test-unit/lib/test/unit/ui/emacs/testrunner.rb 2010-09-12 03:03:44 +0000 (eed17a7) +++ /dev/null @@ -1,49 +0,0 @@ -require 'test/unit/ui/console/testrunner' - -module Test - module Unit - module UI - module Emacs - class TestRunner < Console::TestRunner - private - def output_setup_end - end - - def output_started - end - - def format_fault(fault) - return super unless fault.respond_to?(:label) - format_method_name = "format_fault_#{fault.label.downcase}" - if respond_to?(format_method_name, true) - send(format_method_name, fault) - else - super - end - end - - def format_fault_failure(failure) - if failure.location.size == 1 - location = failure.location[0] - location_display = location.sub(/\A(.+:\d+).*/, ' [\\1]') - else - location_display = "\n" + failure.location.join("\n") - end - result = "#{failure.label}:\n" - result << "#{failure.test_name}#{location_display}:\n" - result << failure.message - result - end - - def format_fault_error(error) - result = "#{error.label}:\n" - result << "#{error.test_name}:\n" - result << "#{error.message}\n" - result << error.backtrace.join("\n") - result - end - end - end - end - end -end Deleted: test-unit/lib/test/unit/ui/testrunner.rb (+0 -20) 100644 =================================================================== --- test-unit/lib/test/unit/ui/testrunner.rb 2010-09-12 03:03:44 +0000 (e872b03) +++ /dev/null @@ -1,20 +0,0 @@ -require 'test/unit/ui/testrunnerutilities' - -module Test - module Unit - module UI - class TestRunner - extend TestRunnerUtilities - - def initialize(suite, options={}) - if suite.respond_to?(:suite) - @suite = suite.suite - else - @suite = suite - end - @options = options - end - end - end - end -end Deleted: test-unit/lib/test/unit/ui/testrunnermediator.rb (+0 -77) 100644 =================================================================== --- test-unit/lib/test/unit/ui/testrunnermediator.rb 2010-09-12 03:03:44 +0000 (7033f3b) +++ /dev/null @@ -1,77 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' -require 'test/unit/util/observable' -require 'test/unit/testresult' - -module Test - module Unit - module UI - - # Provides an interface to write any given UI against, - # hopefully making it easy to write new UIs. - class TestRunnerMediator - RESET = name + "::RESET" - STARTED = name + "::STARTED" - FINISHED = name + "::FINISHED" - - include Util::Observable - - # Creates a new TestRunnerMediator initialized to run - # the passed suite. - def initialize(suite) - @suite = suite - end - - # Runs the suite the TestRunnerMediator was created - # with. - def run_suite - Unit.run = true - - result = create_result - result_listener = result.add_listener(TestResult::CHANGED) do |*args| - notify_listeners(TestResult::CHANGED, *args) - end - fault_listener = result.add_listener(TestResult::FAULT) do |*args| - notify_listeners(TestResult::FAULT, *args) - end - - start_time = Time.now - begin - notify_listeners(RESET, @suite.size) - notify_listeners(STARTED, result) - - @suite.run(result) do |channel, value| - notify_listeners(channel, value) - end - ensure - elapsed_time = Time.now - start_time - result.remove_listener(TestResult::FAULT, fault_listener) - result.remove_listener(TestResult::CHANGED, result_listener) - notify_listeners(FINISHED, elapsed_time) - end - - result - end - - private - # A factory method to create the result the mediator - # should run with. Can be overridden by subclasses if - # one wants to use a different result. - def create_result - TestResult.new - end - - def measure_time - begin_time = Time.now - yield - Time.now - begin_time - end - end - end - end -end Deleted: test-unit/lib/test/unit/ui/testrunnerutilities.rb (+0 -41) 100644 =================================================================== --- test-unit/lib/test/unit/ui/testrunnerutilities.rb 2010-09-12 03:03:44 +0000 (33d80fb) +++ /dev/null @@ -1,41 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -module Test - module Unit - module UI - - # Provides some utilities common to most, if not all, - # TestRunners. - # - #-- - # - # Perhaps there ought to be a TestRunner superclass? There - # seems to be a decent amount of shared code between test - # runners. - - module TestRunnerUtilities - - # Creates a new TestRunner and runs the suite. - def run(suite, options={}) - return new(suite, options).start - end - - # Takes care of the ARGV parsing and suite - # determination necessary for running one of the - # TestRunners from the command line. - def start_command_line_test - if ARGV.empty? - puts "You should supply the name of a test suite file to the runner" - exit - end - require ARGV[0].gsub(/.+::/, '') - new(eval(ARGV[0])).start - end - end - end - end -end Deleted: test-unit/lib/test/unit/util/backtracefilter.rb (+0 -41) 100644 =================================================================== --- test-unit/lib/test/unit/util/backtracefilter.rb 2010-09-12 03:03:44 +0000 (1ea8103) +++ /dev/null @@ -1,41 +0,0 @@ -module Test - module Unit - module Util - module BacktraceFilter - TESTUNIT_FILE_SEPARATORS = %r{[\\/:]} - TESTUNIT_PREFIX = __FILE__.split(TESTUNIT_FILE_SEPARATORS)[0..-3] - TESTUNIT_RB_FILE = /\.rb\Z/ - - module_function - def filter_backtrace(backtrace, prefix=nil) - return ["No backtrace"] unless(backtrace) - split_p = if(prefix) - prefix.split(TESTUNIT_FILE_SEPARATORS) - else - TESTUNIT_PREFIX - end - match = proc do |e| - split_e = e.split(TESTUNIT_FILE_SEPARATORS)[0, split_p.size] - next false unless(split_e[0..-2] == split_p[0..-2]) - split_e[-1].sub(TESTUNIT_RB_FILE, '') == split_p[-1] - end - return backtrace unless(backtrace.detect(&match)) - found_prefix = false - new_backtrace = backtrace.reverse.reject do |e| - if(match[e]) - found_prefix = true - true - elsif(found_prefix) - false - else - true - end - end.reverse - new_backtrace = (new_backtrace.empty? ? backtrace : new_backtrace) - new_backtrace = new_backtrace.reject(&match) - new_backtrace.empty? ? backtrace : new_backtrace - end - end - end - end -end Deleted: test-unit/lib/test/unit/util/observable.rb (+0 -90) 100644 =================================================================== --- test-unit/lib/test/unit/util/observable.rb 2010-09-12 03:03:44 +0000 (3567d34) +++ /dev/null @@ -1,90 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/util/procwrapper' - -module Test - module Unit - module Util - - # This is a utility class that allows anything mixing - # it in to notify a set of listeners about interesting - # events. - module Observable - # We use this for defaults since nil might mean something - NOTHING = "NOTHING/#{__id__}" - - # Adds the passed proc as a listener on the - # channel indicated by channel_name. listener_key - # is used to remove the listener later; if none is - # specified, the proc itself is used. - # - # Whatever is used as the listener_key is - # returned, making it very easy to use the proc - # itself as the listener_key: - # - # listener = add_listener("Channel") { ... } - # remove_listener("Channel", listener) - def add_listener(channel_name, listener_key=NOTHING, &listener) # :yields: value - unless(block_given?) - raise ArgumentError.new("No callback was passed as a listener") - end - - key = listener_key - if (listener_key == NOTHING) - listener_key = listener - key = ProcWrapper.new(listener) - end - - channels[channel_name] ||= {} - channels[channel_name][key] = listener - return listener_key - end - - # Removes the listener indicated by listener_key - # from the channel indicated by - # channel_name. Returns the registered proc, or - # nil if none was found. - def remove_listener(channel_name, listener_key) - channel = channels[channel_name] - return nil unless (channel) - key = listener_key - if (listener_key.instance_of?(Proc)) - key = ProcWrapper.new(listener_key) - end - if (channel.has_key?(key)) - return channel.delete(key) - end - return nil - end - - # Calls all the procs registered on the channel - # indicated by channel_name. If value is - # specified, it is passed in to the procs, - # otherwise they are called with no arguments. - # - #-- - # - # Perhaps this should be private? Would it ever - # make sense for an external class to call this - # method directly? - def notify_listeners(channel_name, *arguments) - channel = channels[channel_name] - return 0 unless (channel) - listeners = channel.values - listeners.each { |listener| listener.call(*arguments) } - return listeners.size - end - - private - def channels - @channels ||= {} - return @channels - end - end - end - end -end Deleted: test-unit/lib/test/unit/util/procwrapper.rb (+0 -48) 100644 =================================================================== --- test-unit/lib/test/unit/util/procwrapper.rb 2010-09-12 03:03:44 +0000 (ad72521) +++ /dev/null @@ -1,48 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -module Test - module Unit - module Util - - # Allows the storage of a Proc passed through '&' in a - # hash. - # - # Note: this may be inefficient, since the hash being - # used is not necessarily very good. In Observable, - # efficiency is not too important, since the hash is - # only accessed when adding and removing listeners, - # not when notifying. - - class ProcWrapper - - # Creates a new wrapper for a_proc. - def initialize(a_proc) - @a_proc = a_proc - @hash = a_proc.inspect.sub(/^(#<#{a_proc.class}:)/){''}.sub(/(>)$/){''}.hex - end - - def hash - return @hash - end - - def ==(other) - case(other) - when ProcWrapper - return @a_proc == other.to_proc - else - return super - end - end - alias :eql? :== - - def to_proc - return @a_proc - end - end - end - end -end Deleted: test-unit/lib/test/unit/version.rb (+0 -7) 100644 =================================================================== --- test-unit/lib/test/unit/version.rb 2010-09-12 03:03:44 +0000 (9d65d76) +++ /dev/null @@ -1,7 +0,0 @@ - -# HACK: quick and dirty to get integrated into the new project - ryan -module Test - module Unit - VERSION = '2.0.1' - end -end Deleted: test-unit/sample/adder.rb (+0 -13) 100644 =================================================================== --- test-unit/sample/adder.rb 2010-09-12 03:03:44 +0000 (aa5c88c) +++ /dev/null @@ -1,13 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -class Adder - def initialize(number) - @number = number - end - def add(number) - return @number + number - end -end - Deleted: test-unit/sample/subtracter.rb (+0 -12) 100644 =================================================================== --- test-unit/sample/subtracter.rb 2010-09-12 03:03:44 +0000 (2c08247) +++ /dev/null @@ -1,12 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -class Subtracter - def initialize(number) - @number = number - end - def subtract(number) - return @number - number - end -end Deleted: test-unit/sample/tc_adder.rb (+0 -18) 100644 =================================================================== --- test-unit/sample/tc_adder.rb 2010-09-12 03:03:44 +0000 (8453beb) +++ /dev/null @@ -1,18 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' -require 'adder' - -class TC_Adder < Test::Unit::TestCase - def setup - @adder = Adder.new(5) - end - def test_add - assert_equal(7, @adder.add(2), "Should have added correctly") - end - def teardown - @adder = nil - end -end Deleted: test-unit/sample/tc_subtracter.rb (+0 -18) 100644 =================================================================== --- test-unit/sample/tc_subtracter.rb 2010-09-12 03:03:44 +0000 (d2c8313) +++ /dev/null @@ -1,18 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' -require 'subtracter' - -class TC_Subtracter < Test::Unit::TestCase - def setup - @subtracter = Subtracter.new(5) - end - def test_subtract - assert_equal(3, @subtracter.subtract(2), "Should have subtracted correctly") - end - def teardown - @subtracter = nil - end -end Deleted: test-unit/sample/ts_examples.rb (+0 -7) 100644 =================================================================== --- test-unit/sample/ts_examples.rb 2010-09-12 03:03:44 +0000 (3d24dd6) +++ /dev/null @@ -1,7 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' -require 'tc_adder' -require 'tc_subtracter' Deleted: test-unit/test/collector/test_descendant.rb (+0 -135) 100644 =================================================================== --- test-unit/test/collector/test_descendant.rb 2010-09-12 03:03:44 +0000 (6b6132e) +++ /dev/null @@ -1,135 +0,0 @@ -require 'test/unit' -require 'test/unit/collector/descendant' - -class TestUnitCollectorDescendant < Test::Unit::TestCase - def setup - @previous_descendants = Test::Unit::TestCase::DESCENDANTS.dup - Test::Unit::TestCase::DESCENDANTS.clear - - @test_case1 = Class.new(Test::Unit::TestCase) do - def self.name - "test-case1" - end - - def test_1 - end - - def test_2 - end - end - - @test_case2 = Class.new(Test::Unit::TestCase) do - def self.name - "test-case2" - end - - def test_0 - end - end - - @no_test_case = Class.new do - def self.name - "no-test-case" - end - - def test_4 - end - end - end - - def teardown - Test::Unit::TestCase::DESCENDANTS.replace(@previous_descendants) - end - - def test_basic_collection - assert_collect(full_suite("name"), "name") - - assert_collect(full_suite("name"), "name") do |collector| - collector.filter = [] - end - end - - def test_filtered_collection - assert_collect(empty_suite) do |collector| - collector.filter = Proc.new {false} - end - - assert_collect(full_suite) do |collector| - collector.filter = Proc.new {true} - end - - assert_collect(full_suite) do |collector| - collector.filter = Proc.new {nil} - end - - assert_collect(empty_suite) do |collector| - collector.filter = [Proc.new {false}, Proc.new {true}] - end - - assert_collect(full_suite) do |collector| - collector.filter = [Proc.new {true}, Proc.new {false}] - end - - assert_collect(empty_suite) do |collector| - collector.filter = [Proc.new {nil}, Proc.new {false}] - end - - assert_collect(full_suite) do |collector| - collector.filter = [Proc.new {nil}, Proc.new {true}] - end - - expected = empty_suite - suite1 = Test::Unit::TestSuite.new(@test_case1.name) - suite1 << @test_case1.new("test_1") - suite2 = Test::Unit::TestSuite.new(@test_case2.name) - suite2 << @test_case2.new("test_0") - expected << suite1 << suite2 - assert_collect(expected) do |collector| - collector.filter = Proc.new do |test| - ['test_1', 'test_0'].include?(test.method_name) - end - end - - expected = empty_suite - suite1 = Test::Unit::TestSuite.new(@test_case1.name) - suite1 << @test_case1.new("test_1") - suite2 = Test::Unit::TestSuite.new(@test_case2.name) - suite2 << @test_case2.new("test_0") - expected << suite1 << suite2 - assert_collect(expected) do |collector| - filters = [Proc.new {|test| test.method_name == 'test_1' ? true : nil}, - Proc.new {|test| test.method_name == 'test_0' ? true : nil}, - Proc.new {false}] - collector.filter = filters - end - end - - private - def assert_collect(expected, *collect_args) - collector = Test::Unit::Collector::Descendant.new - yield(collector) if block_given? - assert_equal(expected, collector.send(:collect, *collect_args)) - end - - def default_name - Test::Unit::Collector::Descendant::NAME - end - - def empty_suite(name=nil) - Test::Unit::TestSuite.new(name || default_name) - end - - def full_suite(name=nil) - sub_suite1 = Test::Unit::TestSuite.new(@test_case1.name) - sub_suite1 << @test_case1.new('test_1') - sub_suite1 << @test_case1.new('test_2') - - sub_suite2 = Test::Unit::TestSuite.new(@test_case2.name) - sub_suite2 << @test_case2.new('test_0') - - suite = empty_suite(name) - suite << sub_suite1 - suite << sub_suite2 - suite - end -end Deleted: test-unit/test/collector/test_dir.rb (+0 -406) 100644 =================================================================== --- test-unit/test/collector/test_dir.rb 2010-09-12 03:03:44 +0000 (2de802c) +++ /dev/null @@ -1,406 +0,0 @@ -require 'test/unit' -require 'test/unit/collector/dir' -require 'pp' - -module Test - module Unit - module Collector - class TestDir < TestCase - class FileSystem - class Directory - def initialize(name, fs, parent=self, &block) - @name = name - @fs = fs - @parent = parent - @contents = {'.' => self, '..' => parent} - instance_eval(&block) if(block) - end - - def file(name, contents) - @contents[name] = contents - end - - def dir(name, &block) - @contents[name] = self.class.new(name, @fs, self, &block) - end - - def entries - @contents.keys - end - - def directory?(name) - return true if(name.nil? || name.empty?) - return false unless(@contents.include?(name)) - @contents[name].kind_of?(self.class) - end - - def file?(name) - return false unless(@contents.include?(name)) - !directory?(name) - end - - def exist?(name) - @contents.include?(name) - end - - def [](name) - raise Errno::ENOENT, name unless(@contents.include?(name)) - @contents[name] - end - - def path_to(name=nil) - if(!name) - @parent.path_to(@name) - elsif(@parent == self) - @fs.join('/', name) - else - @fs.join(@parent.path_to(@name), name) - end - end - end - - class ObjectSpace - def initialize - @objects = [] - end - - def each_object(klass, &block) - @objects.find_all{|o| o.kind_of?(klass)}.each(&block) - end - - def <<(object) - @objects << object - end - end - - attr_reader :object_space - - def initialize(&block) - @root = Directory.new('/', self, &block) - @pwd = @root - @object_space = ObjectSpace.new - @required = [] - end - - def entries(dir) - e = find(dir) - require_directory(dir) - e.entries - end - - def directory?(name) - return true if (base = basename(name)) == '/' - e = find(dirname(name)) - return false unless(e) - e.directory?(base) - end - - def find(path) - if(/\A\// =~ path) - thing = @root - else - thing = @pwd - end - path.scan(/[^\/]+/) do |e| - break thing = false unless(thing.kind_of?(Directory)) - thing = thing[e] - end - thing - end - - def dirname(name) - if (name = name.tr_s('/', '/')) == '/' - name - else - name[%r"\A.+(?=/[^/]+/?\z)|\A/"] || "." - end - end - - def basename(name) - name[%r"(\A/|[^/]+)/*\z", 1] - end - - def split(name) - [dirname(name), basename(name)] - end - - def join(*parts) - parts.join('/').gsub(%r{/+}, '/') - end - - def file?(name) - e = find(dirname(name)) - return false unless(e) - e.file?(basename(name)) - end - - def pwd - @pwd.path_to - end - - def chdir(to) - e = find(to) - require_directory(to) - @pwd = e - end - - def expand_path(path, base = nil) - until /\A\// =~ path - base ||= pwd - path = join(base, path) - base = nil - end - path.gsub!(%r"(?:/\.)+(?=/)", '') - nil while path.sub!(%r"/(?!\.\./)[^/]+/\.\.(?=/)", '') - path.sub!(%r"\A(?:/\.\.)+(?=/)", '') - path.sub!(%r"(?:\A(/)|/)\.\.?\z", '\1') - path - end - - def require_directory(path) - raise Errno::ENOTDIR, path unless(directory?(path)) - end - - def require(file) - return false if(@required.include?(file)) - begin - e = find(file) - rescue Errno::ENOENT => e - if(/\.rb\Z/ =~ file) - raise LoadError, file - end - e = find(file + '.rb') - end - @required << file - @object_space << e - true - rescue Errno::ENOENT - raise LoadError, file - end - end - - def test_dir - inner_dir = nil - dirs = FileSystem::Directory.new('/', nil) do - file 'a', nil - inner_dir = dir 'b' - end - assert_equal(inner_dir, dirs['b']) - end - - def test_fs - fs = FileSystem.new do - file 'a', nil - dir 'b' - end - assert_equal(['.', '..', 'a', 'b'].sort, fs.entries('/').sort) - assert(fs.directory?('/')) - assert(!fs.directory?('/a')) - assert(!fs.directory?('/bogus')) - assert(fs.file?('/a')) - assert(!fs.file?('/')) - assert(!fs.file?('/bogus')) - assert(fs.directory?('/b')) - assert(fs.file?('a')) - assert(fs.directory?('b')) - end - - def test_fs_sub - fs = FileSystem.new do - dir 'a' do - file 'b', nil - dir 'c' do - file 'd', nil - end - end - end - assert(fs.file?('/a/b')) - assert(!fs.file?('/a/b/c/d')) - assert(fs.file?('/a/c/d')) - end - - def test_fs_pwd - fs = FileSystem.new do - file 'a', nil - dir 'b' do - file 'c', nil - dir 'd' do - file 'e', nil - end - end - end - assert_equal('/', fs.pwd) - assert_raises(Errno::ENOENT) do - fs.chdir('bogus') - end - assert_raises(Errno::ENOTDIR) do - fs.chdir('a') - end - fs.chdir('b') - assert_equal('/b', fs.pwd) - fs.chdir('d') - assert_equal('/b/d', fs.pwd) - fs.chdir('..') - assert_equal('/b', fs.pwd) - fs.chdir('..') - assert_equal('/', fs.pwd) - end - - def test_fs_entries - fs = FileSystem.new do - file 'a', nil - dir 'b' do - file 'c', nil - file 'd', nil - end - file 'e', nil - dir 'f' do - file 'g', nil - dir 'h' do - file 'i', nil - end - end - end - assert_equal(['.', '..', 'a', 'b', 'e', 'f'], fs.entries('/').sort) - assert_equal(['.', '..', 'a', 'b', 'e', 'f'], fs.entries('.').sort) - assert_equal(['.', '..', 'a', 'b', 'e', 'f'], fs.entries('b/..').sort) - assert_equal(['.', '..', 'c', 'd'], fs.entries('b').sort) - assert_raises(Errno::ENOENT) do - fs.entries('z') - end - assert_raises(Errno::ENOTDIR) do - fs.entries('a') - end - fs.chdir('f') - assert_equal(['.', '..', 'i'], fs.entries('h').sort) - end - - class TestClass1 - end - class TestClass2 - end - def test_fs_require - fs = FileSystem.new do - file 'test_class1.rb', TestClass1 - dir 'dir' do - file 'test_class2.rb', TestClass2 - end - end - c = [] - fs.object_space.each_object(Class) do |o| - c << o - end - assert_equal([], c) - - assert_raises(LoadError) do - fs.require('bogus') - end - - assert(fs.require('test_class1.rb')) - assert(!fs.require('test_class1.rb')) - c = [] - fs.object_space.each_object(Class) do |o| - c << o - end - assert_equal([TestClass1], c) - - fs.require('dir/test_class2') - c = [] - fs.object_space.each_object(Class) do |o| - c << o - end - assert_equal([TestClass1, TestClass2], c) - - c = [] - fs.object_space.each_object(Time) do |o| - c << o - end - assert_equal([], c) - end - - def setup - @t1 = t1 = create_test(1) - @t2 = t2 = create_test(2) - @t3 = t3 = create_test(3) - @t4 = t4 = create_test(4) - @t5 = t5 = create_test(5) - @t6 = t6 = create_test(6) - fs = FileSystem.new do - file 'test_1.rb', t1 - file 'test_2.rb', t2 - dir 'd1' do - file 'test_3.rb', t3 - end - file 't4.rb', t4 - dir 'd2' do - file 'test_5', t5 - file 'test_6.rb', Time - end - file 't6.rb', t6 - end - fs.require('t6') - @c = Dir.new(fs, fs, fs.object_space, fs) - end - - def create_test(name) - t = Class.new(TestCase) - t.class_eval <<-EOC - def self.name - "T\#{#{name}}" - end - def test_#{name}a - end - def test_#{name}b - end - EOC - t - end - - def test_simple_collect - expected = TestSuite.new('d1') - expected << (@t3.suite) - assert_equal(expected, @c.collect('d1')) - end - - def test_multilevel_collect - expected = TestSuite.new('.') - expected << @t1.suite << @t2.suite - expected << (TestSuite.new('d1') << @t3.suite) - assert_equal(expected, @c.collect) - end - - def test_collect_file - expected = TestSuite.new('test_1.rb') - expected << @t1.suite - assert_equal(expected, @c.collect('test_1.rb')) - - expected = TestSuite.new('t4.rb') - expected << @t4.suite - assert_equal(expected, @c.collect('t4.rb')) - end - - def test_nil_pattern - expected = TestSuite.new('d2') - expected << @t5.suite - @c.pattern.clear - assert_equal(expected, @c.collect('d2')) - end - - def test_filtering - expected = TestSuite.new('.') - expected << @t1.suite - @c.filter = proc{|t| t.method_name == 'test_1a' || t.method_name == 'test_1b'} - assert_equal(expected, @c.collect) - end - - def test_collect_multi - expected = TestSuite.new('[d1, d2]') - expected << (TestSuite.new('d1') << @t3.suite) - expected << (TestSuite.new('d2') << @t5.suite) - @c.pattern.replace([/\btest_/]) - assert_equal(expected, @c.collect('d1', 'd2')) - end - end - end - end -end Deleted: test-unit/test/collector/test_load.rb (+0 -333) 100644 =================================================================== --- test-unit/test/collector/test_load.rb 2010-09-12 03:03:44 +0000 (051c764) +++ /dev/null @@ -1,333 +0,0 @@ -require 'tmpdir' -require 'pathname' - -require 'test/unit' -require 'test/unit/collector/load' - -class TestUnitCollectorLoad < Test::Unit::TestCase - def setup - @previous_descendants = Test::Unit::TestCase::DESCENDANTS.dup - Test::Unit::TestCase::DESCENDANTS.clear - - @temporary_test_cases_module_name = "TempTestCases" - ::Object.const_set(@temporary_test_cases_module_name, Module.new) - - @test_dir = Pathname(Dir.tmpdir) + "test-unit" - @test_dir.rmtree if @test_dir.exist? - @test_dir.mkpath - end - - setup - def setup_top_level_test_cases - @test_case1 = @test_dir + "test_case1.rb" - @test_case2 = @test_dir + "test_case2.rb" - @no_load_test_case3 = @test_dir + "case3.rb" - - @test_case1.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class TestCase1 < Test::Unit::TestCase - def test1_1 - end - - def test1_2 - end - end -end -EOT - end - - @test_case2.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class TestCase2 < Test::Unit::TestCase - def test2 - end - end -end -EOT - end - - @no_load_test_case3.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class NoLoadTestCase3 < Test::Unit::TestCase - def test3 - end - end -end -EOT - end - end - - setup - def setup_sub_level_test_cases - @sub_test_dir = @test_dir + "sub" - @sub_test_dir.mkpath - - @sub_test_case4 = @sub_test_dir + "test_case4.rb" - @no_load_sub_test_case5 = @sub_test_dir + "case5.rb" - @sub_test_case6 = @sub_test_dir + "test_case6.rb" - - @sub_test_case4.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class SubTestCase4 < Test::Unit::TestCase - def test4_1 - end - - def test4_2 - end - end -end -EOT - end - - @no_load_sub_test_case5.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class NoLoadSubTestCase5 < Test::Unit::TestCase - def test5_1 - end - - def test5_2 - end - end -end -EOT - end - - @sub_test_case6.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class SubTestCase6 < Test::Unit::TestCase - def test6 - end - end -end -EOT - end - end - - setup - def setup_sub_level_test_cases2 - @sub2_test_dir = @test_dir + "sub2" - @sub2_test_dir.mkpath - - @no_load_sub2_test_case7 = @sub2_test_dir + "case7.rb" - @sub2_test_case8 = @sub2_test_dir + "test_case8.rb" - @sub2_test_case9 = @sub2_test_dir + "test_case9.rb" - - @no_load_sub2_test_case7.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class NoLoadSub2TestCase7 < Test::Unit::TestCase - def test7_1 - end - - def test7_2 - end - end -end -EOT - end - - @sub2_test_case8.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class Sub2TestCase8 < Test::Unit::TestCase - def test8_1 - end - - def test8_2 - end - end -end -EOT - end - - @sub2_test_case9.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class Sub2TestCase9 < Test::Unit::TestCase - def test9 - end - end -end -EOT - end - end - - setup - def setup_svn_test_cases - @svn_test_dir = @test_dir + ".svn" - @svn_test_dir.mkpath - - @svn_test_case10 = @svn_test_dir + "test_case10.rb" - - @svn_test_case10.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class SvnTestCase10 < Test::Unit::TestCase - def test7 - end - end -end -EOT - end - end - - setup - def setup_sub_cvs_test_cases - @sub_cvs_test_dir = @sub_test_dir + "CVS" - @sub_cvs_test_dir.mkpath - - @sub_cvs_test_case11 = @sub_cvs_test_dir + "test_case11.rb" - - @sub_cvs_test_case11.open("w") do |test_case| - test_case.puts(<<-EOT) -module #{@temporary_test_cases_module_name} - class SubCVSTestCase11 < Test::Unit::TestCase - def test11 - end - end -end -EOT - end - end - - def teardown - @test_dir.rmtree if @test_dir.exist? - ::Object.send(:remove_const, @temporary_test_cases_module_name) - Test::Unit::TestCase::DESCENDANTS.replace(@previous_descendants) - end - - def test_simple_collect - assert_collect([:suite, {:name => @sub_test_dir.basename.to_s}, - [:suite, {:name => _test_case_name("SubTestCase4")}, - [:test, {:name => "test4_1"}], - [:test, {:name => "test4_2"}]], - [:suite, {:name => _test_case_name("SubTestCase6")}, - [:test, {:name => "test6"}]]], - @sub_test_dir.to_s) - end - - def test_multilevel_collect - assert_collect([:suite, {:name => "."}, - [:suite, {:name => _test_case_name("TestCase1")}, - [:test, {:name => "test1_1"}], - [:test, {:name => "test1_2"}]], - [:suite, {:name => _test_case_name("TestCase2")}, - [:test, {:name => "test2"}]], - [:suite, {:name => @sub_test_dir.basename.to_s}, - [:suite, {:name => _test_case_name("SubTestCase4")}, - [:test, {:name => "test4_1"}], - [:test, {:name => "test4_2"}]], - [:suite, {:name => _test_case_name("SubTestCase6")}, - [:test, {:name => "test6"}]]], - [:suite, {:name => @sub2_test_dir.basename.to_s}, - [:suite, {:name => _test_case_name("Sub2TestCase8")}, - [:test, {:name => "test8_1"}], - [:test, {:name => "test8_2"}]], - [:suite, {:name => _test_case_name("Sub2TestCase9")}, - [:test, {:name => "test9"}]]]]) - end - - def test_collect_file - assert_collect([:suite, {:name => @test_case1.basename.to_s}, - [:suite, {:name => _test_case_name("TestCase1")}, - [:test, {:name => "test1_1"}], - [:test, {:name => "test1_2"}]]], - @test_case1.to_s) - - assert_collect([:suite, {:name => @no_load_sub_test_case5.basename.to_s}, - [:suite, {:name => _test_case_name("NoLoadSubTestCase5")}, - [:test, {:name => "test5_1"}], - [:test, {:name => "test5_2"}]]], - @no_load_sub_test_case5.to_s) - end - - def test_nil_pattern - assert_collect([:suite, {:name => @sub_test_dir.basename.to_s}, - [:suite, {:name => _test_case_name("NoLoadSubTestCase5")}, - [:test, {:name => "test5_1"}], - [:test, {:name => "test5_2"}]], - [:suite, {:name => _test_case_name("SubTestCase4")}, - [:test, {:name => "test4_1"}], - [:test, {:name => "test4_2"}]], - [:suite, {:name => _test_case_name("SubTestCase6")}, - [:test, {:name => "test6"}]]], - @sub_test_dir.to_s) do |collector| - collector.patterns.clear - end - end - - def test_filtering - assert_collect([:suite, {:name => "."}, - [:suite, {:name => _test_case_name("TestCase1")}, - [:test, {:name => "test1_1"}], - [:test, {:name => "test1_2"}]]]) do |collector| - collector.filter = Proc.new do |test| - not /\Atest1/.match(test.method_name).nil? - end - end - end - - def test_collect_multi - test_dirs = [@sub_test_dir.to_s, @sub2_test_dir.to_s] - assert_collect([:suite, {:name => "[#{test_dirs.join(', ')}]"}, - [:suite, {:name => @sub_test_dir.basename.to_s}, - [:suite, {:name => _test_case_name("SubTestCase4")}, - [:test, {:name => "test4_1"}], - [:test, {:name => "test4_2"}]], - [:suite, {:name => _test_case_name("SubTestCase6")}, - [:test, {:name => "test6"}]]], - [:suite, {:name => @sub2_test_dir.basename.to_s}, - [:suite, {:name => _test_case_name("Sub2TestCase8")}, - [:test, {:name => "test8_1"}], - [:test, {:name => "test8_2"}]], - [:suite, {:name => _test_case_name("Sub2TestCase9")}, - [:test, {:name => "test9"}]]]], - *test_dirs) - end - - private - def assert_collect(expected, *collect_args) - keep_required_files do - Dir.chdir(@test_dir.to_s) do - collector = Test::Unit::Collector::Load.new - yield(collector) if block_given? - actual = inspect_test_object(collector.send(:collect, *collect_args)) - assert_equal(expected, actual) - end - end - end - - def keep_required_files - required_files = $".dup - yield - ensure - $".replace(required_files) - end - - def _test_case_name(test_case_class_name) - "#{@temporary_test_cases_module_name}::#{test_case_class_name}" - end - - def inspect_test_object(test_object) - return nil if test_object.nil? - case test_object - when Test::Unit::TestSuite - sub_tests = test_object.tests.collect do |test| - inspect_test_object(test) - end.sort_by do |type, attributes, *children| - attributes[:name] - end - [:suite, {:name => test_object.name}, *sub_tests] - when Test::Unit::TestCase - [:test, {:name => test_object.method_name}] - else - raise "unexpected test object: #{test_object.inspect}" - end - end -end Deleted: test-unit/test/collector/test_objectspace.rb (+0 -98) 100644 =================================================================== --- test-unit/test/collector/test_objectspace.rb 2010-09-12 03:03:44 +0000 (a1532ff) +++ /dev/null @@ -1,98 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' -require 'test/unit/collector/objectspace' - -module Test - module Unit - module Collector - class TC_ObjectSpace < TestCase - def setup - @tc1 = Class.new(TestCase) do - def self.name - "tc_1" - end - def test_1 - end - def test_2 - end - end - - @tc2 = Class.new(TestCase) do - def self.name - "tc_2" - end - def test_0 - end - end - - @no_tc = Class.new do - def test_4 - end - end - - @object_space = {Class => [@tc1, @tc2, @no_tc], String => ['']} - def @object_space.each_object(type) - self[type].each{|item| yield(item) } - end - - @c = ObjectSpace.new(@object_space) - end - - def full_suite(name=ObjectSpace::NAME) - expected = TestSuite.new(name) - expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1') << @tc1.new('test_2')) - expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0')) - end - - def empty_suite - TestSuite.new(ObjectSpace::NAME) - end - - def test_basic_collection - assert_equal(full_suite("name"), @c.collect("name")) - - @c.filter = [] - assert_equal(full_suite("name"), @c.collect("name")) - end - - def test_filtered_collection - @c.filter = proc{false} - assert_equal(empty_suite, @c.collect) - - @c.filter = proc{true} - assert_equal(full_suite, @c.collect) - - @c.filter = proc{nil} - assert_equal(full_suite, @c.collect) - - @c.filter = [proc{false}, proc{true}] - assert_equal(empty_suite, @c.collect) - - @c.filter = [proc{true}, proc{false}] - assert_equal(full_suite, @c.collect) - - @c.filter = [proc{nil}, proc{false}] - assert_equal(empty_suite, @c.collect) - - @c.filter = [proc{nil}, proc{true}] - assert_equal(full_suite, @c.collect) - - expected = TestSuite.new(ObjectSpace::NAME) - expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1')) - expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0')) - @c.filter = proc{|test| ['test_1', 'test_0'].include?(test.method_name)} - assert_equal(expected, @c.collect) - - expected = TestSuite.new(ObjectSpace::NAME) - expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1')) - expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0')) - @c.filter = [proc{|t| t.method_name == 'test_1' ? true : nil}, proc{|t| t.method_name == 'test_0' ? true : nil}, proc{false}] - assert_equal(expected, @c.collect) - end - end - end - end -end Deleted: test-unit/test/run-test.rb (+0 -13) 100755 =================================================================== --- test-unit/test/run-test.rb 2010-09-12 03:03:44 +0000 (0f74347) +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env ruby - -$VERBOSE = true - -base_dir = File.expand_path(File.join(File.dirname(__FILE__), "..")) -lib_dir = File.join(base_dir, "lib") -test_dir = File.join(base_dir, "test") - -$LOAD_PATH.unshift(lib_dir) - -require 'test/unit' - -exit Test::Unit::AutoRunner.run(true, test_dir) Deleted: test-unit/test/test_assertions.rb (+0 -693) 100644 =================================================================== --- test-unit/test/test_assertions.rb 2010-09-12 03:03:44 +0000 (024c037) +++ /dev/null @@ -1,693 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' - -module Test - module Unit - class TC_Assertions < TestCase - def check(value, message="") - add_assertion - raise AssertionFailedError.new(message) unless value - end - - def check_assertions(expect_fail, expected_message="", - return_value_expected=false) - @actual_assertion_count = 0 - failed = true - actual_message = nil - @catch_assertions = true - return_value = nil - begin - return_value = yield - failed = false - rescue AssertionFailedError => error - actual_message = error.message - end - @catch_assertions = false - - if expect_fail - message = "Should have failed, but didn't" - else - message = "Should not have failed, but did with message\n" + - "<#{actual_message}>" - end - check(expect_fail == failed, message) - - message = "Should have made one assertion but made\n" + - "<#{@actual_assertion_count}>" - check(1 == @actual_assertion_count, message) - - if expect_fail - case expected_message - when String - check(actual_message == expected_message, - "Should have the correct message.\n" + - "<#{expected_message.inspect}> expected but was\n" + - "<#{actual_message.inspect}>") - when Regexp - check(actual_message =~ expected_message, - "The message should match correctly.\n" + - " expected to match\n" + - "<#{actual_message.inspect}>") - else - check(false, - "Incorrect expected message type in assert_nothing_failed") - end - else - if return_value_expected - check(!return_value.nil?, "Should return a value") - else - check(return_value.nil?, - "Should not return a value but returned <#{return_value}>") - end - end - - return_value - end - - def check_nothing_fails(return_value_expected=false, &proc) - check_assertions(false, "", return_value_expected, &proc) - end - - def check_fails(expected_message="", &proc) - check_assertions(true, expected_message, &proc) - end - - def inspect_tag(tag) - begin - throw tag - rescue NameError - tag.to_s.inspect - rescue ArgumentError - tag.inspect - end - end - - def test_assert_block - check_nothing_fails { - assert_block {true} - } - check_nothing_fails { - assert_block("successful assert_block") {true} - } - check_nothing_fails { - assert_block("successful assert_block") {true} - } - check_fails("assert_block failed.") { - assert_block {false} - } - check_fails("failed assert_block") { - assert_block("failed assert_block") {false} - } - end - - def test_assert - check_nothing_fails{assert("a")} - check_nothing_fails{assert(true)} - check_nothing_fails{assert(true, "successful assert")} - check_fails(" is not true."){assert(nil)} - check_fails(" is not true."){assert(false)} - check_fails("failed assert.\n is not true."){assert(false, "failed assert")} - end - - def test_assert_equal - check_nothing_fails { - assert_equal("string1", "string1") - } - check_nothing_fails { - assert_equal( "string1", "string1", "successful assert_equal") - } - check_nothing_fails { - assert_equal("string1", "string1", "successful assert_equal") - } - - message = <<-EOM.chomp -<"string1"> expected but was -<"string2">. - -diff: -- string1 -? ^ -+ string2 -? ^ -EOM - check_fails(message) { - assert_equal("string1", "string2") - } - - message = <<-EOM.chomp -failed assert_equal. -<"string1"> expected but was -<"string2">. - -diff: -- string1 -? ^ -+ string2 -? ^ -EOM - check_fails(message) { - assert_equal("string1", "string2", "failed assert_equal") - } - - message = <<-EOM.chomp -<"111111"> expected but was -<111111>. - -diff: -- "111111" -? - - -+ 111111 -EOM - check_fails(message) do - assert_equal("111111", 111111) - end - end - - def test_assert_equal_for_too_small_difference - message = <<-EOM.chomp -<1> expected but was -<2>. -EOM - check_fails(message) do - assert_equal(1, 2) - end - end - - def test_assert_equal_for_same_inspected_objects - now = Time.now - now_without_usec = Time.at(now.to_i) - message = <<-EOM.chomp -<#{now.inspect}> expected but was -<#{now.inspect}>. -EOM - check_fails(message) do - assert_equal(now, now_without_usec) - end - end - - def test_assert_equal_with_multi_lines_result - message = <<-EOM.chomp -<#{"a\nb".inspect}> expected but was -<#{"x".inspect}>. - -diff: -+ x -- a -- b -EOM - check_fails(message) do - assert_equal("a\nb", "x") - end - end - - def test_assert_raise - return_value = nil - check_nothing_fails(true) { - return_value = assert_raise(RuntimeError) { - raise "Error" - } - } - check(return_value.kind_of?(Exception), "Should have returned the exception from a successful assert_raise") - check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise") - check_nothing_fails(true) { - assert_raise(ArgumentError, "successful assert_raise") { - raise ArgumentError.new("Error") - } - } - check_nothing_fails(true) { - assert_raise(RuntimeError) { - raise "Error" - } - } - check_nothing_fails(true) { - assert_raise(RuntimeError, "successful assert_raise") { - raise "Error" - } - } - check_fails(" exception expected but none was thrown.") { - assert_raise(RuntimeError) { - 1 + 1 - } - } - check_fails(%r{\Afailed assert_raise.\n exception expected but was\nClass: \nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) { - assert_raise(ArgumentError, "failed assert_raise") { - raise "Error" - } - } - check_fails("Should expect a class of exception, Object.\n is not true.") { - assert_nothing_raised(Object) { - 1 + 1 - } - } - - exceptions = [ArgumentError, TypeError] - modules = [Math, Comparable] - rescues = exceptions + modules - exceptions.each do |exc| - check_nothing_fails(true) { - return_value = assert_raise(*rescues) { - raise exc, "Error" - } - } - check(return_value.instance_of?(exc), "Should have returned #{exc} but was #{return_value.class}") - check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise") - end - modules.each do |mod| - check_nothing_fails(true) { - return_value = assert_raise(*rescues) { - raise Exception.new("Error").extend(mod) - } - } - check(mod === return_value, "Should have returned #{mod}") - check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise") - end - check_fails("<[ArgumentError, TypeError, Math, Comparable]> exception expected but none was thrown.") { - assert_raise(*rescues) { - 1 + 1 - } - } - check_fails(%r{\Afailed assert_raise. -<\[ArgumentError, TypeError\]> exception expected but was -Class: -Message: <"Error"> ----Backtrace--- -.+ ----------------\Z}m) { - assert_raise(ArgumentError, TypeError, "failed assert_raise") { - raise "Error" - } - } - end - - def test_assert_instance_of - check_nothing_fails { - assert_instance_of(String, "string") - } - check_nothing_fails { - assert_instance_of(String, "string", "successful assert_instance_of") - } - check_nothing_fails { - assert_instance_of(String, "string", "successful assert_instance_of") - } - check_fails(%Q{<"string"> expected to be an instance of\n but was\n.}) { - assert_instance_of(Hash, "string") - } - check_fails(%Q{failed assert_instance_of.\n<"string"> expected to be an instance of\n but was\n.}) { - assert_instance_of(Hash, "string", "failed assert_instance_of") - } - end - - def test_assert_nil - check_nothing_fails { - assert_nil(nil) - } - check_nothing_fails { - assert_nil(nil, "successful assert_nil") - } - check_nothing_fails { - assert_nil(nil, "successful assert_nil") - } - check_fails(%Q{<"string"> expected to be nil.}) { - assert_nil("string") - } - check_fails(%Q{failed assert_nil.\n<"string"> expected to be nil.}) { - assert_nil("string", "failed assert_nil") - } - end - - def test_assert_not_nil - check_nothing_fails{assert_not_nil(false)} - check_nothing_fails{assert_not_nil(false, "message")} - check_fails(" expected to not be nil."){assert_not_nil(nil)} - check_fails("message.\n expected to not be nil.") {assert_not_nil(nil, "message")} - end - - def test_assert_kind_of - check_nothing_fails { - assert_kind_of(Module, Array) - } - check_nothing_fails { - assert_kind_of(Object, "string", "successful assert_kind_of") - } - check_nothing_fails { - assert_kind_of(Object, "string", "successful assert_kind_of") - } - check_nothing_fails { - assert_kind_of(Comparable, 1) - } - check_fails(%Q{<"string">\nexpected to be kind_of?\n but was\n.}) { - assert_kind_of(Class, "string") - } - check_fails(%Q{failed assert_kind_of.\n<"string">\nexpected to be kind_of?\n but was\n.}) { - assert_kind_of(Class, "string", "failed assert_kind_of") - } - end - - def test_assert_match - check_nothing_fails { - assert_match(/strin./, "string") - } - check_nothing_fails { - assert_match("strin", "string") - } - check_nothing_fails { - assert_match(/strin./, "string", "successful assert_match") - } - check_nothing_fails { - assert_match(/strin./, "string", "successful assert_match") - } - check_fails(%Q{<"string"> expected to be =~\n.}) { - assert_match(/slin./, "string") - } - check_fails(%Q{<"string"> expected to be =~\n.}) { - assert_match("strin.", "string") - } - check_fails(%Q{failed assert_match.\n<"string"> expected to be =~\n.}) { - assert_match(/slin./, "string", "failed assert_match") - } - end - - def test_assert_same - thing = "thing" - check_nothing_fails { - assert_same(thing, thing) - } - check_nothing_fails { - assert_same(thing, thing, "successful assert_same") - } - check_nothing_fails { - assert_same(thing, thing, "successful assert_same") - } - thing2 = "thing" - check_fails(%Q{<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) { - assert_same(thing, thing2) - } - check_fails(%Q{failed assert_same.\n<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) { - assert_same(thing, thing2, "failed assert_same") - } - end - - def test_assert_nothing_raised - check_nothing_fails { - assert_nothing_raised { - 1 + 1 - } - } - check_nothing_fails { - assert_nothing_raised("successful assert_nothing_raised") { - 1 + 1 - } - } - check_nothing_fails { - assert_nothing_raised("successful assert_nothing_raised") { - 1 + 1 - } - } - check_nothing_fails { - begin - assert_nothing_raised(RuntimeError, StandardError, Comparable, "successful assert_nothing_raised") { - raise ZeroDivisionError.new("ArgumentError") - } - rescue ZeroDivisionError - end - } - check_fails("Should expect a class of exception, Object.\n is not true.") { - assert_nothing_raised(Object) { - 1 + 1 - } - } - check_fails(%r{\AException raised:\nClass: \nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) { - assert_nothing_raised { - raise "Error" - } - } - check_fails(%r{\Afailed assert_nothing_raised\.\nException raised:\nClass: \nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) { - assert_nothing_raised("failed assert_nothing_raised") { - raise "Error" - } - } - check_fails(%r{\AException raised:\nClass: \nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) { - assert_nothing_raised(StandardError, RuntimeError) { - raise "Error" - } - } - check_fails("Failure.") do - assert_nothing_raised do - flunk("Failure") - end - end - end - - def test_flunk - check_fails("Flunked.") { - flunk - } - check_fails("flunk message.") { - flunk("flunk message") - } - end - - def test_assert_not_same - thing = "thing" - thing2 = "thing" - check_nothing_fails { - assert_not_same(thing, thing2) - } - check_nothing_fails { - assert_not_same(thing, thing2, "message") - } - check_fails(%Q{<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) { - assert_not_same(thing, thing) - } - check_fails(%Q{message.\n<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) { - assert_not_same(thing, thing, "message") - } - end - - def test_assert_not_equal - check_nothing_fails { - assert_not_equal("string1", "string2") - } - check_nothing_fails { - assert_not_equal("string1", "string2", "message") - } - check_fails(%Q{<"string"> expected to be != to\n<"string">.}) { - assert_not_equal("string", "string") - } - check_fails(%Q{message.\n<"string"> expected to be != to\n<"string">.}) { - assert_not_equal("string", "string", "message") - } - end - - def test_assert_no_match - check_nothing_fails{assert_no_match(/sling/, "string")} - check_nothing_fails{assert_no_match(/sling/, "string", "message")} - check_fails(%Q{The first argument to assert_no_match should be a Regexp.\n<"asdf"> expected to be an instance of\n but was\n.}) do - assert_no_match("asdf", "asdf") - end - check_fails(%Q{ expected to not match\n<"string">.}) do - assert_no_match(/string/, "string") - end - check_fails(%Q{message.\n expected to not match\n<"string">.}) do - assert_no_match(/string/, "string", "message") - end - end - - def test_assert_throws - check_nothing_fails do - assert_throws(:thing, "message") do - throw :thing - end - end - - tag = :thing2 - check_fails("message.\n" + - "<:thing> expected to be thrown but\n" + - "<#{inspect_tag(tag)}> was thrown.") do - assert_throws(:thing, "message") do - throw :thing2 - end - end - check_fails("message.\n" + - "<:thing> should have been thrown.") do - assert_throws(:thing, "message") do - 1 + 1 - end - end - end - - def test_assert_nothing_thrown - check_nothing_fails do - assert_nothing_thrown("message") do - 1 + 1 - end - end - - tag = :thing - inspected = inspect_tag(tag) - check_fails("message.\n" + - "<#{inspected}> was thrown when nothing was expected.") do - assert_nothing_thrown("message") do - throw tag - end - end - end - - def test_assert_operator - check_nothing_fails { - assert_operator("thing", :==, "thing", "message") - } - check_fails(%Q{<0.15>\ngiven as the operator for #assert_operator must be a Symbol or #respond_to?(:to_str).}) do - assert_operator("thing", 0.15, "thing") - end - check_fails(%Q{message.\n<"thing1"> expected to be\n==\n<"thing2">.}) { - assert_operator("thing1", :==, "thing2", "message") - } - end - - def test_assert_respond_to - check_nothing_fails { - assert_respond_to("thing", :to_s, "message") - } - check_nothing_fails { - assert_respond_to("thing", "to_s", "message") - } - check_fails("<0.15>\ngiven as the method name argument to #assert_respond_to must be a Symbol or #respond_to?(:to_str).") { - assert_respond_to("thing", 0.15) - } - check_fails("message.\n<:symbol>\nof type \nexpected to respond_to?<:non_existent>.") { - assert_respond_to(:symbol, :non_existent, "message") - } - end - - def test_assert_in_delta - check_nothing_fails { - assert_in_delta(1.4, 1.4, 0) - } - check_nothing_fails { - assert_in_delta(0.5, 0.4, 0.1, "message") - } - check_nothing_fails { - float_thing = Object.new - def float_thing.to_f - 0.2 - end - assert_in_delta(0.1, float_thing, 0.1) - } - check_fails("message.\n<0.5> and\n<0.4> expected to be within\n<0.05> of each other.") { - assert_in_delta(0.5, 0.4, 0.05, "message") - } - check_fails(%r{The arguments must respond to to_f; the first float did not\.\n<.+>\nof type \nexpected to respond_to\?<:to_f>.}) { - assert_in_delta(Object.new, 0.4, 0.1) - } - check_fails("The delta should not be negative.\n<-0.1> expected to be\n>=\n<0.0>.") { - assert_in_delta(0.5, 0.4, -0.1, "message") - } - end - - def test_assert_send - object = Object.new - class << object - private - def return_argument(argument, bogus) - return argument - end - end - check_nothing_fails { - assert_send([object, :return_argument, true, "bogus"], "message") - } - check_fails(%r{\Amessage\.\n<.+> expected to respond to\n with a true value.\Z}) { - assert_send([object, :return_argument, false, "bogus"], "message") - } - end - - def test_condition_invariant - object = Object.new - def object.inspect - @changed = true - end - def object.==(other) - @changed ||= false - return (!@changed) - end - check_nothing_fails do - assert_equal(object, object, "message") - end - end - - def test_assert_boolean - check_nothing_fails do - assert_boolean(true) - end - check_nothing_fails do - assert_boolean(false) - end - - check_fails(" or expected but was\n<1>") do - assert_boolean(1) - end - - check_fails(" or expected but was\n") do - assert_boolean(nil) - end - - check_fails("message.\n or expected but was\n<\"XXX\">") do - assert_boolean("XXX", "message") - end - end - - def test_assert_true - check_nothing_fails do - assert_true(true) - end - - check_fails(" expected but was\n") do - assert_true(false) - end - - check_fails(" expected but was\n<1>") do - assert_true(1) - end - - check_fails("message.\n expected but was\n") do - assert_true(nil, "message") - end - end - - def test_assert_false - check_nothing_fails do - assert_false(false) - end - - check_fails(" expected but was\n") do - assert_false(true) - end - - check_fails(" expected but was\n") do - assert_false(nil) - end - - check_fails("message.\n expected but was\n<:false>") do - assert_false(:false, "message") - end - end - - def add_failure(message, location=caller) - unless @catch_assertions - super - end - end - - def add_assertion - if @catch_assertions - @actual_assertion_count += 1 - else - super - end - end - end - end -end Deleted: test-unit/test/test_attribute.rb (+0 -86) 100644 =================================================================== --- test-unit/test/test_attribute.rb 2010-09-12 03:03:44 +0000 (f6e2836) +++ /dev/null @@ -1,86 +0,0 @@ -class TestUnitAttribute < Test::Unit::TestCase - class TestStack < Test::Unit::TestCase - class << self - def suite - Test::Unit::TestSuite.new(name) - end - end - - class Stack - def initialize - @data = [] - end - - def push(data) - @data.push(data) - end - - def peek - @data[-2] - end - - def empty? - @data.empty? - end - - def size - @data.size + 11 - end - end - - def setup - @stack = Stack.new - end - - attribute :category, :accessor - def test_peek - @stack.push(1) - @stack.push(2) - assert_equal(2, @stack.peek) - end - - attribute :bug, 1234 - def test_bug_1234 - assert_equal(0, @stack.size) - end - - def test_no_attributes - assert(@stack.empty?) - @stack.push(1) - assert(!@stack.empty?) - assert_equal(1, @stack.size) - end - end - - def test_set_attributes - test_for_accessor_category = TestStack.new("test_peek") - assert_equal({"category" => :accessor}, - test_for_accessor_category.attributes) - - test_for_bug_1234 = TestStack.new("test_bug_1234") - assert_equal({"bug" => 1234}, test_for_bug_1234.attributes) - - test_no_attributes = TestStack.new("test_no_attributes") - assert_equal({}, test_no_attributes.attributes) - end - - def test_callback - changed_attributes = [] - observer = Proc.new do |test_case, key, old_value, value, method_name| - changed_attributes << [test_case, key, old_value, value, method_name] - end - - test_case = Class.new(TestStack) do - register_attribute_observer(:bug, &observer) - attribute("bug", 9876, "test_bug_1234") - attribute(:description, "Test for peek", "test_peek") - attribute(:bug, 29, "test_peek") - end - - assert_equal([ - [test_case, "bug", 1234, 9876, "test_bug_1234"], - [test_case, "bug", nil, 29, "test_peek"], - ], - changed_attributes) - end -end Deleted: test-unit/test/test_color.rb (+0 -37) 100644 =================================================================== --- test-unit/test/test_color.rb 2010-09-12 03:03:44 +0000 (6aa990a) +++ /dev/null @@ -1,37 +0,0 @@ -class TestUnitColor < Test::Unit::TestCase - def test_color_escape_sequence - assert_escape_sequence(["31"], color("red")) - assert_escape_sequence(["32", "1"], color("green", :bold => true)) - assert_escape_sequence(["0"], color("reset")) - assert_escape_sequence(["45"], color("magenta", :foreground => false)) - end - - def test_mix_color_escape_sequence - assert_escape_sequence(["34", "1"], - mix_color([color("blue"), - color("none", :bold => true)])) - assert_escape_sequence(["34", "1", "4"], - mix_color([color("blue"), - color("none", :bold => true)]) + - color("none", :underline => true)) - assert_escape_sequence(["34", "1", "4"], - color("blue") + - color("none", :bold => true) + - color("none", :underline => true)) - end - - private - def color(name, options={}) - Test::Unit::Color.new(name, options) - end - - def mix_color(colors) - Test::Unit::MixColor.new(colors) - end - - def assert_escape_sequence(expected, color) - assert_equal(expected, color.sequence) - assert_match(/\e\[(?:\d+;)*\d+m/, color.escape_sequence) - assert_equal(expected, color.escape_sequence[2..-2].split(";")) - end -end Deleted: test-unit/test/test_diff.rb (+0 -477) 100644 =================================================================== --- test-unit/test/test_diff.rb 2010-09-12 03:03:44 +0000 (164c9d4) +++ /dev/null @@ -1,477 +0,0 @@ -class TestUnitDiff < Test::Unit::TestCase - def test_to_indexes - assert_to_indexes({"abc def" => [0, 2], "abc" => [1]}, - ["abc def", "abc", "abc def"]) - - assert_to_indexes({?a => [0, 3], ?b => [1], ?c => [2], ?d => [4]}, - "abcad") - - assert_to_indexes({ - ?1 => [0, 35], - ?t => [2, 5, 16], - ?e => [3, 14, 31, 38], - ?s => [4, 6, 12, 13, 20, 32, 44], - ?, => [7, 21, 33], - ?0 => [9, 23], - ?a => [11, 26], - ?r => [15, 30], - ?i => [17, 27, 41], - ?o => [18], - ?n => [19, 39, 42], - ?f => [25], - ?l => [28], - ?u => [29], - ?p => [37], - ?d => [40], - ?g => [43], - }, - "1 tests, 0 assertions, 0 failures, 1 pendings") do |x| - x == " "[0] - end - end - - def test_longest_match - assert_longest_match([0, 1, 3], - %w(b c d), %w(a b c d x y z), - 0, 2, 0, 7) - assert_longest_match([1, 2, 2], - %w(b c d), %w(a b c d x y z), - 1, 2, 0, 6) - assert_longest_match([0, 0, 0], - %w(a b), %w(c), - 0, 1, 0, 0) - assert_longest_match([1, 0, 2], - %w(q a b x c d), %w(a b y c d f), - 0, 5, 0, 5) - assert_longest_match([4, 3, 2], - %w(q a b x c d), %w(a b y c d f), - 3, 5, 2, 5) - - assert_longest_match([1, 0, 2], "qabxcd", "abycdf", 0, 5, 0, 5) - assert_longest_match([0, 0, 1], "efg", "eg", 0, 2, 0, 1) - assert_longest_match([2, 1, 1], "efg", "eg", 1, 2, 1, 1) - end - - def test_longest_match_with_junk_predicate - assert_longest_match([0, 4, 5], " abcd", "abcd abcd", 0, 4, 0, 8) - assert_longest_match([1, 0, 4], " abcd", "abcd abcd", 0, 4, 0, 8) do |x| - x == ' '[0] - end - end - - def test_matches - assert_matches([[0, 0, 2], - [3, 2, 2]], - %w(a b x c d), %w(a b c d)) - assert_matches([[1, 0, 2], - [4, 3, 2]], - %w(q a b x c d), %w(a b y c d f)) - - assert_matches([[1, 0, 2], - [4, 3, 2]], - "qabxcd", "abycdf") - assert_matches([[0, 0, 1], - [2, 1, 1]], - "efg", "eg") - end - - def test_matches_with_junk_predicate - assert_matches([[0, 0, 23], - [24, 24, 11], - [36, 36, 9]], - "1 tests, 0 assertions, 1 failures, 0 pendings", - "1 tests, 0 assertions, 0 failures, 1 pendings") - - assert_matches([[0, 0, 1], - [1, 1, 8], - [9, 9, 1], - [10, 10, 13], - [24, 24, 11], - [36, 36, 9]], - "1 tests, 0 assertions, 1 failures, 0 pendings", - "1 tests, 0 assertions, 0 failures, 1 pendings") do |x| - x == " "[0] - end - end - - def test_blocks - assert_blocks([[0, 0, 2], - [3, 2, 2], - [5, 4, 0]], - %w(a b x c d), %w(a b c d)) - assert_blocks([[1, 0, 2], - [4, 3, 2], - [6, 6, 0]], - %w(q a b x c d), %w(a b y c d f)) - - assert_blocks([[1, 0, 2], - [4, 3, 2], - [6, 6, 0]], - "qabxcd", "abycdf") - assert_blocks([[0, 0, 1], - [2, 1, 1], - [3, 2, 0]], - "efg", "eg") - end - - def test_blocks_with_junk_predicate - assert_blocks([[0, 0, 23], - [24, 24, 11], - [36, 36, 9], - [45, 45, 0]], - "1 tests, 0 assertions, 1 failures, 0 pendings", - "1 tests, 0 assertions, 0 failures, 1 pendings") do |x| - x == " "[0] - end - end - - def test_operations - assert_operations([], %w(), %w()) - - assert_operations([[:delete, 0, 1, 0, 0], - [:equal, 1, 3, 0, 2], - [:replace, 3, 4, 2, 3], - [:equal, 4, 6, 3, 5], - [:insert, 6, 6, 5, 6]], - %w(q a b x c d), %w(a b y c d f)) - - assert_operations([[:delete, 0, 1, 0, 0], - [:equal, 1, 3, 0, 2], - [:replace, 3, 4, 2, 3], - [:equal, 4, 6, 3, 5], - [:insert, 6, 6, 5, 6]], - "qabxcd", "abycdf") - - assert_operations([[:equal, 0, 23, 0, 23], - [:replace, 23, 24, 23, 24], - [:equal, 24, 35, 24, 35], - [:replace, 35, 36, 35, 36], - [:equal, 36, 45, 36, 45]], - "1 tests, 0 assertions, 1 failures, 0 pendings", - "1 tests, 0 assertions, 0 failures, 1 pendings") - - assert_operations([[:equal, 0, 23, 0, 23], - [:replace, 23, 24, 23, 24], - [:equal, 24, 35, 24, 35], - [:replace, 35, 36, 35, 36], - [:equal, 36, 45, 36, 45]], - "1 tests, 0 assertions, 1 failures, 0 pendings", - "1 tests, 0 assertions, 0 failures, 1 pendings") do |x| - x == " "[0] - end - end - - def test_grouped_operations - assert_grouped_operations([[[:equal, 0, 0, 0, 0]]], - %w(), - %w()) - - assert_grouped_operations([[[:equal, 0, 3, 0, 3]]], - %w(a b c), - %w(a b c)) - - assert_grouped_operations([[[:equal, 0, 1, 0, 1], - [:replace, 1, 2, 1, 2], - [:equal, 2, 5, 2, 5]], - [[:equal, 8, 11, 8, 11], - [:replace, 11, 12, 11, 12], - [:equal, 12, 13, 12, 13], - [:delete, 13, 16, 13, 13], - [:equal, 16, 17, 13, 14], - [:replace, 17, 18, 14, 15], - [:equal, 18, 20, 15, 17]]], - %w(1 2 3 4 5 6 7 8 9 a b c d e f g h i j k), - %w(1 i 3 4 5 6 7 8 9 a b cX d h iX j k)) - end - - def test_ratio - assert_ratio(0.75, "abcd", "bcde") - assert_ratio(0.80, "efg", "eg") - end - - def test_same_contents_readable_diff - assert_readable_diff(" aaa", ["aaa"], ["aaa"]) - assert_readable_diff(" aaa\n" \ - " bbb", - ["aaa", "bbb"], ["aaa", "bbb"]) - end - - def test_deleted_readable_diff - assert_readable_diff(" aaa\n" \ - "- bbb", - ["aaa", "bbb"], ["aaa"]) - assert_readable_diff(" aaa\n" \ - "- bbb\n" \ - "- ccc\n" \ - "- ddd", - ["aaa", "bbb", "ccc", "ddd"], ["aaa"]) - end - - def test_inserted_readable_diff - assert_readable_diff(" aaa\n" \ - "+ bbb\n" \ - "+ ccc\n" \ - "+ ddd", - ["aaa"], ["aaa", "bbb", "ccc", "ddd"]) - end - - def test_replace_readable_diff - assert_readable_diff(" aaa\n" \ - "- bbb\n" \ - "+ BbB\n" \ - " ccc\n" \ - "- ddd\n" \ - "- efg\n" \ - "? -\n" \ - "+ eg", - ["aaa", "bbb", "ccc", "ddd", "efg"], - ["aaa", "BbB", "ccc", "eg"]) - - assert_readable_diff("- abcd xyz abc\n" \ - "? -\n" \ - "+ abcd abcd xyz abc\n" \ - "? +++++", - [" abcd xyz abc"], - ["abcd abcd xyz abc"]) - end - - def test_difference_readable_diff - assert_readable_diff("- 1 tests, 0 assertions, 1 failures, 0 pendings\n" \ - "? ^ ^\n" \ - "+ 1 tests, 0 assertions, 0 failures, 1 pendings\n" \ - "? ^ ^", - ["1 tests, 0 assertions, 1 failures, 0 pendings"], - ["1 tests, 0 assertions, 0 failures, 1 pendings"]) - end - - def test_complex_readable_diff - assert_readable_diff(" aaa\n" \ - "- bbb\n" \ - "- ccc\n" \ - "+ \n" \ - "+ # \n" \ - " ddd", - ["aaa", "bbb", "ccc", "ddd"], - ["aaa", "", " # ", "ddd"]) - - assert_readable_diff("- one1\n" \ - "? ^\n" \ - "+ ore1\n" \ - "? ^\n" \ - "- two2\n" \ - "- three3\n" \ - "? - -\n" \ - "+ tree\n" \ - "+ emu", - ["one1", "two2", "three3"], - ["ore1", "tree", "emu"]) - end - - def test_empty_readable_diff - assert_readable_diff("", [""], [""]) - end - - def test_unified_diff - assert_unified_diff("", - ["one", "two", "three"], - ["one", "two", "three"], - "content 1", - "content 2") - - assert_unified_diff("--- Original Sat Jan 26 23:30:50 1991\n" \ - "+++ Current Fri Jun 06 10:20:52 2003\n" \ - "@@ -1,4 +1,4 @@\n" \ - "+zero\n" \ - " one\n" \ - "-two\n" \ - "-three\n" \ - "+tree\n" \ - " four", - ["one", "two", "three", "four"], - ["zero", "one", "tree", "four"], - "Original Sat Jan 26 23:30:50 1991", - "Current Fri Jun 06 10:20:52 2003", - :show_context => false) - - from = File.read(__FILE__).split(/\n/) - to = from.dup - target_line = __LINE__ - to[target_line - 1, 1] = [] - context = " def test_unified_diff" - summary = "@@ -#{target_line - 3},7 +#{target_line - 3},6 @@ #{context}" - assert_unified_diff((["--- revision 10", - "+++ revision 11", - summary] + - from[target_line - 4, 3].collect {|line| " #{line}"} + - ["-#{from[target_line - 1]}"] + - from[target_line, 3].collect {|line| " #{line}"} - ).join("\n"), - from, to, - "revision 10", - "revision 11") - end - - def test_empty_unified_diff - assert_unified_diff("", [""], [""], "From", "To") - assert_unified_diff("", [], [], "From", "To") - end - - def test_diff_lines - assert_diff_lines(["- ddd", - "- efg", - "? -", - "+ eg"], - ["aaa", "bbb", "ccc", "ddd", "efg"], - ["aaa", "BbB", "ccc", "eg"], - 3, 5, 3, 4) - end - - def test_diff_line - assert_diff_line(["- abcDefghiJkl", - "? ^ ^ ^", - "+ abcdefGhijkl", - "? ^ ^ ^"], - "abcDefghiJkl", - "abcdefGhijkl") - - assert_diff_line(["- bcDefghiJklx", - "? ^ ^ ^ -", - "+ abcdefGhijkl", - "? + ^ ^ ^"], - "bcDefghiJklx", - "abcdefGhijkl") - end - - def test_empty_diff_line - assert_diff_line(["- ", - "+ "], - "", "") - end - - def test_format_diff_point - assert_format_diff_point(["- \tabcDefghiJkl", - "? \t ^ ^ ^", - "+ \t\tabcdefGhijkl", - "? \t ^ ^ ^"], - "\tabcDefghiJkl", - "\t\tabcdefGhijkl", - " ^ ^ ^ ", - "+ ^ ^ ^ ") - assert_format_diff_point(["- efg", - "? ^", - "+ eg"], - "efg", - "eg", - " ^", - "") - end - - def test_interesting_line - from = ["class X", - " def find(x=0)", - " body", - " end", - "end"] - to = ["def xxx", - " raise 'not call me'", - "end"] - assert_interesting_line(" def find(x=0)", - from, to, - 2, 1) - assert_interesting_line("def xxx", - from, to, - 2, 0) - assert_interesting_line("class X", - from, to, - 0, 0) - end - - private - def assert_to_indexes(expected, to, &junk_predicate) - matcher = Test::Unit::Diff::SequenceMatcher.new([""], to, &junk_predicate) - assert_equal(expected, matcher.instance_variable_get("@to_indexes")) - end - - def assert_find_best_match_position(expected, from, to, - from_start, from_end, - to_start, to_end, &junk_predicate) - matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate) - assert_equal(expected, matcher.send(:find_best_match_position, - from_start, from_end, - to_start, to_end)) - end - - def assert_longest_match(expected, from, to, - from_start, from_end, - to_start, to_end, &junk_predicate) - matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate) - assert_equal(expected, matcher.longest_match(from_start, from_end, - to_start, to_end)) - end - - def assert_matches(expected, from, to, &junk_predicate) - matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate) - assert_equal(expected, matcher.send(:matches)) - end - - def assert_blocks(expected, from, to, &junk_predicate) - matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate) - assert_equal(expected, matcher.blocks) - end - - def assert_operations(expected, from, to, &junk_predicate) - matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate) - assert_equal(expected, matcher.operations) - end - - def assert_grouped_operations(expected, from, to) - matcher = Test::Unit::Diff::SequenceMatcher.new(from, to) - assert_equal(expected, matcher.grouped_operations) - end - - def assert_ratio(expected, from, to) - matcher = Test::Unit::Diff::SequenceMatcher.new(from, to) - assert_in_delta(expected, 0.001, matcher.ratio) - end - - def assert_readable_diff(expected, from, to) - assert_equal(expected, - Test::Unit::Diff.readable(from.join("\n"), to.join("\n"))) - end - - def assert_unified_diff(expected, from, to, from_label, to_label, options={}) - options = options.merge(:from_label => from_label, - :to_label => to_label) - assert_equal(expected, - Test::Unit::Diff.unified(from.join("\n"), to.join("\n"), - options)) - end - - def assert_diff_lines(expected, from, to, - from_start, from_end, - to_start, to_end) - differ = Test::Unit::Diff::ReadableDiffer.new(from, to) - assert_equal(expected, differ.send(:diff_lines, - from_start, from_end, - to_start, to_end)) - end - - def assert_diff_line(expected, from_line, to_line) - differ = Test::Unit::Diff::ReadableDiffer.new([""], [""]) - assert_equal(expected, differ.send(:diff_line, from_line, to_line)) - end - - def assert_format_diff_point(expected, from_line, to_line, from_tags, to_tags) - differ = Test::Unit::Diff::ReadableDiffer.new([""], [""]) - assert_equal(expected, differ.send(:format_diff_point, - from_line, to_line, - from_tags, to_tags)) - end - - def assert_interesting_line(expected, from, to, from_start, to_start) - differ = Test::Unit::Diff::UnifiedDiffer.new(from, to) - assert_equal(expected, differ.send(:find_interesting_line, - from_start, to_start, - :define_line?)) - end -end Deleted: test-unit/test/test_emacs_runner.rb (+0 -60) 100644 =================================================================== --- test-unit/test/test_emacs_runner.rb 2010-09-12 03:03:44 +0000 (412c8cc) +++ /dev/null @@ -1,60 +0,0 @@ -require 'test/unit' -require 'test/unit/ui/emacs/testrunner' - -class TestUnitEmacsRunner < Test::Unit::TestCase - def test_format_failure_with_a_location - runner = create_runner - test_name = "test_failure" - file = "/home/user/test_xxx.rb" - line = "3" - info = "in `xxx'" - location = "#{file}:#{line}: #{info}" - message = "FAIL!!!" - failure = Test::Unit::Failure.new(test_name, [location], message) - assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure)) -Failure: -#{test_name} [#{file}:#{line}]: -#{message} -EOM - end - - def test_format_failure_with_locations - runner = create_runner - test_name = "test_failure" - locations = ["/home/user/test_xxx.rb:3: in `xxx'", - "/home/user/yyy/test_yyy.rb:999: in `yyy'", - "/home/user/xyz/zzz.rb:29: in `zzz'"] - message = "Many backtrace!!!" - failure = Test::Unit::Failure.new(test_name, locations, message) - assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure)) -Failure: -#{test_name} -#{locations.join("\n")}: -#{message} -EOM - end - - def test_format_error - runner = create_runner - test_name = "test_error" - message = "Error Message!!!" - backtrace = ["/home/user/test_xxx.rb:3: in `xxx'", - "/home/user/yyy/test_yyy.rb:999: in `yyy'", - "/home/user/xyz/zzz.rb:29: in `zzz'"] - exception = RuntimeError.new(message) - exception.set_backtrace(backtrace) - error = Test::Unit::Error.new(test_name, exception) - assert_equal(<<-EOM.chomp, runner.send(:format_fault, error)) -Error: -#{test_name}: -#{exception.class.name}: #{message} -#{backtrace.join("\n")} -EOM - end - - private - def create_runner(suite=nil) - suite ||= Test::Unit::TestSuite.new - Test::Unit::UI::Emacs::TestRunner.new(suite) - end -end Deleted: test-unit/test/test_error.rb (+0 -26) 100644 =================================================================== --- test-unit/test/test_error.rb 2010-09-12 03:03:44 +0000 (56b275b) +++ /dev/null @@ -1,26 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' - -module Test - module Unit - class TC_Error < TestCase - TF_Exception = Struct.new('TF_Exception', :message, :backtrace) - def test_display - ex = TF_Exception.new("message1\nmessage2", ['line1', 'line2']) - e = Error.new("name", ex) - assert_equal("name: #{TF_Exception.name}: message1", e.short_display) - assert_equal(< :append}], - [{:before => :append}], - [{:before => :prepend}], - [{:before => :prepend}]]) - assert_inherited_setup([:custom_setup_method3, - :custom_setup_method0, - :custom_setup_method1, - :setup], - test_case) - assert_inherited_setup([:setup], nil) - end - - def test_setup_with_after_option - test_case = assert_setup([:setup, - :custom_setup_method3, - :custom_setup_method0, - :custom_setup_method1], - [[{:after => :append}], - [{:after => :append}], - [{:after => :prepend}], - [{:after => :prepend}]]) - assert_inherited_setup([:setup, - :custom_setup_method3, - :custom_setup_method0, - :custom_setup_method1], - test_case) - assert_inherited_setup([:setup], nil) - end - - def test_setup_with_invalid_option - assert_invalid_setup_option(:unknown => true) - assert_invalid_setup_option(:before => :unknown) - assert_invalid_setup_option(:after => :unknown) - end - - def test_teardown_without_option - test_case = assert_teardown([:custom_teardown_method3, - :custom_teardown_method1, - :custom_teardown_method0, - :teardown], - []) - assert_inherited_teardown([:custom_teardown_method3, - :custom_teardown_method1, - :custom_teardown_method0, - :teardown], - test_case) - assert_inherited_teardown([:teardown], nil) - end - - def test_teardown_with_before_option - test_case = assert_teardown([:custom_teardown_method3, - :custom_teardown_method0, - :custom_teardown_method1, - :teardown], - [[{:before => :append}], - [{:before => :append}], - [{:before => :prepend}], - [{:before => :prepend}]]) - assert_inherited_teardown([:custom_teardown_method3, - :custom_teardown_method0, - :custom_teardown_method1, - :teardown], - test_case) - assert_inherited_teardown([:teardown], nil) - end - - def test_teardown_with_after_option - test_case = assert_teardown([:teardown, - :custom_teardown_method3, - :custom_teardown_method0, - :custom_teardown_method1], - [[{:after => :append}], - [{:after => :append}], - [{:after => :prepend}], - [{:after => :prepend}]]) - assert_inherited_teardown([:teardown, - :custom_teardown_method3, - :custom_teardown_method0, - :custom_teardown_method1], - test_case) - assert_inherited_teardown([:teardown], nil) - end - - def test_teardown_with_invalid_option - assert_invalid_teardown_option(:unknown => true) - assert_invalid_teardown_option(:before => :unknown) - assert_invalid_teardown_option(:after => :unknown) - end - - private - def assert_setup_customizable(expected, parent, options) - called = [] - test_case = Class.new(parent || Test::Unit::TestCase) do - yield(self, :before) if block_given? - - @@called = called - def setup - @@called << :setup - end - - setup(*(options[0] || [])) if options - def custom_setup_method0 - @@called << :custom_setup_method0 - end - - def custom_setup_method1 - @@called << :custom_setup_method1 - end - setup(*[:custom_setup_method1, *(options[1] || [])]) if options - - setup(*(options[2] || [])) if options - def custom_setup_method2 - @@called << :custom_setup_method2 - end - unregister_setup(:custom_setup_method2) if options - - setup(*(options[3] || [])) if options - def custom_setup_method3 - @@called << :custom_setup_method3 - end - - def test_nothing - end - - yield(self, :after) if block_given? - end - - test_case.new("test_nothing").run(Test::Unit::TestResult.new) {} - assert_equal(expected, called) - test_case - end - - def assert_setup(expected, options) - _test_case = assert_setup_customizable(expected, nil, options) - assert_setup_customizable(expected, nil, options) do |test_case, tag| - test_case.send(:include, EmptyModule) if tag == :before - end - _test_case - end - - def assert_inherited_setup(expected, parent) - _test_case = assert_setup_customizable(expected, parent, nil) - assert_setup_customizable(expected, parent, nil) do |test_case, tag| - test_case.send(:include, EmptyModule) if tag == :before - end - _test_case - end - - def assert_teardown_customizable(expected, parent, options) - called = [] - test_case = Class.new(parent || Test::Unit::TestCase) do - yield(self, :before) if block_given? - - @@called = called - def teardown - @@called << :teardown - end - - teardown(*(options[0] || [])) if options - def custom_teardown_method0 - @@called << :custom_teardown_method0 - end - - def custom_teardown_method1 - @@called << :custom_teardown_method1 - end - teardown(*[:custom_teardown_method1, *(options[1] || [])]) if options - - teardown(*(options[2] || [])) if options - def custom_teardown_method2 - @@called << :custom_teardown_method2 - end - unregister_teardown(:custom_teardown_method2) if options - - teardown(*(options[3] || [])) if options - def custom_teardown_method3 - @@called << :custom_teardown_method3 - end - - def test_nothing - end - - yield(self, :after) if block_given? - end - - test_case.new("test_nothing").run(Test::Unit::TestResult.new) {} - assert_equal(expected, called) - test_case - end - - def assert_teardown(expected, options) - assert_teardown_customizable(expected, nil, options) - assert_teardown_customizable(expected, nil, options) do |test_case, tag| - test_case.send(:include, EmptyModule) if tag == :before - end - end - - def assert_inherited_teardown(expected, parent) - assert_teardown_customizable(expected, parent, nil) - assert_teardown_customizable(expected, parent, nil) do |test_case, tag| - test_case.send(:include, EmptyModule) if tag == :before - end - end - - def assert_invalid_option(fixture_type, option) - exception = assert_raise(ArgumentError) do - Class.new(Test::Unit::TestCase) do - def test_nothing - end - - send(fixture_type, option) - def fixture - end - end - end - assert_equal("must be {:before => :prepend}, {:before => :append}, " + - "{:after => :prepend} or {:after => :append}" + - ": #{option.inspect}", - exception.message) - end - - def assert_invalid_setup_option(option) - assert_invalid_option(:setup, option) - end - - def assert_invalid_teardown_option(option) - assert_invalid_option(:teardown, option) - end -end Deleted: test-unit/test/test_notification.rb (+0 -33) 100644 =================================================================== --- test-unit/test/test_notification.rb 2010-09-12 03:03:44 +0000 (7a85ddb) +++ /dev/null @@ -1,33 +0,0 @@ -require 'test/unit' -require 'testunit_test_util' - -class TestNotification < Test::Unit::TestCase - include TestUnitTestUtil - - class TestCase < Test::Unit::TestCase - class << self - def suite - Test::Unit::TestSuite.new(name) - end - end - - def test_notify - notify("1st notify") - notify("2nd notify. Reach here.") - end - end - - def test_notify - result = _run_test("test_notify") - assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \ - "0 omissions, 2 notifications", - result.to_s) - assert_fault_messages(["1st notify", "2nd notify. Reach here."], - result.notifications) - end - - private - def _run_test(name) - super(TestCase, name) - end -end Deleted: test-unit/test/test_omission.rb (+0 -81) 100644 =================================================================== --- test-unit/test/test_omission.rb 2010-09-12 03:03:44 +0000 (bdafedc) +++ /dev/null @@ -1,81 +0,0 @@ -require 'test/unit' -require 'testunit_test_util' - -class TestUnitOmission < Test::Unit::TestCase - include TestUnitTestUtil - - class TestCase < Test::Unit::TestCase - class << self - def suite - Test::Unit::TestSuite.new(name) - end - end - - def test_omit - omit("1st omit") - omit("2nd omit. Should not be reached here.") - assert(true, "Should not be reached here too.") - end - - def test_omit_with_condition - omit_if(false, "Never omit.") - omit_unless(true, "Never omit too.") - omit_if(true, "Should omit.") - omit("The last omit. Should not be reached here.") - end - - def test_omit_with_block - omit("Omit block") do - flunk("Should not be reached here.") - end - assert(true, "Should be reached here.") - end - - def test_omit_with_block_and_condition - omit_if(false, "Never omit.") do - assert(true, "Should be reached here.") - end - omit_if(true, "Should omit.") do - flunk("Never reached here.") - end - assert(true, "Should be reached here too.") - end - end - - def test_omit - result = _run_test("test_omit") - assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \ - "1 omissions, 0 notifications", - result.to_s) - assert_fault_messages(["1st omit"], result.omissions) - end - - def test_omit_with_condition - result = _run_test("test_omit_with_condition") - assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \ - "1 omissions, 0 notifications", - result.to_s) - assert_fault_messages(["Should omit."], result.omissions) - end - - def test_omit_with_block - result = _run_test("test_omit_with_block") - assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \ - "1 omissions, 0 notifications", - result.to_s) - assert_fault_messages(["Omit block"], result.omissions) - end - - def test_omit_with_condition_and_block - result = _run_test("test_omit_with_block_and_condition") - assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \ - "1 omissions, 0 notifications", - result.to_s) - assert_fault_messages(["Should omit."], result.omissions) - end - - private - def _run_test(name) - super(TestCase, name) - end -end Deleted: test-unit/test/test_pending.rb (+0 -70) 100644 =================================================================== --- test-unit/test/test_pending.rb 2010-09-12 03:03:44 +0000 (de1bc27) +++ /dev/null @@ -1,70 +0,0 @@ -require 'test/unit' -require 'testunit_test_util' - -class TestUnitPending < Test::Unit::TestCase - include TestUnitTestUtil - - class TestCase < Test::Unit::TestCase - class << self - def suite - Test::Unit::TestSuite.new(name) - end - end - - def test_pend - pend("1st pend") - pend("2nd pend. Should not be reached here.") - assert(true, "Should not be reached here too.") - end - - def test_pend_with_failure_in_block - pend("Wait a minute") do - raise "Not implemented yet" - end - assert(true, "Reached here.") - end - - def test_pend_with_no_failure_in_block - pend("Wait a minute") do - "Nothing raised" - end - assert(true, "Not reached here.") - end - end - - def test_pend - test = nil - result = _run_test("test_pend") {|t| test = t} - assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 1 pendings, " \ - "0 omissions, 0 notifications", - result.to_s) - assert_fault_messages(["1st pend"], result.pendings) - assert_true(test.interrupted?) - end - - def test_pend_with_failure_in_block - test = nil - result = _run_test("test_pend_with_failure_in_block") {|t| test = t} - assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 1 pendings, " \ - "0 omissions, 0 notifications", - result.to_s) - assert_fault_messages(["Wait a minute"], result.pendings) - assert_false(test.interrupted?) - end - - def test_pend_with_no_failure_in_block - test = nil - result = _run_test("test_pend_with_no_failure_in_block") {|t| test = t} - assert_equal("1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, " \ - "0 omissions, 0 notifications", - result.to_s) - assert_fault_messages(["Pending block should not be passed: Wait a minute."], - result.failures) - assert_true(test.interrupted?) - end - - private - def _run_test(name, &block) - super(TestCase, name, &block) - end -end Deleted: test-unit/test/test_priority.rb (+0 -89) 100644 =================================================================== --- test-unit/test/test_priority.rb 2010-09-12 03:03:44 +0000 (5b3a8b9) +++ /dev/null @@ -1,89 +0,0 @@ -require 'test/unit' - -class TestUnitPriority < Test::Unit::TestCase - class TestCase < Test::Unit::TestCase - class << self - def suite - Test::Unit::TestSuite.new(name) - end - end - - priority :must - def test_must - assert(true) - end - - def test_must_inherited - assert(true) - end - - priority :important - def test_important - assert(true) - end - - def test_important_inherited - assert(true) - end - - priority :high - def test_high - assert(true) - end - - def test_high_inherited - assert(true) - end - - priority :normal - def test_normal - assert(true) - end - - def test_normal_inherited - assert(true) - end - - priority :low - def test_low - assert(true) - end - - def test_low_inherited - assert(true) - end - - priority :never - def test_never - assert(true) - end - - def test_never_inherited - assert(true) - end - end - - def test_priority - assert_priority("must", 1.0, 0.0001) - assert_priority("important", 0.9, 0.09) - assert_priority("high", 0.70, 0.1) - assert_priority("normal", 0.5, 0.1) - assert_priority("low", 0.25, 0.1) - assert_priority("never", 0.0, 0.0001) - end - - def assert_priority(priority, expected, delta) - assert_need_to_run("test_#{priority}", expected, delta) - assert_need_to_run("test_#{priority}_inherited", expected, delta) - end - - def assert_need_to_run(test_name, expected, delta) - test = TestCase.new(test_name) - n = 1000 - n_need_to_run = 0 - n.times do |i| - n_need_to_run +=1 if Test::Unit::Priority::Checker.need_to_run?(test) - end - assert_in_delta(expected, n_need_to_run.to_f / n, delta) - end -end Deleted: test-unit/test/test_testcase.rb (+0 -430) 100644 =================================================================== --- test-unit/test/test_testcase.rb 2010-09-12 03:03:44 +0000 (6c7c46a) +++ /dev/null @@ -1,430 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' - -module Test - module Unit - class TC_TestCase < TestCase - def test_creation - tc = Class.new(TestCase) do - def test_with_arguments(arg1, arg2) - end - end - - caught = true - catch(:invalid_test) do - tc.new(:test_with_arguments) - caught = false - end - check("Should have caught an invalid test when there are arguments", caught) - - caught = true - catch(:invalid_test) do - tc.new(:non_existent_test) - caught = false - end - check("Should have caught an invalid test when the method does not exist", caught) - end - - def setup - @tc_failure_error = Class.new(TestCase) do - def test_failure - assert_block("failure") { false } - end - def test_error - 1 / 0 - end - def test_nested_failure - nested - end - def nested - assert_block("nested"){false} - end - def return_passed? - return passed? - end - end - - def @tc_failure_error.name - "TC_FailureError" - end - end - - def test_add_failed_assertion - test_case = @tc_failure_error.new(:test_failure) - check("passed? should start out true", test_case.return_passed?) - result = TestResult.new - called = false - result.add_listener(TestResult::FAULT) { - | fault | - check("Should have a Failure", fault.instance_of?(Failure)) - check("The Failure should have the correct message", "failure" == fault.message) - check("The Failure should have the correct test_name (was <#{fault.test_name}>)", fault.test_name == "test_failure(TC_FailureError)") - r = /\A.*#{Regexp.escape(File.basename(__FILE__))}:\d+:in `test_failure'\Z/ - - location = fault.location - check("The location should be an array", location.kind_of?(Array)) - check("The location should have two lines (was: <#{location.inspect}>)", location.size == 2) - check("The Failure should have the correct location (was <#{location[0].inspect}>, expected <#{r.inspect}>)", r =~ location[0]) - called = true - } - progress = [] - test_case.run(result) { |*arguments| progress << arguments } - check("The failure should have triggered the listener", called) - check("The failure should have set passed?", !test_case.return_passed?) - check("The progress block should have been updated correctly", [[TestCase::STARTED, test_case.name], [TestCase::FINISHED, test_case.name]] == progress) - end - - def test_add_failure_nested - test_case = @tc_failure_error.new(:test_nested_failure) - check("passed? should start out true", test_case.return_passed?) - - result = TestResult.new - called = false - result.add_listener(TestResult::FAULT) { - | fault | - check("Should have a Failure", fault.instance_of?(Failure)) - check("The Failure should have the correct message", "nested" == fault.message) - check("The Failure should have the correct test_name (was <#{fault.test_name}>)", fault.test_name == "test_nested_failure(TC_FailureError)") - r = - - location = fault.location - check("The location should be an array", location.kind_of?(Array)) - check("The location should have the correct number of lines (was: <#{location.inspect}>)", location.size == 3) - check("The Failure should have the correct location (was <#{location[0].inspect}>)", /\A.*#{Regexp.escape(File.basename(__FILE__))}:\d+:in `nested'\Z/ =~ location[0]) - check("The Failure should have the correct location (was <#{location[1].inspect}>)", /\A.*#{Regexp.escape(File.basename(__FILE__))}:\d+:in `test_nested_failure'\Z/ =~ location[1]) - called = true - } - test_case.run(result){} - check("The failure should have triggered the listener", called) - end - - def test_add_error - test_case = @tc_failure_error.new(:test_error) - check("passed? should start out true", test_case.return_passed?) - result = TestResult.new - called = false - result.add_listener(TestResult::FAULT) { - | fault | - check("Should have a TestError", fault.instance_of?(Error)) - check("The Error should have the correct message", "ZeroDivisionError: divided by 0" == fault.message) - check("The Error should have the correct test_name", "test_error(TC_FailureError)" == fault.test_name) - check("The Error should have the correct exception", fault.exception.instance_of?(ZeroDivisionError)) - called = true - } - test_case.run(result) {} - check("The error should have triggered the listener", called) - check("The error should have set passed?", !test_case.return_passed?) - end - - def test_no_tests - suite = TestCase.suite - check("Should have a test suite", suite.instance_of?(TestSuite)) - check("Should have one test", suite.size == 1) - check("Should have the default test", suite.tests.first.name == "default_test(Test::Unit::TestCase)") - - result = TestResult.new - suite.run(result) {} - check("Should have had one test run", result.run_count == 1) - check("Should have had one test failure", result.failure_count == 1) - check("Should have had no errors", result.error_count == 0) - end - - def test_suite - tc = Class.new(TestCase) do - def test_succeed - assert_block {true} - end - def test_fail - assert_block {false} - end - def test_error - 1/0 - end - def dont_run - assert_block {true} - end - def test_dont_run(argument) - assert_block {true} - end - def test - assert_block {true} - end - end - - suite = tc.suite - check("Should have a test suite", suite.instance_of?(TestSuite)) - check("Should have three tests", suite.size == 3) - - result = TestResult.new - suite.run(result) {} - check("Should have had three test runs", result.run_count == 3) - check("Should have had one test failure", result.failure_count == 1) - check("Should have had one test error", result.error_count == 1) - end - - - def test_setup_teardown - tc = Class.new(TestCase) do - attr_reader(:setup_called, :teardown_called) - def initialize(test) - super(test) - @setup_called = false - @teardown_called = false - end - def setup - @setup_called = true - end - def teardown - @teardown_called = true - end - def test_succeed - assert_block {true} - end - def test_fail - assert_block {false} - end - def test_error - raise "Error!" - end - end - result = TestResult.new - - test = tc.new(:test_succeed) - test.run(result) {} - check("Should have called setup the correct number of times", test.setup_called) - check("Should have called teardown the correct number of times", test.teardown_called) - - test = tc.new(:test_fail) - test.run(result) {} - check("Should have called setup the correct number of times", test.setup_called) - check("Should have called teardown the correct number of times", test.teardown_called) - - test = tc.new(:test_error) - test.run(result) {} - check("Should have called setup the correct number of times", test.setup_called) - check("Should have called teardown the correct number of times", test.teardown_called) - - check("Should have had two test runs", result.run_count == 3) - check("Should have had a test failure", result.failure_count == 1) - check("Should have had a test error", result.error_count == 1) - end - - def test_assertion_failed_not_called - tc = Class.new(TestCase) do - def test_thing - raise AssertionFailedError.new - end - end - - suite = tc.suite - check("Should have one test", suite.size == 1) - result = TestResult.new - suite.run(result) {} - check("Should have had one test run", result.run_count == 1) - check("Should have had one assertion failure", result.failure_count == 1) - check("Should not have any assertion errors but had #{result.error_count}", result.error_count == 0) - end - - def test_equality - tc1 = Class.new(TestCase) do - def test_1 - end - def test_2 - end - end - - tc2 = Class.new(TestCase) do - def test_1 - end - end - - test1 = tc1.new('test_1') - test2 = tc1.new('test_1') - check("Should be equal", test1 == test2) - check("Should be equal", test2 == test1) - - test1 = tc1.new('test_2') - check("Should not be equal", test1 != test2) - check("Should not be equal", test2 != test1) - - test2 = tc1.new('test_2') - check("Should be equal", test1 == test2) - check("Should be equal", test2 == test1) - - test1 = tc1.new('test_1') - test2 = tc2.new('test_1') - check("Should not be equal", test1 != test2) - check("Should not be equal", test2 != test1) - - - check("Should not be equal", test1 != Object.new) - check("Should not be equal", Object.new != test1) - end - - def test_re_raise_exception - test_case = Class.new(TestCase) do - def test_raise_interrupt - raise Interrupt - end - end - - test = test_case.new("test_raise_interrupt") - begin - test.run(TestResult.new) {} - check("Should not be reached", false) - rescue Exception - check("Interrupt exception should be re-raised", $!.class == Interrupt) - end - end - - def test_startup_shutdown - called = [] - test_case = Class.new(TestCase) do - @@called = called - class << self - def startup - @@called << :startup - end - - def shutdown - @@called << :shutdown - end - end - - def setup - @@called << :setup - end - - def teardown - @@called << :teardown - end - - def test1 - end - - def test2 - end - end - - test_suite = test_case.suite - test_suite.run(TestResult.new) {} - check("startup/shutdown should be called once per test case" + - ": #{called.inspect}", - called == [:startup, - :setup, :teardown, - :setup, :teardown, - :shutdown]) - end - - def test_error_on_startup - test_case = Class.new(TestCase) do - class << self - def startup - raise "from startup" - end - end - - def test_nothing - end - end - - test_suite = test_case.suite - result = TestResult.new - test_suite.run(result) {} - check("Should record an error on startup: #{result}", - result.error_count == 1) - end - - def test_pass_through_error_on_startup - test_case = Class.new(TestCase) do - class << self - def startup - raise Interrupt - end - end - - def test_nothing - end - end - - test_suite = test_case.suite - begin - test_suite.run(TestResult.new) {} - check("Should not be reached", false) - rescue Exception - check("Interrupt should be passed through: #{$!}", - Interrupt === $!) - end - end - - def test_error_on_shutdown - test_case = Class.new(TestCase) do - class << self - def shutdown - raise "from shutdown" - end - end - - def test_nothing - end - end - - test_suite = test_case.suite - result = TestResult.new - test_suite.run(result) {} - check("Should record an error on shutdown: #{result}", - result.error_count == 1) - end - - def test_pass_through_error_on_shutdown - test_case = Class.new(TestCase) do - class << self - def shutdown - raise Interrupt - end - end - - def test_nothing - end - end - - test_suite = test_case.suite - begin - test_suite.run(TestResult.new) {} - check("Should not be reached", false) - rescue Exception - check("Interrupt should be passed through: #{$!}", - Interrupt === $!) - end - end - - def test_interrupted - test_case = Class.new(TestCase) do - def test_fail - flunk - end - - def test_nothing - end - end - - failed_test = test_case.new(:test_fail) - failed_test.run(TestResult.new) {} - check("Should be interrupted", failed_test.interrupted?) - - success_test = test_case.new(:test_nothing) - success_test.run(TestResult.new) {} - check("Should not be interrupted", !success_test.interrupted?) - end - - private - def check(message, passed) - add_assertion - raise AssertionFailedError.new(message) unless passed - end - end - end -end Deleted: test-unit/test/test_testresult.rb (+0 -113) 100644 =================================================================== --- test-unit/test/test_testresult.rb 2010-09-12 03:03:44 +0000 (889179e) +++ /dev/null @@ -1,113 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/testcase' -require 'test/unit/testresult' - -module Test - module Unit - class TC_TestResult < TestCase - def setup - @my_result = TestResult.new - @my_result.add_assertion() - @failure = "failure" - @my_result.add_failure(@failure) - @error = "error" - @my_result.add_error(@error) - end - - def test_result_changed_notification - called1 = false - @my_result.add_listener(TestResult::CHANGED) do |result| - assert_equal(@my_result, result) - called1 = true - end - @my_result.add_assertion - assert_true(called1) - - called1, called2 = false, false - @my_result.add_listener(TestResult::CHANGED) do |result| - assert_equal(@my_result, result) - called2 = true - end - @my_result.add_assertion - assert_equal([true, true], [called1, called2]) - - called1, called2 = false, false - @my_result.add_failure("") - assert_equal([true, true], [called1, called2]) - - called1, called2 = false, false - @my_result.add_error("") - assert_equal([true, true], [called1, called2]) - - called1, called2 = false, false - @my_result.add_run - assert_equal([true, true], [called1, called2]) - end - - def test_fault_notification - called1 = false - fault = "fault" - @my_result.add_listener(TestResult::FAULT) do |passed_fault| - assert_equal(fault, passed_fault) - called1 = true - end - - @my_result.add_assertion - assert_false(called1) - - @my_result.add_failure(fault) - assert_true(called1) - - called1, called2 = false, false - @my_result.add_listener(TestResult::FAULT) do |passed_fault| - assert_equal(fault, passed_fault) - called2 = true - end - - @my_result.add_assertion - assert_equal([false, false], [called1, called2]) - - called1, called2 = false, false - @my_result.add_failure(fault) - assert_equal([true, true], [called1, called2]) - - called1, called2 = false, false - @my_result.add_error(fault) - assert_equal([true, true], [called1, called2]) - - called1, called2 = false, false - @my_result.add_run - assert_equal([false, false], [called1, called2]) - end - - def test_passed? - result = TestResult.new - assert_true(result.passed?) - - result.add_assertion - assert_true(result.passed?) - - result.add_run - assert_true(result.passed?) - - result.add_failure("") - assert_false(result.passed?) - - result = TestResult.new - result.add_error("") - assert_false(result.passed?) - end - - def test_faults - assert_equal([@failure, @error], @my_result.faults) - - notification = "notification" - @my_result.add_notification(notification) - assert_equal([@failure, @error, notification], @my_result.faults) - end - end - end -end Deleted: test-unit/test/test_testsuite.rb (+0 -129) 100644 =================================================================== --- test-unit/test/test_testsuite.rb 2010-09-12 03:03:44 +0000 (5f6631d) +++ /dev/null @@ -1,129 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' - -module Test - module Unit - class TC_TestSuite < TestCase - def setup - @testcase1 = Class.new(TestCase) do - def test_succeed1 - assert_block { true } - end - def test_fail - assert_block { false } - end - end - - @testcase2 = Class.new(TestCase) do - def test_succeed2 - assert_block { true } - end - def test_error - raise - end - end - end - - def test_add - s = TestSuite.new - assert_equal(s, s << self.class.new("test_add")) - end - - def test_delete - s = TestSuite.new - t1 = self.class.new("test_delete") - s << t1 - t2 = self.class.new("test_add") - s << t2 - assert_equal(t1, s.delete(t1)) - assert_nil(s.delete(t1)) - assert_equal(TestSuite.new << t2, s) - end - - def test_size - suite = TestSuite.new - suite2 = TestSuite.new - suite2 << self.class.new("test_size") - suite << suite2 - suite << self.class.new("test_size") - assert_equal(2, suite.size, "The count should be correct") - end - - def test_run - progress = [] - suite = @testcase1.suite - result = TestResult.new - suite.run(result) { |*values| progress << values } - - assert_equal(2, result.run_count, "Should have had four test runs") - assert_equal(1, result.failure_count, "Should have had one test failure") - assert_equal(0, result.error_count, "Should have had one test error") - assert_equal([[TestSuite::STARTED, suite.name], - [TestCase::STARTED, "test_fail(#{suite.name})"], - [TestCase::FINISHED, "test_fail(#{suite.name})"], - [TestCase::STARTED, "test_succeed1(#{suite.name})"], - [TestCase::FINISHED, "test_succeed1(#{suite.name})"], - [TestSuite::FINISHED, suite.name]], - progress, "Should have had the correct progress") - - suite = TestSuite.new - suite << @testcase1.suite - suite << @testcase2.suite - result = TestResult.new - progress = [] - suite.run(result) { |*values| progress << values } - - assert_equal(4, result.run_count, "Should have had four test runs") - assert_equal(1, result.failure_count, "Should have had one test failure") - assert_equal(1, result.error_count, "Should have had one test error") - assert_equal(14, progress.size, "Should have had the correct number of progress calls") - end - - def test_empty? - assert(TestSuite.new.empty?, "A new test suite should be empty?") - assert(!@testcase2.suite.empty?, "A test suite with tests should not be empty") - end - - def test_equality - suite1 = TestSuite.new - suite2 = TestSuite.new - assert_equal(suite1, suite2) - assert_equal(suite2, suite1) - - suite1 = TestSuite.new('name') - assert_not_equal(suite1, suite2) - assert_not_equal(suite2, suite1) - - suite2 = TestSuite.new('name') - assert_equal(suite1, suite2) - assert_equal(suite2, suite1) - - suite1 << 'test' - assert_not_equal(suite1, suite2) - assert_not_equal(suite2, suite1) - - suite2 << 'test' - assert_equal(suite1, suite2) - assert_equal(suite2, suite1) - - suite2 = Object.new - class << suite2 - def name - 'name' - end - def tests - ['test'] - end - end - assert_not_equal(suite1, suite2) - assert_not_equal(suite2, suite1) - - assert_not_equal(suite1, Object.new) - assert_not_equal(Object.new, suite1) - end - end - end -end Deleted: test-unit/test/testunit_test_util.rb (+0 -14) 100644 =================================================================== --- test-unit/test/testunit_test_util.rb 2010-09-12 03:03:44 +0000 (33527b9) +++ /dev/null @@ -1,14 +0,0 @@ -module TestUnitTestUtil - private - def assert_fault_messages(expected, faults) - assert_equal(expected, faults.collect {|fault| fault.message}) - end - - def _run_test(test_case, name) - result = Test::Unit::TestResult.new - test = test_case.new(name) - yield(test) if block_given? - test.run(result) {} - result - end -end Deleted: test-unit/test/ui/test_testrunmediator.rb (+0 -20) 100644 =================================================================== --- test-unit/test/ui/test_testrunmediator.rb 2010-09-12 03:03:44 +0000 (332a843) +++ /dev/null @@ -1,20 +0,0 @@ -require 'test/unit/ui/testrunnermediator' - -class TestUnitUIMediator < Test::Unit::TestCase - def test_run_suite_with_interrupt_exception - test_case = Class.new(Test::Unit::TestCase) do - def test_raise_interrupt - raise Interrupt - end - end - mediator = Test::Unit::UI::TestRunnerMediator.new(test_case.suite) - finished = false - mediator.add_listener(Test::Unit::UI::TestRunnerMediator::FINISHED) do - finished = true - end - assert_raise(Interrupt) do - mediator.run_suite - end - assert(finished) - end -end Deleted: test-unit/test/util/test_backtracefilter.rb (+0 -41) 100644 =================================================================== --- test-unit/test/util/test_backtracefilter.rb 2010-09-12 03:03:44 +0000 (d4e40ea) +++ /dev/null @@ -1,41 +0,0 @@ -require 'test/unit' - -require 'test/unit/util/backtracefilter' - -module Test::Unit::Util - class TestBacktraceFilter < Test::Unit::TestCase - include BacktraceFilter - - def test_filter_backtrace - backtrace = [%q{C:\some\old\path/test/unit/assertions.rb:44:in 'assert'}, - %q{tc_thing.rb:4:in 'a'}, - %q{tc_thing.rb:4:in 'test_stuff'}, - %q{C:\some\old\path/test/unit/testcase.rb:44:in 'send'}, - %q{C:\some\old\path\test\unit\testcase.rb:44:in 'run'}, - %q{C:\some\old\path\test\unit.rb:44:in 'run'}, - %q{tc_thing.rb:3}] - assert_equal(backtrace[1..2], filter_backtrace(backtrace, %q{C:\some\old\path\test\unit}), "Should filter out all TestUnit-specific lines") - -backtrace = [%q{tc_thing.rb:4:in 'a'}, - %q{tc_thing.rb:4:in 'test_stuff'}, - %q{tc_thing.rb:3}] - assert_equal(backtrace, filter_backtrace(backtrace, %q{C:\some\old\path\test\unit}), "Shouldn't filter too much") - - backtrace = [%q{C:\some\old\path/test/unit/assertions.rb:44:in 'assert'}, - %q{tc_thing.rb:4:in 'a'}, - %q{tc_thing.rb:4:in 'test_stuff'}, - %q{tc_thing.rb:3}] - assert_equal(backtrace[1..3], filter_backtrace(backtrace, %q{C:\some\old\path\test\unit}), "Should filter out all TestUnit-specific lines") - - backtrace = [%q{C:\some\old\path/test/unit/assertions.rb:44:in 'assert'}, - %q{C:\some\old\path/test/unit/testcase.rb:44:in 'send'}, - %q{C:\some\old\path\test\unit\testcase.rb:44:in 'run'}, - %q{C:\some\old\path\test\unit.rb:44:in 'run'}] - assert_equal(backtrace, filter_backtrace(backtrace, %q{C:\some\old\path\test\unit}), "Should filter out all TestUnit-specific lines") - end - - def test_nil_backtrace - assert_equal(["No backtrace"], filter_backtrace(nil)) - end - end -end Deleted: test-unit/test/util/test_observable.rb (+0 -102) 100644 =================================================================== --- test-unit/test/util/test_observable.rb 2010-09-12 03:03:44 +0000 (6cd1018) +++ /dev/null @@ -1,102 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/util/observable' - -module Test - module Unit - module Util - class TC_Observable < TestCase - - class TF_Observable - include Observable - end - - def setup - @observable = TF_Observable.new - end - - def test_simple_observation - assert_raises(ArgumentError, "add_listener should throw an exception if no callback is supplied") do - @observable.add_listener(:property, "a") - end - - heard = false - callback = proc { heard = true } - assert_equal("a", @observable.add_listener(:property, "a", &callback), "add_listener should return the listener that was added") - - count = 0 - @observable.instance_eval do - count = notify_listeners(:property) - end - assert_equal(1, count, "notify_listeners should have returned the number of listeners that were notified") - assert(heard, "Should have heard the property changed") - - heard = false - assert_equal(callback, @observable.remove_listener(:property, "a"), "remove_listener should return the callback") - - count = 1 - @observable.instance_eval do - count = notify_listeners(:property) - end - assert_equal(0, count, "notify_listeners should have returned the number of listeners that were notified") - assert(!heard, "Should not have heard the property change") - end - - def test_value_observation - value = nil - @observable.add_listener(:property, "a") do |passed_value| - value = passed_value - end - count = 0 - @observable.instance_eval do - count = notify_listeners(:property, "stuff") - end - assert_equal(1, count, "Should have update the correct number of listeners") - assert_equal("stuff", value, "Should have received the value as an argument to the listener") - end - - def test_multiple_value_observation - values = [] - @observable.add_listener(:property, "a") do |first_value, second_value| - values = [first_value, second_value] - end - count = 0 - @observable.instance_eval do - count = notify_listeners(:property, "stuff", "more stuff") - end - assert_equal(1, count, "Should have update the correct number of listeners") - assert_equal(["stuff", "more stuff"], values, "Should have received the value as an argument to the listener") - end - - def test_add_remove_with_default_listener - assert_raises(ArgumentError, "add_listener should throw an exception if no callback is supplied") do - @observable.add_listener(:property) - end - - heard = false - callback = proc { heard = true } - assert_equal(callback, @observable.add_listener(:property, &callback), "add_listener should return the listener that was added") - - count = 0 - @observable.instance_eval do - count = notify_listeners(:property) - end - assert_equal(1, count, "notify_listeners should have returned the number of listeners that were notified") - assert(heard, "Should have heard the property changed") - - heard = false - assert_equal(callback, @observable.remove_listener(:property, callback), "remove_listener should return the callback") - - count = 1 - @observable.instance_eval do - count = notify_listeners(:property) - end - assert_equal(0, count, "notify_listeners should have returned the number of listeners that were notified") - assert(!heard, "Should not have heard the property change") - end - end - end - end -end Deleted: test-unit/test/util/test_procwrapper.rb (+0 -36) 100644 =================================================================== --- test-unit/test/util/test_procwrapper.rb 2010-09-12 03:03:44 +0000 (3e552c7) +++ /dev/null @@ -1,36 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' -require 'test/unit/util/procwrapper' - -module Test - module Unit - module Util - class TC_ProcWrapper < TestCase - def munge_proc(&a_proc) - return a_proc - end - def setup - @original = proc {} - @munged = munge_proc(&@original) - @wrapped_original = ProcWrapper.new(@original) - @wrapped_munged = ProcWrapper.new(@munged) - end - def test_wrapping - assert_same(@original, @wrapped_original.to_proc, "The wrapper should return what was wrapped") - end - def test_hashing - - assert_equal(@wrapped_original.hash, @wrapped_munged.hash, "The original and munged should have the same hash when wrapped") - assert_equal(@wrapped_original, @wrapped_munged, "The wrappers should be equivalent") - - a_hash = {@wrapped_original => @original} - assert(a_hash[@wrapped_original], "Should be able to access the wrapper in the hash") - assert_equal(a_hash[@wrapped_original], @original, "Should be able to access the wrapper in the hash") - end - end - end - end -end Modified: test/run-test.rb (+2 -3) =================================================================== --- test/run-test.rb 2010-09-12 03:03:44 +0000 (92058da) +++ test/run-test.rb 2010-09-12 03:48:18 +0000 (98afe63) @@ -1,7 +1,6 @@ #!/usr/bin/env ruby base_dir = File.expand_path(File.join(File.dirname(__FILE__), "..")) -test_unit_dir = File.join(base_dir, "test-unit", "lib") ext_dir = File.join(base_dir, "ext", "cairo") lib_dir = File.join(base_dir, "lib") test_dir = File.join(base_dir, "test") @@ -12,8 +11,8 @@ if system("which make > /dev/null") end end -$LOAD_PATH.unshift(test_unit_dir) - +require 'rubygems' +gem 'test-unit' require 'test/unit' $LOAD_PATH.unshift(base_dir) From null+rcairo at clear-code.com Sun Sep 12 01:44:21 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 05:44:21 +0000 Subject: [cairo-commit:00066] rcairo/rcairo [master] use more meaningful name. Message-ID: <20100912054436.C072F170F61@taiyaki.ru> Kouhei Sutou 2010-09-12 05:44:21 +0000 (Sun, 12 Sep 2010) New Revision: 5e22f2b2dd4df802f8b7df5c556b074a4da3216d Log: use more meaningful name. Renamed files: samples/pac-nomralize.rb (from samples/pac2.rb) Renamed: samples/pac-nomralize.rb (+1 -1) 98% =================================================================== --- samples/pac2.rb 2010-09-12 05:43:25 +0000 (ae3c384) +++ samples/pac-nomralize.rb 2010-09-12 05:44:21 +0000 (ab57a3f) @@ -1,5 +1,5 @@ =begin - pac2.rb - rcairo sample script with #scale and #translate. + pac-normalize.rb - rcairo sample script with #scale and #translate. Original: pac.rb in http://www.artima.com/rubycs/articles/pdf_writer3.html =end From null+rcairo at clear-code.com Sun Sep 12 01:42:22 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 05:42:22 +0000 Subject: [cairo-commit:00067] rcairo/rcairo [master] add a sample for TeeSurface. Message-ID: <20100912054436.A7AE1170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 05:42:22 +0000 (Sun, 12 Sep 2010) New Revision: c19ea191d1ef582ef8de5491b8d13776fcfd7aaa Log: add a sample for TeeSurface. Added files: samples/pac-tee.rb Added: samples/pac-tee.rb (+170 -0) 100644 =================================================================== --- /dev/null +++ samples/pac-tee.rb 2010-09-12 05:42:22 +0000 (b458577) @@ -0,0 +1,170 @@ +=begin + pac-tee.rb - rcairo sample script with TeeSurface. + + Original: pac.rb in http://www.artima.com/rubycs/articles/pdf_writer3.html +=end + +top = File.expand_path(File.join(File.dirname(__FILE__), "..")) +$LOAD_PATH.unshift File.join(top, "ext", "cairo") +$LOAD_PATH.unshift File.join(top, "lib") + +require "cairo" + +def pac(surface, width, height) + cr = Cairo::Context.new(surface) + + # NOTE: You may need to set line width when use Cairo::Context#scale + cr.set_line_width(cr.line_width / [width, height].max) + + cr.scale(width, height) + + cr.save do + cr.set_source_color(:black) + cr.rectangle(0, 0, 1, 1) + cr.fill + end + + # Wall + wall_width = 0.89 + wall_height = 0.03 + wall_space = 0.5 + wall_x = 0.02 + wall1_y = 1 - 0.86 + wall2_y = wall1_y + wall_space + wall_radius = 0.01 + + cr.set_source_color(:magenta) + cr.rounded_rectangle(wall_x, wall1_y, wall_width, wall_height, wall_radius) + cr.fill + cr.set_source_color(:cyan) + cr.rounded_rectangle(wall_x, wall1_y, wall_width, wall_height, wall_radius) + cr.stroke + + cr.set_source_color(:magenta) + cr.rounded_rectangle(wall_x, wall2_y, wall_width, wall_height, wall_radius) + cr.fill + cr.set_source_color(:cyan) + cr.rounded_rectangle(wall_x, wall2_y, wall_width, wall_height, wall_radius) + cr.stroke + + # Body + body_x = 0.17 + body_y = 1 - 0.58 + body_width = 0.23 + body_height = 0.33 + + cr.save do + cr.translate(body_x, body_y) + cr.set_source_color(:yellow) + cr.scale(body_width, body_height) + cr.arc(0, 0, 0.5, 30 * (Math::PI / 180), 330 * (Math::PI / 180)) + cr.line_to(0, 0) + cr.close_path + cr.fill + end + + # Dot + dot_width = 0.02 + dot_height = 0.03 + small_dot_width = 0.01 + small_dot_height = 0.015 + dot_x = 0.29 + dot_y = 1 - 0.58 + dot_step = 0.05 + + cr.save do + cr.set_source_color(:yellow) + cr.save do + cr.translate(dot_x, dot_y) + cr.scale(dot_width, dot_height) + cr.circle(0, 0, 1).fill + end + + 4.times do |i| + cr.save do + cr.translate(dot_x + dot_step * (i + 1), dot_y) + cr.scale(small_dot_width, small_dot_height) + cr.circle(0, 0, 1).fill + end + end + end + + # Ghost + ghost_x = 0.59 + ghost_x_step = 0.03 + ghost_y = 1 - 0.42 + ghost_y_step = 0.04 + ghost_width = 0.18 + ghost_height = 0.29 + ghost_radius= 0.08 + cr.move_to(ghost_x, ghost_y) + cr.line_to(ghost_x, ghost_y - ghost_height) + cr.curve_to(ghost_x + ghost_width / 3.0, + ghost_y - ghost_height - ghost_radius, + ghost_x + ghost_width * (2.0 / 3.0), + ghost_y - ghost_height - ghost_radius, + ghost_x + ghost_width, + ghost_y - ghost_height) + cr.line_to(ghost_x + ghost_width, ghost_y) + i = 0 + (ghost_x + ghost_width).step(ghost_x, -ghost_x_step) do |x| + cr.line_to(x, ghost_y + -ghost_y_step * (i % 2)) + i += 1 + end + cr.close_path + + cr.set_source_color(:blue) + cr.fill_preserve + cr.set_source_color(:cyan) + cr.stroke + + # Ghost Eyes + eye_x = 0.62 + eye_y = 1 - 0.63 + eye_space = 0.06 + white_eye_width = 0.03 + white_eye_height = 0.04 + black_eye_width = 0.01 + black_eye_height = 0.02 + + cr.set_source_color(:white) + cr.rectangle(eye_x, eye_y - white_eye_height, + white_eye_width, white_eye_height) + cr.fill + cr.rectangle(eye_x + eye_space, eye_y - white_eye_height, + white_eye_width, white_eye_height) + cr.fill + + cr.set_source_color(:black) + cr.rectangle(eye_x, eye_y - black_eye_height, + black_eye_width, black_eye_height) + cr.fill + cr.rectangle(eye_x + eye_space, eye_y - black_eye_height, + black_eye_width, black_eye_height) + cr.fill + + cr.show_page +end + +paper = Cairo::Paper.parse(:a4_landscape) + +size_in_points = paper.size("pt") +image_surface = Cairo::ImageSurface.new(*size_in_points) + +tee_surface = Cairo::TeeSurface.new(image_surface) + +add_scalable_surface = Proc.new do |surface_class_name, suffix| + if Cairo.const_defined?(surface_class_name) + surface_class = Cairo.const_get(surface_class_name) + tee_surface << surface_class.new("pac-tee.#{suffix}", paper) + else + puts("#{surface_class_name} isn't supported.") + end +end + +add_scalable_surface.call("PSSurface", "ps") +add_scalable_surface.call("PDFSurface", "pdf") +add_scalable_surface.call("SVGSurface", "svg") + +pac(tee_surface, *size_in_points) +image_surface.write_to_png("pac-tee.png") From null+rcairo at clear-code.com Sun Sep 12 01:45:36 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 05:45:36 +0000 Subject: [cairo-commit:00068] rcairo/rcairo [master] pac2 -> pac-normalize. Message-ID: <20100912054547.24A35170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 05:45:36 +0000 (Sun, 12 Sep 2010) New Revision: 5a57a6f9b43b662ea636a91859f6bb8172ef02d4 Log: pac2 -> pac-normalize. Modified files: samples/pac-nomralize.rb Modified: samples/pac-nomralize.rb (+2 -2) =================================================================== --- samples/pac-nomralize.rb 2010-09-12 05:44:21 +0000 (ab57a3f) +++ samples/pac-nomralize.rb 2010-09-12 05:45:36 +0000 (57723c6) @@ -151,13 +151,13 @@ paper = Cairo::Paper.parse(:a4_landscape) size_in_points = paper.size("pt") Cairo::ImageSurface.new(*size_in_points) do |surface| cr = pac(surface, *size_in_points) - cr.target.write_to_png("pac2.png") + cr.target.write_to_png("pac-normalize.png") end scalable_surface_output = Proc.new do |surface_class_name, suffix| if Cairo.const_defined?(surface_class_name) surface_class = Cairo.const_get(surface_class_name) - surface_class.new("pac2.#{suffix}", paper) do |surface| + surface_class.new("pac-normalize.#{suffix}", paper) do |surface| pac(surface, *size_in_points) end else From null+rcairo at clear-code.com Sun Sep 12 01:43:25 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 05:43:25 +0000 Subject: [cairo-commit:00069] rcairo/rcairo [master] fix load path. Message-ID: <20100912054436.B5F5A170F31@taiyaki.ru> Kouhei Sutou 2010-09-12 05:43:25 +0000 (Sun, 12 Sep 2010) New Revision: 0bb30cb2826807a20a9104910f5a3b94c93b632b Log: fix load path. Modified files: samples/blur.rb samples/pac.rb samples/pac2.rb samples/png.rb samples/scalable.rb samples/text-on-path.rb samples/text2.rb Modified: samples/blur.rb (+2 -3) =================================================================== --- samples/blur.rb 2010-09-12 05:42:22 +0000 (49dc16e) +++ samples/blur.rb 2010-09-12 05:43:25 +0000 (fd63e55) @@ -1,9 +1,8 @@ #!/usr/bin/env ruby top = File.expand_path(File.join(File.dirname(__FILE__), "..")) -src = File.join(top, "src") -$LOAD_PATH.unshift src -$LOAD_PATH.unshift File.join(src, "lib") +$LOAD_PATH.unshift File.join(top, "ext", "cairo") +$LOAD_PATH.unshift File.join(top, "lib") require 'cairo' Modified: samples/pac.rb (+2 -3) =================================================================== --- samples/pac.rb 2010-09-12 05:42:22 +0000 (dc0b0ed) +++ samples/pac.rb 2010-09-12 05:43:25 +0000 (8cbf104) @@ -5,9 +5,8 @@ =end top = File.expand_path(File.join(File.dirname(__FILE__), "..")) -src = File.join(top, "src") -$LOAD_PATH.unshift src -$LOAD_PATH.unshift File.join(src, "lib") +$LOAD_PATH.unshift File.join(top, "ext", "cairo") +$LOAD_PATH.unshift File.join(top, "lib") require "cairo" Modified: samples/pac2.rb (+2 -3) =================================================================== --- samples/pac2.rb 2010-09-12 05:42:22 +0000 (efd01eb) +++ samples/pac2.rb 2010-09-12 05:43:25 +0000 (ae3c384) @@ -5,9 +5,8 @@ =end top = File.expand_path(File.join(File.dirname(__FILE__), "..")) -src = File.join(top, "src") -$LOAD_PATH.unshift src -$LOAD_PATH.unshift File.join(src, "lib") +$LOAD_PATH.unshift File.join(top, "ext", "cairo") +$LOAD_PATH.unshift File.join(top, "lib") require "cairo" Modified: samples/png.rb (+2 -3) =================================================================== --- samples/png.rb 2010-09-12 05:42:22 +0000 (62ce45e) +++ samples/png.rb 2010-09-12 05:43:25 +0000 (4bf501b) @@ -1,9 +1,8 @@ #!/usr/bin/env ruby top = File.expand_path(File.join(File.dirname(__FILE__), "..")) -src = File.join(top, "src") -$LOAD_PATH.unshift src -$LOAD_PATH.unshift File.join(src, "lib") +$LOAD_PATH.unshift File.join(top, "ext", "cairo") +$LOAD_PATH.unshift File.join(top, "lib") require 'cairo' Modified: samples/scalable.rb (+2 -3) =================================================================== --- samples/scalable.rb 2010-09-12 05:42:22 +0000 (ed84c2a) +++ samples/scalable.rb 2010-09-12 05:43:25 +0000 (722af9b) @@ -1,9 +1,8 @@ #!/usr/bin/env ruby top = File.expand_path(File.join(File.dirname(__FILE__), "..")) -src = File.join(top, "src") -$LOAD_PATH.unshift src -$LOAD_PATH.unshift File.join(src, "lib") +$LOAD_PATH.unshift File.join(top, "ext", "cairo") +$LOAD_PATH.unshift File.join(top, "lib") require 'cairo' require 'stringio' Modified: samples/text-on-path.rb (+2 -3) =================================================================== --- samples/text-on-path.rb 2010-09-12 05:42:22 +0000 (9c752bf) +++ samples/text-on-path.rb 2010-09-12 05:43:25 +0000 (d2e6e8b) @@ -1,9 +1,8 @@ #!/usr/bin/env ruby top = File.expand_path(File.join(File.dirname(__FILE__), "..")) -src = File.join(top, "src") -$LOAD_PATH.unshift src -$LOAD_PATH.unshift File.join(src, "lib") +$LOAD_PATH.unshift File.join(top, "ext", "cairo") +$LOAD_PATH.unshift File.join(top, "lib") require 'cairo' require 'pango' Modified: samples/text2.rb (+2 -3) =================================================================== --- samples/text2.rb 2010-09-12 05:42:22 +0000 (dce6a90) +++ samples/text2.rb 2010-09-12 05:43:25 +0000 (4d7e291) @@ -1,9 +1,8 @@ #!/usr/bin/env ruby top = File.expand_path(File.join(File.dirname(__FILE__), "..")) -src = File.join(top, "src") -$LOAD_PATH.unshift src -$LOAD_PATH.unshift File.join(src, "lib") +$LOAD_PATH.unshift File.join(top, "ext", "cairo") +$LOAD_PATH.unshift File.join(top, "lib") require 'optparse' require 'ostruct' From null+rcairo at clear-code.com Sun Sep 12 02:05:29 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 06:05:29 +0000 Subject: [cairo-commit:00070] rcairo/rcairo [master] use pkg-config for detecting cairo on Windows. Message-ID: <20100912060618.CCB74170F61@taiyaki.ru> Kouhei Sutou 2010-09-12 06:05:29 +0000 (Sun, 12 Sep 2010) New Revision: d7220496112a2d533f640865d57d379f4b7a1d52 Log: use pkg-config for detecting cairo on Windows. Modified files: ext/cairo/extconf.rb Modified: ext/cairo/extconf.rb (+8 -12) =================================================================== --- ext/cairo/extconf.rb 2010-09-12 05:56:52 +0000 (89321e9) +++ ext/cairo/extconf.rb 2010-09-12 06:05:29 +0000 (ea3cb8c) @@ -26,8 +26,7 @@ package = "cairo" module_name = "cairo" major, minor, micro = 1, 2, 0 -PKGConfig.have_package(package, major, minor, micro) or exit 1 - +base_dir = Pathname(__FILE__).dirname.parent.parent checking_for(checking_message("Win32 OS")) do case RUBY_PLATFORM when /cygwin|mingw|mswin32/ @@ -35,16 +34,11 @@ checking_for(checking_message("Win32 OS")) do import_library_name = "libruby-#{module_name}.a" $DLDFLAGS << " -Wl,--out-implib=#{import_library_name}" $cleanfiles << import_library_name - local_cairo_install_dir = base_dir + "vendor" + "local" - $CFLAGS += " -I#{local_cairo_install_dir}/include" - local_cairo_lib_dir = local_cairo_install_dir + "lib" - ["cairo.lib", "libcairo.dll.a"].each do |libcairo_base| - libcairo = local_cairo_lib_dir + libcairo_base - if libcairo.exist? - $LDFLAGS += " -L#{local_cairo_lib_dir}" - break - end - end + binary_base_dir = base_dir + "vendor" + "local" + $CFLAGS += " -I#{binary_base_dir}/include" + pkg_config_dir = binary_base_dir + "lib" + "pkgconfig" + PKGConfig.add_path(pkg_config_dir.to_s) + PKGConfig.set_override_variable("prefix", binary_base_dir.to_s) true else false @@ -72,6 +66,8 @@ checking_for(checking_message("Mac OS X")) do end end +PKGConfig.have_package(package, major, minor, micro) or exit 1 + $defs << "-DRB_CAIRO_COMPILATION" have_header("ruby/st.h") unless have_macro("HAVE_RUBY_ST_H", "ruby.h") From null+rcairo at clear-code.com Sun Sep 12 01:56:52 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 05:56:52 +0000 Subject: [cairo-commit:00071] rcairo/rcairo [master] support 1.10.0. Message-ID: <20100912060618.C347A170F31@taiyaki.ru> Kouhei Sutou 2010-09-12 05:56:52 +0000 (Sun, 12 Sep 2010) New Revision: 6723428fceea5bf6e01ce19a7daec44367d681e7 Log: support 1.10.0. Modified files: README.rdoc Modified: README.rdoc (+1 -1) =================================================================== --- README.rdoc 2010-09-12 05:56:40 +0000 (643e56e) +++ README.rdoc 2010-09-12 05:56:52 +0000 (ea48986) @@ -13,7 +13,7 @@ http://cairographics.org/ == Dependencies * ruby >= 1.8 (1.9.2 also supported!) -* cairo >= 1.2.0 (1.8.10 also supported!) +* cairo >= 1.2.0 (1.10.0 also supported!) == Install From null+rcairo at clear-code.com Sun Sep 12 02:06:09 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 06:06:09 +0000 Subject: [cairo-commit:00072] rcairo/rcairo [master] fix cairo version check macro position. Message-ID: <20100912060618.E477A170F63@taiyaki.ru> Kouhei Sutou 2010-09-12 06:06:09 +0000 (Sun, 12 Sep 2010) New Revision: c53179676177c01d94731a9c38321f3f4fbfdeb9 Log: fix cairo version check macro position. Modified files: ext/cairo/rb_cairo_device.c Modified: ext/cairo/rb_cairo_device.c (+2 -1) =================================================================== --- ext/cairo/rb_cairo_device.c 2010-09-12 06:05:42 +0000 (69c3384) +++ ext/cairo/rb_cairo_device.c 2010-09-12 06:06:09 +0000 (e7e829c) @@ -30,13 +30,14 @@ VALUE rb_cCairo_XCBDevice = Qnil; VALUE rb_cCairo_XlibDevice = Qnil; VALUE rb_cCairo_XMLDevice = Qnil; +#if CAIRO_CHECK_VERSION(1, 10, 0) + static cairo_user_data_key_t cr_closure_key; static cairo_user_data_key_t cr_object_holder_key; static cairo_user_data_key_t cr_finished_key; #define _SELF (RVAL2CRDEVICE(self)) -#if CAIRO_CHECK_VERSION(1, 10, 0) static inline void cr_device_check_status (cairo_device_t *device) { From null+rcairo at clear-code.com Sun Sep 12 01:56:40 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 05:56:40 +0000 Subject: [cairo-commit:00073] rcairo/rcairo [master] 1.8.6 -> 1.10.0. Message-ID: <20100912060618.B910E170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 05:56:40 +0000 (Sun, 12 Sep 2010) New Revision: ba9956ff0d1fc0a9b2f1d165c0370874230902be Log: 1.8.6 -> 1.10.0. Modified files: ext/cairo/rb_cairo.c Modified: ext/cairo/rb_cairo.c (+1 -1) =================================================================== --- ext/cairo/rb_cairo.c 2010-09-12 05:45:36 +0000 (fd058de) +++ ext/cairo/rb_cairo.c 2010-09-12 05:56:40 +0000 (9e3224e) @@ -76,7 +76,7 @@ Init_cairo () rb_define_const (rb_mCairo, "BINDINGS_VERSION", rb_ary_new3 (4, - INT2FIX (1), INT2FIX (8), INT2FIX (6), Qnil)); + INT2FIX (1), INT2FIX (10), INT2FIX (0), Qnil)); rb_define_module_function (rb_mCairo, "satisfied_version?", rb_cairo_satisfied_version, -1); From null+rcairo at clear-code.com Sun Sep 12 02:15:10 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 06:15:10 +0000 Subject: [cairo-commit:00074] rcairo/rcairo [master] fix typos. Message-ID: <20100912061537.BC2AB170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 06:15:10 +0000 (Sun, 12 Sep 2010) New Revision: 46e55949b2dbd10fc00a17ed02f028f94913b294 Log: fix typos. Modified files: ext/cairo/cairo.def Modified: ext/cairo/cairo.def (+3 -3) =================================================================== --- ext/cairo/cairo.def 2010-09-12 06:06:09 +0000 (0173eeb) +++ ext/cairo/cairo.def 2010-09-12 06:15:10 +0000 (b00bd99) @@ -72,9 +72,9 @@ EXPORTS rb_mCairo_SVGVersion DATA rb_mCairo_PSLevel DATA rb_mCairo_PDFVersion DATA - rb_cCairo_TextClusterFlag DATA - rb_cCairo_ScriptMode DATA - rb_cCairo_MimeType DATA + rb_mCairo_TextClusterFlag DATA + rb_mCairo_ScriptMode DATA + rb_mCairo_MimeType DATA rb_mCairo_Color DATA rb_cCairo_Color_Base DATA From null+rcairo at clear-code.com Sun Sep 12 02:15:26 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 06:15:26 +0000 Subject: [cairo-commit:00075] rcairo/rcairo [master] download binary files automatically. Message-ID: <20100912061537.CCE9C278001@taiyaki.ru> Kouhei Sutou 2010-09-12 06:15:26 +0000 (Sun, 12 Sep 2010) New Revision: 00fa38c983e59eda4f4d5c273aae17b4637c4e9a Log: download binary files automatically. Modified files: Rakefile Modified: Rakefile (+41 -5) =================================================================== --- Rakefile 2010-09-12 06:15:10 +0000 (5185239) +++ Rakefile 2010-09-12 06:15:26 +0000 (b26d1a5) @@ -90,20 +90,56 @@ end project.spec.dependencies.delete_if {|dependency| dependency.name == "hoe"} +binary_dir = File.join("vendor", "local") Rake::ExtensionTask.new("cairo", project.spec) do |ext| ext.cross_compile = true ext.cross_compiling do |spec| if /mingw|mswin/ =~ spec.platform.to_s - cairo_win32_dir = File.join("vendor", "local") - cairo_files = [] - Find.find(cairo_win32_dir) do |f| - cairo_files << f + binary_files = [] + Find.find(binary_dir) do |name| + next unless File.file?(name) + next if /\.zip\z/i =~ name + binary_files << name end - spec.files += cairo_files + spec.files += binary_files end end end +task 'cross' => "download_windows_binaries" + +def download_windows_binaries(binary_dir) + base_url = "http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/" + dependencies = [ + ["cairo", "1.10.0-1"], + ["cairo-dev", "1.10.0-1"], + ["libpng", "1.4.3-1"], + ["zlib", "1.2.5-2"], + ["expat", "2.0.1-1"], + ["fontconfig", "2.8.0-2"], + ["freetype", "2.4.2-1"], + ] + dependencies.each do |name, version| + file_name = "#{name}_#{version}_win32.zip" + full_file_name = File.join(binary_dir, file_name) + next if File.exist?(full_file_name) + open("#{base_url}#{file_name}", "rb") do |input| + File.open(full_file_name, "wb") do |output| + output.print(input.read) + end + end + sh("unzip", full_file_name, "-d", binary_dir) + end +end + +task "download_windows_binaries" do + require 'open-uri' + unless File.exist?(binary_dir) + mkdir_p(binary_dir) + download_windows_binaries(binary_dir) + end +end + # fix Hoe's incorrect guess. project.spec.executables.clear From null+rcairo at clear-code.com Sun Sep 12 02:05:42 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 06:05:42 +0000 Subject: [cairo-commit:00076] rcairo/rcairo [master] define missing PS_LEVEL_ENUM_DEFINED macro. Message-ID: <20100912060618.D6823170F62@taiyaki.ru> Kouhei Sutou 2010-09-12 06:05:42 +0000 (Sun, 12 Sep 2010) New Revision: 2fb82c0d1480d776a534214f7e52b43013e0d3d0 Log: define missing PS_LEVEL_ENUM_DEFINED macro. Modified files: ext/cairo/rb_cairo_constants.c Modified: ext/cairo/rb_cairo_constants.c (+1 -0) =================================================================== --- ext/cairo/rb_cairo_constants.c 2010-09-12 06:05:29 +0000 (b63d286) +++ ext/cairo/rb_cairo_constants.c 2010-09-12 06:05:42 +0000 (114de33) @@ -149,6 +149,7 @@ DEFINE_RVAL2ENUM(svg_version, SVG_VERSION) #ifdef CAIRO_HAS_PS_SURFACE # if CAIRO_CHECK_VERSION(1, 5, 2) DEFINE_RVAL2ENUM(ps_level, PS_LEVEL) +#define PS_LEVEL_ENUM_DEFINED 1 # endif #endif From null+rcairo at clear-code.com Sun Sep 12 02:39:36 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 06:39:36 +0000 Subject: [cairo-commit:00077] rcairo/rcairo [master] work with Ruby 1.9. Message-ID: <20100912063947.03165170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 06:39:36 +0000 (Sun, 12 Sep 2010) New Revision: e1754994c3a497abd6352c55e69f4549610c9cd1 Log: work with Ruby 1.9. Modified files: test/test_context.rb test/test_font_face.rb test/test_surface.rb Modified: test/test_context.rb (+4 -4) =================================================================== --- test/test_context.rb 2010-09-12 06:15:26 +0000 (498415e) +++ test/test_context.rb 2010-09-12 06:39:36 +0000 (df3e228) @@ -12,17 +12,17 @@ class ContextTest < Test::Unit::TestCase def test_new_and_destroy context = Cairo::Context.new(@surface) @surface.destroy - assert_no_match(/%%EOF\s*\z/m, @output.string) + assert_not_equal("%%EOF\n", @output.string[-6..-1]) context.destroy - assert_match(/%%EOF\s*\z/m, @output.string) + assert_equal("%%EOF\n", @output.string[-6..-1]) end def test_new_with_block Cairo::Context.new(@surface) do |context| @surface.destroy - assert_no_match(/%%EOF\s*\z/m, @output.string) + assert_not_equal("%%EOF\n", @output.string[-6..-1]) end - assert_match(/%%EOF\s*\z/m, @output.string) + assert_equal("%%EOF\n", @output.string[-6..-1]) end def test_new_with_block_and_destroy Modified: test/test_font_face.rb (+34 -21) =================================================================== --- test/test_font_face.rb 2010-09-12 06:15:26 +0000 (f481a08) +++ test/test_font_face.rb 2010-09-12 06:39:36 +0000 (63f37d4) @@ -93,15 +93,18 @@ class FontFaceTest < Test::Unit::TestCase Cairo::FontOptions.new) result = scaled_font.text_to_glyphs(0, 0, "text") assert_equal([[[Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents]], - [[Cairo::ScaledFont, ?t, Cairo::Context, Cairo::TextExtents], - [Cairo::ScaledFont, ?e, Cairo::Context, Cairo::TextExtents], - [Cairo::ScaledFont, ?x, Cairo::Context, Cairo::TextExtents]], + [[Cairo::ScaledFont, codepoint("t"), + Cairo::Context, Cairo::TextExtents], + [Cairo::ScaledFont, codepoint("e"), + Cairo::Context, Cairo::TextExtents], + [Cairo::ScaledFont, codepoint("x"), + Cairo::Context, Cairo::TextExtents]], [[Cairo::ScaledFont, "text", Cairo::UserFontFace::TextToGlyphsData]], - [[Cairo::ScaledFont, ?t], - [Cairo::ScaledFont, ?e], - [Cairo::ScaledFont, ?x], - [Cairo::ScaledFont, ?t]], + [[Cairo::ScaledFont, codepoint("t")], + [Cairo::ScaledFont, codepoint("e")], + [Cairo::ScaledFont, codepoint("x")], + [Cairo::ScaledFont, codepoint("t")]], [[], [], Cairo::TextClusterFlag::BACKWARD]], [classify_cairo_object(init_args), classify_cairo_object(render_glyph_args), @@ -155,15 +158,18 @@ class FontFaceTest < Test::Unit::TestCase Cairo::FontOptions.new) result = scaled_font.text_to_glyphs(0, 0, "text") assert_equal([[[Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents]], - [[Cairo::ScaledFont, ?t, Cairo::Context, Cairo::TextExtents], - [Cairo::ScaledFont, ?e, Cairo::Context, Cairo::TextExtents], - [Cairo::ScaledFont, ?x, Cairo::Context, Cairo::TextExtents]], + [[Cairo::ScaledFont, codepoint("t"), + Cairo::Context, Cairo::TextExtents], + [Cairo::ScaledFont, codepoint("e"), + Cairo::Context, Cairo::TextExtents], + [Cairo::ScaledFont, codepoint("x"), + Cairo::Context, Cairo::TextExtents]], [[Cairo::ScaledFont, "text", Cairo::UserFontFace::TextToGlyphsData]], - [[Cairo::ScaledFont, ?t], - [Cairo::ScaledFont, ?e], - [Cairo::ScaledFont, ?x], - [Cairo::ScaledFont, ?t]], + [[Cairo::ScaledFont, codepoint("t")], + [Cairo::ScaledFont, codepoint("e")], + [Cairo::ScaledFont, codepoint("x")], + [Cairo::ScaledFont, codepoint("t")]], [[], [], Cairo::TextClusterFlag::BACKWARD]], [classify_cairo_object(face.init_args), classify_cairo_object(face.render_glyph_args), @@ -207,15 +213,18 @@ class FontFaceTest < Test::Unit::TestCase Cairo::FontOptions.new) result = scaled_font.text_to_glyphs(0, 0, "text") assert_equal([[[Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents]], - [[Cairo::ScaledFont, ?t, Cairo::Context, Cairo::TextExtents], - [Cairo::ScaledFont, ?e, Cairo::Context, Cairo::TextExtents], - [Cairo::ScaledFont, ?x, Cairo::Context, Cairo::TextExtents]], + [[Cairo::ScaledFont, codepoint("t"), + Cairo::Context, Cairo::TextExtents], + [Cairo::ScaledFont, codepoint("e"), + Cairo::Context, Cairo::TextExtents], + [Cairo::ScaledFont, codepoint("x"), + Cairo::Context, Cairo::TextExtents]], [[Cairo::ScaledFont, "text", Cairo::UserFontFace::TextToGlyphsData]], - [[Cairo::ScaledFont, ?t], - [Cairo::ScaledFont, ?e], - [Cairo::ScaledFont, ?x], - [Cairo::ScaledFont, ?t]], + [[Cairo::ScaledFont, codepoint("t")], + [Cairo::ScaledFont, codepoint("e")], + [Cairo::ScaledFont, codepoint("x")], + [Cairo::ScaledFont, codepoint("t")]], [], [], [], @@ -241,4 +250,8 @@ class FontFaceTest < Test::Unit::TestCase object end end + + def codepoint(character) + character.unpack("U")[0] + end end Modified: test/test_surface.rb (+4 -4) =================================================================== --- test/test_surface.rb 2010-09-12 06:15:26 +0000 (d9957da) +++ test/test_surface.rb 2010-09-12 06:39:36 +0000 (ddb76db) @@ -7,17 +7,17 @@ class SurfaceTest < Test::Unit::TestCase def test_new output = StringIO.new surface = Cairo::PDFSurface.new(output, 10, 10) - assert_no_match(/%%EOF\s*\z/m, output.string) + assert_not_equal("%%EOF\n", output.string[-6..-1]) surface.finish - assert_match(/%%EOF\s*\z/m, output.string) + assert_equal("%%EOF\n", output.string[-6..-1]) end def test_new_with_block output = StringIO.new Cairo::PDFSurface.new(output, 10, 10) do |surface| - assert_no_match(/%%EOF\s*\z/m, output.string) + assert_not_equal("%%EOF\n", output.string[-6..-1]) end - assert_match(/%%EOF\s*\z/m, output.string) + assert_equal("%%EOF\n", output.string[-6..-1]) end def test_new_with_block_and_finish From null+rcairo at clear-code.com Sun Sep 12 03:11:41 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 07:11:41 +0000 Subject: [cairo-commit:00078] rcairo/rcairo [master] fix GC problem. Message-ID: <20100912071152.D362A170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 07:11:41 +0000 (Sun, 12 Sep 2010) New Revision: 3cd7f323e9d84934c6e51cd957dbed3acc0ee79e Log: fix GC problem. Modified files: ext/cairo/rb_cairo_device.c ext/cairo/rb_cairo_surface.c Modified: ext/cairo/rb_cairo_device.c (+2 -0) =================================================================== --- ext/cairo/rb_cairo_device.c 2010-09-12 06:39:36 +0000 (e7e829c) +++ ext/cairo/rb_cairo_device.c 2010-09-12 07:11:41 +0000 (e22b5ee) @@ -260,6 +260,8 @@ cr_ ## type ## _device_initialize (VALUE self, \ } \ else \ { \ + rb_ivar_set (self, rb_cairo__io_id_output, \ + file_name_or_output); \ cairo_device_set_user_data (device, &cr_closure_key, \ closure, \ rb_cairo__io_closure_free); \ Modified: ext/cairo/rb_cairo_surface.c (+20 -0) =================================================================== --- ext/cairo/rb_cairo_surface.c 2010-09-12 06:39:36 +0000 (816b8a7) +++ ext/cairo/rb_cairo_surface.c 2010-09-12 07:11:41 +0000 (e0a3a41) @@ -1355,6 +1355,7 @@ cr_tee_surface_initialize (VALUE self, VALUE master) surface = cairo_tee_surface_create (RVAL2CRSURFACE (master)); cr_surface_check_status (surface); DATA_PTR (self) = surface; + rb_iv_set (self, "surfaces", rb_ary_new3 (1, master)); if (rb_block_given_p ()) yield_and_finish (self); return Qnil; @@ -1368,6 +1369,7 @@ cr_tee_surface_add (VALUE self, VALUE target) surface = _SELF; cairo_tee_surface_add (surface, RVAL2CRSURFACE (target)); cr_surface_check_status (surface); + rb_ary_push (rb_iv_get (self, "surfaces"), target); return Qnil; } @@ -1382,6 +1384,8 @@ static VALUE cr_tee_surface_remove (VALUE self, VALUE target_or_index) { cairo_surface_t *surface = NULL, *target; + VALUE rb_surfaces; + int i; surface = _SELF; if (rb_cairo__is_kind_of (target_or_index, rb_cCairo_Surface)) @@ -1401,6 +1405,22 @@ cr_tee_surface_remove (VALUE self, VALUE target_or_index) } cairo_tee_surface_remove (surface, target); cr_surface_check_status (surface); + + rb_surfaces = rb_iv_get (self, "surfaces"); + for (i = 0; i < RARRAY_LEN (rb_surfaces); i++) + { + VALUE rb_marked_surface; + cairo_surface_t *marked_surface; + + rb_marked_surface = RARRAY_PTR (rb_surfaces)[i]; + marked_surface = RVAL2CRSURFACE (rb_marked_surface); + if (marked_surface == target) + { + rb_ary_delete (rb_surfaces, rb_marked_surface); + break; + } + } + return Qnil; } From null+rcairo at clear-code.com Sun Sep 12 03:20:34 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 07:20:34 +0000 Subject: [cairo-commit:00079] rcairo/rcairo [master] add 1.10.0 entry. Message-ID: <20100912072045.B1BFC170F27@taiyaki.ru> Kouhei Sutou 2010-09-12 07:20:34 +0000 (Sun, 12 Sep 2010) New Revision: 78d9a98827196dd5d8d583f82f7ac8f15ea6f48f Log: add 1.10.0 entry. Modified files: NEWS Modified: NEWS (+7 -0) =================================================================== --- NEWS 2010-09-12 07:11:41 +0000 (144fab6) +++ NEWS 2010-09-12 07:20:34 +0000 (bbe1411) @@ -1,3 +1,10 @@ +Release 1.10.0 (2010-09-12) Kouhei Sutou ) +=========================================================== + +Features +----- + * Support cairo 1.10.0. + Release 1.8.5 (2010-08-28) Kouhei Sutou ) =========================================================== From null+rcairo at clear-code.com Sun Sep 12 09:05:09 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 13:05:09 +0000 Subject: [cairo-commit:00080] rcairo/rcairo [master] move pkg-config dependencies to developement dependencies. Message-ID: <20100912130521.B4929278002@taiyaki.ru> Kouhei Sutou 2010-09-12 13:05:09 +0000 (Sun, 12 Sep 2010) New Revision: ad314058c811a73bf77d9d6b0d5be97e439ca660 Log: move pkg-config dependencies to developement dependencies. Modified files: Rakefile Modified: Rakefile (+1 -1) =================================================================== --- Rakefile 2010-09-12 12:54:53 +0000 (b26d1a5) +++ Rakefile 2010-09-12 13:05:09 +0000 (357ea34) @@ -78,7 +78,7 @@ project = Hoe.spec('cairo') do |project| :require_paths => ['lib'], :has_rdoc => false, } - project.extra_deps << ['pkg-config', '>= 0'] + project.extra_dev_deps << ['pkg-config', '>= 0'] platform = ENV["FORCE_PLATFORM"] project.spec_extras[:platform] = platform if platform news = File.join(base_dir, "NEWS") From null+rcairo at clear-code.com Sun Sep 12 08:54:53 2010 From: null+rcairo at clear-code.com (null+rcairo at clear-code.com) Date: Sun, 12 Sep 2010 12:54:53 +0000 Subject: [cairo-commit:00081] rcairo/rcairo [master] 1.10.0 -> 1.10.1. Message-ID: <20100912130521.A5ECD278001@taiyaki.ru> Kouhei Sutou 2010-09-12 12:54:53 +0000 (Sun, 12 Sep 2010) New Revision: 515923bd1edc7d19fe0f8fc0a4a10593a89194b3 Log: 1.10.0 -> 1.10.1. Modified files: ext/cairo/rb_cairo.c ext/cairo/rb_cairo.h Modified: ext/cairo/rb_cairo.c (+4 -1) =================================================================== --- ext/cairo/rb_cairo.c 2010-09-12 07:20:34 +0000 (9e3224e) +++ ext/cairo/rb_cairo.c 2010-09-12 12:54:53 +0000 (89554c3) @@ -76,7 +76,10 @@ Init_cairo () rb_define_const (rb_mCairo, "BINDINGS_VERSION", rb_ary_new3 (4, - INT2FIX (1), INT2FIX (10), INT2FIX (0), Qnil)); + INT2FIX (RB_CAIRO_VERSION_MAJOR), + INT2FIX (RB_CAIRO_VERSION_MINOR), + INT2FIX (RB_CAIRO_VERSION_MICRO), + Qnil)); rb_define_module_function (rb_mCairo, "satisfied_version?", rb_cairo_satisfied_version, -1); Modified: ext/cairo/rb_cairo.h (+4 -0) =================================================================== --- ext/cairo/rb_cairo.h 2010-09-12 07:20:34 +0000 (e772f65) +++ ext/cairo/rb_cairo.h 2010-09-12 12:54:53 +0000 (c329890) @@ -71,6 +71,10 @@ RB_CAIRO_BEGIN_DECLS # define RB_CAIRO_VAR extern #endif +#define RB_CAIRO_VERSION_MAJOR 1 +#define RB_CAIRO_VERSION_MINOR 10 +#define RB_CAIRO_VERSION_MICRO 1 + RB_CAIRO_VAR VALUE rb_mCairo; RB_CAIRO_VAR VALUE rb_cCairo_Context; RB_CAIRO_VAR VALUE rb_cCairo_Point;