michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Utilities to wrap gtest, based on libjingle's gunit michael@0: michael@0: // Some sections of this code are under the following license: michael@0: michael@0: /* michael@0: * libjingle michael@0: * Copyright 2004--2008, Google Inc. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions are met: michael@0: * michael@0: * 1. Redistributions of source code must retain the above copyright notice, michael@0: * this list of conditions and the following disclaimer. michael@0: * 2. Redistributions in binary form must reproduce the above copyright notice, michael@0: * this list of conditions and the following disclaimer in the documentation michael@0: * and/or other materials provided with the distribution. michael@0: * 3. The name of the author may not be used to endorse or promote products michael@0: * derived from this software without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED michael@0: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF michael@0: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO michael@0: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; michael@0: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, michael@0: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR michael@0: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF michael@0: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: // Original author: ekr@rtfm.com michael@0: #ifndef gtest_utils_h__ michael@0: #define gtest_utils_h__ michael@0: michael@0: #include michael@0: michael@0: #include "nspr.h" michael@0: #include "prinrval.h" michael@0: #include "prthread.h" michael@0: michael@0: #define GTEST_HAS_RTTI 0 michael@0: #include "gtest/gtest.h" michael@0: michael@0: // Wait up to timeout seconds for expression to be true michael@0: #define WAIT(expression, timeout) \ michael@0: do { \ michael@0: for (PRIntervalTime start = PR_IntervalNow(); !(expression) && \ michael@0: ! ((PR_IntervalNow() - start) > PR_MillisecondsToInterval(timeout));) \ michael@0: PR_Sleep(10); \ michael@0: } while(0) michael@0: michael@0: // Same as GTEST_WAIT, but stores the result in res. Used when michael@0: // you also want the result of expression but wish to avoid michael@0: // double evaluation. michael@0: #define WAIT_(expression, timeout, res) \ michael@0: do { \ michael@0: for (PRIntervalTime start = PR_IntervalNow(); !(res = (expression)) && \ michael@0: ! ((PR_IntervalNow() - start) > PR_MillisecondsToInterval(timeout));) \ michael@0: PR_Sleep(10); \ michael@0: } while(0) michael@0: michael@0: #define ASSERT_TRUE_WAIT(expression, timeout) \ michael@0: do { \ michael@0: bool res; \ michael@0: WAIT_(expression, timeout, res); \ michael@0: ASSERT_TRUE(res); \ michael@0: } while(0); michael@0: michael@0: #define EXPECT_TRUE_WAIT(expression, timeout) \ michael@0: do { \ michael@0: bool res; \ michael@0: WAIT_(expression, timeout, res); \ michael@0: EXPECT_TRUE(res); \ michael@0: } while(0); michael@0: michael@0: #endif michael@0: michael@0: michael@0: