diff --git a/meson.build b/meson.build index 3d7f77cf..61d0e096 100644 --- a/meson.build +++ b/meson.build @@ -153,6 +153,15 @@ endif # Build glue # +vala_unit_proj = subproject( + 'vala-unit', + default_options: [ + 'install=false', + 'valadoc=@0@'.format(enable_valadoc) + ] +) +vala_unit_dep = vala_unit_proj.get_variable('vala_unit_dep') + if enable_valadoc valadoc = find_program('valadoc') endif diff --git a/subprojects/vala-unit/COPYING b/subprojects/vala-unit/COPYING new file mode 100644 index 00000000..74e18dbd --- /dev/null +++ b/subprojects/vala-unit/COPYING @@ -0,0 +1,464 @@ +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + diff --git a/subprojects/vala-unit/README.md b/subprojects/vala-unit/README.md new file mode 100644 index 00000000..aeb012d1 --- /dev/null +++ b/subprojects/vala-unit/README.md @@ -0,0 +1,6 @@ + +ValaUnit +======== + +A Glib-based, xUnit-style unit testing and mock object framework for +Vala projects. diff --git a/subprojects/vala-unit/meson.build b/subprojects/vala-unit/meson.build new file mode 100644 index 00000000..eb1975b3 --- /dev/null +++ b/subprojects/vala-unit/meson.build @@ -0,0 +1,152 @@ +project( + 'vala-unit', + [ 'vala', 'c' ], + version: '1.0', + license: 'LGPL2.1+', + meson_version: '>= 0.50', +) + +enable_install = get_option('install') +enable_valadoc = get_option('valadoc') + +add_project_arguments( + [ + '--abi-stability', + '--enable-checking', + '--enable-experimental-non-null', + '--fatal-warnings', + '--nostdpkg' + ], + language: 'vala' +) + +target_vala = '0.44' +target_glib = '2.62' + +if not meson.get_compiler('vala').version().version_compare('>=' + target_vala) + error('Vala does not meet minimum required version: ' + target_vala) +endif + +gee = dependency('gee-0.8') +gio = dependency('gio-2.0') +glib = dependency('glib-2.0', version: '>=' + target_glib) +gobject = dependency('gobject-2.0') + +g_ir_compiler = find_program('g-ir-compiler') +if enable_valadoc + valadoc = find_program('valadoc') +endif + +dependencies = [ + gee, + gio, + glib, + gobject +] + +lib_sources = files( + 'src/async-result-waiter.vala', + 'src/collection-assertions.vala', + 'src/expected-call.vala', + 'src/mock-object.vala', + 'src/test-adaptor.vala', + 'src/test-assertions.vala', + 'src/test-case.vala', +) + +test_sources = files( + 'test/collection-assertions.vala', + 'test/test-assertions.vala', + 'test/test-driver.vala', +) + +package_name = 'ValaUnit' +package_version = '1.0' +package_full = '@0@-@1@'.format(package_name, package_version) +package_vapi = '@0@-@1@'.format(meson.project_name(), package_version) +package_gir = package_full + '.gir' + +vala_unit_lib = library( + meson.project_name(), + lib_sources, + dependencies: dependencies, + # Ensure we always get debug symbols. + override_options : [ + 'debug=true', + 'strip=false', + ], + vala_vapi: package_vapi + '.vapi', + vala_gir: package_gir, + install: enable_install, + install_dir: [true, true, true, true] +) + +vala_unit_dep = declare_dependency( + link_with : vala_unit_lib, + include_directories: include_directories('.') +) + +custom_target( + meson.project_name() + '-typelib', + command: [ + g_ir_compiler, + '--output', '@OUTPUT@', + meson.current_build_dir() / package_gir, + ], + output: [package_full + '.typelib'], + depends: vala_unit_lib, + install: enable_install, + install_dir: get_option('libdir') / 'girepository-1.0' +) + +if enable_valadoc + # Hopefully Meson will get baked-in valadoc support, so we don't have + # to do this any more. https://github.com/mesonbuild/meson/issues/894 + valadoc_dep_args = [] + foreach dep : dependencies + valadoc_dep_args += '--pkg' + valadoc_dep_args += dep.name() + endforeach + + docs = custom_target( + 'valadoc', + build_by_default: true, + depends: [vala_unit_lib], + input: lib_sources, + output: 'valadoc', + command: [ + valadoc, + '--verbose', + '--force', + '--fatal-warnings', + '--package-name=@0@'.format(package_vapi), + '--package-version=@0@'.format(meson.project_version()), + '-b', meson.current_source_dir(), + '-o', '@OUTPUT@', + '@INPUT@', + ] + valadoc_dep_args + ) + + if enable_install + install_subdir( + meson.current_build_dir() / 'valadoc', + install_dir: get_option('datadir') / 'doc' / 'vala-unit' / 'valadoc' + ) + endif +endif + +test_driver = executable( + 'test-driver', + test_sources, + dependencies: dependencies + [ vala_unit_dep ], + # Always do a plain debug build to avoid compiler optimsations that + # might render testing invalid, and to ensure we get debug symbols. + # Ensure we always get debug symbols. + override_options : [ + 'debug=true', + 'optimization=0', + 'strip=false', + ], +) + +test('tests', test_driver) diff --git a/subprojects/vala-unit/meson_options.txt b/subprojects/vala-unit/meson_options.txt new file mode 100644 index 00000000..e4a8a24d --- /dev/null +++ b/subprojects/vala-unit/meson_options.txt @@ -0,0 +1,12 @@ +option( + 'install', + type: 'boolean', + value: true, + description: 'Whether to install the library\'s files' +) +option( + 'valadoc', + type: 'boolean', + value: true, + description: 'Whether to build the documentaton (requires valadoc).' +) diff --git a/subprojects/vala-unit/src/async-result-waiter.vala b/subprojects/vala-unit/src/async-result-waiter.vala new file mode 100644 index 00000000..02025d97 --- /dev/null +++ b/subprojects/vala-unit/src/async-result-waiter.vala @@ -0,0 +1,108 @@ +/* + * Copyright © 2020 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + + +/** + * Allows non-async code to wait for async calls to be completed. + * + * To use instances of this class, call an async function or method + * using the `begin()` form, passing {@link async_completion} as + * completion argument (that is, the last argument): + * + * {{{ + * var waiter = new AsyncResultWaiter(); + * my_async_call.begin("foo", waiter.async_completion); + * }}} + * + * Then, when you want to ensure the call is complete, pass the result + * of calling {@link async_result} to its `end()` form: + * + * {{{ + * my_async_call.end(waiter.async_result()); + * }}} + * + * This will block until the async call has completed. + * + * Note that {@link TestCase} exposes the same interface, so it is + * usually easier to just call those when testing a single async call, + * or multiple, non-interleaved async calls. + * + * This class is implemented as a FIFO queue of {@link + * GLib.AsyncResult} instances, and thus can be used for waiting for + * multiple calls. Note however the ordering depends on the order in + * which the async calls being invoked are executed and are + * completed. Thus if testing multiple interleaved async calls, you + * should probably use an instance of this class per call. + */ +public class ValaUnit.AsyncResultWaiter : GLib.Object { + + + /** The main loop that is executed when waiting for async results. */ + public GLib.MainContext main_loop { get; construct set; } + + private GLib.AsyncQueue results = + new GLib.AsyncQueue(); + + + /** + * Constructs a new waiter. + * + * @param main_loop a main loop context to execute when waiting + * for an async result + */ + public AsyncResultWaiter(GLib.MainContext main_loop) { + Object(main_loop: main_loop); + } + + /** + * The last argument of an async call to be tested. + * + * Records the given {@link GLib.AsyncResult}, adding it to the + * internal FIFO queue. This method should be called as the + * completion of an async call to be tested. + * + * To use it, pass as the last argument to the `begin()` form of + * the async call: + * + * {{{ + * var waiter = new AsyncResultWaiter(); + * my_async_call.begin("foo", waiter.async_completion); + * }}} + */ + public void async_completion(GLib.Object? object, + GLib.AsyncResult result) { + this.results.push(result); + // Notify the loop so that if async_result() has already been + // called, that method won't block. + this.main_loop.wakeup(); + } + + /** + * Waits for async calls to complete, returning the most recent one. + * + * This returns the first {@link GLib.AsyncResult} from the + * internal FIFO queue that has been provided by {@link + * async_completion}. If none are available, it will pump the main + * loop, blocking until one becomes available. + * + * To use it, pass its return value as the argument to the `end()` + * call: + * + * {{{ + * my_async_call.end(waiter.async_result()); + * }}} + */ + public GLib.AsyncResult async_result() { + GLib.AsyncResult? result = this.results.try_pop(); + while (result == null) { + this.main_loop.iteration(true); + result = this.results.try_pop(); + } + return (GLib.AsyncResult) result; + } + +} diff --git a/subprojects/vala-unit/src/collection-assertions.vala b/subprojects/vala-unit/src/collection-assertions.vala new file mode 100644 index 00000000..3b34acda --- /dev/null +++ b/subprojects/vala-unit/src/collection-assertions.vala @@ -0,0 +1,499 @@ +/* + * Copyright © 2020 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + +/** + * Defines default test assertions for specific strings, arrays and collections. + * + * Call {@link TestAssertions.assert_string}, {@link + * TestAssertions.assert_array} and {@link + * TestAssertions.assert_collection} methods, accessible from + * subclasses of {@link TestCase} to construct these objects. + */ +public interface ValaUnit.CollectionAssertions : GLib.Object { + + + /** + * Asserts the collection is empty. + * + * Returns the same object to allow assertion chaining. + */ + public abstract CollectionAssertions is_empty() + throws GLib.Error; + + /** + * Asserts the collection is non-empty. + * + * Returns the same object to allow assertion chaining. + */ + public abstract CollectionAssertions is_non_empty() + throws GLib.Error; + + /** + * Asserts the collection has an expected length. + * + * Returns the same object to allow assertion chaining. + */ + public abstract CollectionAssertions size(uint32 expected) + throws GLib.Error; + + /** + * Asserts the collection contains an expected element. + * + * Returns the same object to allow assertion chaining. + */ + public abstract CollectionAssertions contains(E expected) + throws GLib.Error; + + /** + * Asserts the collection does not contain an expected element. + * + * Returns the same object to allow assertion chaining. + */ + public abstract CollectionAssertions not_contains(E expected) + throws GLib.Error; + + /** + * Asserts the collection's first element is as expected. + * + * Returns the same object to allow assertion chaining. + */ + public CollectionAssertions first_is(E expected) + throws GLib.Error { + at_index_is(0, expected); + return this; + } + + /** + * Asserts the collection's nth element is as expected. + * + * Note the give position is is 1-based, not 0-based. + * + * Returns the same object to allow assertion chaining. + */ + public abstract CollectionAssertions at_index_is(uint32 position, + E expected) + throws GLib.Error; + + +} + +internal class ValaUnit.StringCollectionAssertion : GLib.Object, + CollectionAssertions { + + + private string actual; + private string? context; + + + internal StringCollectionAssertion(string actual, string? context) { + this.actual = actual; + this.context = context; + } + + public CollectionAssertions is_empty() throws GLib.Error { + if (this.actual.length != 0) { + ValaUnit.assert( + "“%s”.length = %u, expected empty".printf( + this.actual, + this.actual.length + ), + this.context + ); + } + return this; + } + + public CollectionAssertions is_non_empty() + throws GLib.Error { + if (this.actual.length == 0) { + ValaUnit.assert( + "string is empty, expected non-empty", this.context + ); + } + return this; + } + + public CollectionAssertions size(uint32 expected) + throws GLib.Error { + if (this.actual.length != expected) { + ValaUnit.assert( + "“%s”.length = %u, expected %u".printf( + this.actual, + this.actual.length, + expected + ), + this.context + ); + } + return this; + } + + public CollectionAssertions contains(string expected) + throws GLib.Error { + if (!(expected in this.actual)) { + ValaUnit.assert( + "“%s” does not contain “%s”".printf( + this.actual, + expected + ), + this.context + ); + } + return this; + } + + public CollectionAssertions not_contains(string expected) + throws GLib.Error { + if (expected in this.actual) { + ValaUnit.assert( + "“%s” should not contain “%s”".printf( + this.actual, + expected + ), + this.context + ); + } + return this; + } + + public CollectionAssertions at_index_is(uint32 index, + string expected) + throws GLib.Error { + if (this.actual.index_of(expected) != index) { + ValaUnit.assert( + "“%s”[%u:%u] != “%s”".printf( + this.actual, + index, + index + (uint) expected.length, + expected + ), + this.context + ); + } + return this; + } + +} + + +internal class ValaUnit.ArrayCollectionAssertion : GLib.Object, + CollectionAssertions { + + + private E[] actual; + private string? context; + + + internal ArrayCollectionAssertion(E[] actual, string? context) + throws TestError { + this.actual = actual; + this.context = context; + + GLib.Type UNSUPPORTED[] = { + typeof(bool), + typeof(char), + typeof(short), + typeof(int), + typeof(int64), + typeof(uchar), + typeof(ushort), + typeof(uint), + typeof(uint64), + typeof(float), + typeof(double) + }; + var type = typeof(E); + if (type.is_enum() || type in UNSUPPORTED) { + throw new TestError.UNSUPPORTED( + "Arrays containing non-pointer values not currently supported. See GNOME/vala#964" + ); + } + } + + public CollectionAssertions is_empty() throws GLib.Error { + if (this.actual.length != 0) { + ValaUnit.assert( + "%s is not empty".printf( + to_collection_display() + ), + this.context + ); + } + return this; + } + + public CollectionAssertions is_non_empty() + throws GLib.Error { + if (this.actual.length == 0) { + ValaUnit.assert( + "%s is empty, expected non-empty".printf( + to_collection_display() + ), + this.context + ); + } + return this; + } + + public CollectionAssertions size(uint32 expected) + throws GLib.Error { + if (this.actual.length != expected) { + ValaUnit.assert( + "%s.length == %d, expected %u".printf( + to_collection_display(), + this.actual.length, + expected + ), + this.context + ); + } + return this; + } + + public CollectionAssertions contains(E expected) + throws GLib.Error { + E boxed_expected = box_value(expected); + bool found = false; + for (int i = 0; i < this.actual.length; i++) { + try { + assert_equal(box_value(this.actual[i]), boxed_expected); + found = true; + break; + } catch (TestError.FAILED err) { + // no-op + } + } + if (!found) { + ValaUnit.assert( + "%s does not contain %s".printf( + to_collection_display(), + to_display_string(boxed_expected) + ), + this.context + ); + } + return this; + } + + public CollectionAssertions not_contains(E expected) + throws GLib.Error { + E boxed_expected = box_value(expected); + for (int i = 0; i < this.actual.length; i++) { + try { + assert_equal(box_value(this.actual[i]), boxed_expected); + ValaUnit.assert( + "%s does not contain %s".printf( + to_collection_display(), + to_display_string(boxed_expected) + ), + this.context + ); + break; + } catch (TestError.FAILED err) { + // no-op + } + } + return this; + } + + public CollectionAssertions at_index_is(uint32 index, E expected) + throws GLib.Error { + if (index >= this.actual.length) { + ValaUnit.assert( + "%s.length == %u, expected >= %u".printf( + to_collection_display(), + this.actual.length, + index + ), + this.context + ); + } + E boxed_actual = box_value(this.actual[index]); + E boxed_expected = box_value(expected); + try { + assert_equal(boxed_actual, boxed_expected); + } catch (TestError.FAILED err) { + ValaUnit.assert( + "%s[%u] == %s, expected: %s".printf( + to_collection_display(), + index, + to_display_string(boxed_actual), + to_display_string(boxed_expected) + ), + this.context + ); + } + return this; + } + + private string to_collection_display() { + var buf = new GLib.StringBuilder(); + int len = this.actual.length; + buf.append(typeof(E).name()); + buf.append("[]"); + + if (len > 0) { + buf.append_c('{'); + buf.append(to_display_string(box_value(this.actual[0]))); + + if (len == 2) { + buf.append_c(','); + buf.append(to_display_string(box_value(this.actual[1]))); + } else if (len > 2) { + buf.append(", … (%d more)".printf(len - 2)); + } + buf.append_c('}'); + } + return buf.str; + } + +} + + +internal class ValaUnit.GeeCollectionAssertion : + GLib.Object, + CollectionAssertions { + + + private Gee.Collection actual; + private string? context; + + + internal GeeCollectionAssertion(Gee.Collection actual, string? context) { + this.actual = actual; + this.context = context; + } + + public CollectionAssertions is_empty() throws GLib.Error { + if (!this.actual.is_empty) { + ValaUnit.assert( + "%s.length = %d, expected empty".printf( + to_collection_display(), + this.actual.size + ), + this.context + ); + } + return this; + } + + public CollectionAssertions is_non_empty() + throws GLib.Error { + if (this.actual.is_empty) { + ValaUnit.assert( + "%s is empty, expected non-empty".printf( + to_collection_display() + ), + this.context + ); + } + return this; + } + + public CollectionAssertions size(uint32 expected) + throws GLib.Error { + if (this.actual.size != expected) { + ValaUnit.assert( + "%s.size == %d, expected %u".printf( + to_collection_display(), + this.actual.size, + expected + ), + this.context + ); + } + return this; + } + + public CollectionAssertions contains(E expected) + throws GLib.Error { + if (!(expected in this.actual)) { + ValaUnit.assert( + "%s does not contain %s".printf( + to_collection_display(), + to_display_string(box_value(expected)) + ), + this.context + ); + } + return this; + } + + public CollectionAssertions not_contains(E expected) + throws GLib.Error { + if (expected in this.actual) { + ValaUnit.assert( + "%s should not contain %s".printf( + to_collection_display(), + to_display_string(box_value(expected)) + ), + this.context + ); + } + return this; + } + + public CollectionAssertions at_index_is(uint32 index, E expected) + throws GLib.Error { + if (index >= this.actual.size) { + ValaUnit.assert( + "%s.length == %d, expected >= %u".printf( + to_collection_display(), + this.actual.size, + index + ), + this.context + ); + } + Gee.Iterator iterator = this.actual.iterator(); + for (int i = 0; i <= index; i++) { + iterator.next(); + } + E boxed_actual = box_value(iterator.get()); + E boxed_expected = box_value(expected); + try { + assert_equal(boxed_actual, boxed_expected); + } catch (TestError.FAILED err) { + ValaUnit.assert( + "%s[%u] == %s, expected: %s".printf( + to_collection_display(), + index, + to_display_string(boxed_actual), + to_display_string(boxed_expected) + ), + this.context + ); + } + return this; + } + + private string to_collection_display() { + var buf = new GLib.StringBuilder(); + int len = this.actual.size; + buf.append("Gee.Collection<"); + buf.append(typeof(E).name()); + buf.append_c('>'); + + if (len > 0) { + Gee.Iterator iterator = this.actual.iterator(); + iterator.next(); + buf.append_c('{'); + buf.append(to_display_string(box_value(iterator.get()))); + + if (len == 2) { + iterator.next(); + buf.append_c(','); + buf.append(to_display_string(box_value(iterator.get()))); + } else if (len > 2) { + buf.append(", … (%d more)".printf(len - 2)); + } + buf.append_c('}'); + } + return buf.str; + } + +} diff --git a/subprojects/vala-unit/src/expected-call.vala b/subprojects/vala-unit/src/expected-call.vala new file mode 100644 index 00000000..1230624c --- /dev/null +++ b/subprojects/vala-unit/src/expected-call.vala @@ -0,0 +1,148 @@ +/* + * Copyright 2018-2020 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + +/** + * Represents an expected method call on a mock object. + * + * An instance of this object is returned when calling {@link + * MockObject.expect_call}, and may be used to further specify + * expectations, such that the mock method should throw a specific + * error or return a specific value or object. + */ +public class ValaUnit.ExpectedCall : GLib.Object { + + + /** Options for handling async calls. */ + public enum AsyncCallOptions { + + /** Check and return from the expected call immediately. */ + CONTINUE, + + /** + * Check and return from the expected call when idle. + * + * This will yield when the call is made, being resuming when + * idle. + */ + CONTINUE_AT_IDLE, + + /** + * Check and return from the expected call when requested. + * + * This will yield when the call is made, resuming when {@link + * ExpectedCall.async_resume} is called. + */ + PAUSE; + + } + + + /** The name of the expected call. */ + public string name { get; private set; } + + /** Determines how async calls are handled. */ + public AsyncCallOptions async_behaviour { + get; private set; default = CONTINUE; + } + + /** The error to be thrown by the call, if any. */ + public GLib.Error? throw_error { get; private set; default = null; } + + /** An object to be returned by the call, if any. */ + public GLib.Object? return_object { get; private set; default = null; } + + /** A value to be returned by the call, if any. */ + public GLib.Variant? return_value { get; private set; default = null; } + + /** Determines if the call has been made or not. */ + public bool was_called { get; private set; default = false; } + + /** Determines if an async call has been resumed or not. */ + public bool async_resumed { get; private set; default = false; } + + // XXX Arrays can't be GObject properties :( + internal GLib.Object?[]? expected_args = null; + private GLib.Object?[]? called_args = null; + + internal unowned GLib.SourceFunc? async_callback = null; + + + internal ExpectedCall(string name, GLib.Object?[]? args) { + this.name = name; + this.expected_args = args; + } + + /** Sets the behaviour for an async call. */ + public ExpectedCall async_call(AsyncCallOptions behaviour) { + this.async_behaviour = behaviour; + return this; + } + + /** Sets an object that the call should return. */ + public ExpectedCall returns_object(GLib.Object value) { + this.return_object = value; + return this; + } + + /** Sets a bool value that the call should return. */ + public ExpectedCall returns_boolean(bool value) { + this.return_value = new GLib.Variant.boolean(value); + return this; + } + + /** Sets an error that the cal should throw. */ + public ExpectedCall @throws(GLib.Error err) { + this.throw_error = err; + return this; + } + + /** + * Resumes an async call that has been paused. + * + * Throws an assertion error if the call has not yet been called + * or has not been paused. + */ + public void async_resume() throws TestError { + if (this.async_callback == null) { + throw new TestError.FAILED( + "Async call not called, could not resume" + ); + } + if (this.async_resumed) { + throw new TestError.FAILED( + "Async call already resumed" + ); + } + this.async_resumed = true; + this.async_callback(); + } + + /** Determines if an argument was given in the specific position. */ + public T called_arg(int pos) throws TestError { + if (this.called_args == null || this.called_args.length < (pos + 1)) { + throw new TestError.FAILED( + "%s call argument %u, type %s, not present".printf( + this.name, pos, typeof(T).name() + ) + ); + } + if (!(this.called_args[pos] is T)) { + throw new TestError.FAILED( + "%s call argument %u not of type %s".printf( + this.name, pos, typeof(T).name() + ) + ); + } + return (T) this.called_args[pos]; + } + + internal void called(GLib.Object?[]? args) { + this.was_called = true; + this.called_args = args; + } + +} diff --git a/subprojects/vala-unit/src/mock-object.vala b/subprojects/vala-unit/src/mock-object.vala new file mode 100644 index 00000000..766777a4 --- /dev/null +++ b/subprojects/vala-unit/src/mock-object.vala @@ -0,0 +1,318 @@ +/* + * Copyright © 2018-2020 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + +/** + * Denotes a dummy object that can be injected into code being tested. + * + * Mock objects are unit testing fixtures that are used to provide + * instances of specific classes or interfaces which are required by + * the code being tested. For example, if an object being tested + * requires certain objects to be passed in via its constructor or as + * arguments of method calls and uses these to implement its + * behaviour, mock objects that fulfill these requirements can be used. + * + * Mock objects provide a means of both ensuring code being tested + * makes expected method calls with expected arguments on its + * dependencies, and a means of orchestrating the return value and + * exceptions raised when these methods are called, if any. + * + * To specify a specific method should be called on a mock object, + * call {@link expect_call} with the name of the method and optionally + * the arguments that are expected. The returned {@link ExpectedCall} + * object can be used to specify any exception or return values for + * the method. After executing the code being tested, call {@link + * assert_expectations} to ensure that the actual calls made matched + * those expected. + */ +public interface ValaUnit.MockObject : GLib.Object, TestAssertions { + + + public static GLib.Object box_arg(T value) { + return new BoxArgument(value); + } + + public static GLib.Object int_arg(int value) { + return new IntArgument(value); + } + + public static GLib.Object uint_arg(uint value) { + return new UintArgument(value); + } + + protected abstract Gee.Queue expected { get; set; } + + + public ExpectedCall expect_call(string name, GLib.Object?[]? args = null) { + ExpectedCall expected = new ExpectedCall(name, args); + this.expected.offer(expected); + return expected; + } + + public void assert_expectations() throws GLib.Error { + assert_true(this.expected.is_empty, + "%d expected calls not made".printf(this.expected.size)); + reset_expectations(); + } + + public void reset_expectations() { + this.expected.clear(); + } + + protected bool boolean_call(string name, + GLib.Object?[] args, + bool default_return) + throws GLib.Error { + ExpectedCall expected = call_made(name, args); + return check_boolean_call(expected, default_return); + } + + protected async bool boolean_call_async(string name, + GLib.Object?[] args, + bool default_return) + throws GLib.Error { + ExpectedCall expected = call_made(name, args); + if (async_call_yield(expected, this.boolean_call_async.callback)) { + yield; + } + return check_boolean_call(expected, default_return); + } + + protected R object_call(string name, + GLib.Object?[] args, + R default_return) + throws GLib.Error { + ExpectedCall expected = call_made(name, args); + return check_object_call(expected, default_return); + } + + protected async R object_call_async(string name, + GLib.Object?[] args, + R default_return) + throws GLib.Error { + ExpectedCall expected = call_made(name, args); + if (async_call_yield(expected, this.object_call_async.callback)) { + yield; + } + return check_object_call(expected, default_return); + } + + protected R object_or_throw_call(string name, + GLib.Object?[] args, + GLib.Error default_error) + throws GLib.Error { + ExpectedCall expected = call_made(name, args); + return check_object_or_throw_call(expected, default_error); + } + + protected async R object_or_throw_call_async(string name, + GLib.Object?[] args, + GLib.Error default_error) + throws GLib.Error { + ExpectedCall expected = call_made(name, args); + if (async_call_yield(expected, this.object_or_throw_call_async.callback)) { + yield; + } + return check_object_or_throw_call(expected, default_error); + } + + protected void void_call(string name, GLib.Object?[] args) + throws GLib.Error { + ExpectedCall expected = call_made(name, args); + check_for_exception(expected); + } + + protected async void void_call_async(string name, GLib.Object?[] args) + throws GLib.Error { + ExpectedCall expected = call_made(name, args); + if (async_call_yield(expected, this.void_call_async.callback)) { + yield; + } + check_for_exception(expected); + } + + private ExpectedCall call_made(string name, GLib.Object?[] args) + throws GLib.Error { + assert_false(this.expected.is_empty, "Unexpected call: %s".printf(name)); + + ExpectedCall expected = this.expected.poll(); + assert_equal(name, expected.name, "Unexpected call"); + if (expected.expected_args != null) { + assert_args(args, expected.expected_args, "Call %s".printf(name)); + } + + expected.called(args); + return expected; + } + + private void assert_args(GLib.Object?[] actual_args, + GLib.Object?[] expected_args, + string context) + throws GLib.Error { + int args = 0; + foreach (var expected in expected_args) { + if (args >= actual_args.length) { + break; + } + + GLib.Object? actual = actual_args[args]; + string arg_context = "%s, argument #%d".printf(context, args++); + + if (expected is Argument) { + assert_non_null(actual, arg_context); + ((Argument) expected).assert((GLib.Object) actual, arg_context); + } else if (expected != null) { + var non_null_expected = (GLib.Object) expected; + + assert_non_null(actual, arg_context); + var non_null_actual = (GLib.Object) actual; + + assert_equal( + non_null_expected.get_type(), non_null_actual.get_type(), + arg_context + ); + assert_equal( + non_null_actual, + non_null_expected, + arg_context + ); + } else { + assert_null(actual, arg_context); + + } + } + + assert_equal( + actual_args.length, + expected_args.length, + "%s: argument list length".printf(context) + ); + } + + private bool async_call_yield(ExpectedCall expected, + GLib.SourceFunc @callback) { + var @yield = false; + if (expected.async_behaviour != CONTINUE) { + expected.async_callback = @callback; + if (expected.async_behaviour == CONTINUE_AT_IDLE) { + GLib.Idle.add(() => { + try { + expected.async_resume(); + } catch (GLib.Error err) { + critical( + "Async call already resumed: %s", err.message + ); + } + return GLib.Source.REMOVE; + }); + } + @yield = true; + } + return @yield; + } + + private inline bool check_boolean_call(ExpectedCall expected, + bool default_return) + throws GLib.Error { + check_for_exception(expected); + bool return_value = default_return; + if (expected.return_value != null) { + return_value = ((GLib.Variant) expected.return_value).get_boolean(); + } + return return_value; + } + + private inline R check_object_call(ExpectedCall expected, + R default_return) + throws GLib.Error { + check_for_exception(expected); + R? return_object = default_return; + if (expected.return_object != null) { + return_object = (R) expected.return_object; + } + return return_object; + } + + private inline R check_object_or_throw_call(ExpectedCall expected, + GLib.Error default_error) + throws GLib.Error { + check_for_exception(expected); + if (expected.return_object == null) { + throw default_error; + } + return expected.return_object; + } + + private inline void check_for_exception(ExpectedCall expected) + throws GLib.Error { + if (expected.throw_error != null) { + throw expected.throw_error; + } + } + +} + +private interface ValaUnit.Argument { + + public abstract void assert(GLib.Object object, string context) + throws GLib.Error; + +} + +private class ValaUnit.BoxArgument : GLib.Object, Argument, TestAssertions { + + private T value; + + internal BoxArgument(T value) { + this.value = value; + } + + public new void assert(GLib.Object object, string context) + throws GLib.Error { + assert_true( + object is BoxArgument, + "%s: Expected %s value".printf(context, this.get_type().name()) + ); + assert_true(this.value == ((BoxArgument) object).value, context); + } + +} + +private class ValaUnit.IntArgument : GLib.Object, Argument, TestAssertions { + + private int value; + + internal IntArgument(int value) { + this.value = value; + } + + public new void assert(GLib.Object object, string context) + throws GLib.Error { + assert_true( + object is IntArgument, "%s: Expected int value".printf(context) + ); + assert_equal(((IntArgument) object).value, this.value, context); + } + +} + +private class ValaUnit.UintArgument : GLib.Object, Argument, TestAssertions { + + private uint value; + + internal UintArgument(uint value) { + this.value = value; + } + + public new void assert(GLib.Object object, string context) + throws GLib.Error { + assert_true( + object is UintArgument, "%s: Expected uint value".printf(context) + ); + assert_equal(((UintArgument) object).value, this.value, context); + } + +} diff --git a/subprojects/vala-unit/src/test-adaptor.vala b/subprojects/vala-unit/src/test-adaptor.vala new file mode 100644 index 00000000..3e45c7f4 --- /dev/null +++ b/subprojects/vala-unit/src/test-adaptor.vala @@ -0,0 +1,75 @@ +/* + * Copyright © 2009 Julien Peeters + * Copyright © 2017-2020 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + * + * Author(s): + * Julien Peeters + * Michael Gratton + */ + + +/** + * A ValaUnit to GLib testing framework adaptor. + */ +internal class ValaUnit.TestAdaptor : GLib.Object { + + + public string name { get; private set; } + public TestCase test_case { get; private set; } + + private TestCase.TestMethod test; + + + public TestAdaptor(string name, + owned TestCase.TestMethod test, + TestCase test_case) { + this.name = name; + this.test = (owned) test; + this.test_case = test_case; + } + + public void set_up(void* fixture) { + try { + this.test_case.set_up(); + } catch (GLib.Error err) { + log_error(err); + GLib.assert_not_reached(); + } + } + + public void run(void* fixture) { + try { + this.test(); + } catch (TestError.SKIPPED err) { + GLib.Test.skip(err.message); + } catch (GLib.Error err) { + log_error(err); + GLib.Test.fail(); + } + } + + public void tear_down(void* fixture) { + try { + this.test_case.tear_down(); + } catch (Error err) { + log_error(err); + GLib.assert_not_reached(); + } + } + + private void log_error(GLib.Error err) { + GLib.stderr.puts(this.test_case.name); + GLib.stderr.putc('/'); + + GLib.stderr.puts(this.name); + GLib.stderr.puts(": "); + + GLib.stderr.puts(err.message); + GLib.stderr.putc('\n'); + GLib.stderr.flush(); + } + +} diff --git a/subprojects/vala-unit/src/test-assertions.vala b/subprojects/vala-unit/src/test-assertions.vala new file mode 100644 index 00000000..b1478601 --- /dev/null +++ b/subprojects/vala-unit/src/test-assertions.vala @@ -0,0 +1,533 @@ +/* + * Copyright © 2020 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + +namespace ValaUnit { + + /** Error thrown when a test condition has failed */ + public errordomain TestError { + + /** Thrown when test assertion failed. */ + FAILED, + + /** Thrown when test has been skipped. */ + SKIPPED, + + /** Thrown when an assertion is not currently supported. */ + UNSUPPORTED; + + } + + internal inline void assert_equal(T actual, + T expected, + string? context = null) + throws TestError { + if ((actual == null && expected != null) || + (actual != null && expected == null)) { + assert_is_not_equal(actual, expected, context); + } + if (actual != null && expected != null) { + // Can't just do a direct comparison here, since under the + // hood we'll be comparing gconstpointers, which will + // nearly always be incorrect + var type = typeof(T); + if (type.is_object()) { + if (((GLib.Object) actual) != + ((GLib.Object) expected)) { + ValaUnit.assert( + "%s are not equal".printf(typeof(T).name()), + context + ); + } + } else if (type.is_enum()) { + assert_equal_enum(actual, expected, context); + } else if (type == typeof(string)) { + assert_equal_string((string?) actual, (string?) expected, context); + } else if (type == typeof(int)) { + assert_equal_int((int?) actual, (int?) expected, context); + } else if (type == typeof(short)) { + assert_equal_short((short?) actual, (short?) expected, context); + } else if (type == typeof(char)) { + assert_equal_char((char?) actual, (char?) expected, context); + } else if (type == typeof(long)) { + assert_equal_long((long?) actual, (long?) expected, context); + } else if (type == typeof(int64)) { + assert_equal_int64((int64?) actual, (int64?) expected, context); + } else if (type == typeof(uint)) { + assert_equal_uint((uint?) actual, (uint?) expected, context); + } else if (type == typeof(uchar)) { + assert_equal_uchar((uchar?) actual, (uchar?) expected, context); + } else if (type == typeof(ushort)) { + assert_equal_ushort((ushort?) actual, (ushort?) expected, context); + } else if (type == typeof(ulong)) { + assert_equal_ulong((ulong?) actual, (ulong?) expected, context); + } else if (type == typeof(uint64)) { + assert_equal_uint64((uint64?) actual, (uint64?) expected, context); + } else if (type == typeof(double)) { + assert_equal_double((double?) actual, (double?) expected, context); + } else if (type == typeof(float)) { + assert_equal_float((float?) actual, (float?) expected, context); + } else if (type == typeof(bool)) { + assert_equal_bool((bool?) actual, (bool?) expected, context); + } else { + ValaUnit.assert( + "%s is not a supported type for equality tests".printf( + type.name() + ), + context + ); + } + } + } + + internal inline void assert(string message, string? context) + throws TestError { + var buf = new GLib.StringBuilder(); + if (context != null) { + buf.append_c('['); + buf.append((string) context); + buf.append("] "); + } + buf.append(message); + + throw new TestError.FAILED(buf.str); + } + + /** + * Unpacks generics-based value types and repacks as boxed. + * + * Per GNOME/vala#564, non-boxed, non-pointer values will be + * passed as a pointer, where the memory address of the pointer is + * the actual value (!). This method works around that by casting + * back to a value, then boxing so that the value is allocated and + * passed by reference instead. + * + * This will only work when the values are not already boxed. + */ + internal T box_value(T value) { + var type = typeof(T); + T boxed = value; + + if (type == typeof(int) || type.is_enum()) { + int actual = (int) value; + boxed = (int?) actual; + } else if (type == typeof(short)) { + short actual = (short) value; + boxed = (short?) actual; + } else if (type == typeof(char)) { + } else if (type == typeof(long)) { + } else if (type == typeof(int64)) { + } else if (type == typeof(uint)) { + } else if (type == typeof(uchar)) { + } else if (type == typeof(ushort)) { + } else if (type == typeof(ulong)) { + } else if (type == typeof(uint64)) { + } else if (type == typeof(double)) { + } else if (type == typeof(float)) { + } else if (type == typeof(bool)) { + } + + return boxed; + } + + internal string to_display_string(T value) { + var type = typeof(T); + var display = ""; + + if (value == null) { + display = "(null)"; + } else if (type == typeof(string)) { + display = "“%s”".printf((string) ((string?) value)); + } else if (type.is_enum()) { + display = GLib.EnumClass.to_string( + typeof(T), (int) ((int?) value) + ); + } else if (type == typeof(int)) { + display = ((int) ((int?) value)).to_string(); + } else if (type == typeof(short)) { + display = ((short) ((short?) value)).to_string(); + } else if (type == typeof(char)) { + display = "‘%s’".printf(((char) ((char?) value)).to_string()); + } else if (type == typeof(long)) { + display = ((long) ((long?) value)).to_string(); + } else if (type == typeof(int64)) { + display = ((int64) ((int64?) value)).to_string(); + } else if (type == typeof(uint)) { + display = ((uint) ((uint?) value)).to_string(); + } else if (type == typeof(uchar)) { + display = "‘%s’".printf(((uchar) ((uchar?) value)).to_string()); + } else if (type == typeof(ushort)) { + display = ((ushort) ((ushort?) value)).to_string(); + } else if (type == typeof(ulong)) { + display = ((long) ((long?) value)).to_string(); + } else if (type == typeof(uint64)) { + display = ((uint64) ((uint64?) value)).to_string(); + } else if (type == typeof(double)) { + display = ((double) ((double?) value)).to_string(); + } else if (type == typeof(float)) { + display = ((float) ((float?) value)).to_string(); + } else if (type == typeof(bool)) { + display = ((bool) ((bool?) value)).to_string(); + } else { + display = type.name(); + } + + return display; + } + + private inline void assert_is_not_equal(T actual, + T expected, + string? context) + throws TestError { + assert( + "%s != %s".printf( + to_display_string(actual), + to_display_string(expected) + ), + context + ); + } + + private void assert_equal_enum(T actual, + T expected, + string? context) + throws TestError { + int actual_val = (int) ((int?) actual); + int expected_val = (int) ((int?) expected); + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_string(string? actual, + string? expected, + string? context) + throws TestError { + string actual_val = (string) actual; + string expected_val = (string) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_int(int? actual, int? expected, string? context) + throws TestError { + int actual_val = (int) actual; + int expected_val = (int) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_char(char? actual, char? expected, string? context) + throws TestError { + char actual_val = (char) actual; + char expected_val = (char) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_short(short? actual, short? expected, string? context) + throws TestError { + short actual_val = (short) actual; + short expected_val = (short) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_long(long? actual, long? expected, string? context) + throws TestError { + long actual_val = (long) actual; + long expected_val = (long) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_int64(int64? actual, int64? expected, string? context) + throws TestError { + int64 actual_val = (int64) actual; + int64 expected_val = (int64) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_uint(uint? actual, uint? expected, string? context) + throws TestError { + uint actual_val = (uint) actual; + uint expected_val = (uint) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_uchar(uchar? actual, uchar? expected, string? context) + throws TestError { + uchar actual_val = (uchar) actual; + uchar expected_val = (uchar) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_ushort(ushort? actual, ushort? expected, string? context) + throws TestError { + ushort actual_val = (ushort) actual; + ushort expected_val = (ushort) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_ulong(ulong? actual, ulong? expected, string? context) + throws TestError { + ulong actual_val = (ulong) actual; + ulong expected_val = (ulong) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_uint64(uint64? actual, uint64? expected, string? context) + throws TestError { + uint64 actual_val = (uint64) actual; + uint64 expected_val = (uint64) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_float(float? actual, float? expected, string? context) + throws TestError { + float actual_val = (float) actual; + float expected_val = (float) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_double(double? actual, double? expected, string? context) + throws TestError { + double actual_val = (double) actual; + double expected_val = (double) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + + private void assert_equal_bool(bool? actual, bool? expected, string? context) + throws TestError { + bool actual_val = (bool) actual; + bool expected_val = (bool) expected; + if (actual_val != expected_val) { + assert_is_not_equal(actual, expected, context); + } + } + +} + +/** + * Defines default test assertions. + * + * Note that {@link TestCase} implements this, so when making + * assertions in test methods, you can just call these directly. + */ +public interface ValaUnit.TestAssertions : GLib.Object { + + + /** Asserts a value is null */ + public void assert_non_null(T actual, string? context = null) + throws TestError { + if (actual == null) { + ValaUnit.assert( + "%s is null, expected non-null".printf(typeof(T).name()), + context + ); + } + } + + /** Asserts a value is null */ + public void assert_null(T actual, string? context = null) + throws TestError { + if (actual != null) { + ValaUnit.assert( + "%s is non-null, expected null".printf(typeof(T).name()), + context + ); + } + } + + /** Asserts the two given values refer to the same object or value. */ + public void assert_equal(T actual, T expected, string? context = null) + throws TestError { + ValaUnit.assert_equal(actual, expected, context); + } + + /** Asserts the two given values refer to the same object or value. */ + public void assert_within(double actual, + double expected, + double epsilon, + string? context = null) + throws TestError { + if (actual > expected + epsilon || actual < expected - epsilon) { + ValaUnit.assert( + "%f is not within ±%f of %f".printf(actual, epsilon, expected), + context + ); + } + } + + /** Asserts a Boolean value is true. */ + public void assert_true(bool actual, string? context = null) + throws TestError { + if (!actual) { + ValaUnit.assert("Is false, expected true", context); + } + } + + /** Asserts a Boolean value is false. */ + public void assert_false(bool actual, string? context = null) + throws TestError { + if (actual) { + ValaUnit.assert("Is true, expected false", context); + } + } + + /** Asserts a collection is non-null and empty. */ + public CollectionAssertions assert_string(string? actual, + string? context = null) + throws TestError { + if (actual == null) { + ValaUnit.assert("Expected a string, was null", context); + } + return new StringCollectionAssertion((string) actual, context); + } + + /** Asserts a collection is non-null and empty. */ + public CollectionAssertions assert_array(E[]? actual, + string? context = null) + throws TestError { + if (actual == null) { + ValaUnit.assert("Expected an array, was null", context); + } + return new ArrayCollectionAssertion((E[]) actual, context); + } + + /** Asserts a collection is non-null and empty. */ + public CollectionAssertions assert_collection( + Gee.Collection? actual, + string? context = null + ) throws TestError { + if (actual == null) { + ValaUnit.assert("Expected a collection, was null", context); + } + return new GeeCollectionAssertion( + (Gee.Collection) actual, context + ); + } + + /** Asserts a comparator value is equal, that is, 0. */ + public void assert_compare_eq(int actual, string? context = null) + throws TestError { + if (actual != 0) { + ValaUnit.assert( + "Comparison is not equal: %d".printf(actual), context + ); + } + } + + /** Asserts a comparator value is greater-than, that is, > 0. */ + public void assert_compare_gt(int actual, string? context = null) + throws TestError { + if (actual < 0) { + ValaUnit.assert( + "Comparison is not greater than: %d".printf(actual), context + ); + } + } + + /** Asserts a comparator value is less-than, that is, < 0. */ + public void assert_compare_lt(int actual, string? context = null) + throws TestError { + if (actual > 0) { + ValaUnit.assert( + "Comparison is not less than: %d".printf(actual), context + ); + } + } + + /** + * Asserts an error matches an expected type. + * + * The actual error's domain and code must be the same as that of + * the expected, but its message is ignored. + */ + public void assert_error(GLib.Error? actual, + GLib.Error expected, + string? context = null) throws TestError { + if (actual == null) { + ValaUnit.assert( + "Expected error: %s %i, was null".printf( + expected.domain.to_string(), expected.code + ), + context + ); + } else { + var non_null = (GLib.Error) actual; + if (expected.domain != non_null.domain || + expected.code != non_null.code) { + ValaUnit.assert( + "Expected error: %s %i, was actually %s %i: %s".printf( + expected.domain.to_string(), + expected.code, + non_null.domain.to_string(), + non_null.code, + non_null.message + ), + context + ); + } + } + } + + public void assert_no_error(GLib.Error? err, string? context = null) + throws TestError { + if (err != null) { + var non_null = (GLib.Error) err; + ValaUnit.assert( + "Unexpected error: %s %i: %s".printf( + non_null.domain.to_string(), + non_null.code, + non_null.message + ), + context + ); + } + } + + // The following deliberately shadow un-prefixed GLib calls so as + // to get consistent behaviour when called + + /** + * Asserts a Boolean value is true. + */ + public void assert(bool actual, string? context = null) + throws TestError { + assert_true(actual, context); + } + + /** + * Asserts this call is never made. + */ + public void assert_not_reached(string? context = null) + throws TestError { + ValaUnit.assert("This call should not be reached", context); + } + +} diff --git a/subprojects/vala-unit/src/test-case.vala b/subprojects/vala-unit/src/test-case.vala new file mode 100644 index 00000000..9a7fc888 --- /dev/null +++ b/subprojects/vala-unit/src/test-case.vala @@ -0,0 +1,207 @@ +/* + * Copyright © 2009 Julien Peeters + * Copyright © 2017-2020 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + * + * Author(s): + * Julien Peeters + * Michael Gratton + */ + + +/** + * The primary class for creating unit tests. + * + * A test case is a collection of related test methods. + * + * To create and run tests, extend this class with one or more test + * methods that implement {@link TestMethod} and call {@link add_test} + * for each. These may then be added to the root {@link + * GLib.TestSuite} or a child test suite of the root, then executed by + * calling {@link GLib.Test.run}. + * + * To make test assertions in test methods, call the `assert` methods + * on this class instead of those defined by GLib. + */ +public abstract class ValaUnit.TestCase : GLib.Object, TestAssertions { + + + /** The delegate that test methods must implement. */ + public delegate void TestMethod() throws GLib.Error; + + + private class SignalWaiter : Object { + + public bool was_fired = false; + + public void @callback(Object source) { + was_fired = true; + } + } + + + /** The name of this test case. */ + public string name { get; private set; } + + /** The collection of GLib tests defined by this test case. */ + public GLib.TestSuite suite { get; private set; } + + /** Main loop context for this test case. */ + protected GLib.MainContext main_loop { + get; private set; default = GLib.MainContext.default(); + } + + private TestAdaptor[] adaptors = new TestAdaptor[0]; + private AsyncResultWaiter async_waiter; + + + /** + * Constructs a new named test case. + * + * The given name is used as the name of the GLib test suite that + * collects all tests. + */ + protected TestCase(string name) { + this.name = name; + this.suite = new GLib.TestSuite(name); + this.async_waiter = new AsyncResultWaiter(this.main_loop); + } + + /** + * Test case fixture set-up method. + * + * This method is called prior to running a test method. + * + * Test cases should override this method when they require test + * fixtures to be initialised before a test is run. + */ + public virtual void set_up() throws GLib.Error { + // no-op + } + + /** + * Test case fixture set-up method. + * + * This method is called after a test method is successfully run. + * + * Test cases should override this method when they require test + * fixtures to be destroyed after a test is run. + */ + public virtual void tear_down() throws GLib.Error { + // no-op + } + + /** + * Adds a test method to be executed as part of this test case. + * + * Adding a test method add it to {@link suite} with the given + * name, ensuring the {@link set_up}, test, and {@link tear_down} + * methods are executed when the test suite is run. + */ + protected void add_test(string name, owned TestMethod test) { + var adaptor = new TestAdaptor(name, (owned) test, this); + this.adaptors += adaptor; + + this.suite.add( + new GLib.TestCase( + adaptor.name, + adaptor.set_up, + adaptor.run, + adaptor.tear_down + ) + ); + } + + /** + * Calls the same method on the test case's default async waiter. + * + * @see AsyncResultWaiter.async_result + */ + protected AsyncResult async_result() { + return this.async_waiter.async_result(); + } + + /** + * Calls the same method on the test case's default async waiter. + * + * @see AsyncResultWaiter.async_completion + */ + protected void async_completion(GLib.Object? object, + AsyncResult result) { + this.async_waiter.async_completion(object, result); + } + + /** + * Waits for a mock object's call to be completed. + * + * This method busy waits on the test's main loop until either + * until {@link ExpectedCall.was_called} is true, or until the + * given timeout in seconds has occurred. + * + * Returns //true// if the call was made, or //false// if the + * timeout was reached. + */ + protected bool wait_for_call(ExpectedCall call, double timeout = 1.0) { + GLib.Timer timer = new GLib.Timer(); + timer.start(); + while (!call.was_called && timer.elapsed() < timeout) { + this.main_loop.iteration(false); + } + return call.was_called; + } + + /** + * Waits for an object's signal to be fired. + * + * This method busy waits on the test's main loop until either + * until the object emits the named signal, or until the given + * timeout in seconds has occurred. + * + * Returns //true// if the signal was fired, or //false// if the + * timeout was reached. + */ + protected bool wait_for_signal(GLib.Object source, + string name, + double timeout = 0.5) { + SignalWaiter handler = new SignalWaiter(); + ulong id = GLib.Signal.connect_swapped( + source, name, (GLib.Callback) handler.callback, handler + ); + + GLib.Timer timer = new GLib.Timer(); + timer.start(); + while (!handler.was_fired && timer.elapsed() < timeout) { + this.main_loop.iteration(false); + } + + source.disconnect(id); + return handler.was_fired; + } + + /** + * Immediately causes the current test to fail. + * + * Throws a {@link TestError.FAILED} with the given reason, + * terminating the test. + */ + protected void fail(string? message = null) throws TestError.FAILED { + throw new TestError.FAILED( + message != null ? (string) message : "Test failed" + ); + } + + /** + * Immediately skips the rest of the current test. + * + * Throws a {@link TestError.SKIPPED} with the given reason, + * terminating the test. + */ + protected void skip(string? message = null) throws TestError.SKIPPED { + throw new TestError.SKIPPED( + message != null ? (string) message : "Test skipped" + ); + } + +} diff --git a/subprojects/vala-unit/test/collection-assertions.vala b/subprojects/vala-unit/test/collection-assertions.vala new file mode 100644 index 00000000..1a82678b --- /dev/null +++ b/subprojects/vala-unit/test/collection-assertions.vala @@ -0,0 +1,219 @@ +/* + * Copyright © 2020 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + +public class CollectionAssertions : ValaUnit.TestCase { + + + + public CollectionAssertions() { + base("CollectionAssertions"); + add_test("string_collection", string_collection); + add_test("string_array_collection", string_array_collection); + add_test("int_array_collection", int_array_collection); + add_test("string_gee_collection", string_gee_collection); + add_test("int_gee_collection", int_gee_collection); + } + + public void string_collection() throws GLib.Error { + assert_string("hello", "non-empty string") + .is_non_empty() + .size(5) + .contains("lo") + .not_contains("☃") + .first_is("h") + .first_is("hell") + .at_index_is(1, "e") + .at_index_is(1, "ell"); + + + assert_string("", "empty string") + .is_empty() + .size(0) + .contains("") + .not_contains("☃"); + + try { + assert_string("").is_non_empty(); + fail("Expected ::is_non_empty to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + + try { + assert_string("hello").is_empty(); + fail("Expected ::is_empty to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + + try { + assert_string("hello").contains("☃"); + fail("Expected ::contains to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + } + + public void string_array_collection() throws GLib.Error { + assert_array(new string[] { "hello", "world"}) + .is_non_empty() + .size(2) + .contains("hello") + .not_contains("☃") + .first_is("hello") + .at_index_is(1, "world"); + + + assert_array(new string[0]) + .is_empty() + .size(0) + .not_contains("☃"); + + try { + assert_array(new string[0]).is_non_empty(); + fail("Expected ::is_non_empty to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + + try { + assert_array(new string[] { "hello", "world"}).is_empty(); + fail("Expected ::is_empty to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + + try { + assert_array(new string[] { "hello", "world"}).contains("☃"); + fail("Expected ::contains to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + } + + public void int_array_collection() throws GLib.Error { + skip("Arrays containing non-pointer values not currently supported. See GNOME/vala#964"); + int[] array = new int[] { 42, 1337 }; + int[] empty = new int[0]; + + assert_array(array) + .is_non_empty() + .size(2) + .contains(42) + .not_contains(-1) + .first_is(42) + .at_index_is(1, 1337); + + assert_array(empty) + .is_empty() + .size(0) + .not_contains(42); + + try { + assert_array(empty).is_non_empty(); + fail("Expected ::is_non_empty to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + + try { + assert_array(array).is_empty(); + fail("Expected ::is_empty to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + + try { + assert_array(array).contains(-1); + fail("Expected ::contains to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + } + + public void string_gee_collection() throws GLib.Error { + var strv = new string[] { "hello", "world" }; + assert_collection(new_gee_collection(strv)) + .is_non_empty() + .size(2) + .contains("hello") + .not_contains("☃") + .first_is("hello") + .at_index_is(1, "world"); + + assert_collection(new_gee_collection(new string[0])) + .is_empty() + .size(0) + .not_contains("☃"); + + try { + assert_collection(new_gee_collection(new string[0])).is_non_empty(); + fail("Expected ::is_non_empty to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + + try { + assert_collection(new_gee_collection(strv)).is_empty(); + fail("Expected ::is_empty to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + + try { + assert_collection(new_gee_collection(strv)).contains("☃"); + fail("Expected ::contains to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + } + + public void int_gee_collection() throws GLib.Error { +#if !VALA_0_50 + skip("Collections containing non-pointer values not currently supported. See GNOME/vala#992"); +#endif + var intv = new int[] { 42, 1337 }; + assert_collection(new_gee_collection(intv)) + .is_non_empty() + .size(2) + .contains(42) + .not_contains(-1) + .first_is(42) + .at_index_is(1, 1337); + + assert_collection(new_gee_collection(new int[0])) + .is_empty() + .size(0) + .not_contains(42); + + try { + assert_collection(new_gee_collection(new int[0])).is_non_empty(); + fail("Expected ::is_non_empty to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + + try { + assert_collection(new_gee_collection(intv)).is_empty(); + fail("Expected ::is_empty to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + + try { + assert_collection(new_gee_collection(intv)).contains(-1); + fail("Expected ::contains to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + } + + private Gee.Collection new_gee_collection(T[] values) { + return new Gee.ArrayList.wrap(values); + } + +} diff --git a/subprojects/vala-unit/test/test-assertions.vala b/subprojects/vala-unit/test/test-assertions.vala new file mode 100644 index 00000000..1e4cebd0 --- /dev/null +++ b/subprojects/vala-unit/test/test-assertions.vala @@ -0,0 +1,299 @@ +/* + * Copyright © 2020 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + +public class TestAssertions : ValaUnit.TestCase { + + + private class TestObject : GLib.Object { } + + private enum TestEnum { CHECK, ONE, TWO; } + + [Flags] + private enum TestFlags { CHECK, ONE, TWO; } + + private struct TestStruct { + public string member; + } + + + public TestAssertions() { + base("TestAssertions"); + add_test("gobject_equality_assertions", gobject_equality_assertions); + add_test("string_equality_assertions", string_equality_assertions); + add_test("int_equality_assertions", int_equality_assertions); + add_test("short_equality_assertions", short_equality_assertions); + add_test("long_equality_assertions", long_equality_assertions); + add_test("uint_equality_assertions", uint_equality_assertions); + add_test("float_equality_assertions", float_equality_assertions); + add_test("double_equality_assertions", double_equality_assertions); + add_test("char_equality_assertions", char_equality_assertions); + add_test("unichar_equality_assertions", unichar_equality_assertions); + add_test("enum_equality_assertions", enum_equality_assertions); + add_test("bool_equality_assertions", bool_equality_assertions); + add_test("struct_equality_assertions", struct_equality_assertions); + add_test("string_collection", string_collection); + add_test("array_collection", array_collection); + add_test("gee_collection", gee_collection); + } + + public void gobject_equality_assertions() throws GLib.Error { + TestObject o1 = new TestObject(); + TestObject o2 = new TestObject(); + + expect_equal_success(o1, o1); + expect_equal_failure(o1, o2); + } + + public void string_equality_assertions() throws GLib.Error { + // Consts + expect_equal_success("foo", "foo"); + expect_equal_failure("foo", "bar"); + + // Variables + var foo1 = "foo"; + var foo2 = "foo"; + var bar = "bar"; + expect_equal_success(foo1, foo1); + expect_equal_success(foo1, foo2); + expect_equal_failure(foo1, bar); + + // Boxing variations + expect_equal_success(foo1, foo1); + expect_equal_success(foo1, foo2); + expect_equal_failure(foo1, bar); + expect_equal_success("foo", "foo"); + expect_equal_failure("foo", "bar"); + expect_equal_success((string?) foo1, (string?) foo1); + expect_equal_success((string?) foo1, (string?) foo2); + expect_equal_failure((string?) foo1, (string?) bar); + expect_equal_success((string?) "foo", (string?) "foo"); + expect_equal_failure((string?) "foo", (string?) "bar"); + } + + public void int_equality_assertions() throws GLib.Error { + // Consts + expect_equal_success(42, 42); + expect_equal_failure(1337, -1); + + // Variables + int forty_two_a = 42; + int forty_two_b = 42; + int l33t = 1337; + int neg = -1; + expect_equal_success(forty_two_a, forty_two_a); + expect_equal_success(forty_two_a, forty_two_b); + expect_equal_failure(l33t, neg); + } + + public void short_equality_assertions() throws GLib.Error { + skip("Cannot determine if a variable is a short. See GNOME/vala#993"); + + // Consts + expect_equal_success(42, 42); + expect_equal_failure(1337, -1); + + // Variables + short forty_two_a = 42; + short forty_two_b = 42; + short l33t = 1337; + short neg = -1; + expect_equal_success(forty_two_a, forty_two_a); + expect_equal_success(forty_two_a, forty_two_b); + expect_equal_failure(l33t, neg); + } + + public void long_equality_assertions() throws GLib.Error { + // Consts + expect_equal_success(42, 42); + expect_equal_failure(1337, -1); + + // Variables + long forty_two_a = 42; + long forty_two_b = 42; + long l33t = 1337; + long neg = -1; + expect_equal_success(forty_two_a, forty_two_a); + expect_equal_success(forty_two_a, forty_two_b); + expect_equal_failure(l33t, neg); + } + + public void int64_equality_assertions() throws GLib.Error { + // Consts + expect_equal_success(42, 42); + expect_equal_failure(1337, -1); + + // Variables + int64 forty_two_a = 42; + int64 forty_two_b = 42; + int64 l33t = 1337; + int64 neg = -1; + expect_equal_success(forty_two_a, forty_two_a); + expect_equal_success(forty_two_a, forty_two_b); + expect_equal_failure(l33t, neg); + + // Boundary tests + var max = int64.MAX; + var min = int64.MIN; + expect_equal_success(max, max); + expect_equal_success(min, min); + expect_equal_failure(min, max); + expect_equal_failure(max, min); + } + + public void uint_equality_assertions() throws GLib.Error { + // Consts + expect_equal_success(42, 42); + expect_equal_failure(1337, -1); + + // Variables + int forty_two_a = 42; + int forty_two_b = 42; + int l33t = 1337; + int neg = -1; + expect_equal_success(forty_two_a, forty_two_a); + expect_equal_success(forty_two_a, forty_two_b); + expect_equal_failure(l33t, neg); + } + + public void float_equality_assertions() throws GLib.Error { + // Consts + // + expect_equal_success(42.0f, 42.0f); + expect_equal_failure(1337.0f, (-1.0f)); + + // Variables + float forty_two_a = 42.0f; + float forty_two_b = 42.0f; + float l33t = 1337.0f; + float neg = -1.0f; + expect_equal_success(forty_two_a, forty_two_a); + expect_equal_success(forty_two_a, forty_two_b); + expect_equal_failure(l33t, neg); + + // Boundary tests + var max = float.MAX; + var min = float.MIN; + expect_equal_success(max, max); + expect_equal_success(min, min); + expect_equal_failure(min, max); + expect_equal_failure(max, min); + } + + public void double_equality_assertions() throws GLib.Error { + // Consts + // + expect_equal_success(42.0, 42.0); + expect_equal_failure(1337.0, -1.0); + + // Variables + double forty_two_a = 42.0; + double forty_two_b = 42.0; + double l33t = 1337.0; + double neg = -1.0; + expect_equal_success(forty_two_a, forty_two_a); + expect_equal_success(forty_two_a, forty_two_b); + expect_equal_failure(l33t, neg); + + // Boundary tests + var max = double.MAX; + var min = double.MIN; + expect_equal_success(max, max); + expect_equal_success(min, min); + expect_equal_failure(min, max); + expect_equal_failure(max, min); + } + + public void char_equality_assertions() throws GLib.Error { + expect_equal_success('a', 'a'); + expect_equal_failure('a', 'b'); + } + + public void unichar_equality_assertions() throws GLib.Error { + expect_equal_success('☃', '☃'); + expect_equal_failure('❄', '❅'); + } + + public void enum_equality_assertions() throws GLib.Error { + expect_equal_success(ONE, ONE); + expect_equal_failure(ONE, TWO); + } + + public void bool_equality_assertions() throws GLib.Error { + expect_equal_success(true, true); + expect_equal_success(false, false); + + expect_equal_failure(true, false); + expect_equal_failure(false, true); + } + + public void struct_equality_assertions() throws GLib.Error { + var foo = TestStruct() { member = "foo" }; + + expect_equal_failure(foo, foo); + + // Silence the build warning about `member` being unused + foo.member += ""; + } + + public void string_collection() throws GLib.Error { + assert_string("a"); + try { + assert_string(null); + fail("Expected null string collection assertion to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + } + + public void array_collection() throws GLib.Error { + assert_array(new string[] { "a" }); + try { + assert_array(null); + fail("Expected null array collection assertion to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + } + + public void gee_collection() throws GLib.Error { + assert_collection(new_gee_collection(new string[] { "a" })); + try { + assert_collection>(null); + fail("Expected null Gee collection assertion to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + } + + private void expect_equal_success(T actual, + T expected, + string? context = null) + throws GLib.Error { + try { + assert_equal(actual, expected, context); + } catch (ValaUnit.TestError.FAILED err) { + fail(@"Expected equal test to succeed: $(err.message)"); + } + } + + private void expect_equal_failure(T actual, + T expected, + string? context = null) + throws GLib.Error { + try { + assert_equal(actual, expected, context); + fail("Expected equal test to fail"); + } catch (ValaUnit.TestError.FAILED err) { + // all good + } + } + + private Gee.Collection new_gee_collection(T[] values) { + return new Gee.ArrayList.wrap(values); + } + +} diff --git a/subprojects/vala-unit/test/test-driver.vala b/subprojects/vala-unit/test/test-driver.vala new file mode 100644 index 00000000..9b6f3698 --- /dev/null +++ b/subprojects/vala-unit/test/test-driver.vala @@ -0,0 +1,26 @@ +/* + * Copyright © 2020 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + +int main(string[] args) { + Test.init(ref args); + + TestSuite root = TestSuite.get_root(); + root.add_suite(new TestAssertions().suite); + root.add_suite(new CollectionAssertions().suite); + + MainLoop loop = new MainLoop (); + + int ret = -1; + Idle.add(() => { + ret = Test.run(); + loop.quit(); + return false; + }); + + loop.run(); + return ret; +} diff --git a/test/client/accounts/accounts-manager-test.vala b/test/client/accounts/accounts-manager-test.vala index 9f2d57ca..f4d89636 100644 --- a/test/client/accounts/accounts-manager-test.vala +++ b/test/client/accounts/accounts-manager-test.vala @@ -80,8 +80,8 @@ class Accounts.ManagerTest : TestCase { ); this.test.create_account.end(async_result()); - assert_int(1, this.test.size, "Account manager size"); - assert_equal(account, this.test.get_account(TEST_ID), "Is not contained"); + assert_equal(this.test.size, 1, "Account manager size"); + assert_equal(this.test.get_account(TEST_ID), account, "Is not contained"); assert_true(was_added, "Was not added"); assert_true(was_enabled, "Was not enabled"); } diff --git a/test/client/application/application-client-test.vala b/test/client/application/application-client-test.vala index 2981b5c6..da2ff593 100644 --- a/test/client/application/application-client-test.vala +++ b/test/client/application/application-client-test.vala @@ -36,13 +36,13 @@ class Application.ClientTest : TestCase { int status; this.test_article.local_command_line(ref unowned_args, out status); - assert_string( - _INSTALL_PREFIX + "/share/geary", - this.test_article.get_resource_directory().get_path() + assert_equal( + this.test_article.get_resource_directory().get_path(), + _INSTALL_PREFIX + "/share/geary" ); - assert_string( - _INSTALL_PREFIX + "/share/applications", - this.test_article.get_desktop_directory().get_path() + assert_equal( + this.test_article.get_desktop_directory().get_path(), + _INSTALL_PREFIX + "/share/applications" ); } diff --git a/test/client/components/client-web-view-test-case.vala b/test/client/components/client-web-view-test-case.vala index a1abab26..10d21b1f 100644 --- a/test/client/components/client-web-view-test-case.vala +++ b/test/client/components/client-web-view-test-case.vala @@ -23,7 +23,7 @@ public abstract class ClientWebViewTestCase : TestCase { try { ClientWebView.load_resources(GLib.File.new_for_path("/tmp")); } catch (GLib.Error err) { - assert_not_reached(); + GLib.assert_not_reached(); } } diff --git a/test/client/composer/composer-web-view-test.vala b/test/client/composer/composer-web-view-test.vala index 2d2f25a0..ab935f0a 100644 --- a/test/client/composer/composer-web-view-test.vala +++ b/test/client/composer/composer-web-view-test.vala @@ -56,7 +56,7 @@ public class Composer.WebViewTest : ClientWebViewTestCase { load_body_fixture(BODY); this.test_view.get_html.begin(this.async_completion); string html = this.test_view.get_html.end(async_result()); - assert_string(PageStateTest.CLEAN_BODY_TEMPLATE.printf(BODY), html); + assert_equal(html, PageStateTest.CLEAN_BODY_TEMPLATE.printf(BODY)); } public void get_html_for_draft() throws GLib.Error { @@ -64,7 +64,7 @@ public class Composer.WebViewTest : ClientWebViewTestCase { load_body_fixture(BODY); this.test_view.get_html_for_draft.begin(this.async_completion); string html = this.test_view.get_html.end(async_result()); - assert_string(PageStateTest.COMPLETE_BODY_TEMPLATE.printf(BODY), html); + assert_equal(html, PageStateTest.COMPLETE_BODY_TEMPLATE.printf(BODY)); } public void get_text() throws Error { diff --git a/test/client/util/util-avatar-test.vala b/test/client/util/util-avatar-test.vala index 87f2e5b5..ac290ad8 100644 --- a/test/client/util/util-avatar-test.vala +++ b/test/client/util/util-avatar-test.vala @@ -13,24 +13,32 @@ public class Util.Avatar.Test : TestCase { } public void extract_initials() throws GLib.Error { - assert_string("A", extract_initials_from_name("aardvark")); - assert_string("AB", extract_initials_from_name("aardvark baardvark")); - assert_string("AB", extract_initials_from_name("aardvark baardvark")); - assert_string("AC", extract_initials_from_name("aardvark baardvark caardvark")); + assert_equal(extract_initials_from_name("aardvark"), "A"); + assert_equal(extract_initials_from_name("aardvark baardvark"), "AB"); + assert_equal(extract_initials_from_name("aardvark baardvark"), "AB"); + assert_equal( + extract_initials_from_name("aardvark baardvark caardvark"), "AC" + ); - assert_string("A", extract_initials_from_name("!aardvark")); - assert_string("AB", extract_initials_from_name("aardvark !baardvark")); - assert_string("AC", extract_initials_from_name("aardvark baardvark !caardvark")); + assert_equal( + extract_initials_from_name("!aardvark"), "A" + ); + assert_equal( + extract_initials_from_name("aardvark !baardvark"), "AB" + ); + assert_equal( + extract_initials_from_name("aardvark baardvark !caardvark"), "AC" + ); - assert_string("Ó", extract_initials_from_name("óvári")); + assert_equal(extract_initials_from_name("óvári"), "Ó"); - assert_true(extract_initials_from_name("") == null); - assert_true(extract_initials_from_name(" ") == null); - assert_true(extract_initials_from_name(" ") == null); - assert_true(extract_initials_from_name("!") == null); - assert_true(extract_initials_from_name("!!") == null); - assert_true(extract_initials_from_name("! !") == null); - assert_true(extract_initials_from_name("! !!") == null); + assert_null(extract_initials_from_name("")); + assert_null(extract_initials_from_name(" ")); + assert_null(extract_initials_from_name(" ")); + assert_null(extract_initials_from_name("!")); + assert_null(extract_initials_from_name("!!")); + assert_null(extract_initials_from_name("! !")); + assert_null(extract_initials_from_name("! !!")); } } diff --git a/test/client/util/util-cache-test.vala b/test/client/util/util-cache-test.vala index 1a40b7a9..5064130d 100644 --- a/test/client/util/util-cache-test.vala +++ b/test/client/util/util-cache-test.vala @@ -22,32 +22,32 @@ public class Util.Cache.Test : TestCase { Lru test_article = new Lru(2); assert_true(test_article.is_empty); - assert_uint(0, test_article.size); + assert_equal(test_article.size, 0); assert_true(test_article.get_entry(A) == null); test_article.set_entry(A, A); - assert_string(A, test_article.get_entry(A)); + assert_equal(test_article.get_entry(A), A); assert_false(test_article.is_empty); - assert_uint(1, test_article.size); + assert_equal(test_article.size, 1); test_article.set_entry(B, B); - assert_string(B, test_article.get_entry(B)); - assert_uint(2, test_article.size); + assert_equal(test_article.get_entry(B), B); + assert_equal(test_article.size, 2); test_article.set_entry(C, C); - assert_string(C, test_article.get_entry(C)); - assert_uint(2, test_article.size); + assert_equal(test_article.get_entry(C), C); + assert_equal(test_article.size, 2); assert_true(test_article.get_entry(A) == null); test_article.set_entry(D, D); - assert_string(D, test_article.get_entry(D)); - assert_uint(2, test_article.size); + assert_equal(test_article.get_entry(D), D); + assert_equal(test_article.size, 2); assert_true(test_article.get_entry(B) == null); test_article.clear(); assert_true(test_article.is_empty); - assert_uint(0, test_article.size); + assert_equal(test_article.size, 0); } public void lru_eviction() throws GLib.Error { @@ -63,8 +63,8 @@ public class Util.Cache.Test : TestCase { test_article.get_entry(A); test_article.set_entry(C, C); - assert_string(C, test_article.get_entry(C)); - assert_string(A, test_article.get_entry(A)); + assert_equal(test_article.get_entry(C), C); + assert_equal(test_article.get_entry(A), A); assert_true(test_article.get_entry(B) == null); } diff --git a/test/client/util/util-email-test.vala b/test/client/util/util-email-test.vala index 3630276c..a7161146 100644 --- a/test/client/util/util-email-test.vala +++ b/test/client/util/util-email-test.vala @@ -35,8 +35,8 @@ public class Util.Email.Test : TestCase { ); assert_non_null(originator); - assert_string("from", originator.name); - assert_string("from@example.com", originator.address); + assert_equal(originator.name, "from"); + assert_equal(originator.address, "from@example.com"); } public void sender_originator() throws GLib.Error { @@ -49,8 +49,8 @@ public class Util.Email.Test : TestCase { ); assert_non_null(originator); - assert_string("sender", originator.name); - assert_string("sender@example.com", originator.address); + assert_equal(originator.name, "sender"); + assert_equal(originator.address, "sender@example.com"); } public void reply_to_originator() throws GLib.Error { @@ -63,8 +63,8 @@ public class Util.Email.Test : TestCase { ); assert_non_null(originator); - assert_string("reply-to", originator.name); - assert_string("reply-to@example.com", originator.address); + assert_equal(originator.name, "reply-to"); + assert_equal(originator.address, "reply-to@example.com"); } public void reply_to_via_originator() throws GLib.Error { @@ -77,8 +77,8 @@ public class Util.Email.Test : TestCase { ); assert_non_null(originator); - assert_string("test", originator.name); - assert_string("test@example.com", originator.address); + assert_equal(originator.name, "test"); + assert_equal(originator.address, "test@example.com"); } public void plain_via_originator() throws GLib.Error { @@ -91,8 +91,8 @@ public class Util.Email.Test : TestCase { ); assert_non_null(originator); - assert_string("test", originator.name); - assert_string("bot@example.com", originator.address); + assert_equal(originator.name, "test"); + assert_equal(originator.address, "bot@example.com"); } private Geary.Email new_email(Geary.RFC822.MailboxAddress? from, diff --git a/test/client/util/util-js-test.vala b/test/client/util/util-js-test.vala index 203f9e55..1fbe5276 100644 --- a/test/client/util/util-js-test.vala +++ b/test/client/util/util-js-test.vala @@ -12,7 +12,7 @@ public class Util.JS.Test : TestCase { add_test("escape_string", escape_string); } - public void escape_string() throws Error { + public void escape_string() throws GLib.Error { assert(Util.JS.escape_string("\n") == """\n"""); assert(Util.JS.escape_string("\r") == """\r"""); assert(Util.JS.escape_string("\t") == """\t"""); diff --git a/test/engine/api/geary-account-information-test.vala b/test/engine/api/geary-account-information-test.vala index 12d733e0..3157fd4b 100644 --- a/test/engine/api/geary-account-information-test.vala +++ b/test/engine/api/geary-account-information-test.vala @@ -88,39 +88,35 @@ class Geary.AccountInformationTest : TestCase { public void test_service_label() throws GLib.Error { AccountInformation test = new_information(); - assert_string("", test.service_label); + assert_equal(test.service_label, ""); test = new_information(); test.incoming.host = "example.com"; - assert_string( - "example.com", test.service_label, "Email domain equals host name" - ); + assert_equal(test.service_label, "example.com"); test = new_information(); test.incoming.host = "test.example.com"; - assert_string( - "example.com", test.service_label, "Email domain host name suffix" - ); + assert_equal(test.service_label, "example.com"); test = new_information(); test.incoming.host = "other.com"; test.outgoing.host = "other.com"; - assert_string("other.com", test.service_label); + assert_equal(test.service_label, "other.com"); test = new_information(); test.incoming.host = "mail.other.com"; test.outgoing.host = "mail.other.com"; - assert_string("other.com", test.service_label); + assert_equal(test.service_label, "other.com"); test = new_information(); test.incoming.host = "imap.other.com"; test.outgoing.host = "smtp.other.com"; - assert_string("other.com", test.service_label); + assert_equal(test.service_label, "other.com"); test = new_information(); test.incoming.host = "not-mail.other.com"; test.outgoing.host = "not-mail.other.com"; - assert_string("other.com", test.service_label); + assert_equal(test.service_label, "other.com"); } private AccountInformation new_information(ServiceProvider provider = diff --git a/test/engine/api/geary-account-mock.vala b/test/engine/api/geary-account-mock.vala index 461a32fe..d7fb167e 100644 --- a/test/engine/api/geary-account-mock.vala +++ b/test/engine/api/geary-account-mock.vala @@ -5,7 +5,9 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -public class Geary.MockAccount : Account, MockObject { +public class Geary.MockAccount : Account, + ValaUnit.TestAssertions, + ValaUnit.MockObject { public class MockSearchQuery : SearchQuery { @@ -47,8 +49,8 @@ public class Geary.MockAccount : Account, MockObject { } - protected Gee.Queue expected { - get; set; default = new Gee.LinkedList(); + protected Gee.Queue expected { + get; set; default = new Gee.LinkedList(); } diff --git a/test/engine/api/geary-attachment-test.vala b/test/engine/api/geary-attachment-test.vala index f101c683..7859da28 100644 --- a/test/engine/api/geary-attachment-test.vala +++ b/test/engine/api/geary-attachment-test.vala @@ -59,17 +59,13 @@ class Geary.AttachmentTest : TestCase { get_safe_file_name_with_unknown_content_type); } - public override void set_up() { - try { - this.content_type = Mime.ContentType.parse(CONTENT_TYPE); - this.default_type = Mime.ContentType.ATTACHMENT_DEFAULT; - this.content_disposition = new Mime.ContentDisposition("attachment", null); + public override void set_up() throws GLib.Error { + this.content_type = Mime.ContentType.parse(CONTENT_TYPE); + this.default_type = Mime.ContentType.ATTACHMENT_DEFAULT; + this.content_disposition = new Mime.ContentDisposition("attachment", null); - File source = File.new_for_path(_SOURCE_ROOT_DIR); - this.file = source.get_child(FILE_PATH); - } catch (Error err) { - assert_not_reached(); - } + File source = File.new_for_path(_SOURCE_ROOT_DIR); + this.file = source.get_child(FILE_PATH); } public void get_safe_file_name_with_content_name() throws Error { @@ -219,7 +215,7 @@ class Geary.AttachmentTest : TestCase { test.get_safe_file_name.begin(null, this.async_completion); - assert_string(TEST_FILENAME, test.get_safe_file_name.end(async_result())); + assert_equal(test.get_safe_file_name.end(async_result()), TEST_FILENAME); } } diff --git a/test/engine/api/geary-contact-store-mock.vala b/test/engine/api/geary-contact-store-mock.vala index 63143006..2dbf4271 100644 --- a/test/engine/api/geary-contact-store-mock.vala +++ b/test/engine/api/geary-contact-store-mock.vala @@ -5,10 +5,11 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -internal class Geary.ContactStoreMock : ContactStore, MockObject, GLib.Object { +internal class Geary.ContactStoreMock : GLib.Object, + ContactStore, ValaUnit.TestAssertions, ValaUnit.MockObject { - protected Gee.Queue expected { - get; set; default = new Gee.LinkedList(); + protected Gee.Queue expected { + get; set; default = new Gee.LinkedList(); } public async Contact? get_by_rfc822(Geary.RFC822.MailboxAddress address, diff --git a/test/engine/api/geary-credentials-mediator-mock.vala b/test/engine/api/geary-credentials-mediator-mock.vala index d00be1d2..0604ea77 100644 --- a/test/engine/api/geary-credentials-mediator-mock.vala +++ b/test/engine/api/geary-credentials-mediator-mock.vala @@ -6,11 +6,14 @@ */ public class Geary.MockCredentialsMediator : - GLib.Object, CredentialsMediator, MockObject { + GLib.Object, + CredentialsMediator, + ValaUnit.TestAssertions, + ValaUnit.MockObject { - protected Gee.Queue expected { - get; set; default = new Gee.LinkedList(); + protected Gee.Queue expected { + get; set; default = new Gee.LinkedList(); } public virtual async bool load_token(AccountInformation account, diff --git a/test/engine/api/geary-engine-test.vala b/test/engine/api/geary-engine-test.vala index 4a343d65..a671ee0d 100644 --- a/test/engine/api/geary-engine-test.vala +++ b/test/engine/api/geary-engine-test.vala @@ -55,15 +55,11 @@ class Geary.EngineTest : TestCase { this.account.set_account_directories(this.tmp, this.tmp); } - public override void tear_down () { + public override void tear_down() throws GLib.Error { this.account = null; - try { - this.res.delete(); - this.tmp.delete(); - this.tmp = null; - } catch (Error err) { - assert_not_reached(); - } + this.res.delete(); + this.tmp.delete(); + this.tmp = null; } public void add_account() throws GLib.Error { diff --git a/test/engine/api/geary-folder-mock.vala b/test/engine/api/geary-folder-mock.vala index e3b01804..44852c93 100644 --- a/test/engine/api/geary-folder-mock.vala +++ b/test/engine/api/geary-folder-mock.vala @@ -5,7 +5,9 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -public class Geary.MockFolder : Folder, MockObject { +public class Geary.MockFolder : Folder, + ValaUnit.TestAssertions, + ValaUnit.MockObject { public override Account account { @@ -28,8 +30,8 @@ public class Geary.MockFolder : Folder, MockObject { get { return this._opening_monitor; } } - protected Gee.Queue expected { - get; set; default = new Gee.LinkedList(); + protected Gee.Queue expected { + get; set; default = new Gee.LinkedList(); } diff --git a/test/engine/api/geary-folder-path-test.vala b/test/engine/api/geary-folder-path-test.vala index 018a3045..c985a6bf 100644 --- a/test/engine/api/geary-folder-path-test.vala +++ b/test/engine/api/geary-folder-path-test.vala @@ -41,16 +41,12 @@ public class Geary.FolderPathTest : TestCase { } public void get_child_from_root() throws GLib.Error { - assert_string( - "test", - this.root.get_child("test").name - ); + assert_equal(this.root.get_child("test").name, "test"); } public void get_child_from_child() throws GLib.Error { - assert_string( - "test2", - this.root.get_child("test1").get_child("test2").name + assert_equal( + this.root.get_child("test1").get_child("test2").name, "test2" ); } @@ -63,32 +59,20 @@ public class Geary.FolderPathTest : TestCase { } public void as_array() throws GLib.Error { - assert_true(this.root.as_array().length == 0, "Root list"); - assert_int( - 1, - this.root.get_child("test").as_array().length, - "Child array length" - ); - assert_string( - "test", - this.root.get_child("test").as_array()[0], - "Child array contents" - ); - assert_int( - 2, - this.root.get_child("test1").get_child("test2").as_array().length, - "Descendent array length" - ); - assert_string( - "test1", - this.root.get_child("test1").get_child("test2").as_array()[0], - "Descendent first child" - ); - assert_string( - "test2", - this.root.get_child("test1").get_child("test2").as_array()[1], - "Descendent second child" - ); + assert_array( + this.root.as_array(), + "Root list" + ).size(0); + + assert_array( + this.root.get_child("test").as_array(), + "Child array" + ).size(1).contains("test"); + + assert_array( + this.root.get_child("test1").get_child("test2").as_array(), + "Descendent array" + ).size(2).first_is("test1").at_index_is(1, "test2"); } public void is_top_level() throws GLib.Error { @@ -115,24 +99,25 @@ public class Geary.FolderPathTest : TestCase { } public void path_to_string() throws GLib.Error { - assert_string(">", this.root.to_string()); - assert_string(">test", this.root.get_child("test").to_string()); - assert_string( - ">test1>test2", - this.root.get_child("test1").get_child("test2").to_string() + assert_equal(this.root.to_string(), ">"); + assert_equal(this.root.get_child("test").to_string(), ">test"); + assert_equal( + this.root.get_child("test1").get_child("test2").to_string(), + ">test1>test2" ); } public void path_parent() throws GLib.Error { assert_null(this.root.parent, "Root parent"); assert_string( - "", this.root.get_child("test").parent.name, - "Root child parent"); - assert_string( - "test1", + "Root child parent" + ).is_empty(); + assert_equal( this.root.get_child("test1").get_child("test2").parent.name, - "Child parent"); + "test1", + "Child parent" + ); } public void path_equal() throws GLib.Error { @@ -170,138 +155,148 @@ public class Geary.FolderPathTest : TestCase { } public void path_compare() throws GLib.Error { - assert_int(0, this.root.compare_to(this.root), "Root equality"); - assert_int(0, + // / == / + assert_compare_eq(this.root.compare_to(this.root), "Root equality"); + // /a == /a + assert_compare_eq( this.root.get_child("a").compare_to(this.root.get_child("a")), "Equal child comparison" ); - // a is less than b - assert_true( - this.root.get_child("a").compare_to(this.root.get_child("b")) < 0, - "Greater than child comparison" - ); - - // b is greater than than a - assert_true( - this.root.get_child("b").compare_to(this.root.get_child("a")) > 0, + // /a < /b + assert_compare_lt( + this.root.get_child("a").compare_to(this.root.get_child("b")), "Less than child comparison" ); - assert_true( - this.root.get_child("a").get_child("test") - .compare_to(this.root.get_child("a")) > 0, - "Greater than descendant" + // /b > /a + assert_compare_gt( + this.root.get_child("b").compare_to(this.root.get_child("a")), + "Greater than child comparison" ); - assert_true( + + // /a < /a/test + assert_compare_lt( this.root.get_child("a") - .compare_to(this.root.get_child("a").get_child("test")) < 0, + .compare_to(this.root.get_child("a").get_child("test")), "Less than descendant" ); - assert_true( + // /a/test > /a + assert_compare_gt( + this.root.get_child("a").get_child("test") + .compare_to(this.root.get_child("a")), + "Greater than descendant" + ); + + // /a/b == /a/b + assert_compare_eq( this.root.get_child("a").get_child("b") - .compare_to(this.root.get_child("a").get_child("b")) == 0, + .compare_to(this.root.get_child("a").get_child("b")), "N-path equality" ); - assert_true( + // /a/test < /b/test + assert_compare_lt( this.root.get_child("a").get_child("test") - .compare_to(this.root.get_child("b").get_child("test")) < 0, - "Greater than disjoint paths" - ); - assert_true( - this.root.get_child("b").get_child("test") - .compare_to(this.root.get_child("a").get_child("test")) > 0, + .compare_to(this.root.get_child("b").get_child("test")), "Less than disjoint paths" ); - assert_true( - this.root.get_child("a").get_child("d") - .compare_to(this.root.get_child("b").get_child("c")) < 0, - "Greater than double disjoint" + // /b/test > /a/test + assert_compare_gt( + this.root.get_child("b").get_child("test") + .compare_to(this.root.get_child("a").get_child("test")), + "Greater than disjoint paths" ); - assert_true( + + // /a/d < /b/c + assert_compare_lt( + this.root.get_child("a").get_child("d") + .compare_to(this.root.get_child("b").get_child("c")), + "Less than double disjoint" + ); + + // /b/c > /a/d + assert_compare_gt( this.root.get_child("b").get_child("c") - .compare_to(this.root.get_child("a").get_child("d")) > 0, + .compare_to(this.root.get_child("a").get_child("d")), "Less than double disjoint" ); } public void path_compare_normalised() throws GLib.Error { - assert_int(0, this.root.compare_normalized_ci(this.root), "Root equality"); - assert_int(0, + assert_compare_eq( + this.root.compare_normalized_ci(this.root), "Root equality" + ); + assert_compare_eq( this.root.get_child("a").compare_normalized_ci(this.root.get_child("a")), "Equal child comparison" ); - // a is less than b - assert_true( - this.root.get_child("a").compare_normalized_ci(this.root.get_child("b")) < 0, + assert_compare_lt( + this.root.get_child("a").compare_normalized_ci(this.root.get_child("b")), "Greater than child comparison" ); - // b is greater than than a - assert_true( - this.root.get_child("b").compare_normalized_ci(this.root.get_child("a")) > 0, + assert_compare_gt( + this.root.get_child("b").compare_normalized_ci(this.root.get_child("a")), "Less than child comparison" ); - assert_true( + assert_compare_lt( this.root.get_child("a").get_child("test") - .compare_normalized_ci(this.root.get_child("b").get_child("test")) < 0, + .compare_normalized_ci(this.root.get_child("b").get_child("test")), "Greater than disjoint parents" ); - assert_true( + assert_compare_gt( this.root.get_child("b").get_child("test") - .compare_normalized_ci(this.root.get_child("a").get_child("test")) > 0, + .compare_normalized_ci(this.root.get_child("a").get_child("test")), "Less than disjoint parents" ); - assert_true( + assert_compare_gt( this.root.get_child("a").get_child("test") - .compare_normalized_ci(this.root.get_child("a")) > 0, + .compare_normalized_ci(this.root.get_child("a")), "Greater than descendant" ); - assert_true( + assert_compare_lt( this.root.get_child("a") - .compare_normalized_ci(this.root.get_child("a").get_child("test")) < 0, + .compare_normalized_ci(this.root.get_child("a").get_child("test")), "Less than descendant" ); } public void root_instances_compare() throws GLib.Error { - assert_int( - 0, this.root.compare_to(new FolderRoot(TEST_LABEL, false)), + assert_compare_eq( + this.root.compare_to(new FolderRoot(TEST_LABEL, false)), "Root equality" ); - assert_int( - 0, this.root.get_child("a").compare_to(new FolderRoot(TEST_LABEL, false).get_child("a")), + assert_compare_eq( + this.root.get_child("a").compare_to(new FolderRoot(TEST_LABEL, false).get_child("a")), "Equal child comparison" ); - assert_true( + assert_compare_gt( this.root.get_child("a").compare_to( - new FolderRoot("#other", false).get_child("a")) > 0, + new FolderRoot("#other", false).get_child("a")), "Root label inequality with children" ); - // a is less than b - assert_true( - this.root.get_child("a").compare_to(new FolderRoot(TEST_LABEL, false).get_child("b")) < 0, + assert_compare_lt( + this.root.get_child("a").compare_to(new FolderRoot(TEST_LABEL, false).get_child("b")), "Greater than child comparison" ); - // b is greater than than a - assert_true( - this.root.get_child("b").compare_to(new FolderRoot(TEST_LABEL, false).get_child("a")) > 0, + assert_compare_gt( + this.root.get_child("b").compare_to(new FolderRoot(TEST_LABEL, false).get_child("a")), "Less than child comparison" ); - assert_true( + assert_compare_gt( this.root.get_child("a").get_child("test") - .compare_to(new FolderRoot(TEST_LABEL, false).get_child("a")) > 0, + .compare_to(new FolderRoot(TEST_LABEL, false).get_child("a")), "Greater than descendant" ); assert_true( @@ -310,20 +305,20 @@ public class Geary.FolderPathTest : TestCase { "Less than descendant" ); - assert_true( + assert_compare_eq( this.root.get_child("a").get_child("b") - .compare_to(new FolderRoot(TEST_LABEL, false).get_child("a").get_child("b")) == 0, + .compare_to(new FolderRoot(TEST_LABEL, false).get_child("a").get_child("b")), "N-path equality" ); - assert_true( + assert_compare_lt( this.root.get_child("a").get_child("a") - .compare_to(new FolderRoot(TEST_LABEL, false).get_child("b").get_child("b")) < 0, + .compare_to(new FolderRoot(TEST_LABEL, false).get_child("b").get_child("b")), "Less than double disjoint" ); - assert_true( + assert_compare_gt( this.root.get_child("b").get_child("a") - .compare_to(new FolderRoot(TEST_LABEL, false).get_child("a").get_child("a")) > 0, + .compare_to(new FolderRoot(TEST_LABEL, false).get_child("a").get_child("a")), "Greater than double disjoint" ); diff --git a/test/engine/api/geary-service-information-test.vala b/test/engine/api/geary-service-information-test.vala index 88e54270..4d733747 100644 --- a/test/engine/api/geary-service-information-test.vala +++ b/test/engine/api/geary-service-information-test.vala @@ -15,18 +15,18 @@ class Geary.TlsNegotiationMethodTest : TestCase { } public void to_value() throws GLib.Error { - assert_string("start-tls", TlsNegotiationMethod.START_TLS.to_value()); + assert_equal(TlsNegotiationMethod.START_TLS.to_value(), "start-tls"); } public void for_value() throws GLib.Error { - assert_int( - TlsNegotiationMethod.START_TLS, - TlsNegotiationMethod.for_value("start-tls"), + assert_equal( + TlsNegotiationMethod.for_value("start-tls").to_string(), + TlsNegotiationMethod.START_TLS.to_string(), "start-tls" ); - assert_int( - TlsNegotiationMethod.START_TLS, - TlsNegotiationMethod.for_value("Start-TLS"), + assert_equal( + TlsNegotiationMethod.for_value("Start-TLS").to_string(), + TlsNegotiationMethod.START_TLS.to_string(), "Start-TLS" ); } diff --git a/test/engine/app/app-conversation-monitor-test.vala b/test/engine/app/app-conversation-monitor-test.vala index 3224cf8b..2d813d31 100644 --- a/test/engine/app/app-conversation-monitor-test.vala +++ b/test/engine/app/app-conversation-monitor-test.vala @@ -105,7 +105,7 @@ class Geary.App.ConversationMonitorTest : TestCase { this.base_folder, Email.Field.NONE, 10 ); - ExpectedCall open = this.base_folder + ValaUnit.ExpectedCall open = this.base_folder .expect_call("open_async") .throws(new EngineError.SERVER_UNAVAILABLE("Mock error")); @@ -129,7 +129,7 @@ class Geary.App.ConversationMonitorTest : TestCase { this.base_folder, Email.Field.NONE, 10 ); - ExpectedCall open = this.base_folder + ValaUnit.ExpectedCall open = this.base_folder .expect_call("open_async") .async_call(PAUSE) .throws(new GLib.IOError.CANCELLED("Mock error")); @@ -137,10 +137,10 @@ class Geary.App.ConversationMonitorTest : TestCase { .expect_call("close_async") .throws(new EngineError.ALREADY_CLOSED("Mock error")); - var start_waiter = new AsyncResultWaiter(this.main_loop); + var start_waiter = new ValaUnit.AsyncResultWaiter(this.main_loop); monitor.start_monitoring.begin(NONE, null, start_waiter.async_completion); - var stop_waiter = new AsyncResultWaiter(this.main_loop); + var stop_waiter = new ValaUnit.AsyncResultWaiter(this.main_loop); monitor.stop_monitoring.begin(null, stop_waiter.async_completion); open.async_resume(); @@ -161,7 +161,7 @@ class Geary.App.ConversationMonitorTest : TestCase { this.base_folder, Email.Field.NONE, 10 ); - ExpectedCall open = this.base_folder + ValaUnit.ExpectedCall open = this.base_folder .expect_call("open_async") .throws(new EngineError.SERVER_UNAVAILABLE("Mock error")); this.base_folder @@ -191,9 +191,9 @@ class Geary.App.ConversationMonitorTest : TestCase { ConversationMonitor monitor = setup_monitor({e1}, paths); - assert_int(1, monitor.size, "Conversation count"); + assert_equal(monitor.size, 1, "Conversation count"); assert_non_null(monitor.window_lowest, "Lowest window id"); - assert_equal(e1.id, monitor.window_lowest, "Lowest window id"); + assert_equal(monitor.window_lowest, e1.id, "Lowest window id"); Conversation c1 = Collection.first(monitor.read_only_view); assert_equal(e1, c1.get_email_by_id(e1.id), "Email not present in conversation"); @@ -212,9 +212,9 @@ class Geary.App.ConversationMonitorTest : TestCase { ConversationMonitor monitor = setup_monitor({e3, e2, e1}, paths); - assert_int(3, monitor.size, "Conversation count"); + assert_equal(monitor.size, 3, "Conversation count"); assert_non_null(monitor.window_lowest, "Lowest window id"); - assert_equal(e1.id, monitor.window_lowest, "Lowest window id"); + assert_equal(monitor.window_lowest, e1.id, "Lowest window id"); } public void load_related_message() throws Error { @@ -233,13 +233,13 @@ class Geary.App.ConversationMonitorTest : TestCase { ConversationMonitor monitor = setup_monitor({e2}, paths, {related_paths}); - assert_int(1, monitor.size, "Conversation count"); + assert_equal(monitor.size, 1, "Conversation count"); assert_non_null(monitor.window_lowest, "Lowest window id"); - assert_equal(e2.id, monitor.window_lowest, "Lowest window id"); + assert_equal(monitor.window_lowest, e2.id, "Lowest window id"); Conversation c1 = Collection.first(monitor.read_only_view); - assert_equal(e1, c1.get_email_by_id(e1.id), "Related email not present in conversation"); - assert_equal(e2, c1.get_email_by_id(e2.id), "In folder not present in conversation"); + assert_equal(c1.get_email_by_id(e1.id), e1, "Related email not present in conversation"); + assert_equal(c1.get_email_by_id(e2.id), e2, "In folder not present in conversation"); } public void base_folder_message_appended() throws Error { @@ -250,7 +250,7 @@ class Geary.App.ConversationMonitorTest : TestCase { paths.set(e1.id, this.base_folder.path); ConversationMonitor monitor = setup_monitor(); - assert_int(0, monitor.size, "Initial conversation count"); + assert_equal(monitor.size, 0, "Initial conversation count"); this.base_folder.expect_call("list_email_by_sparse_id_async") .returns_object(new Gee.ArrayList.wrap({e1})); @@ -269,7 +269,7 @@ class Geary.App.ConversationMonitorTest : TestCase { this.base_folder.assert_expectations(); this.account.assert_expectations(); - assert_int(1, monitor.size, "Conversation count"); + assert_equal(monitor.size, 1, "Conversation count"); } public void base_folder_message_removed() throws Error { @@ -291,17 +291,17 @@ class Geary.App.ConversationMonitorTest : TestCase { ConversationMonitor monitor = setup_monitor( {e3, e2}, paths, {null, e2_related_paths} ); - assert_int(2, monitor.size, "Initial conversation count"); - assert_equal(e2.id, monitor.window_lowest, "Lowest window id"); + assert_equal(monitor.size, 2, "Initial conversation count"); + assert_equal(monitor.window_lowest, e2.id, "Lowest window id"); this.base_folder.email_removed(new Gee.ArrayList.wrap({e2.id})); wait_for_signal(monitor, "conversations-removed"); - assert_int(1, monitor.size, "Conversation count"); - assert_equal(e3.id, monitor.window_lowest, "Lowest window id"); + assert_equal(monitor.size, 1, "Conversation count"); + assert_equal(monitor.window_lowest, e3.id, "Lowest window id"); this.base_folder.email_removed(new Gee.ArrayList.wrap({e3.id})); wait_for_signal(monitor, "conversations-removed"); - assert_int(0, monitor.size, "Conversation count"); + assert_equal(monitor.size, 0, "Conversation count"); assert_null(monitor.window_lowest, "Lowest window id"); // Close the monitor to cancel the final load so it does not @@ -330,7 +330,7 @@ class Geary.App.ConversationMonitorTest : TestCase { related_paths.set(e3, this.other_folder.path); ConversationMonitor monitor = setup_monitor({e1}, paths); - assert_int(1, monitor.size, "Initial conversation count"); + assert_equal(monitor.size, 1, "Initial conversation count"); this.other_folder.expect_call("open_async"); this.other_folder.expect_call("list_email_by_sparse_id_async") @@ -389,11 +389,11 @@ class Geary.App.ConversationMonitorTest : TestCase { this.other_folder.assert_expectations(); this.account.assert_expectations(); - assert_int(1, monitor.size, "Conversation count"); + assert_equal(monitor.size, 1, "Conversation count"); Conversation c1 = Collection.first(monitor.read_only_view); - assert_int(2, c1.get_count(), "Conversation message count"); - assert_equal(e3, c1.get_email_by_id(e3.id), + assert_equal(c1.get_count(), 2, "Conversation message count"); + assert_equal(c1.get_email_by_id(e3.id), e3, "Appended email not present in conversation"); } @@ -405,7 +405,7 @@ class Geary.App.ConversationMonitorTest : TestCase { paths.set(e1.id, this.base_folder.path); ConversationMonitor monitor = setup_monitor({e1}, paths); - assert_int(1, monitor.size, "Conversation count"); + assert_equal(monitor.size, 1, "Conversation count"); // Mark message as deleted Gee.HashMap flags_changed = @@ -418,7 +418,10 @@ class Geary.App.ConversationMonitorTest : TestCase { wait_for_signal(monitor, "email-flags-changed"); - assert_int(0, monitor.size, "Conversation count should now be zero after being marked deleted."); + assert_equal( + monitor.size, 0, + "Conversation count should now be zero after being marked deleted." + ); } private Email setup_email(int id, Email? references = null) { @@ -465,7 +468,7 @@ class Geary.App.ConversationMonitorTest : TestCase { */ this.base_folder.expect_call("open_async"); - ExpectedCall list_call = this.base_folder + ValaUnit.ExpectedCall list_call = this.base_folder .expect_call("list_email_by_id_async") .returns_object(new Gee.ArrayList.wrap(base_folder_email)); @@ -491,7 +494,7 @@ class Geary.App.ConversationMonitorTest : TestCase { bool found_related = false; Gee.Set seen_ids = new Gee.HashSet(); foreach (Email base_email in base_folder_email) { - ExpectedCall call = + ValaUnit.ExpectedCall call = this.account.expect_call("local_search_message_id_async"); seen_ids.add(base_email.message_id); if (has_related && related_paths[base_i] != null) { @@ -531,8 +534,8 @@ class Geary.App.ConversationMonitorTest : TestCase { } } - ExpectedCall contains = - this.account.expect_call("get_containing_folders_async"); + ValaUnit.ExpectedCall contains = + this.account.expect_call("get_containing_folders_async"); if (paths != null) { contains.returns_object(paths); } diff --git a/test/engine/app/app-conversation-set-test.vala b/test/engine/app/app-conversation-set-test.vala index 2966e134..37801b9b 100644 --- a/test/engine/app/app-conversation-set-test.vala +++ b/test/engine/app/app-conversation-set-test.vala @@ -469,11 +469,11 @@ class Geary.App.ConversationSetTest : TestCase { this.base_folder.path, ids, removed, trimmed ); - assert_int(0, this.test.size, "ConversationSet size"); - assert_int(0, this.test.get_email_count(), "ConversationSet email size"); + assert_equal(this.test.size, 0, "ConversationSet size"); + assert_equal(this.test.get_email_count(), 0, "ConversationSet email size"); - assert_int(1, removed.size, "Removed size"); - assert_int(0, trimmed.size, "Trimmed size"); + assert_collection(removed, "Removed size").size(1); + assert_equal(trimmed.size, 0, "Trimmed size"); } private Email setup_email(int id, Email? references = null) { diff --git a/test/engine/app/app-conversation-test.vala b/test/engine/app/app-conversation-test.vala index 03ebd8f2..98a519fd 100644 --- a/test/engine/app/app-conversation-test.vala +++ b/test/engine/app/app-conversation-test.vala @@ -160,9 +160,9 @@ class Geary.App.ConversationTest : TestCase { Geary.Email e2 = setup_email(2); this.test.add(e2, singleton(other_path)); - assert_int( - 2, this.test.get_emails(Conversation.Ordering.NONE).size - ); + assert_collection( + this.test.get_emails(Conversation.Ordering.NONE) + ).size(2); } public void get_emails_by_location() throws GLib.Error { @@ -173,31 +173,15 @@ class Geary.App.ConversationTest : TestCase { Geary.Email e2 = setup_email(2); this.test.add(e2, singleton(other_path)); - assert_int( - 1, this.test.get_emails(Conversation.Ordering.NONE, - Conversation.Location.IN_FOLDER).size, - "Unexpected in-folder size" - ); - assert_equal( - e1, - traverse(this.test.get_emails(Conversation.Ordering.NONE, - Conversation.Location.IN_FOLDER)) - .first(), + assert_collection( + this.test.get_emails(NONE, IN_FOLDER), "Unexpected in-folder element" - ); + ).size(1).contains(e1); - assert_int( - 1, this.test.get_emails(Conversation.Ordering.NONE, - Conversation.Location.OUT_OF_FOLDER).size, - "Unexpected out-of-folder size" - ); - assert_equal( - e2, - traverse(this.test.get_emails(Conversation.Ordering.NONE, - Conversation.Location.OUT_OF_FOLDER)) - .first(), + assert_collection( + this.test.get_emails(NONE, OUT_OF_FOLDER), "Unexpected out-of-folder element" - ); + ).size(1).contains(e2); } public void get_emails_blacklist() throws GLib.Error { @@ -211,39 +195,17 @@ class Geary.App.ConversationTest : TestCase { Gee.Collection blacklist = new Gee.ArrayList(); blacklist.add(other_path); - assert_int( - 1, this.test.get_emails(Conversation.Ordering.NONE, - Conversation.Location.ANYWHERE, - blacklist - ).size, - "Unexpected other blacklist size" - ); - assert_equal( - e1, - traverse(this.test.get_emails(Conversation.Ordering.NONE, - Conversation.Location.ANYWHERE, - blacklist) - ).first(), + assert_collection( + this.test.get_emails(NONE, ANYWHERE, blacklist), "Unexpected other blacklist element" - ); + ).size(1).contains(e1); blacklist.clear(); blacklist.add(this.base_folder.path); - assert_int( - 1, this.test.get_emails(Conversation.Ordering.NONE, - Conversation.Location.ANYWHERE, - blacklist - ).size, - "Unexpected other blacklist size" - ); - assert_equal( - e2, - traverse(this.test.get_emails(Conversation.Ordering.NONE, - Conversation.Location.ANYWHERE, - blacklist) - ).first(), + assert_collection( + this.test.get_emails(NONE, ANYWHERE, blacklist), "Unexpected other blacklist element" - ); + ).size(1).contains(e2); } public void get_emails_marked_for_deletion() throws GLib.Error { @@ -251,25 +213,24 @@ class Geary.App.ConversationTest : TestCase { e1.set_flags(new Geary.EmailFlags.with(Geary.EmailFlags.DELETED)); this.test.add(e1, singleton(this.base_folder.path)); - assert_int( - 0, this.test.get_emails(Conversation.Ordering.NONE, - Conversation.Location.ANYWHERE - ).size, + assert_collection( + this.test.get_emails(NONE, ANYWHERE), "Message marked for deletion still present in conversation" - ); + ).is_empty(); } public void count_email_in_folder() throws GLib.Error { Geary.Email e1 = setup_email(1); this.test.add(e1, singleton(this.base_folder.path)); - assert_uint( - 1, this.test.get_count_in_folder(this.base_folder.path), + assert_equal( + this.test.get_count_in_folder(this.base_folder.path), + 1, "In-folder count" ); - assert_uint( - 0, + assert_equal( this.test.get_count_in_folder(this.folder_root.get_child("other")), + 0, "Out-folder count" ); } diff --git a/test/engine/common/common-contact-harvester-mock.vala b/test/engine/common/common-contact-harvester-mock.vala index d949a934..9dce3d45 100644 --- a/test/engine/common/common-contact-harvester-mock.vala +++ b/test/engine/common/common-contact-harvester-mock.vala @@ -5,7 +5,9 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -internal class Geary.MockContactHarvester : ContactHarvester, GLib.Object { +internal class Geary.MockContactHarvester : + Geary.BaseObject, + ContactHarvester { public async void harvest_from_email(Gee.Collection messages, GLib.Cancellable? cancellable) diff --git a/test/engine/common/common-contact-harvester-test.vala b/test/engine/common/common-contact-harvester-test.vala index fb5efbf7..c4901b55 100644 --- a/test/engine/common/common-contact-harvester-test.vala +++ b/test/engine/common/common-contact-harvester-test.vala @@ -58,7 +58,7 @@ class Geary.ContactHarvesterImplTest : TestCase { this.senders ); this.store.expect_call("get_by_rfc822"); - ExpectedCall update_call = this.store.expect_call("update_contacts"); + ValaUnit.ExpectedCall update_call = this.store.expect_call("update_contacts"); this.email.set_receivers( new RFC822.MailboxAddresses.single(this.test_address), null, null ); @@ -70,13 +70,13 @@ class Geary.ContactHarvesterImplTest : TestCase { this.store.assert_expectations(); Gee.Collection contacts = update_call.called_arg>(0); - assert_int(1, contacts.size, "contacts length"); + assert_collection(contacts).size(1); Contact? created = Collection.first(contacts) as Contact; assert_non_null(created, "contacts contents"); - assert_string("Test", created.real_name); - assert_string("test@example.com", created.email); - assert_string("test@example.com", created.normalized_email); + assert_equal(created.real_name, "Test"); + assert_equal(created.email, "test@example.com"); + assert_equal(created.normalized_email, "test@example.com"); } public void blacklisted_folder_type() throws GLib.Error { @@ -103,7 +103,7 @@ class Geary.ContactHarvesterImplTest : TestCase { this.senders ); this.store.expect_call("get_by_rfc822"); - ExpectedCall update_call = this.store.expect_call("update_contacts"); + ValaUnit.ExpectedCall update_call = this.store.expect_call("update_contacts"); this.email.set_receivers( new RFC822.MailboxAddresses.single(this.test_address), null, null ); @@ -116,9 +116,9 @@ class Geary.ContactHarvesterImplTest : TestCase { Gee.Collection contacts = update_call.called_arg>(0); Contact? created = Collection.first(contacts) as Contact; - assert_int( - Contact.Importance.SEEN, + assert_equal( created.highest_importance, + Contact.Importance.SEEN, "call contact importance" ); } @@ -130,7 +130,7 @@ class Geary.ContactHarvesterImplTest : TestCase { this.senders ); this.store.expect_call("get_by_rfc822"); - ExpectedCall update_call = this.store.expect_call("update_contacts"); + ValaUnit.ExpectedCall update_call = this.store.expect_call("update_contacts"); this.email.set_receivers( new RFC822.MailboxAddresses.single(this.test_address), null, null ); @@ -143,9 +143,9 @@ class Geary.ContactHarvesterImplTest : TestCase { Gee.Collection contacts = update_call.called_arg>(0); Contact? created = Collection.first(contacts) as Contact; - assert_int( - Contact.Importance.SENT_TO, + assert_equal( created.highest_importance, + Contact.Importance.SENT_TO, "call contact importance" ); } @@ -157,7 +157,7 @@ class Geary.ContactHarvesterImplTest : TestCase { this.senders ); this.store.expect_call("get_by_rfc822"); - ExpectedCall update_call = this.store.expect_call("update_contacts"); + ValaUnit.ExpectedCall update_call = this.store.expect_call("update_contacts"); this.email.set_receivers( new RFC822.MailboxAddresses.single(this.sender_address), null, null ); @@ -170,9 +170,9 @@ class Geary.ContactHarvesterImplTest : TestCase { Gee.Collection contacts = update_call.called_arg>(0); Contact? created = Collection.first(contacts) as Contact; - assert_int( - Contact.Importance.RECEIVED_FROM, + assert_equal( created.highest_importance, + Contact.Importance.RECEIVED_FROM, "call contact importance" ); } diff --git a/test/engine/common/common-contact-store-impl-test.vala b/test/engine/common/common-contact-store-impl-test.vala index 2e65e776..2cc8ec52 100644 --- a/test/engine/common/common-contact-store-impl-test.vala +++ b/test/engine/common/common-contact-store-impl-test.vala @@ -83,10 +83,10 @@ class Geary.ContactStoreImplTest : TestCase { ); Contact? existing = test_article.get_by_rfc822.end(async_result()); assert_non_null(existing, "Existing contact"); - assert_string("Test@example.com", existing.email, "Existing email"); - assert_string("test@example.com", existing.normalized_email, "Existing normalized_email"); - assert_string("Test Name", existing.real_name, "Existing real_name"); - assert_int(50, existing.highest_importance, "Existing highest_importance"); + assert_equal(existing.email, "Test@example.com", "Existing email"); + assert_equal(existing.normalized_email, "test@example.com", "Existing normalized_email"); + assert_equal(existing.real_name, "Test Name", "Existing real_name"); + assert_equal(existing.highest_importance, 50, "Existing highest_importance"); assert_false(existing.flags.always_load_remote_images(), "Existing flags"); test_article.get_by_rfc822.begin( @@ -109,7 +109,7 @@ class Geary.ContactStoreImplTest : TestCase { Gee.Collection results = test_article.search.end( async_result() ); - assert_int(0, results.size); + assert_equal(results.size, 0); } public void search_email_match() throws GLib.Error { @@ -123,13 +123,13 @@ class Geary.ContactStoreImplTest : TestCase { Gee.Collection results = test_article.search.end( async_result() ); - assert_int(1, results.size, "results.size"); + assert_equal(results.size, 1, "results.size"); Contact search_hit = Collection.first(results); - assert_string("Test@example.com", search_hit.email, "Existing email"); - assert_string("test@example.com", search_hit.normalized_email, "Existing normalized_email"); - assert_string("Test Name", search_hit.real_name, "Existing real_name"); - assert_int(50, search_hit.highest_importance, "Existing highest_importance"); + assert_equal(search_hit.email, "Test@example.com", "Existing email"); + assert_equal(search_hit.normalized_email, "test@example.com", "Existing normalized_email"); + assert_equal(search_hit.real_name, "Test Name", "Existing real_name"); + assert_equal(search_hit.highest_importance, 50, "Existing highest_importance"); assert_false(search_hit.flags.always_load_remote_images(), "Existing flags"); } @@ -144,13 +144,13 @@ class Geary.ContactStoreImplTest : TestCase { Gee.Collection results = test_article.search.end( async_result() ); - assert_int(1, results.size, "results.size"); + assert_equal(results.size, 1, "results.size"); Contact search_hit = Collection.first(results); - assert_string("Test@example.com", search_hit.email, "Existing email"); - assert_string("test@example.com", search_hit.normalized_email, "Existing normalized_email"); - assert_string("Test Name", search_hit.real_name, "Existing real_name"); - assert_int(50, search_hit.highest_importance, "Existing highest_importance"); + assert_equal(search_hit.email, "Test@example.com", "Existing email"); + assert_equal(search_hit.normalized_email, "test@example.com", "Existing normalized_email"); + assert_equal(search_hit.real_name, "Test Name", "Existing real_name"); + assert_equal(search_hit.highest_importance, 50, "Existing highest_importance"); assert_false(search_hit.flags.always_load_remote_images(), "Existing flags"); } @@ -178,10 +178,10 @@ class Geary.ContactStoreImplTest : TestCase { Gee.Collection results = test_article.search.end( async_result() ); - assert_int(1, results.size, "results.size"); + assert_equal(results.size, 1, "results.size"); Contact search_hit = Collection.first(results); - assert_string("Germán", search_hit.real_name, "Existing real_name"); + assert_equal(search_hit.real_name, "Germán", "Existing real_name"); } public void search_utf8_multi_byte_names() throws GLib.Error { @@ -209,10 +209,10 @@ class Geary.ContactStoreImplTest : TestCase { Gee.Collection results = test_article.search.end( async_result() ); - assert_int(1, results.size, "results.size"); + assert_equal(results.size, 1, "results.size"); Contact search_hit = Collection.first(results); - assert_string("年収1億円目指せ", search_hit.real_name, "Existing real_name"); + assert_equal(search_hit.real_name, "年収1億円目指せ", "Existing real_name"); } public void update_new_contact() throws GLib.Error { @@ -237,10 +237,10 @@ class Geary.ContactStoreImplTest : TestCase { ); Contact? persisted = test_article.get_by_rfc822.end(async_result()); assert_non_null(persisted, "persisted"); - assert_string("New@example.com", persisted.email, "Persisted email"); - assert_string("new@example.com", persisted.normalized_email, "Persisted normalized_email"); - assert_string("New", persisted.real_name, "Persisted real_name"); - assert_int(0, persisted.highest_importance, "Persisted highest_importance"); + assert_equal(persisted.email, "New@example.com", "Persisted email"); + assert_equal(persisted.normalized_email, "new@example.com", "Persisted normalized_email"); + assert_equal(persisted.real_name, "New", "Persisted real_name"); + assert_equal(persisted.highest_importance, 0, "Persisted highest_importance"); assert_true(persisted.flags.always_load_remote_images(), "Persisted real_name"); } @@ -265,10 +265,10 @@ class Geary.ContactStoreImplTest : TestCase { ); Contact? updated = test_article.get_by_rfc822.end(async_result()); assert_non_null(updated, "updated"); - assert_string("Test@example.com", updated.email, "Updated email"); - assert_string("test@example.com", updated.normalized_email, "Updated normalized_email"); - assert_string("Updated", updated.real_name, "Updated real_name"); - assert_int(100, updated.highest_importance, "Updated highest_importance"); + assert_equal(updated.email, "Test@example.com", "Updated email"); + assert_equal(updated.normalized_email, "test@example.com", "Updated normalized_email"); + assert_equal(updated.real_name, "Updated", "Updated real_name"); + assert_equal(updated.highest_importance, 100, "Updated highest_importance"); assert_true(updated.flags.always_load_remote_images(), "Added flags"); // Now try removing the flag and ensure it sticks diff --git a/test/engine/db/db-versioned-database-test.vala b/test/engine/db/db-versioned-database-test.vala index 53ac49ee..07b80da8 100644 --- a/test/engine/db/db-versioned-database-test.vala +++ b/test/engine/db/db-versioned-database-test.vala @@ -40,7 +40,7 @@ class Geary.Db.VersionedDatabaseTest : TestCase { Geary.Db.Result result = db.query("SELECT * FROM TestTable;"); assert_false(result.finished, "Row not inserted"); - assert_string("value", result.string_for("col")); + assert_equal(result.string_for("col"), "value"); assert_false(result.next(), "Multiple rows inserted"); db.file.delete(); diff --git a/test/engine/imap-db/imap-db-account-test.vala b/test/engine/imap-db/imap-db-account-test.vala index c526372d..49234c6b 100644 --- a/test/engine/imap-db/imap-db-account-test.vala +++ b/test/engine/imap-db/imap-db-account-test.vala @@ -99,7 +99,7 @@ class Geary.ImapDB.AccountTest : TestCase { "SELECT * FROM FolderTable;" ); assert_false(result.finished, "Folder not created"); - assert_string("test", result.string_for("name"), "Folder name"); + assert_equal(result.string_for("name"), "test", "Folder name"); assert_true(result.is_null_for("parent_id"), "Folder parent"); assert_false(result.next(), "Multiple rows inserted"); } @@ -138,8 +138,8 @@ class Geary.ImapDB.AccountTest : TestCase { "SELECT * FROM FolderTable WHERE id != 1;" ); assert_false(result.finished, "Folder not created"); - assert_string("child", result.string_for("name"), "Folder name"); - assert_int(1, result.int_for("parent_id"), "Folder parent"); + assert_equal(result.string_for("name"), "child", "Folder name"); + assert_equal(result.int_for("parent_id"), 1, "Folder parent"); assert_false(result.next(), "Multiple rows inserted"); } @@ -161,8 +161,8 @@ class Geary.ImapDB.AccountTest : TestCase { this.account.list_folders_async.end(async_result()); Folder test1 = traverse(result).first(); - assert_int(1, result.size, "Base folder not listed"); - assert_string("test1", test1.get_path().name, "Base folder name"); + assert_equal(result.size, 1, "Base folder not listed"); + assert_equal(test1.get_path().name, "test1", "Base folder name"); this.account.list_folders_async.begin( test1.get_path(), @@ -172,8 +172,8 @@ class Geary.ImapDB.AccountTest : TestCase { result = this.account.list_folders_async.end(async_result()); Folder test2 = traverse(result).first(); - assert_int(1, result.size, "Child folder not listed"); - assert_string("test2", test2.get_path().name, "Child folder name"); + assert_equal(result.size, 1, "Child folder not listed"); + assert_equal(test2.get_path().name, "test2", "Child folder name"); this.account.list_folders_async.begin( test2.get_path(), @@ -183,8 +183,8 @@ class Geary.ImapDB.AccountTest : TestCase { result = this.account.list_folders_async.end(async_result()); Folder test3 = traverse(result).first(); - assert_int(1, result.size, "Grandchild folder not listed"); - assert_string("test3", test3.get_path().name, "Grandchild folder name"); + assert_equal(result.size, 1, "Grandchild folder not listed"); + assert_equal(test3.get_path().name, "test3", "Grandchild folder name"); } public void delete_folder() throws GLib.Error { @@ -268,7 +268,7 @@ class Geary.ImapDB.AccountTest : TestCase { Folder? result = this.account.fetch_folder_async.end(async_result()); assert_non_null(result); - assert_string("test1", result.get_path().name); + assert_equal(result.get_path().name, "test1"); } public void fetch_child_folder() throws GLib.Error { @@ -287,7 +287,7 @@ class Geary.ImapDB.AccountTest : TestCase { Folder? result = this.account.fetch_folder_async.end(async_result()); assert_non_null(result); - assert_string("test2", result.get_path().name); + assert_equal(result.get_path().name, "test2"); } public void fetch_nonexistent_folder() throws GLib.Error { @@ -336,7 +336,7 @@ class Geary.ImapDB.AccountTest : TestCase { async_result() ); - assert_int(2, result.size, "Not enough email listed"); + assert_equal(result.size, 2, "Not enough email listed"); assert_true(new EmailIdentifier(1, null).equal_to(result[0].id)); assert_true(new EmailIdentifier(2, null).equal_to(result[1].id)); diff --git a/test/engine/imap-db/imap-db-attachment-test.vala b/test/engine/imap-db/imap-db-attachment-test.vala index e8e2f260..79caa5f6 100644 --- a/test/engine/imap-db/imap-db-attachment-test.vala +++ b/test/engine/imap-db/imap-db-attachment-test.vala @@ -26,19 +26,17 @@ class Geary.ImapDB.AttachmentTest : TestCase { Attachment test = new Attachment.from_part( 1, new Geary.RFC822.Part(part) ); - assert_string( - Geary.Mime.ContentType.ATTACHMENT_DEFAULT.to_string(), - test.content_type.to_string() + assert_equal( + test.content_type.to_string(), + Geary.Mime.ContentType.ATTACHMENT_DEFAULT.to_string() ); - assert_null_string(test.content_id, "content_id"); - assert_null_string(test.content_description, "content_description"); - assert_int( - Geary.Mime.DispositionType.UNSPECIFIED, - test.content_disposition.disposition_type, - "content disposition type" + assert_null(test.content_id, "content_id"); + assert_null(test.content_description, "content_description"); + assert_equal( + test.content_disposition.disposition_type, UNSPECIFIED ); assert_false(test.has_content_filename, "has_content_filename"); - assert_null_string(test.content_filename, "content_filename"); + assert_null(test.content_filename, "content_filename"); } public void new_from_complete_mime_part() throws Error { @@ -61,15 +59,14 @@ class Geary.ImapDB.AttachmentTest : TestCase { 1, new Geary.RFC822.Part(part) ); - assert_string(TYPE, test.content_type.to_string()); - assert_string(ID, test.content_id); - assert_string(DESC, test.content_description); - assert_int( - Geary.Mime.DispositionType.ATTACHMENT, - test.content_disposition.disposition_type + assert_equal(test.content_type.to_string(), TYPE); + assert_equal(test.content_id, ID); + assert_equal(test.content_description, DESC); + assert_equal( + test.content_disposition.disposition_type, ATTACHMENT ); assert_true(test.has_content_filename, "has_content_filename"); - assert_string(test.content_filename, NAME, "content_filename"); + assert_equal(NAME, test.content_filename, "content_filename"); } public void new_from_inline_mime_part() throws Error { @@ -85,9 +82,8 @@ class Geary.ImapDB.AttachmentTest : TestCase { 1, new Geary.RFC822.Part(part) ); - assert_int( - Geary.Mime.DispositionType.INLINE, - test.content_disposition.disposition_type + assert_equal( + test.content_disposition.disposition_type, INLINE ); } @@ -169,29 +165,29 @@ CREATE TABLE MessageAttachmentTable ( null ); - assert_int(1, attachments.size, "No attachment provided"); + assert_equal(attachments.size, 1, "No attachment provided"); Geary.Attachment attachment = attachments[0]; assert_non_null(attachment.file, "Attachment file"); - assert_int( + assert_equal( + attachment.filesize, DECODED_BODY.data.length, - (int) attachment.filesize, "Attachment file size" ); uint8[] buf = new uint8[4096]; size_t len = 0; attachments[0].file.read().read_all(buf, out len); - assert_string(DECODED_BODY, (string) buf[0:len]); + assert_equal((string) buf[0:len], DECODED_BODY); Geary.Db.Result result = this.db.query( "SELECT * FROM MessageAttachmentTable;" ); assert_false(result.finished, "Row not inserted"); - assert_int(1, result.int_for("message_id"), "Row message id"); - assert_int( - DECODED_BODY.data.length, + assert_equal(result.int_for("message_id"), 1, "Row message id"); + assert_equal( result.int_for("filesize"), + DECODED_BODY.data.length, "Row file size" ); assert_false(result.next(), "Multiple rows inserted"); @@ -201,8 +197,7 @@ CREATE TABLE MessageAttachmentTable ( const string TYPE = "text/plain"; const string ID = "test-id"; const string DESCRIPTION = "test description"; - const Geary.Mime.DispositionType DISPOSITION_TYPE = - Geary.Mime.DispositionType.INLINE; + const Geary.Mime.DispositionType DISPOSITION_TYPE = INLINE; const string FILENAME = "test.txt"; GMime.Part part = new_part(TYPE, ENCODED_BODY.data); @@ -224,38 +219,38 @@ CREATE TABLE MessageAttachmentTable ( null ); - assert_int(1, attachments.size, "No attachment provided"); + assert_equal(attachments.size, 1, "No attachment provided"); Geary.Attachment attachment = attachments[0]; - assert_string(TYPE, attachment.content_type.to_string()); - assert_string(ID, attachment.content_id); - assert_string(DESCRIPTION, attachment.content_description); - assert_string(FILENAME, attachment.content_filename); - assert_int( - DISPOSITION_TYPE, + assert_equal(attachment.content_type.to_string(), TYPE); + assert_equal(attachment.content_id, ID); + assert_equal(attachment.content_description, DESCRIPTION); + assert_equal(attachment.content_filename, FILENAME); + assert_equal( attachment.content_disposition.disposition_type, + DISPOSITION_TYPE, "Attachment disposition type" ); uint8[] buf = new uint8[4096]; size_t len = 0; attachment.file.read().read_all(buf, out len); - assert_string(DECODED_BODY, (string) buf[0:len]); + assert_equal((string) buf[0:len], DECODED_BODY); Geary.Db.Result result = this.db.query( "SELECT * FROM MessageAttachmentTable;" ); assert_false(result.finished, "Row not inserted"); - assert_int(1, result.int_for("message_id"), "Row message id"); - assert_string(TYPE, result.string_for("mime_type")); - assert_string(ID, result.string_for("content_id")); - assert_string(DESCRIPTION, result.string_for("description")); - assert_int( + assert_equal(result.int_for("message_id"), 1, "Row message id"); + assert_equal(result.string_for("mime_type"), TYPE); + assert_equal(result.string_for("content_id"), ID); + assert_equal(result.string_for("description"), DESCRIPTION); + assert_equal( + (Geary.Mime.DispositionType) result.int_for("disposition"), DISPOSITION_TYPE, - result.int_for("disposition"), "Row disposition type" ); - assert_string(FILENAME, result.string_for("filename")); + assert_equal(result.string_for("filename"), FILENAME); assert_false(result.next(), "Multiple rows inserted"); } @@ -285,12 +280,12 @@ abriquent pour te la vendre une =C3=A2me vulgaire."""; null ); - assert_int(1, attachments.size, "No attachment provided"); + assert_equal(attachments.size, 1, "No attachment provided"); uint8[] buf = new uint8[4096]; size_t len = 0; attachments[0].file.read().read_all(buf, out len); - assert_string(QP_DECODED, (string) buf[0:len]); + assert_equal((string) buf[0:len], QP_DECODED); } public void list_attachments() throws Error { @@ -310,8 +305,8 @@ VALUES (2, 'text/plain'); null ); - assert_int(1, loaded.size, "Expected one row loaded"); - assert_int(1, (int) loaded[0].message_id, "Unexpected message id"); + assert_equal(loaded.size, 1, "Expected one row loaded"); + assert_equal(loaded[0].message_id, 1, "Unexpected message id"); } public void delete_attachments() throws Error { @@ -343,7 +338,9 @@ VALUES (2, 'text/plain'); "SELECT * FROM MessageAttachmentTable;" ); assert_false(result.finished); - assert_int(2, result.int_for("message_id"), "Unexpected message_id"); + assert_equal( + result.int_for("message_id"), 2, "Unexpected message_id" + ); assert_false(result.next(), "Attachment not deleted from db"); assert_false(attachments[0].file.query_exists(null), diff --git a/test/engine/imap-db/imap-db-database-test.vala b/test/engine/imap-db/imap-db-database-test.vala index fd5046ae..1f03d4a9 100644 --- a/test/engine/imap-db/imap-db-database-test.vala +++ b/test/engine/imap-db/imap-db-database-test.vala @@ -1,3 +1,4 @@ + /* * Copyright 2018 Michael Gratton * @@ -106,7 +107,7 @@ class Geary.ImapDB.DatabaseTest : TestCase { ); db.open.end(async_result()); - assert_int(26, db.get_schema_version(), "Post-upgrade version"); + assert_equal(db.get_schema_version(), 26, "Post-upgrade version"); // Since schema v22 deletes the re-creates all attachments, // attachment 12 should no longer exist on the file system and @@ -157,7 +158,7 @@ class Geary.ImapDB.DatabaseTest : TestCase { int i = 0; while (!result.finished) { assert_true(i < expected.length, "Too many rows"); - assert_string(expected[i], result.string_at(0)); + assert_equal(result.string_at(0), expected[i]); i++; result.next(); } diff --git a/test/engine/imap-db/imap-db-folder-test.vala b/test/engine/imap-db/imap-db-folder-test.vala index eac4c0b8..23da4669 100644 --- a/test/engine/imap-db/imap-db-folder-test.vala +++ b/test/engine/imap-db/imap-db-folder-test.vala @@ -93,9 +93,9 @@ class Geary.ImapDB.FolderTest : TestCase { Gee.Map results = this.folder.create_or_merge_email_async.end(async_result()); - assert_int(1, results.size); - assert(results.get(mock)); - assert_int(0, this.folder.get_properties().email_unread); + assert_equal(results.size, 1); + assert_true(results.get(mock)); + assert_equal(this.folder.get_properties().email_unread, 0); } public void create_unread_email() throws GLib.Error { @@ -113,9 +113,9 @@ class Geary.ImapDB.FolderTest : TestCase { Gee.Map results = this.folder.create_or_merge_email_async.end(async_result()); - assert_int(1, results.size); - assert(results.get(mock)); - assert_int(1, this.folder.get_properties().email_unread); + assert_equal(results.size, 1); + assert_true(results.get(mock)); + assert_equal(this.folder.get_properties().email_unread, 1); } public void create_no_unread_update() throws GLib.Error { @@ -133,9 +133,9 @@ class Geary.ImapDB.FolderTest : TestCase { Gee.Map results = this.folder.create_or_merge_email_async.end(async_result()); - assert_int(1, results.size); - assert(results.get(mock)); - assert_int(0, this.folder.get_properties().email_unread); + assert_equal(results.size, 1); + assert_true(results.get(mock)); + assert_equal(this.folder.get_properties().email_unread, 0); } public void merge_email() throws GLib.Error { @@ -163,8 +163,8 @@ class Geary.ImapDB.FolderTest : TestCase { Gee.Map results = this.folder.create_or_merge_email_async.end(async_result()); - assert_int(1, results.size); - assert(!results.get(mock)); + assert_equal(results.size, 1); + assert_true(!results.get(mock)); // Fetch it again to make sure it's been merged using required // fields to check @@ -182,8 +182,8 @@ class Geary.ImapDB.FolderTest : TestCase { assert_no_error(err); } - assert_string(fixture_to, merged.to.to_string()); - assert_string(mock_subject, merged.subject.to_string()); + assert_equal(merged.to.to_string(), fixture_to); + assert_equal(merged.subject.to_string(), mock_subject); } public void merge_add_flags() throws GLib.Error { @@ -214,8 +214,8 @@ class Geary.ImapDB.FolderTest : TestCase { Gee.Map results = this.folder.create_or_merge_email_async.end(async_result()); - assert_int(1, results.size); - assert(!results.get(test)); + assert_equal(results.size, 1); + assert_false(results.get(test)); assert_flags((EmailIdentifier) test.id, test_flags); } @@ -248,8 +248,8 @@ class Geary.ImapDB.FolderTest : TestCase { Gee.Map results = this.folder.create_or_merge_email_async.end(async_result()); - assert_int(1, results.size); - assert(!results.get(test)); + assert_equal(results.size, 1); + assert_false(results.get(test)); assert_flags((EmailIdentifier) test.id, test_flags); } @@ -381,7 +381,7 @@ class Geary.ImapDB.FolderTest : TestCase { int i = 0; while (!result.finished) { assert_true(i < expected.length, "Too many rows"); - assert_int64(expected[i], result.int64_at(0)); + assert_equal(result.int64_at(0), expected[i]); i++; result.next(); } diff --git a/test/engine/imap/command/imap-create-command-test.vala b/test/engine/imap/command/imap-create-command-test.vala index cf6abc19..91933c7a 100644 --- a/test/engine/imap/command/imap-create-command-test.vala +++ b/test/engine/imap/command/imap-create-command-test.vala @@ -15,19 +15,19 @@ class Geary.Imap.CreateCommandTest : TestCase { } public void basic_create() throws Error { - assert_string( - "---- create owatagusiam/", - new CreateCommand(new MailboxSpecifier("owatagusiam/")).to_string() + assert_equal( + new CreateCommand(new MailboxSpecifier("owatagusiam/")).to_string(), + "---- create owatagusiam/" ); } public void special_use() throws Error { - assert_string( - "---- create Everything (use (\\All))", + assert_equal( new CreateCommand.special_use( new MailboxSpecifier("Everything"), ALL_MAIL - ).to_string() + ).to_string(), + "---- create Everything (use (\\All))" ); } diff --git a/test/engine/imap/command/imap-fetch-command-test.vala b/test/engine/imap/command/imap-fetch-command-test.vala index db477599..fdb56d4d 100644 --- a/test/engine/imap/command/imap-fetch-command-test.vala +++ b/test/engine/imap/command/imap-fetch-command-test.vala @@ -29,9 +29,9 @@ class Geary.Imap.FetchCommandTest : TestCase { new Gee.LinkedList(); data_items.add(FetchDataSpecifier.UID); - assert_string( - "---- fetch 1 uid", - new FetchCommand(this.msg_set, data_items, null).to_string() + assert_equal( + new FetchCommand(this.msg_set, data_items, null).to_string(), + "---- fetch 1 uid" ); } @@ -44,9 +44,9 @@ class Geary.Imap.FetchCommandTest : TestCase { ) ); - assert_string( - "---- fetch 1 body[text]", - new FetchCommand(this.msg_set, null, body_items).to_string() + assert_equal( + new FetchCommand(this.msg_set, null, body_items).to_string(), + "---- fetch 1 body[text]" ); } @@ -56,9 +56,9 @@ class Geary.Imap.FetchCommandTest : TestCase { data_items.add(FetchDataSpecifier.UID); data_items.add(FetchDataSpecifier.BODY); - assert_string( - "---- fetch 1 (uid body)", - new FetchCommand(this.msg_set, data_items, null).to_string() + assert_equal( + new FetchCommand(this.msg_set, data_items, null).to_string(), + "---- fetch 1 (uid body)" ); } @@ -76,9 +76,9 @@ class Geary.Imap.FetchCommandTest : TestCase { ) ); - assert_string( - "---- fetch 1 (body[header] body[text])", - new FetchCommand(this.msg_set, null, body_items).to_string() + assert_equal( + new FetchCommand(this.msg_set, null, body_items).to_string(), + "---- fetch 1 (body[header] body[text])" ); } @@ -101,9 +101,9 @@ class Geary.Imap.FetchCommandTest : TestCase { ) ); - assert_string( - "---- fetch 1 (uid flags body[header] body[text])", - new FetchCommand(this.msg_set, data_items, body_items).to_string() + assert_equal( + new FetchCommand(this.msg_set, data_items, body_items).to_string(), + "---- fetch 1 (uid flags body[header] body[text])" ); } diff --git a/test/engine/imap/message/imap-mailbox-specifier-test.vala b/test/engine/imap/message/imap-mailbox-specifier-test.vala index d3a52046..71f5f160 100644 --- a/test/engine/imap/message/imap-mailbox-specifier-test.vala +++ b/test/engine/imap/message/imap-mailbox-specifier-test.vala @@ -17,13 +17,13 @@ class Geary.Imap.MailboxSpecifierTest : TestCase { } public void to_parameter() throws Error { - assert_string( - "test", - new MailboxSpecifier("test").to_parameter().to_string() + assert_equal( + new MailboxSpecifier("test").to_parameter().to_string(), + "test" ); - assert_string( - "foo/bar", - new MailboxSpecifier("foo/bar").to_parameter().to_string() + assert_equal( + new MailboxSpecifier("foo/bar").to_parameter().to_string(), + "foo/bar" ); // The param won't be quoted or escaped since @@ -32,55 +32,58 @@ class Geary.Imap.MailboxSpecifierTest : TestCase { Parameter quoted = new MailboxSpecifier("""foo\bar""").to_parameter(); assert_true(quoted is QuotedStringParameter, "Backslash was not quoted"); - assert_string( - "ol&AOk-", - new MailboxSpecifier("olé").to_parameter().to_string() + assert_equal( + new MailboxSpecifier("olé").to_parameter().to_string(), + "ol&AOk-" ); } public void from_parameter() throws Error { - assert_string( - "test", + assert_equal( new MailboxSpecifier.from_parameter( - new UnquotedStringParameter("test")).name + new UnquotedStringParameter("test") + ).name, + "test" ); // This won't be quoted or escaped since QuotedStringParameter // doesn't actually handle that. - assert_string( - "foo\\bar", + assert_equal( new MailboxSpecifier.from_parameter( - new QuotedStringParameter("""foo\bar""")).name + new QuotedStringParameter("""foo\bar""") + ).name, + "foo\\bar" ); - assert_string( - "olé", + assert_equal( new MailboxSpecifier.from_parameter( - new UnquotedStringParameter("ol&AOk-")).name + new UnquotedStringParameter("ol&AOk-") + ).name, + "olé" ); } public void from_folder_path() throws Error { FolderRoot root = new FolderRoot("#test"); MailboxSpecifier inbox = new MailboxSpecifier("Inbox"); - assert_string( - "Foo", + assert_equal( new MailboxSpecifier.from_folder_path( root.get_child("Foo"), inbox, "$" - ).name + ).name, + "Foo" ); - assert_string( - "Foo$Bar", + assert_equal( new MailboxSpecifier.from_folder_path( root.get_child("Foo").get_child("Bar"), inbox, "$" - ).name + ).name, + "Foo$Bar" ); - assert_string( - "Inbox", + assert_equal( new MailboxSpecifier.from_folder_path( root.get_child(MailboxSpecifier.CANONICAL_INBOX_NAME), inbox, "$" - ).name + ).name, + "Inbox" ); try { diff --git a/test/engine/imap/parameter/imap-list-parameter-test.vala b/test/engine/imap/parameter/imap-list-parameter-test.vala index 6f179787..f590347c 100644 --- a/test/engine/imap/parameter/imap-list-parameter-test.vala +++ b/test/engine/imap/parameter/imap-list-parameter-test.vala @@ -23,8 +23,8 @@ class Geary.Imap.ListParameterTest : TestCase { parent_1.add(child); parent_2.add(child); - assert_int(1, parent_1.size, "Parent 1 does not contain child"); - assert_int(1, parent_2.size, "Parent 2 does not contain child"); + assert_equal(parent_1.size, 1, "Parent 1 does not contain child"); + assert_equal(parent_2.size, 1, "Parent 2 does not contain child"); } } diff --git a/test/engine/imap/transport/imap-client-session-test.vala b/test/engine/imap/transport/imap-client-session-test.vala index f1a9e9e5..2aed9211 100644 --- a/test/engine/imap/transport/imap-client-session-test.vala +++ b/test/engine/imap/transport/imap-client-session-test.vala @@ -98,7 +98,7 @@ class Geary.Imap.ClientSessionTest : TestCase { test_article.connect_async.end(async_result()); assert_not_reached(); } catch (GLib.IOError.TIMED_OUT err) { - assert_double(timer.elapsed(), CONNECT_TIMEOUT, CONNECT_TIMEOUT * 0.5); + assert_within(timer.elapsed(), CONNECT_TIMEOUT, CONNECT_TIMEOUT * 0.5); } TestServer.Result result = this.server.wait_for_script(this.main_loop); @@ -278,9 +278,9 @@ class Geary.Imap.ClientSessionTest : TestCase { assert_true(test_article.capabilities.supports_imap4rev1()); assert_false(test_article.capabilities.has_capability("AUTH")); - assert_int(2, test_article.capabilities.revision); + assert_equal(test_article.capabilities.revision, 2); - assert_string("Inbox", test_article.inbox.mailbox.name); + assert_equal(test_article.inbox.mailbox.name, "Inbox"); assert_true(test_article.inbox.mailbox.is_inbox); test_article.disconnect_async.begin(null, this.async_completion); @@ -322,9 +322,9 @@ class Geary.Imap.ClientSessionTest : TestCase { assert_true(test_article.capabilities.supports_imap4rev1()); assert_false(test_article.capabilities.has_capability("AUTH")); - assert_int(2, test_article.capabilities.revision); + assert_equal(test_article.capabilities.revision, 2); - assert_string("Inbox", test_article.inbox.mailbox.name); + assert_equal(test_article.inbox.mailbox.name, "Inbox"); assert_true(test_article.inbox.mailbox.is_inbox); test_article.disconnect_async.begin(null, this.async_completion); @@ -383,19 +383,22 @@ class Geary.Imap.ClientSessionTest : TestCase { ); test_article.initiate_session_async.end(async_result()); - assert_int(1, test_article.get_personal_namespaces().size); - assert_string( - "INBOX.", test_article.get_personal_namespaces()[0].prefix + assert_equal(test_article.get_personal_namespaces().size, 1); + assert_equal( + test_article.get_personal_namespaces()[0].prefix, + "INBOX." ); - assert_int(1, test_article.get_shared_namespaces().size); - assert_string( - "shared.", test_article.get_shared_namespaces()[0].prefix + assert_equal(test_article.get_shared_namespaces().size, 1); + assert_equal( + test_article.get_shared_namespaces()[0].prefix, + "shared." ); - assert_int(1, test_article.get_other_users_namespaces().size); - assert_string( - "user.", test_article.get_other_users_namespaces()[0].prefix + assert_equal(test_article.get_other_users_namespaces().size, 1); + assert_equal( + test_article.get_other_users_namespaces()[0].prefix, + "user." ); test_article.disconnect_async.begin(null, this.async_completion); diff --git a/test/engine/imap/transport/imap-deserializer-test.vala b/test/engine/imap/transport/imap-deserializer-test.vala index b3a61712..156207cd 100644 --- a/test/engine/imap/transport/imap-deserializer-test.vala +++ b/test/engine/imap/transport/imap-deserializer-test.vala @@ -75,9 +75,9 @@ class Geary.Imap.DeserializerTest : TestCase { this.process.begin(Expect.MESSAGE, this.async_completion); RootParameters? message = this.process.end(async_result()); - assert_int(2, message.size); + assert_equal(message.size, 2); assert_true(message.get(1) is UnquotedStringParameter, "Not parsed as atom"); - assert_string(bytes, message.get(1).to_string()); + assert_equal(message.get(1).to_string(), bytes); } public void parse_quoted() throws Error { @@ -89,9 +89,9 @@ class Geary.Imap.DeserializerTest : TestCase { this.process.begin(Expect.MESSAGE, this.async_completion); RootParameters? message = this.process.end(async_result()); - assert_int(2, message.size); + assert_equal(message.size, 2); assert_true(message.get(1) is QuotedStringParameter, "Not parsed as quoted"); - assert_string(bytes, message.get(1).to_string()); + assert_equal(message.get(1).to_string(), bytes); } public void parse_number() throws Error { @@ -103,9 +103,9 @@ class Geary.Imap.DeserializerTest : TestCase { this.process.begin(Expect.MESSAGE, this.async_completion); RootParameters? message = this.process.end(async_result()); - assert_int(2, message.size); + assert_equal(message.size, 2); assert_true(message.get(1) is NumberParameter, "Not parsed as number"); - assert_string(bytes, message.get(1).to_string()); + assert_equal(message.get(1).to_string(), bytes); } public void parse_list() throws Error { @@ -117,9 +117,9 @@ class Geary.Imap.DeserializerTest : TestCase { this.process.begin(Expect.MESSAGE, this.async_completion); RootParameters? message = this.process.end(async_result()); - assert_int(2, message.size); + assert_equal(message.size, 2); assert_true(message.get(1) is ListParameter, "Not parsed as list"); - assert_string(bytes, message.get(1).to_string()); + assert_equal(message.get(1).to_string(), bytes); } public void parse_flag() throws GLib.Error { @@ -165,9 +165,9 @@ class Geary.Imap.DeserializerTest : TestCase { this.process.begin(Expect.MESSAGE, this.async_completion); RootParameters? message = this.process.end(async_result()); - assert_int(2, message.size); + assert_equal(message.size, 2); assert_true(message.get(1) is ResponseCode, "Not parsed as response code"); - assert_string(bytes, message.get(1).to_string()); + assert_equal(message.get(1).to_string(), bytes); } public void parse_bad_list() throws Error { @@ -358,7 +358,7 @@ class Geary.Imap.DeserializerTest : TestCase { assert(this.deser.is_halted()); } - protected async RootParameters? process(Expect expected) { + protected async RootParameters? process(Expect expected) throws GLib.Error { RootParameters? message = null; bool eos = false; bool deserialize_failure = false; @@ -401,6 +401,7 @@ class Geary.Imap.DeserializerTest : TestCase { default: assert_not_reached(); + break; } return message; diff --git a/test/engine/mime/mime-content-type-test.vala b/test/engine/mime/mime-content-type-test.vala index 5fc1160e..14b6f3dc 100644 --- a/test/engine/mime/mime-content-type-test.vala +++ b/test/engine/mime/mime-content-type-test.vala @@ -17,20 +17,20 @@ class Geary.Mime.ContentTypeTest : TestCase { } public void static_defaults() throws Error { - assert_string( - "text/plain; charset=us-ascii", - ContentType.DISPLAY_DEFAULT.to_string() + assert_equal( + ContentType.DISPLAY_DEFAULT.to_string(), + "text/plain; charset=us-ascii" ); - assert_string( - "application/octet-stream", - ContentType.ATTACHMENT_DEFAULT.to_string() + assert_equal( + ContentType.ATTACHMENT_DEFAULT.to_string(), + "application/octet-stream" ); } public void parse() throws GLib.Error { var test_article = ContentType.parse("text/plain"); - assert_string("text", test_article.media_type); - assert_string("plain", test_article.media_subtype); + assert_equal(test_article.media_type, "text"); + assert_equal(test_article.media_subtype, "plain"); try { ContentType.parse(""); diff --git a/test/engine/rfc822/rfc822-mailbox-address-test.vala b/test/engine/rfc822/rfc822-mailbox-address-test.vala index 7436629d..8718636d 100644 --- a/test/engine/rfc822/rfc822-mailbox-address-test.vala +++ b/test/engine/rfc822/rfc822-mailbox-address-test.vala @@ -223,9 +223,9 @@ class Geary.RFC822.MailboxAddressTest : TestCase { assert(new MailboxAddress("Test", "example@example@example.com").to_full_display() == "example@example@example.com"); - assert_string( - "\"Testerson, Test\" ", - new MailboxAddress("Testerson, Test", "test@example.com").to_full_display() + assert_equal( + new MailboxAddress("Testerson, Test", "test@example.com").to_full_display(), + "\"Testerson, Test\" " ); } @@ -241,13 +241,13 @@ class Geary.RFC822.MailboxAddressTest : TestCase { } public void to_rfc822_address() throws GLib.Error { - assert_string( - "example@example.com", - new MailboxAddress(null, "example@example.com").to_rfc822_address() + assert_equal( + new MailboxAddress(null, "example@example.com").to_rfc822_address(), + "example@example.com" ); - assert_string( - "test.account@example.com", - new MailboxAddress(null, "test.account@example.com").to_rfc822_address() + assert_equal( + new MailboxAddress(null, "test.account@example.com").to_rfc822_address(), + "test.account@example.com" ); //assert(new MailboxAddress(null, "test test@example.com").to_rfc822_address() == // "\"test test\"@example.com"); @@ -256,34 +256,34 @@ class Geary.RFC822.MailboxAddressTest : TestCase { //assert(new MailboxAddress(null, "test\"test@example.com").to_rfc822_address() == // "\"test\"test\"@example.com"); - assert_string( - "$test@example.com", - new MailboxAddress(null, "$test@example.com").to_rfc822_address() + assert_equal( + new MailboxAddress(null, "$test@example.com").to_rfc822_address(), + "$test@example.com" ); - assert_string( - "\"test@test\"@example.com", - new MailboxAddress(null, "test@test@example.com").to_rfc822_address() + assert_equal( + new MailboxAddress(null, "test@test@example.com").to_rfc822_address(), + "\"test@test\"@example.com" ); // RFC 2047 reserved words in the local-part must be used // as-is, and in particular not encoded per that RFC. See RFC // 2047 §5 and GNOME/geary#336 string RFC_2074 = "libc-alpha-sc.1553427554.ndgdflaalknmibgfkpak-hi-angel=yandex.ru@sourceware.org"; - assert_string( - RFC_2074, - new MailboxAddress(null, RFC_2074).to_rfc822_address() + assert_equal( + new MailboxAddress(null, RFC_2074).to_rfc822_address(), + RFC_2074 ); // Likewise, Unicode chars should be passed through. Note that // these can only be sent if a UTF8 connection is negotiated // with the SMTP server - assert_string( - "©@example.com", - new MailboxAddress(null, "©@example.com").to_rfc822_address() + assert_equal( + new MailboxAddress(null, "©@example.com").to_rfc822_address(), + "©@example.com" ); - assert_string( - "😸@example.com", - new MailboxAddress(null, "😸@example.com").to_rfc822_address() + assert_equal( + new MailboxAddress(null, "😸@example.com").to_rfc822_address(), + "😸@example.com" ); } @@ -310,15 +310,15 @@ class Geary.RFC822.MailboxAddressTest : TestCase { assert(new MailboxAddress("😸", "example@example.com").to_rfc822_string() == "=?UTF-8?b?8J+YuA==?= "); - assert_string( - "\"Surname, Name\" ", - new MailboxAddress("Surname, Name", "example@example.com").to_rfc822_string() + assert_equal( + new MailboxAddress("Surname, Name", "example@example.com").to_rfc822_string(), + "\"Surname, Name\" " ); - assert_string( - "\"Surname, Name\" ", + assert_equal( new MailboxAddress .from_rfc822_string("\"Surname, Name\" ") - .to_rfc822_string() + .to_rfc822_string(), + "\"Surname, Name\" " ); } diff --git a/test/engine/rfc822/rfc822-mailbox-addresses-test.vala b/test/engine/rfc822/rfc822-mailbox-addresses-test.vala index f3fc2fa8..465a9877 100644 --- a/test/engine/rfc822/rfc822-mailbox-addresses-test.vala +++ b/test/engine/rfc822/rfc822-mailbox-addresses-test.vala @@ -18,29 +18,30 @@ class Geary.RFC822.MailboxAddressesTest : TestCase { public void from_rfc822_string_encoded() throws GLib.Error { MailboxAddresses addrs = new MailboxAddresses.from_rfc822_string("test@example.com"); - assert(addrs.size == 1); + assert_equal(addrs.size, 1); addrs = new MailboxAddresses.from_rfc822_string("test1@example.com, test2@example.com"); - assert(addrs.size == 2); + assert_equal(addrs.size, 2); // Courtesy Mailsploit https://www.mailsploit.com addrs = new MailboxAddresses.from_rfc822_string("\"=?utf-8?b?dGVzdCIgPHBvdHVzQHdoaXRlaG91c2UuZ292Pg==?==?utf-8?Q?=00=0A?=\" "); - assert(addrs.size == 1); + assert_equal(addrs.size, 1); // Courtesy Mailsploit https://www.mailsploit.com addrs = new MailboxAddresses.from_rfc822_string("\"=?utf-8?Q?=42=45=47=49=4E=20=2F=20=28=7C=29=7C=3C=7C=3E=7C=40=7C=2C=7C=3B=7C=3A=7C=5C=7C=22=7C=2F=7C=5B=7C=5D=7C=3F=7C=2E=7C=3D=20=2F=20=00=20=50=41=53=53=45=44=20=4E=55=4C=4C=20=42=59=54=45=20=2F=20=0D=0A=20=50=41=53=53=45=44=20=43=52=4C=46=20=2F=20?==?utf-8?b?RU5E=?=\", "); - assert(addrs.size == 2); + assert_equal(addrs.size, 2); } public void from_rfc822_string_quoted() throws GLib.Error { MailboxAddresses addrs = new MailboxAddresses.from_rfc822_string( "\"Surname, Name\" " ) ; - assert_int(1, addrs.size); - assert_string("Surname, Name", addrs[0].name); - assert_string("mail@example.com", addrs[0].address); - - assert_string("\"Surname, Name\" ", addrs.to_rfc822_string()); + assert_equal(addrs.size, 1); + assert_equal(addrs[0].name, "Surname, Name"); + assert_equal(addrs[0].address, "mail@example.com"); + assert_equal( + addrs.to_rfc822_string(), "\"Surname, Name\" " + ); } public void to_rfc822_string() throws GLib.Error { diff --git a/test/engine/rfc822/rfc822-message-data-test.vala b/test/engine/rfc822/rfc822-message-data-test.vala index c6bc1553..acc08cb1 100644 --- a/test/engine/rfc822/rfc822-message-data-test.vala +++ b/test/engine/rfc822/rfc822-message-data-test.vala @@ -22,13 +22,13 @@ class Geary.RFC822.MessageDataTest : TestCase { new Geary.Memory.StringBuffer(PLAIN_BODY1_HEADERS), new Geary.Memory.StringBuffer(PLAIN_BODY1_ENCODED) ); - assert_string(PLAIN_BODY1_EXPECTED, plain_preview1.buffer.to_string()); + assert_equal(plain_preview1.buffer.to_string(), PLAIN_BODY1_EXPECTED); PreviewText base64_preview = new PreviewText.with_header( new Geary.Memory.StringBuffer(BASE64_BODY_HEADERS), new Geary.Memory.StringBuffer(BASE64_BODY_ENCODED) ); - assert_string(BASE64_BODY_EXPECTED, base64_preview.buffer.to_string()); + assert_equal(base64_preview.buffer.to_string(), BASE64_BODY_EXPECTED); string html_part_headers = "Content-Type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"; @@ -36,76 +36,76 @@ class Geary.RFC822.MessageDataTest : TestCase { new Geary.Memory.StringBuffer(html_part_headers), new Geary.Memory.StringBuffer(HTML_BODY1_ENCODED) ); - assert_string(HTML_BODY1_EXPECTED, html_preview1.buffer.to_string()); + assert_equal(html_preview1.buffer.to_string(), HTML_BODY1_EXPECTED); PreviewText html_preview2 = new PreviewText.with_header( new Geary.Memory.StringBuffer(html_part_headers), new Geary.Memory.StringBuffer(HTML_BODY2_ENCODED) ); - assert_string(HTML_BODY2_EXPECTED, html_preview2.buffer.to_string()); + assert_equal(html_preview2.buffer.to_string(), HTML_BODY2_EXPECTED); } public void header_from_rfc822() throws GLib.Error { Header test_article = new Header(new Memory.StringBuffer(HEADER_FIXTURE)); - assert_string("Test ", test_article.get_header("From")); - assert_string("test", test_article.get_header("Subject")); - assert_null_string(test_article.get_header("Blah")); + assert_equal(test_article.get_header("From"), "Test "); + assert_equal(test_article.get_header("Subject"), "test"); + assert_null(test_article.get_header("Blah")); } public void header_names_from_rfc822() throws GLib.Error { Header test_article = new Header(new Memory.StringBuffer(HEADER_FIXTURE)); - assert_int(2, test_article.get_header_names().length); - assert_string("From", test_article.get_header_names()[0]); - assert_string("Subject", test_article.get_header_names()[1]); + assert_equal(test_article.get_header_names().length, 2); + assert_equal(test_article.get_header_names()[0], "From"); + assert_equal(test_article.get_header_names()[1], "Subject"); } public void date_from_rfc822() throws GLib.Error { const string FULL_HOUR_TZ = "Thu, 28 Feb 2019 00:00:00 -0100"; Date full_hour_tz = new Date.from_rfc822_string(FULL_HOUR_TZ); - assert_int64( - ((int64) (-1 * 3600)) * 1000 * 1000, + assert_equal( full_hour_tz.value.get_utc_offset(), + ((int64) (-1 * 3600)) * 1000 * 1000, "full_hour_tz.value.get_utc_offset" ); - assert_int(0, full_hour_tz.value.get_hour(), "full_hour_tz hour"); - assert_int(0, full_hour_tz.value.get_minute(), "full_hour_tz minute"); - assert_int(0, full_hour_tz.value.get_second(), "full_hour_tz second"); - assert_int(28, full_hour_tz.value.get_day_of_month(), "full_hour_tz day"); - assert_int(2, full_hour_tz.value.get_month(), "full_hour_tz month"); - assert_int(2019, full_hour_tz.value.get_year(), "full_hour_tz year"); + assert_equal(full_hour_tz.value.get_hour(), 0, "full_hour_tz hour"); + assert_equal(full_hour_tz.value.get_minute(), 0, "full_hour_tz minute"); + assert_equal(full_hour_tz.value.get_second(), 0, "full_hour_tz second"); + assert_equal(full_hour_tz.value.get_day_of_month(), 28, "full_hour_tz day"); + assert_equal(full_hour_tz.value.get_month(), 2, "full_hour_tz month"); + assert_equal(full_hour_tz.value.get_year(), 2019, "full_hour_tz year"); - assert_int64( - full_hour_tz.value.to_utc().to_unix(), + assert_equal( full_hour_tz.value.to_unix(), + full_hour_tz.value.to_utc().to_unix(), "to_unix not UTC" ); const string HALF_HOUR_TZ = "Thu, 28 Feb 2019 00:00:00 +1030"; Date half_hour_tz = new Date.from_rfc822_string(HALF_HOUR_TZ); - assert_int64( - ((int64) (10.5 * 3600)) * 1000 * 1000, - half_hour_tz.value.get_utc_offset() + assert_equal( + half_hour_tz.value.get_utc_offset(), + ((int64) (10.5 * 3600)) * 1000 * 1000 ); - assert_int(0, half_hour_tz.value.get_hour()); - assert_int(0, half_hour_tz.value.get_minute()); - assert_int(0, half_hour_tz.value.get_second()); - assert_int(28, half_hour_tz.value.get_day_of_month()); - assert_int(2, half_hour_tz.value.get_month()); - assert_int(2019, half_hour_tz.value.get_year()); + assert_equal(half_hour_tz.value.get_hour(), 0); + assert_equal(half_hour_tz.value.get_minute(), 0); + assert_equal(half_hour_tz.value.get_second(), 0); + assert_equal(half_hour_tz.value.get_day_of_month(), 28); + assert_equal(half_hour_tz.value.get_month(), 2); + assert_equal(half_hour_tz.value.get_year(), 2019); } public void date_to_rfc822() throws GLib.Error { const string FULL_HOUR_TZ = "Thu, 28 Feb 2019 00:00:00 -0100"; Date full_hour_tz = new Date.from_rfc822_string(FULL_HOUR_TZ); - assert_string(FULL_HOUR_TZ, full_hour_tz.to_rfc822_string()); + assert_equal(full_hour_tz.to_rfc822_string(), FULL_HOUR_TZ); const string HALF_HOUR_TZ = "Thu, 28 Feb 2019 00:00:00 +1030"; Date half_hour_tz = new Date.from_rfc822_string(HALF_HOUR_TZ); - assert_string(HALF_HOUR_TZ, half_hour_tz.to_rfc822_string()); + assert_equal(half_hour_tz.to_rfc822_string(), HALF_HOUR_TZ); const string NEG_HALF_HOUR_TZ = "Thu, 28 Feb 2019 00:00:00 -1030"; Date neg_half_hour_tz = new Date.from_rfc822_string(NEG_HALF_HOUR_TZ); - assert_string(NEG_HALF_HOUR_TZ, neg_half_hour_tz.to_rfc822_string()); + assert_equal(neg_half_hour_tz.to_rfc822_string(), NEG_HALF_HOUR_TZ); } diff --git a/test/engine/rfc822/rfc822-message-test.vala b/test/engine/rfc822/rfc822-message-test.vala index 478d5633..fa8b5779 100644 --- a/test/engine/rfc822/rfc822-message-test.vala +++ b/test/engine/rfc822/rfc822-message-test.vala @@ -86,7 +86,7 @@ This is the second line. Message enc = string_to_message(ENCODED_TO); // Courtesy Mailsploit https://www.mailsploit.com - assert_string("potus@whitehouse.gov ", enc.to[0].name); + assert_equal(enc.to[0].name, "potus@whitehouse.gov "); } public void duplicate_mailbox() throws GLib.Error { @@ -112,7 +112,7 @@ This is the second line. assert_true(test.has_plain_body(), "Expected plain body"); assert_false(test.has_html_body(), "Expected non-html body"); - assert_string(BASIC_PLAIN_BODY, test.get_plain_body(false, null)); + assert_equal(test.get_plain_body(false, null), BASIC_PLAIN_BODY); } public void text_plain_as_html() throws GLib.Error { @@ -120,9 +120,9 @@ This is the second line. assert_true(test.has_plain_body(), "Expected plain body"); assert_false(test.has_html_body(), "Expected non-html body"); - assert_string( - HTML_CONVERSION_TEMPLATE.printf(BASIC_PLAIN_BODY), - test.get_plain_body(true, null) + assert_equal( + test.get_plain_body(true, null), + HTML_CONVERSION_TEMPLATE.printf(BASIC_PLAIN_BODY) ); } @@ -131,7 +131,7 @@ This is the second line. assert_true(test.has_html_body(), "Expected html body"); assert_false(test.has_plain_body(), "Expected non-plain body"); - assert_string(BASIC_HTML_BODY, test.get_html_body(null)); + assert_equal(test.get_html_body(null), BASIC_HTML_BODY); } public void text_html_as_plain() throws GLib.Error { @@ -139,7 +139,7 @@ This is the second line. assert_true(test.has_html_body(), "Expected html body"); assert_false(test.has_plain_body(), "Expected non-plain body"); - assert_string(BASIC_HTML_BODY, test.get_html_body(null)); + assert_equal(test.get_html_body(null), BASIC_HTML_BODY); } public void tnef_extract_attachments() throws GLib.Error { @@ -155,7 +155,7 @@ This is the second line. assert_true(test.has_plain_body(), "Expected plain body"); assert_true(test.has_html_body(), "Expected html body"); - assert_string(BASIC_PLAIN_BODY, test.get_plain_body(false, null)); + assert_equal(test.get_plain_body(false, null), BASIC_PLAIN_BODY); } public void multipart_alternative_as_converted_html() throws GLib.Error { @@ -163,9 +163,9 @@ This is the second line. assert_true(test.has_plain_body(), "Expected plain body"); assert_true(test.has_html_body(), "Expected html body"); - assert_string( - HTML_CONVERSION_TEMPLATE.printf(BASIC_PLAIN_BODY), - test.get_plain_body(true, null) + assert_equal( + test.get_plain_body(true, null), + HTML_CONVERSION_TEMPLATE.printf(BASIC_PLAIN_BODY) ); } @@ -174,7 +174,7 @@ This is the second line. assert_true(test.has_plain_body(), "Expected plain body"); assert_true(test.has_html_body(), "Expected html body"); - assert_string(BASIC_HTML_BODY, test.get_html_body(null)); + assert_equal(test.get_html_body(null), BASIC_HTML_BODY); } public void get_preview() throws GLib.Error { @@ -434,21 +434,21 @@ This is the second line. string expected) throws GLib.Error { assert_non_null(actual, expected); - assert_string(expected, actual.to_string()); + assert_equal(actual.to_string(), expected); } private void assert_address(Geary.RFC822.MailboxAddress? address, string expected) throws GLib.Error { assert_non_null(address, expected); - assert_string(expected, address.to_rfc822_string()); + assert_equal(address.to_rfc822_string(), expected); } private void assert_addresses(Geary.RFC822.MailboxAddresses? addresses, string expected) throws GLib.Error { assert_non_null(addresses, expected); - assert_string(expected, addresses.to_rfc822_string()); + assert_equal(addresses.to_rfc822_string(), expected); } private void assert_addresses_list(Gee.List? addresses, @@ -466,7 +466,7 @@ This is the second line. string expected) throws GLib.Error { assert_non_null(ids, "ids are null"); - assert_string(expected, ids.to_rfc822_string()); + assert_equal(ids.to_rfc822_string(), expected); } // Courtesy Mailsploit https://www.mailsploit.com diff --git a/test/engine/rfc822/rfc822-part-test.vala b/test/engine/rfc822/rfc822-part-test.vala index 933d1505..d6c90333 100644 --- a/test/engine/rfc822/rfc822-part-test.vala +++ b/test/engine/rfc822/rfc822-part-test.vala @@ -26,8 +26,8 @@ class Geary.RFC822.PartTest : TestCase { public void new_from_minimal_mime_part() throws GLib.Error { Part test = new Part(new_part("test/plain", CR_BODY.data)); - assert_null_string(test.content_id, "content_id"); - assert_null_string(test.content_description, "content_description"); + assert_null(test.content_id, "content_id"); + assert_null(test.content_description, "content_description"); assert_null(test.content_disposition, "content_disposition"); } @@ -48,13 +48,12 @@ class Geary.RFC822.PartTest : TestCase { Part test = new Part(part); - assert_string(TYPE, test.content_type.to_string()); - assert_string(ID, test.content_id); - assert_string(DESC, test.content_description); + assert_equal(test.content_type.to_string(), TYPE); + assert_equal(test.content_id, ID); + assert_equal(test.content_description, DESC); assert_non_null(test.content_disposition, "content_disposition"); - assert_int( - Geary.Mime.DispositionType.INLINE, - test.content_disposition.disposition_type + assert_equal( + test.content_disposition.disposition_type, INLINE ); } @@ -63,7 +62,7 @@ class Geary.RFC822.PartTest : TestCase { Memory.Buffer buf = test.write_to_buffer(Part.EncodingConversion.NONE); - assert_string(CR_BODY, buf.to_string()); + assert_equal(buf.to_string(), CR_BODY); } public void write_to_buffer_plain_crlf() throws GLib.Error { @@ -72,7 +71,7 @@ class Geary.RFC822.PartTest : TestCase { Memory.Buffer buf = test.write_to_buffer(Part.EncodingConversion.NONE); // CRLF should be stripped - assert_string(CR_BODY, buf.to_string()); + assert_equal(buf.to_string(), CR_BODY); } public void write_to_buffer_plain_ical() throws GLib.Error { @@ -81,7 +80,7 @@ class Geary.RFC822.PartTest : TestCase { Memory.Buffer buf = test.write_to_buffer(Part.EncodingConversion.NONE); // CRLF should not be stripped - assert_string(ICAL_BODY, buf.to_string()); + assert_equal(buf.to_string(), ICAL_BODY); } public void write_to_buffer_plain_utf8() throws GLib.Error { @@ -89,7 +88,7 @@ class Geary.RFC822.PartTest : TestCase { Memory.Buffer buf = test.write_to_buffer(Part.EncodingConversion.NONE); - assert_string(UTF8_BODY, buf.to_string()); + assert_equal(buf.to_string(), UTF8_BODY); } private GMime.Part new_part(string? mime_type, diff --git a/test/engine/util-ascii-test.vala b/test/engine/util-ascii-test.vala index 483e030a..56e98cd7 100644 --- a/test/engine/util-ascii-test.vala +++ b/test/engine/util-ascii-test.vala @@ -14,31 +14,31 @@ class Geary.Ascii.Test : TestCase { } public void index_of() throws Error { - assert_int(-1, Ascii.index_of("", 'a')); - assert_int(0, Ascii.index_of("a", 'a')); - assert_int(0, Ascii.index_of("aa", 'a')); + assert_equal(Ascii.index_of("", 'a'), -1); + assert_equal(Ascii.index_of("a", 'a'), 0); + assert_equal(Ascii.index_of("aa", 'a'), 0); - assert_int(0, Ascii.index_of("abcabc", 'a')); - assert_int(1, Ascii.index_of("abcabc", 'b')); - assert_int(2, Ascii.index_of("abcabc", 'c')); + assert_equal(Ascii.index_of("abcabc", 'a'), 0); + assert_equal(Ascii.index_of("abcabc", 'b'), 1); + assert_equal(Ascii.index_of("abcabc", 'c'), 2); - assert_int(0, Ascii.index_of("@", '@')); + assert_equal(Ascii.index_of("@", '@'), 0); - assert_int(-1, Ascii.index_of("abc", 'd')); + assert_equal(Ascii.index_of("abc", 'd'), -1); } public void last_index_of() throws Error { - assert_int(-1, Ascii.last_index_of("", 'a')); - assert_int(0, Ascii.last_index_of("a", 'a')); - assert_int(1, Ascii.last_index_of("aa", 'a')); + assert_equal(Ascii.last_index_of("", 'a'), -1); + assert_equal(Ascii.last_index_of("a", 'a'), 0); + assert_equal(Ascii.last_index_of("aa", 'a'), 1); - assert_int(3, Ascii.last_index_of("abcabc", 'a')); - assert_int(4, Ascii.last_index_of("abcabc", 'b')); - assert_int(5, Ascii.last_index_of("abcabc", 'c')); + assert_equal(Ascii.last_index_of("abcabc", 'a'), 3); + assert_equal(Ascii.last_index_of("abcabc", 'b'), 4); + assert_equal(Ascii.last_index_of("abcabc", 'c'), 5); - assert_int(0, Ascii.last_index_of("@", '@')); + assert_equal(Ascii.last_index_of("@", '@'), 0); - assert_int(-1, Ascii.last_index_of("abc", 'd')); + assert_equal(Ascii.last_index_of("abc", 'd'), -1); } } diff --git a/test/engine/util-config-file-test.vala b/test/engine/util-config-file-test.vala index 7cf3e849..40509161 100644 --- a/test/engine/util-config-file-test.vala +++ b/test/engine/util-config-file-test.vala @@ -42,8 +42,12 @@ class Geary.ConfigFileTest : TestCase { public void test_string() throws Error { this.test_group.set_string(TEST_KEY, "a string"); - assert_string("a string", this.test_group.get_string(TEST_KEY)); - assert_string("default", this.test_group.get_string(TEST_KEY_MISSING, "default")); + assert_equal( + this.test_group.get_string(TEST_KEY), "a string" + ); + assert_equal( + this.test_group.get_string(TEST_KEY_MISSING, "default"), "default" + ); } public void test_string_fallback() throws Error { @@ -51,7 +55,7 @@ class Geary.ConfigFileTest : TestCase { fallback.set_string("fallback-test-key", "a string"); this.test_group.set_fallback("fallback", "fallback-"); - assert_string("a string", this.test_group.get_string(TEST_KEY)); + assert_equal(this.test_group.get_string(TEST_KEY), "a string"); } public void test_string_list() throws Error { @@ -60,12 +64,12 @@ class Geary.ConfigFileTest : TestCase { ); Gee.List saved = this.test_group.get_string_list(TEST_KEY); - assert_int(2, saved.size, "Saved string list"); - assert_string("a", saved[0]); - assert_string("b", saved[1]); + assert_collection( + saved, "Saved string list" + ).first_is("a").at_index_is(1, "b"); Gee.List def = this.test_group.get_string_list(TEST_KEY_MISSING); - assert_int(0, def.size, "Default string list"); + assert_collection(def, "Default string list").is_empty(); } public void test_bool() throws Error { @@ -77,14 +81,14 @@ class Geary.ConfigFileTest : TestCase { public void test_int() throws Error { this.test_group.set_int(TEST_KEY, 42); - assert_int(42, this.test_group.get_int(TEST_KEY)); - assert_int(42, this.test_group.get_int(TEST_KEY_MISSING, 42)); + assert_equal(this.test_group.get_int(TEST_KEY), 42); + assert_equal(this.test_group.get_int(TEST_KEY_MISSING, 42), 42); } public void test_uint16() throws Error { this.test_group.set_uint16(TEST_KEY, 42); - assert_int(42, this.test_group.get_uint16(TEST_KEY)); - assert_int(42, this.test_group.get_uint16(TEST_KEY_MISSING, 42)); + assert_equal(this.test_group.get_uint16(TEST_KEY), 42); + assert_equal(this.test_group.get_uint16(TEST_KEY_MISSING, 42), 42); } public void test_has_key() throws Error { diff --git a/test/engine/util-html-test.vala b/test/engine/util-html-test.vala index b59230de..dc6501aa 100644 --- a/test/engine/util-html-test.vala +++ b/test/engine/util-html-test.vala @@ -21,60 +21,60 @@ class Geary.HTML.UtilTest : TestCase { } public void preserve_whitespace() throws GLib.Error { - assert_string("some text", Geary.HTML.smart_escape("some text")); - assert_string("some  text", Geary.HTML.smart_escape("some text")); - assert_string("some   text", Geary.HTML.smart_escape("some text")); - assert_string("some    text", Geary.HTML.smart_escape("some\ttext")); + assert_equal(smart_escape("some text"), "some text"); + assert_equal(smart_escape("some text"), "some  text"); + assert_equal(smart_escape("some text"), "some   text"); + assert_equal(smart_escape("some\ttext"), "some    text"); - assert_string("some
text", Geary.HTML.smart_escape("some\ntext")); - assert_string("some
text", Geary.HTML.smart_escape("some\rtext")); - assert_string("some
text", Geary.HTML.smart_escape("some\r\ntext")); + assert_equal(smart_escape("some\ntext"), "some
text"); + assert_equal(smart_escape("some\rtext"), "some
text"); + assert_equal(smart_escape("some\r\ntext"), "some
text"); - assert_string("some

text", Geary.HTML.smart_escape("some\n\ntext")); - assert_string("some

text", Geary.HTML.smart_escape("some\r\rtext")); - assert_string("some

text", Geary.HTML.smart_escape("some\n\rtext")); - assert_string("some

text", Geary.HTML.smart_escape("some\r\n\r\ntext")); + assert_equal(smart_escape("some\n\ntext"), "some

text"); + assert_equal(smart_escape("some\r\rtext"), "some

text"); + assert_equal(smart_escape("some\n\rtext"), "some

text"); + assert_equal(smart_escape("some\r\n\r\ntext"), "some

text"); } public void smart_escape_div() throws Error { string html = "
ohhai
"; - assert(Geary.HTML.smart_escape(html) == html); + assert_equal(smart_escape(html), html); } public void smart_escape_no_closing_tag() throws Error { string html = "
ohhai"; - assert(Geary.HTML.smart_escape(html) == html); + assert_equal(smart_escape(html), html); } public void smart_escape_img() throws Error { string html = ""; - assert(Geary.HTML.smart_escape(html) == html); + assert_equal(smart_escape(html), html); } public void smart_escape_xhtml_img() throws Error { string html = ""; - assert(Geary.HTML.smart_escape(html) == html); + assert_equal(smart_escape(html), html); } public void smart_escape_mixed() throws Error { string html = "mixed
ohhai
text"; - assert(Geary.HTML.smart_escape(html) == html); + assert_equal(smart_escape(html), html); } public void smart_escape_text() throws GLib.Error { - assert_string("some text", Geary.HTML.smart_escape("some text")); - assert_string("<some text", Geary.HTML.smart_escape("")); + assert_equal(smart_escape("some text"), "some text"); + assert_equal(smart_escape(""), "some text>"); } public void smart_escape_text_url() throws GLib.Error { - assert_string( - "<http://example.com>", - Geary.HTML.smart_escape("") + assert_equal( + smart_escape(""), + "<http://example.com>" ); - assert_string( - "<http://example.com>", - Geary.HTML.smart_escape("") + assert_equal( + smart_escape(""), + "<http://example.com>" ); } @@ -94,13 +94,13 @@ px; }