1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/mtransport/test/gtest_utils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +// Utilities to wrap gtest, based on libjingle's gunit 1.11 + 1.12 +// Some sections of this code are under the following license: 1.13 + 1.14 +/* 1.15 + * libjingle 1.16 + * Copyright 2004--2008, Google Inc. 1.17 + * 1.18 + * Redistribution and use in source and binary forms, with or without 1.19 + * modification, are permitted provided that the following conditions are met: 1.20 + * 1.21 + * 1. Redistributions of source code must retain the above copyright notice, 1.22 + * this list of conditions and the following disclaimer. 1.23 + * 2. Redistributions in binary form must reproduce the above copyright notice, 1.24 + * this list of conditions and the following disclaimer in the documentation 1.25 + * and/or other materials provided with the distribution. 1.26 + * 3. The name of the author may not be used to endorse or promote products 1.27 + * derived from this software without specific prior written permission. 1.28 + * 1.29 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 1.30 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1.31 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 1.32 + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.33 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.34 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 1.35 + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 1.36 + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 1.37 + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 1.38 + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.39 + */ 1.40 + 1.41 +// Original author: ekr@rtfm.com 1.42 +#ifndef gtest_utils_h__ 1.43 +#define gtest_utils_h__ 1.44 + 1.45 +#include <iostream> 1.46 + 1.47 +#include "nspr.h" 1.48 +#include "prinrval.h" 1.49 +#include "prthread.h" 1.50 + 1.51 +#define GTEST_HAS_RTTI 0 1.52 +#include "gtest/gtest.h" 1.53 + 1.54 +// Wait up to timeout seconds for expression to be true 1.55 +#define WAIT(expression, timeout) \ 1.56 + do { \ 1.57 + for (PRIntervalTime start = PR_IntervalNow(); !(expression) && \ 1.58 + ! ((PR_IntervalNow() - start) > PR_MillisecondsToInterval(timeout));) \ 1.59 + PR_Sleep(10); \ 1.60 + } while(0) 1.61 + 1.62 +// Same as GTEST_WAIT, but stores the result in res. Used when 1.63 +// you also want the result of expression but wish to avoid 1.64 +// double evaluation. 1.65 +#define WAIT_(expression, timeout, res) \ 1.66 + do { \ 1.67 + for (PRIntervalTime start = PR_IntervalNow(); !(res = (expression)) && \ 1.68 + ! ((PR_IntervalNow() - start) > PR_MillisecondsToInterval(timeout));) \ 1.69 + PR_Sleep(10); \ 1.70 + } while(0) 1.71 + 1.72 +#define ASSERT_TRUE_WAIT(expression, timeout) \ 1.73 + do { \ 1.74 + bool res; \ 1.75 + WAIT_(expression, timeout, res); \ 1.76 + ASSERT_TRUE(res); \ 1.77 + } while(0); 1.78 + 1.79 +#define EXPECT_TRUE_WAIT(expression, timeout) \ 1.80 + do { \ 1.81 + bool res; \ 1.82 + WAIT_(expression, timeout, res); \ 1.83 + EXPECT_TRUE(res); \ 1.84 + } while(0); 1.85 + 1.86 +#endif 1.87 + 1.88 + 1.89 +