--- /dev/null
+Copyright 2008, Google Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+ * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%define crosswalk_extensions tizen-extensions-crosswalk
%define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions}
+%define tizen_ut_build 0
+
Name: webapi-plugins
-Version: 2.49
+Version: 2.65
Release: 0
License: Apache-2.0 and BSD-3-Clause and MIT
Group: Development/Libraries
GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_path}"
+# ut flags
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}"
+
# feature flags
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_mobile_feature_account_support}"
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_alarm_support=%{?tizen_mobile_feature_alarm_support}"
GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_path}"
+# ut flags
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}"
+
# feature flags
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_mobile_feature_account_support}"
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_alarm_support=%{?tizen_mobile_feature_alarm_support}"
GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_path}"
+# ut flags
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}"
+
# feature flags
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_wearable_feature_account_support}"
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_alarm_support=%{?tizen_wearable_feature_alarm_support}"
GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_path}"
+# ut flags
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}"
+
# feature flags
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_wearable_feature_account_support}"
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_alarm_support=%{?tizen_wearable_feature_alarm_support}"
GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_path}"
+# ut flags
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}"
+
# feature flags
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_tv_feature_account_support}"
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_alarm_support=%{?tizen_tv_feature_alarm_support}"
GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_path}"
+# ut flags
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}"
+
# feature flags
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_common_feature_account_support}"
GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_alarm_support=%{?tizen_common_feature_alarm_support}"
%if "%{?unified_build}" == "1" || "%{?profile}" == "mobile"
mkdir -p %{buildroot}%{crosswalk_extensions_path}/mobile
+
+# tizen ut mobile
+%if "%{?tizen_ut_build}" == "1"
+mkdir -p %{buildroot}/usr/bin
+install -p -m 755 out/bin_mobile/webapi_common_tests %{buildroot}/usr/bin/
+%endif
+
install -p -m 644 out/bin_mobile/libtizen*.so %{buildroot}%{crosswalk_extensions_path}/mobile
# execute desc_gentool
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:%{buildroot}%{crosswalk_extensions_path}/mobile out/Default/desc_gentool \
# devel files
mkdir -p %{buildroot}%{_libdir}/pkgconfig
-sed -i s,__LIB_DIR__,%{crosswalk_extensions_path},g packaging/%{name}.pc.in
-sed -i s,__INCLUDE_DIR__,%{_includedir}/%{name}/src,g packaging/%{name}.pc.in
cp packaging/%{name}.pc.in %{buildroot}%{_libdir}/pkgconfig/%{name}.pc
+sed -i s,__LIB_DIR__,%{crosswalk_extensions_path},g %{buildroot}%{_libdir}/pkgconfig/%{name}.pc
+sed -i s,__INCLUDE_DIR__,%{_includedir}/%{name}/src,g %{buildroot}%{_libdir}/pkgconfig/%{name}.pc
mkdir -p %{buildroot}%{_includedir}/%{name}/src/common
mkdir -p %{buildroot}%{_includedir}/%{name}/src/common/filesystem
install -p -m 644 src/common/*.h %{buildroot}%{_includedir}/%{name}/src/common
mkdir -p %{buildroot}%{_includedir}/%{name}/tools
install -p -m 644 tools/generate_api.py %{buildroot}%{_includedir}/%{name}/tools
install -p -m 644 tools/mergejs.py %{buildroot}%{_includedir}/%{name}/tools
-install -p -m 644 tools/js_minimize.py %{buildroot}%{_includedir}/%{name}/tools
cp -a tools/gyp %{buildroot}%{_includedir}/%{name}/tools/gyp
cp -a tools/slimit %{buildroot}%{_includedir}/%{name}/tools/slimit
cp -a out/Default/desc_gentool %{buildroot}%{_includedir}/%{name}/tools/desc_gentool
%{crosswalk_extensions_path}/mobile/plugins.json
%manifest webapi-plugins.manifest
+# UT files
+%if "%{?tizen_ut_build}" == "1"
+%license GTEST.BSD-3-Clause
+/usr/bin/webapi_common_tests
+%endif
+
# mobile-extension-emulator
%ifarch %{ix86} x86_64
%post mobile-extension-emulator
);
}
- var result = native_.callSync('Account_setExtendedData', {
+ var result = native_.callSync('AccountSetExtendedData', {
accountId: this.id,
key: args.key,
value: args.value
}
var result = native_.call(
- 'Account_getExtendedData',
+ 'AccountGetExtendedData',
{ accountId: this.id },
function(result) {
if (native_.isFailure(result)) {
);
}
- var result = native_.callSync('Account_getExtendedDataSync', {
+ var result = native_.callSync('AccountGetExtendedDataSync', {
accountId: this.id,
key: args.key
});
{ name: 'account', type: types_.PLATFORM_OBJECT, values: Account }
]);
- var result = native_.callSync('AccountManager_add', {
+ var result = native_.callSync('AccountManagerAdd', {
userName: args.account.userName,
iconUri: args.account.iconUri,
applicationId: args.account.provider.applicationId
{ name: 'accountId', type: types_.UNSIGNED_LONG }
]);
- var result = native_.callSync('AccountManager_remove', { accountId: args.accountId });
+ var result = native_.callSync('AccountManagerRemove', { accountId: args.accountId });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
{ name: 'account', type: types_.PLATFORM_OBJECT, values: Account }
]);
- var result = native_.callSync('AccountManager_update', {
+ var result = native_.callSync('AccountManagerUpdate', {
accountId: args.account.id,
userName: args.account.userName,
iconUri: args.account.iconUri
{ name: 'accountId', type: types_.UNSIGNED_LONG }
]);
- var result = native_.callSync('AccountManager_getAccount', {
+ var result = native_.callSync('AccountManagerGetAccount', {
accountId: args.accountId
});
]);
var result = native_.call(
- 'AccountManager_getAccounts',
+ 'AccountManagerGetAccounts',
{
applicationId: args.applicationId
},
{ name: 'applicationId', type: types_.STRING }
]);
- var result = native_.callSync('AccountManager_getProvider', {
+ var result = native_.callSync('AccountManagerGetProvider', {
applicationId: args.applicationId
});
]);
var result = native_.call(
- 'AccountManager_getProviders',
+ 'AccountManagerGetProviders',
{
capability: args.capability
},
var id = ++this.nextID;
if (T_.isEmptyObject(this.instances)) {
- var result = native_.callSync('AccountManager_addAccountListener');
+ var result = native_.callSync('AccountManagerAddAccountListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
if (T_.isEmptyObject(this.instances)) {
native_.removeListener(ACCOUNT_LISTENER, this.appCallback);
- var result = native_.callSync('AccountManager_removeAccountListener');
+ var result = native_.callSync('AccountManagerRemoveAccountListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&AccountInstance::x, this, _1, _2));
- REGISTER_ASYNC("AccountManager_getAccounts", AccountManagerGetAccounts);
- REGISTER_ASYNC("AccountManager_getProviders", AccountManagerGetProviders);
- REGISTER_ASYNC("Account_getExtendedData", AccountGetExtendedData);
-#undef REGISTER_ASYNC
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&AccountInstance::x, this, _1, _2));
- REGISTER_SYNC("AccountManager_removeAccountListener", AccountManagerRemoveAccountListener);
- REGISTER_SYNC("AccountManager_update", AccountManagerUpdate);
- REGISTER_SYNC("AccountManager_remove", AccountManagerRemove);
- REGISTER_SYNC("AccountManager_getAccount", AccountManagerGetAccount);
- REGISTER_SYNC("AccountManager_getProvider", AccountManagerGetProvider);
- REGISTER_SYNC("AccountManager_addAccountListener", AccountManagerAddAccountListener);
- REGISTER_SYNC("AccountManager_add", AccountManagerAdd);
- REGISTER_SYNC("Account_setExtendedData", AccountSetExtendedData);
- REGISTER_SYNC("Account_getExtendedDataSync", AccountGetExtendedDataSync);
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&AccountInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(AccountManagerGetAccounts);
+ REGISTER_METHOD(AccountManagerGetProviders);
+ REGISTER_METHOD(AccountGetExtendedData);
+
+ REGISTER_METHOD(AccountManagerRemoveAccountListener);
+ REGISTER_METHOD(AccountManagerUpdate);
+ REGISTER_METHOD(AccountManagerRemove);
+ REGISTER_METHOD(AccountManagerGetAccount);
+ REGISTER_METHOD(AccountManagerGetProvider);
+ REGISTER_METHOD(AccountManagerAddAccountListener);
+ REGISTER_METHOD(AccountManagerAdd);
+ REGISTER_METHOD(AccountSetExtendedData);
+ REGISTER_METHOD(AccountGetExtendedDataSync);
+
+#undef REGISTER_METHOD
}
AccountInstance::~AccountInstance() {
callArgs.seconds = Converter.toString(seconds);
callArgs.isPeriodSet = !T.isNullOrUndefined(args.alarm.period);
- var result = native.callSync('AlarmManager_add', callArgs);
+ var result = native.callSync('AlarmManagerAdd', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
} else {
//add marker for UserNotification implementation
callArgs.newImpl = callArgs.notification instanceof tizen.UserNotification;
- var result = native.callSync('AlarmManager_addAlarmNotification', callArgs);
+ var result = native.callSync('AlarmManagerAddAlarmNotification', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
} else {
}
]);
- var result = native.callSync('AlarmManager_remove', { id: Number(args.id) });
+ var result = native.callSync('AlarmManagerRemove', { id: Number(args.id) });
if (native.isFailure(result)) {
throw native.getErrorObject(result);
};
AlarmManager.prototype.removeAll = function() {
- var result = native.callSync('AlarmManager_removeAll', {});
+ var result = native.callSync('AlarmManagerRemoveAll', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
]);
- var result = native.callSync('AlarmManager_get', { id: Number(args.id) });
+ var result = native.callSync('AlarmManagerGet', { id: Number(args.id) });
if (native.isFailure(result)) {
throw native.getErrorObject(result);
function _prepareDetailInfo(noti) {
if (!noti || !noti.textContents || !noti.textContents.detailInfo) {
- console.log('Do nothing - detailInfo is NOT present');
+ privUtils_.log('Do nothing - detailInfo is NOT present');
return;
}
var detailInfo = noti.textContents.detailInfo;
}
]);
- var result = native.callSync('AlarmManager_getAlarmNotification', {
+ var result = native.callSync('AlarmManagerGetAlarmNotification', {
id: Number(args.id)
});
};
AlarmManager.prototype.getAll = function() {
- var result = native.callSync('AlarmManager_getAll', {});
+ var result = native.callSync('AlarmManagerGetAll', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
tizen.AlarmRelative.prototype.constructor = tizen.AlarmRelative;
tizen.AlarmRelative.prototype.getRemainingSeconds = function() {
- var result = native.callSync('AlarmRelative_getRemainingSeconds', {
+ var result = native.callSync('AlarmManagerGetRemainingSeconds', {
id: Number(this.id)
});
if (_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated) {
privUtils_.warn(
'Since Tizen 4.0 constructor AlarmAbsolute(Date date, ' +
- 'long period) is deprecated, thus period attribute ' +
- 'should not be used.'
+ 'long period) is deprecated, thus period attribute should ' +
+ 'not be used.'
);
}
return m_period;
if (_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated) {
privUtils_.warn(
'Since Tizen 4.0 constructor AlarmAbsolute(Date date, ' +
- 'long period) is deprecated, thus period attribute ' +
- 'should not be used.'
+ 'long period) is deprecated, thus period attribute should ' +
+ 'not be used.'
);
}
tizen.AlarmAbsolute.prototype.constructor = tizen.AlarmAbsolute;
tizen.AlarmAbsolute.prototype.getNextScheduledDate = function() {
- var result = native.callSync('AlarmAbsolute_getNextScheduledDate', {
+ var result = native.callSync('AlarmManagerGetNextScheduledDate', {
id: Number(this.id)
});
ScopeLogger();
using namespace std::placeholders;
- RegisterSyncHandler("AlarmManager_add", std::bind(&AlarmManager::Add, &manager_, _1, _2));
- RegisterSyncHandler("AlarmManager_remove", std::bind(&AlarmManager::Remove, &manager_, _1, _2));
- RegisterSyncHandler("AlarmManager_removeAll",
- std::bind(&AlarmManager::RemoveAll, &manager_, _1, _2));
- RegisterSyncHandler("AlarmManager_get", std::bind(&AlarmManager::Get, &manager_, _1, _2));
- RegisterSyncHandler("AlarmManager_getAll", std::bind(&AlarmManager::GetAll, &manager_, _1, _2));
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&AlarmInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(AlarmManagerAdd);
+ REGISTER_METHOD(AlarmManagerRemove);
+ REGISTER_METHOD(AlarmManagerRemoveAll);
+ REGISTER_METHOD(AlarmManagerGet);
+ REGISTER_METHOD(AlarmManagerGetAll);
+
// AlarmRelative
- RegisterSyncHandler("AlarmRelative_getRemainingSeconds",
- std::bind(&AlarmManager::GetRemainingSeconds, &manager_, _1, _2));
+ REGISTER_METHOD(AlarmManagerGetRemainingSeconds);
+
// AlarmAbsolute
- RegisterSyncHandler("AlarmAbsolute_getNextScheduledDate",
- std::bind(&AlarmManager::GetNextScheduledDate, &manager_, _1, _2));
+ REGISTER_METHOD(AlarmManagerGetNextScheduledDate);
// Block of code related to Notification
#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
- RegisterSyncHandler("AlarmManager_addAlarmNotification",
- std::bind(&AlarmManager::AddAlarmNotification, &manager_, _1, _2));
- RegisterSyncHandler("AlarmManager_getAlarmNotification",
- std::bind(&AlarmManager::GetAlarmNotification, &manager_, _1, _2));
-#endif
+ REGISTER_METHOD(AlarmManagerAddAlarmNotification);
+ REGISTER_METHOD(AlarmManagerGetAlarmNotification);
+#endif // TIZEN_MOBILE or TIZEN_WEARABLE
+
+#undef REGISTER_METHOD
}
AlarmInstance::~AlarmInstance() {
ScopeLogger();
}
+void AlarmInstance::AlarmManagerAdd(const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ manager_.Add(args, out);
+}
+
+void AlarmInstance::AlarmManagerRemove(const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ manager_.Remove(args, out);
+}
+
+void AlarmInstance::AlarmManagerRemoveAll(const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ manager_.RemoveAll(args, out);
+}
+
+void AlarmInstance::AlarmManagerGet(const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ manager_.Get(args, out);
+}
+
+void AlarmInstance::AlarmManagerGetAll(const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ manager_.GetAll(args, out);
+}
+
+#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
+void AlarmInstance::AlarmManagerAddAlarmNotification(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ manager_.AddAlarmNotification(args, out);
+}
+
+void AlarmInstance::AlarmManagerGetAlarmNotification(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ manager_.GetAlarmNotification(args, out);
+}
+#endif // TIZEN_MOBILE or TIZEN_WEARABLE
+
+void AlarmInstance::AlarmManagerGetRemainingSeconds(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ manager_.GetRemainingSeconds(args, out);
+}
+
+void AlarmInstance::AlarmManagerGetNextScheduledDate(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ manager_.GetNextScheduledDate(args, out);
+}
+
} // namespace Alarm
} // namespace extension
AlarmInstance();
virtual ~AlarmInstance();
+ void AlarmManagerAdd(const picojson::value& args, picojson::object& out);
+ void AlarmManagerRemove(const picojson::value& args, picojson::object& out);
+ void AlarmManagerRemoveAll(const picojson::value& args, picojson::object& out);
+ void AlarmManagerGet(const picojson::value& args, picojson::object& out);
+ void AlarmManagerGetAll(const picojson::value& args, picojson::object& out);
+ void AlarmManagerAddAlarmNotification(const picojson::value& args, picojson::object& out);
+ void AlarmManagerGetAlarmNotification(const picojson::value& args, picojson::object& out);
+ void AlarmManagerGetRemainingSeconds(const picojson::value& args, picojson::object& out);
+ void AlarmManagerGetNextScheduledDate(const picojson::value& args, picojson::object& out);
+
private:
AlarmManager manager_;
};
return;
}
} else {
- app_control_create(&app_control);
- app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
+ int ret = app_control_create(&app_control);
+
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "app_control_create() failed."),
+ &out,
+ ("app_control_create() failed: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+ ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::UNKNOWN_ERR, "app_control_set_operation() failed."), &out,
+ ("app_control_set_operation() failed: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
}
app_control_set_app_id(app_control, app_id.c_str());
};
if (ALARM_ERROR_NONE != alarm_get_app_control(id, &app_control)) {
+ // This is a special kind of alarm, which has the notification instead of an app_control handle.
+ // In case of error during app_control gathering, we check if it has notification. If both calls
+ // end with error, then we report NOT_FOUND_ERROR
if (ALARM_ERROR_NONE != alarm_get_notification(id, ¬ification_handle)) {
return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Alarm not found.",
("Alarm not found: %d (%s)", ret, get_error_message(ret)));
var ApplicationManager = function() {};
ApplicationManager.prototype.getCurrentApplication = function() {
- var result = native.callSync('ApplicationManager_getCurrentApplication', {});
+ var result = native.callSync('ApplicationManagerGetCurrentApplication', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
};
var result = native.call(
- 'ApplicationManager_kill',
+ 'ApplicationManagerKill',
{ contextId: args.contextId },
callback
);
}
};
- var result = native.call('ApplicationManager_launch', { id: args.id }, callback);
-
+ var result = native.call('ApplicationManagerLaunch', { id: args.id }, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
native.addListener(replyCallbackId, registeredReplyCallback);
}
- var result = native.call('ApplicationManager_launchAppControl', callArgs, callback);
+ var result = native.call('ApplicationManagerLaunchAppControl', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
};
var callArgs = { appControl: args.appControl };
- var result = native.call('ApplicationManager_findAppControl', callArgs, callback);
+ var result = native.call('ApplicationManagerFindAppControl', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
- var result = native.call('ApplicationManager_getAppsContext', {}, callback);
+ var result = native.call('ApplicationManagerGetAppsContext', {}, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.contextId = args.contextId;
}
- var result = native.callSync('ApplicationManager_getAppContext', callArgs);
+ var result = native.callSync('ApplicationManagerGetAppContext', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
- var result = native.call('ApplicationManager_getAppsInfo', {}, callback);
+ var result = native.call('ApplicationManagerGetAppsInfo', {}, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.id = args.id;
}
- var result = native.callSync('ApplicationManager_getAppInfo', callArgs);
+ var result = native.callSync('ApplicationManagerGetAppInfo', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.id = args.id;
}
- var result = native.callSync('ApplicationManager_getAppCerts', callArgs);
+ var result = native.callSync('ApplicationManagerGetAppCerts', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.id = args.id;
}
- var result = native.callSync('ApplicationManager_getAppSharedURI', callArgs);
+ var result = native.callSync('ApplicationManagerGetAppSharedURI', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.id = args.id;
}
- var result = native.callSync('ApplicationManager_getAppMetaData', callArgs);
+ var result = native.callSync('ApplicationManagerGetAppMetaData', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
};
var result = native.call(
- 'ApplicationManager_getBatteryUsageInfo',
+ 'ApplicationManagerGetBatteryUsageInfo',
callArgs,
callback
);
}
};
- var result = native.call('ApplicationManager_getAppsUsageInfo', callArgs, callback);
+ var result = native.call('ApplicationManagerGetAppsUsageInfo', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
var id = this.nextId;
if (!this.nativeSet) {
this.native.addListener(this.listenerName, this.onListenerCalled.bind(this));
- var result = this.native.callSync('ApplicationManager_addAppInfoEventListener');
+ var result = this.native.callSync('ApplicationManagerAddAppInfoEventListener');
if (this.native.isFailure(result)) {
throw this.native.getErrorObject(result);
}
}
if (this.nativeSet && T.isEmptyObject(this.listeners)) {
- this.native.callSync('ApplicationManager_removeAppInfoEventListener');
+ this.native.callSync('ApplicationManagerRemoveAppInfoEventListener');
this.native.removeListener(this.listenerName);
this.nativeSet = false;
}
ApplicationManager.prototype.addAppInfoEventListener = function() {
privUtils_.warn(
- 'DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will ' +
- 'be removed from next release. ' +
+ 'DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be ' +
+ 'removed from next release. ' +
'Use tizen.package.setPackageInfoEventListener() instead.'
);
ApplicationManager.prototype.removeAppInfoEventListener = function() {
privUtils_.warn(
- 'DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will ' +
- 'be removed from next release. ' +
+ 'DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be ' +
+ 'removed from next release. ' +
'Use tizen.package.unsetPackageInfoEventListener() instead.'
);
StatusListenerManager.prototype.addListener = function(callback, appId) {
if (!this.nativeSet) {
var result = this.native.callSync(
- 'ApplicationManager_addAppStatusChangeListener'
+ 'ApplicationManagerAddStatusListener'
);
if (this.native.isFailure(result)) {
throw this.native.getErrorObject(result);
if (this.nativeSet) {
var result = this.native.callSync(
- 'ApplicationManager_removeStatusChangeListener'
+ 'ApplicationManagerRemoveStatusListener'
);
if (this.native.isFailure(result)) {
throw this.native.getErrorObject(result);
};
Application.prototype.getRequestedAppControl = function() {
- var result = native.callSync('Application_getRequestedAppControl', {});
+ var result = native.callSync('ApplicationGetRequestedAppControl', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
});
- var result = native.callSync('Application_addEventListener', data);
+ var result = native.callSync('ApplicationAddEventListener', data);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
if (!Object.keys(event_listeners_[eventName]).length) {
native.removeListener(eventName);
- var result = native.callSync('Application_removeEventListener', {
+ var result = native.callSync('ApplicationRemoveEventListener', {
name: eventName
});
if (native.isFailure(result)) {
data: args.data
};
- var result = native.callSync('Application_broadcastEvent', nativeData);
+ var result = native.callSync('ApplicationBroadcastEvent', nativeData);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
data: args.data
};
- var result = native.callSync('Application_broadcastTrustedEvent', nativeData);
+ var result = native.callSync('ApplicationBroadcastTrustedEvent', nativeData);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
function sizeGetter() {
if (undefined === size) {
var callArgs = { packageId: this.packageId }; // jshint ignore:line
- var result = native.callSync('ApplicationInformation_getSize', callArgs);
+ var result = native.callSync('ApplicationInformationGetSize', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.data = [];
}
- var result = native.callSync('RequestedApplicationControl_replyResult', callArgs);
+ var result = native.callSync('RequestedApplicationControlReplyResult', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
};
RequestedApplicationControl.prototype.replyFailure = function() {
- var result = native.callSync('RequestedApplicationControl_replyFailure', {});
+ var result = native.callSync('RequestedApplicationControlReplyFailure', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&ApplicationInstance::x, this, _1, _2));
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&ApplicationInstance::M, this, _1, _2))
+
// ApplicationManager
- REGISTER_SYNC("ApplicationManager_getCurrentApplication", GetCurrentApplication);
- REGISTER_SYNC("ApplicationManager_getAppContext", GetAppContext);
- REGISTER_SYNC("ApplicationManager_getAppInfo", GetAppInfo);
- REGISTER_SYNC("ApplicationManager_getAppCerts", GetAppCerts);
- REGISTER_SYNC("ApplicationManager_getAppSharedURI", GetAppSharedURI);
- REGISTER_SYNC("ApplicationManager_getAppMetaData", GetAppMetaData);
- REGISTER_SYNC("ApplicationManager_addAppInfoEventListener", AddAppInfoEventListener);
- REGISTER_SYNC("ApplicationManager_removeAppInfoEventListener", RemoveAppInfoEventListener);
- REGISTER_SYNC("ApplicationManager_addAppStatusChangeListener", AddStatusListener);
- REGISTER_SYNC("ApplicationManager_removeStatusChangeListener", RemoveStatusListener);
+ REGISTER_METHOD(ApplicationManagerGetCurrentApplication);
+ REGISTER_METHOD(ApplicationManagerGetAppContext);
+ REGISTER_METHOD(ApplicationManagerGetAppInfo);
+ REGISTER_METHOD(ApplicationManagerGetAppCerts);
+ REGISTER_METHOD(ApplicationManagerGetAppSharedURI);
+ REGISTER_METHOD(ApplicationManagerGetAppMetaData);
+ REGISTER_METHOD(ApplicationManagerAddAppInfoEventListener);
+ REGISTER_METHOD(ApplicationManagerRemoveAppInfoEventListener);
+ REGISTER_METHOD(ApplicationManagerAddStatusListener);
+ REGISTER_METHOD(ApplicationManagerRemoveStatusListener);
// Application
- REGISTER_SYNC("Application_getRequestedAppControl", GetRequestedAppControl);
- REGISTER_SYNC("Application_broadcastEvent", BroadcastEvent);
- REGISTER_SYNC("Application_broadcastTrustedEvent", BroadcastTrustedEvent);
- REGISTER_SYNC("Application_addEventListener", AddEventListener);
- REGISTER_SYNC("Application_removeEventListener", RemoveEventListener);
+ REGISTER_METHOD(ApplicationGetRequestedAppControl);
+ REGISTER_METHOD(ApplicationBroadcastEvent);
+ REGISTER_METHOD(ApplicationBroadcastTrustedEvent);
+ REGISTER_METHOD(ApplicationAddEventListener);
+ REGISTER_METHOD(ApplicationRemoveEventListener);
// RequestedApplicationControl
- REGISTER_SYNC("RequestedApplicationControl_replyResult", ReplyResult);
- REGISTER_SYNC("RequestedApplicationControl_replyFailure", ReplyFailure);
+ REGISTER_METHOD(RequestedApplicationControlReplyResult);
+ REGISTER_METHOD(RequestedApplicationControlReplyFailure);
// ApplicationInformation
- REGISTER_SYNC("ApplicationInformation_getSize", GetSize);
-#undef REGISTER_SYNC
+ REGISTER_METHOD(ApplicationInformationGetSize);
-#define REGISTER_ASYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&ApplicationInstance::x, this, _1, _2));
// ApplicationManager
- REGISTER_ASYNC("ApplicationManager_kill", Kill);
- REGISTER_ASYNC("ApplicationManager_launch", Launch);
- REGISTER_ASYNC("ApplicationManager_launchAppControl", LaunchAppControl);
- REGISTER_ASYNC("ApplicationManager_findAppControl", FindAppControl);
- REGISTER_ASYNC("ApplicationManager_getAppsContext", GetAppsContext);
- REGISTER_ASYNC("ApplicationManager_getAppsInfo", GetAppsInfo);
- REGISTER_ASYNC("ApplicationManager_getAppsUsageInfo", GetAppsUsageInfo);
- REGISTER_ASYNC("ApplicationManager_getBatteryUsageInfo", GetBatteryUsageInfo);
-#undef REGISTER_ASYNC
+ REGISTER_METHOD(ApplicationManagerKill);
+ REGISTER_METHOD(ApplicationManagerLaunch);
+ REGISTER_METHOD(ApplicationManagerLaunchAppControl);
+ REGISTER_METHOD(ApplicationManagerFindAppControl);
+ REGISTER_METHOD(ApplicationManagerGetAppsContext);
+ REGISTER_METHOD(ApplicationManagerGetAppsInfo);
+ REGISTER_METHOD(ApplicationManagerGetAppsUsageInfo);
+ REGISTER_METHOD(ApplicationManagerGetBatteryUsageInfo);
+
+#undef REGISTER_METHOD
}
ApplicationInstance::~ApplicationInstance() {
ScopeLogger();
}
-void ApplicationInstance::GetCurrentApplication(const picojson::value& args,
- picojson::object& out) {
+void ApplicationInstance::ApplicationManagerGetCurrentApplication(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.GetCurrentApplication(app_id_, &out);
}
-void ApplicationInstance::GetAppContext(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerGetAppContext(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.GetAppContext(args, &out);
}
-void ApplicationInstance::GetAppInfo(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerGetAppInfo(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
std::string app_id = app_id_;
manager_.GetAppInfo(app_id, &out);
}
-void ApplicationInstance::GetAppCerts(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerGetAppCerts(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeAppManagerCertificate, &out);
manager_.GetAppCerts(app_id, &out);
}
-void ApplicationInstance::GetAppSharedURI(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerGetAppSharedURI(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
std::string app_id = app_id_;
manager_.GetAppSharedUri(app_id, &out);
}
-void ApplicationInstance::GetAppMetaData(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerGetAppMetaData(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeApplicationInfo, &out);
manager_.GetAppMetaData(app_id, &out);
}
-void ApplicationInstance::GetBatteryUsageInfo(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerGetBatteryUsageInfo(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeAppHistoryRead, &out);
manager_.GetBatteryUsageInfo(args, &out);
}
-void ApplicationInstance::GetAppsUsageInfo(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerGetAppsUsageInfo(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeAppHistoryRead, &out);
manager_.GetAppsUsageInfo(args, &out);
}
-void ApplicationInstance::AddAppInfoEventListener(const picojson::value& args,
- picojson::object& out) {
+void ApplicationInstance::ApplicationManagerAddAppInfoEventListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next "
manager_.StartAppInfoEventListener(&out);
}
-void ApplicationInstance::RemoveAppInfoEventListener(const picojson::value& args,
- picojson::object& out) {
+void ApplicationInstance::ApplicationManagerRemoveAppInfoEventListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be removed from "
ReportSuccess(out);
}
-void ApplicationInstance::GetRequestedAppControl(const picojson::value& args,
- picojson::object& out) {
+void ApplicationInstance::ApplicationGetRequestedAppControl(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
current_application_.GetRequestedAppControl(args, &out);
}
-void ApplicationInstance::ReplyResult(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::RequestedApplicationControlReplyResult(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
current_application_.app_control().ReplyResult(args, &out);
}
-void ApplicationInstance::ReplyFailure(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::RequestedApplicationControlReplyFailure(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
current_application_.app_control().ReplyFailure(&out);
}
-void ApplicationInstance::GetSize(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationInformationGetSize(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeApplicationInfo, &out);
manager_.GetApplicationInformationSize(args, &out);
}
-void ApplicationInstance::Kill(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerKill(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeAppManagerKill, &out);
manager_.Kill(args);
}
-void ApplicationInstance::Launch(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerLaunch(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeApplicationLaunch, &out);
manager_.Launch(args);
}
-void ApplicationInstance::LaunchAppControl(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerLaunchAppControl(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeApplicationLaunch, &out);
manager_.LaunchAppControl(args);
}
-void ApplicationInstance::FindAppControl(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerFindAppControl(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.FindAppControl(args);
}
-void ApplicationInstance::GetAppsContext(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerGetAppsContext(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.GetAppsContext(args);
}
-void ApplicationInstance::GetAppsInfo(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerGetAppsInfo(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.GetAppsInfo(args);
}
-void ApplicationInstance::BroadcastEvent(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationBroadcastEvent(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.BroadcastEventHelper(args, out, false);
}
-void ApplicationInstance::BroadcastTrustedEvent(const picojson::value& args,
- picojson::object& out) {
+void ApplicationInstance::ApplicationBroadcastTrustedEvent(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.BroadcastEventHelper(args, out, true);
}
-void ApplicationInstance::AddEventListener(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationAddEventListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
const std::string& event_name = args.get("name").get<std::string>();
}
}
-void ApplicationInstance::RemoveEventListener(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationRemoveEventListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
const std::string& event_name = args.get("name").get<std::string>();
manager_.StopEventListener(event_name);
}
-void ApplicationInstance::AddStatusListener(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerAddStatusListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
JsonCallback cb = [this](picojson::value* event) -> void {
}
}
-void ApplicationInstance::RemoveStatusListener(const picojson::value& args, picojson::object& out) {
+void ApplicationInstance::ApplicationManagerRemoveStatusListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
PlatformResult result = manager_.StopStatusChangeListener();
virtual ~ApplicationInstance();
private:
- void GetCurrentApplication(const picojson::value& args, picojson::object& out);
- void GetAppContext(const picojson::value& args, picojson::object& out);
- void GetAppInfo(const picojson::value& args, picojson::object& out);
- void GetAppCerts(const picojson::value& args, picojson::object& out);
- void GetAppSharedURI(const picojson::value& args, picojson::object& out);
- void GetAppMetaData(const picojson::value& args, picojson::object& out);
- void GetBatteryUsageInfo(const picojson::value& args, picojson::object& out);
- void GetAppsUsageInfo(const picojson::value& args, picojson::object& out);
- void AddAppInfoEventListener(const picojson::value& args, picojson::object& out);
- void RemoveAppInfoEventListener(const picojson::value& args, picojson::object& out);
- void GetRequestedAppControl(const picojson::value& args, picojson::object& out);
- void ReplyResult(const picojson::value& args, picojson::object& out);
- void ReplyFailure(const picojson::value& args, picojson::object& out);
- void GetSize(const picojson::value& args, picojson::object& out);
- void Kill(const picojson::value& args, picojson::object& out);
- void Launch(const picojson::value& args, picojson::object& out);
- void LaunchAppControl(const picojson::value& args, picojson::object& out);
- void FindAppControl(const picojson::value& args, picojson::object& out);
- void GetAppsContext(const picojson::value& args, picojson::object& out);
- void GetAppsInfo(const picojson::value& args, picojson::object& out);
- void BroadcastEvent(const picojson::value& args, picojson::object& out);
- void BroadcastTrustedEvent(const picojson::value& args, picojson::object& out);
- void AddEventListener(const picojson::value& args, picojson::object& out);
- void RemoveEventListener(const picojson::value& args, picojson::object& out);
- void AddStatusListener(const picojson::value& args, picojson::object& out);
- void RemoveStatusListener(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerAddAppInfoEventListener(const picojson::value& args,
+ picojson::object& out);
+ void ApplicationManagerAddStatusListener(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerFindAppControl(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerGetAppCerts(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerGetAppContext(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerGetAppInfo(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerGetAppMetaData(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerGetAppSharedURI(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerGetAppsContext(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerGetAppsInfo(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerGetAppsUsageInfo(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerGetBatteryUsageInfo(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerGetCurrentApplication(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerKill(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerLaunch(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerLaunchAppControl(const picojson::value& args, picojson::object& out);
+ void ApplicationManagerRemoveAppInfoEventListener(const picojson::value& args,
+ picojson::object& out);
+ void ApplicationManagerRemoveStatusListener(const picojson::value& args, picojson::object& out);
+
+ void ApplicationAddEventListener(const picojson::value& args, picojson::object& out);
+ void ApplicationBroadcastEvent(const picojson::value& args, picojson::object& out);
+ void ApplicationBroadcastTrustedEvent(const picojson::value& args, picojson::object& out);
+ void ApplicationGetRequestedAppControl(const picojson::value& args, picojson::object& out);
+ void ApplicationRemoveEventListener(const picojson::value& args, picojson::object& out);
+
+ void RequestedApplicationControlReplyFailure(const picojson::value& args, picojson::object& out);
+ void RequestedApplicationControlReplyResult(const picojson::value& args, picojson::object& out);
+
+ void ApplicationInformationGetSize(const picojson::value& args, picojson::object& out);
ApplicationManager manager_;
Application current_application_;
#include <glib.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <thread>
#include <type_traits>
#include <app_control_internal.h>
LoggerE("app_manager_event_destroy failed, error: %d", ret);
}
}
+
+ // Calling order of reply_callback and result_callback of launchAppControl
+ // cannot be determined, reply_callback depends on application scenario, which
+ // cannot be predicted. Moreover reply_callback is optional and can be called or not,
+ // thus callback_data is relesed here at the end of application lifetime.
+ std::for_each(launch_app_control_set.begin(), launch_app_control_set.end(),
+ [](LaunchAppControlCallbackData* const& data) {
+ LoggerD("Releasing callback data: %p", data);
+ delete data;
+ });
}
void ApplicationManager::GetCurrentApplication(const std::string& app_id, picojson::object* out) {
picojson::value app_info = picojson::value(picojson::object());
picojson::object& app_info_obj = app_info.get<picojson::object>();
- ApplicationUtils::CreateApplicationInformation(handle, &app_info_obj);
+ utils::CreateApplicationInformation(handle, &app_info_obj);
pkgmgrinfo_appinfo_destroy_appinfo(handle);
picojson::value result = picojson::value(picojson::object());
return; \
}
-void ApplicationManager::AsyncResponse(PlatformResult& result,
+void ApplicationManager::AsyncResponse(const PlatformResult& result,
std::shared_ptr<picojson::value>* response) {
ScopeLogger();
LogAndReportError(result, &(*response)->get<picojson::object>());
kill();
}
-void ApplicationManager::Launch(const picojson::value& args) {
+namespace {
+
+PlatformResult PrepareAppControlForLaunchAppControl(const picojson::value& args,
+ app_control_h* app_control) {
ScopeLogger();
- int callback_id = -1;
- const auto& callback = args.get(kCallbackId);
- if (callback.is<double>()) {
- callback_id = static_cast<int>(callback.get<double>());
+ const auto& control = args.get("appControl");
+ if (!control.is<picojson::object>()) {
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed.");
}
+ const picojson::object& app_control_obj = control.get<picojson::object>();
- std::shared_ptr<picojson::value> response(new picojson::value(picojson::object()));
- picojson::object& obj = response->get<picojson::object>();
- obj.insert(std::make_pair(kCallbackId, picojson::value(static_cast<double>(callback_id))));
+ app_control_h tmp_app_control = nullptr;
+ auto result = utils::ApplicationControlToService(app_control_obj, &tmp_app_control);
+ std::unique_ptr<std::remove_pointer<app_control_h>::type, decltype(&app_control_destroy)>
+ app_control_ptr(tmp_app_control, &app_control_destroy);
- const auto& app_id = args.get("id");
- if (!app_id.is<std::string>()) {
- PlatformResult ret =
- LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed.");
- AsyncResponse(ret, &response);
- return;
+ if (result.IsError()) {
+ LoggerE("Application control to service failed.");
+ return result;
}
- const std::string& id = app_id.get<std::string>();
-
- auto launch = [id](const std::shared_ptr<picojson::value>& response) -> void {
- ScopeLogger("launch");
- PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
- const char* app_id = id.c_str();
- const int retry_count = 3;
- int retry = 0;
- int ret = 0;
-
- while (retry < retry_count) {
- ret = aul_open_app(app_id);
+ std::string app_id;
+ const auto& id = args.get("id");
+ if (id.is<std::string>()) {
+ app_id = id.get<std::string>();
+ }
- if (ret >= 0) {
- break;
- }
+ if (!app_id.empty()) {
+ LoggerD("app_id: %s", app_id.c_str());
- // delay 300ms for each retry
- struct timespec sleep_time = {0, 300L * 1000L * 1000L};
- nanosleep(&sleep_time, nullptr);
- ++retry;
+ int ret = app_control_set_app_id(app_control_ptr.get(), app_id.c_str());
- LoggerD("Retry launch request: %d", retry);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LoggerE("Failed to set app id: %d (%s)", ret, get_error_message(ret));
+ return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed.");
}
+ }
- if (ret < 0) {
- result = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown error has occurred.");
-
- LoggerD("Aul open return: %d (%s)", ret, get_error_message(ret));
- switch (ret) {
- case AUL_R_EINVAL:
- case AUL_R_ERROR:
- case AUL_R_ENOAPP:
- result =
- LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Launchpad returns not found error.",
- ("aul_open_app returns Not Found error"));
- break;
-
- case AUL_R_ECOMM:
- result = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Internal IPC error has occurred.",
- ("aul_open_app returns internal IPC error"));
- break;
- }
-
- LogAndReportError(result, &response->get<picojson::object>());
- } else {
- LoggerD("Launch request success");
- ReportSuccess(response->get<picojson::object>());
- }
- };
+ *app_control = app_control_ptr.release();
- launch(response);
- Instance::PostMessage(&this->instance_, response->serialize().c_str());
+ return PlatformResult(ErrorCode::NO_ERROR);
}
+} // namespace
+
void ApplicationManager::LaunchAppControl(const picojson::value& args) {
ScopeLogger();
response_obj.insert(
std::make_pair(kCallbackId, picojson::value(static_cast<double>(callback_id))));
- PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
- const auto& control = args.get("appControl");
- if (!control.is<picojson::object>()) {
- result = LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed.");
- AsyncResponse(result, &response);
+ app_control_h app_control = nullptr;
+ auto prepare_app_control_result = PrepareAppControlForLaunchAppControl(args, &app_control);
+ if (prepare_app_control_result.IsError()) {
+ AsyncResponse(LogAndCreateResult(prepare_app_control_result), &response);
return;
}
- const picojson::object& app_control_obj = control.get<picojson::object>();
- std::string launch_mode_str;
- const auto& launch_mode = control.get("launchMode");
- if (launch_mode.is<std::string>()) {
- launch_mode_str = launch_mode.get<std::string>();
+ std::unique_ptr<std::remove_pointer<app_control_h>::type, decltype(&app_control_destroy)>
+ app_control_ptr(app_control, &app_control_destroy);
+
+ std::string reply_callback_id;
+ const auto& reply = args.get("replyCallback");
+ if (reply.is<std::string>()) {
+ reply_callback_id = reply.get<std::string>();
}
- app_control_h app_control = nullptr;
- result = ApplicationUtils::ApplicationControlToService(app_control_obj, &app_control);
- std::shared_ptr<std::remove_pointer<app_control_h>::type> app_control_ptr(
- app_control, &app_control_destroy); // automatically release the memory
+ LaunchAppControlCallbackData* launch_app_user_data = new (std::nothrow)
+ LaunchAppControlCallbackData{&this->instance_, response, reply_callback_id};
- if (result.IsError()) {
- LoggerE("Application control to service failed.");
- AsyncResponse(result, &response);
+ if (!launch_app_user_data) {
+ LoggerE("Memory allocation fail!");
+ AsyncResponse(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error."), &response);
return;
}
- std::string app_id;
- const auto& id = args.get("id");
- if (id.is<std::string>()) {
- app_id = id.get<std::string>();
- }
+ app_control_reply_cb reply_callback = nullptr;
+ if (!reply_callback_id.empty()) {
+ launch_app_user_data->reply_callback_id = reply_callback_id;
- std::string reply_callback;
- const auto& reply = args.get("replyCallback");
- if (reply.is<std::string>()) {
- reply_callback = reply.get<std::string>();
+ reply_callback = [](app_control_h request, app_control_h reply, app_control_result_e result,
+ void* user_data) {
+ ScopeLogger("reply_callback");
+
+ LaunchAppControlCallbackData* callback_data =
+ static_cast<LaunchAppControlCallbackData*>(user_data);
+ if (!callback_data) {
+ LoggerD("reply_callback failed: user_data is nullptr");
+ return;
+ }
+
+ picojson::value return_value = picojson::value(picojson::object());
+ picojson::object& return_value_obj = return_value.get<picojson::object>();
+ return_value_obj.insert(
+ std::make_pair(kListenerId, picojson::value(callback_data->reply_callback_id)));
+
+ if (APP_CONTROL_RESULT_SUCCEEDED == result) {
+ LoggerD("App started");
+ return_value_obj.insert(std::make_pair("data", picojson::value(picojson::array())));
+ if (!utils::ServiceToApplicationControlDataArray(
+ reply, &return_value_obj.find("data")->second.get<picojson::array>())) {
+ return_value_obj.erase("data");
+ }
+ ReportSuccess(return_value_obj);
+ } else {
+ ReportError(return_value_obj);
+ }
+
+ Instance::PostMessage(callback_data->instance, return_value.serialize().c_str());
+ // Calling order of reply_callback and result_callback cannot be determined,
+ // thus callback_data is not released here, but stored for release in destructor of
+ // ApplicationManager
+ };
}
- auto launch = [this, app_control_ptr, app_id, launch_mode_str,
- reply_callback](const std::shared_ptr<picojson::value>& response) -> void {
- ScopeLogger("Entered into asynchronous function, launch");
+ app_control_result_cb result_callback = [](app_control_h launch_request,
+ app_control_error_e launch_result, void* user_data) {
+ ScopeLogger("LaunchAppControl result_callback");
- if (!app_id.empty()) {
- LoggerD("app_id: %s", app_id.c_str());
+ LaunchAppControlCallbackData* callback_data =
+ static_cast<LaunchAppControlCallbackData*>(user_data);
- int ret = app_control_set_app_id(app_control_ptr.get(), app_id.c_str());
+ auto result = utils::TranslateAppControlError(launch_result);
- if (APP_CONTROL_ERROR_NONE != ret) {
- LogAndReportError(
- PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."),
- &response->get<picojson::object>(),
- ("Failed to set app id: %d (%s)", ret, get_error_message(ret)));
- return;
- }
+ if (result.IsError()) {
+ LogAndReportError(result, &(callback_data->response->get<picojson::object>()));
+ } else {
+ ReportSuccess(callback_data->response->get<picojson::object>());
}
- app_control_reply_cb callback = nullptr;
- struct ReplayCallbackData {
- ApplicationInstance* app_instance;
- std::string reply_callback;
- };
+ Instance::PostMessage(callback_data->instance, callback_data->response->serialize().c_str());
- ReplayCallbackData* user_data = nullptr;
+ // Calling order of reply_callback and result_callback cannot be determined,
+ // thus callback_data is not released here, but stored for release in destructor of
+ // ApplicationManager
+ };
- if (!reply_callback.empty()) {
- user_data = new ReplayCallbackData();
- user_data->app_instance = &this->instance_;
- user_data->reply_callback = reply_callback;
+ /*
+ * TODO: Observe how often app_control_send_launch_request_async tries to launch the application.
+ * Previous implementation, using synchronous app_control_send_launch_request,
+ * tries to launch the application 3 times, before reporting an error.
+ * New implementation, using app_control_send_launch_request_async makes only one attempt.
+ * If problems, such as failed application start occur, multiple attempts may solve the problem.
+ */
+ auto launch_result = utils::TranslateAppControlError(
+ static_cast<app_control_error_e>(app_control_send_launch_request_async(
+ app_control_ptr.get(), result_callback, reply_callback, launch_app_user_data)));
+
+ if (launch_result.IsError()) {
+ delete launch_app_user_data;
+ AsyncResponse(launch_result, &response);
+ } else {
+ // Calling order of reply_callback and result_callback cannot be determined,
+ // reply_callback depends on application scenario, which cannot be predicted.
+ // Moreover reply_callback is optional and can be called or not,
+ // thus callback_data is stored for releasing in destructor of ApplicationManager
+ // at the end of application lifetime.
+ launch_app_control_set.insert(launch_app_user_data);
+ LoggerD("App launched, data %p stored for later release", launch_app_user_data);
+ }
+}
+namespace {
- callback = [](app_control_h request, app_control_h reply, app_control_result_e result,
- void* user_data) {
- LoggerD("send_launch_request callback");
+PlatformResult TranslateLaunchError(app_control_error_e return_code) {
+ ScopeLogger();
- picojson::value return_value = picojson::value(picojson::object());
- picojson::object& return_value_obj = return_value.get<picojson::object>();
- ReplayCallbackData* reply_callback = static_cast<ReplayCallbackData*>(user_data);
+ auto result = utils::TranslateAppControlError(return_code);
+ if (ErrorCode::SECURITY_ERR == result.error_code()) {
+ result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error.");
+ }
- if (APP_CONTROL_RESULT_SUCCEEDED == result) {
- const std::string data = "data";
- return_value_obj.insert(std::make_pair(data, picojson::value(picojson::array())));
- if (!ApplicationUtils::ServiceToApplicationControlDataArray(
- reply, &return_value_obj.find(data)->second.get<picojson::array>())) {
- return_value_obj.erase(data);
- }
- ReportSuccess(return_value_obj);
- } else {
- ReportError(return_value_obj);
- }
+ return result;
+}
- return_value_obj.insert(
- std::make_pair("listenerId", picojson::value(reply_callback->reply_callback)));
- Instance::PostMessage(reply_callback->app_instance, return_value.serialize().c_str());
- delete reply_callback;
- };
- }
+PlatformResult PrepareAppControlForLaunch(const picojson::value& args, app_control_h* app_control) {
+ ScopeLogger();
- const int retry_count = 3;
+ const auto& app_id = args.get("id");
+ if (!app_id.is<std::string>()) {
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed.");
+ }
+ const auto app_id_str = app_id.get<std::string>();
- int retry = 0;
- int ret = 0;
+ app_control_h tmp_app_control = nullptr;
+ int result = app_control_create(&tmp_app_control);
+ if (APP_CONTROL_ERROR_NONE != result) {
+ LoggerD("app_control_create() failed: %d (%s)", result, get_error_message(result));
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occurred.");
+ }
- while (retry < retry_count) {
- LoggerD("Calling launch request. Attempt number: %d", retry);
+ std::unique_ptr<std::remove_pointer<app_control_h>::type, decltype(&app_control_destroy)>
+ app_control_ptr(tmp_app_control, &app_control_destroy);
- ret = app_control_send_launch_request(app_control_ptr.get(), callback, user_data);
- LoggerD("App control launch request returned: %d, %s", ret, get_error_message(ret));
- if (APP_CONTROL_ERROR_NONE == ret) {
- break;
- }
+ if (!app_id_str.empty()) {
+ LoggerD("app_id: %s", app_id_str.c_str());
- // delay 300ms for each retry
- struct timespec sleep_time = {0, 300L * 1000L * 1000L};
- nanosleep(&sleep_time, nullptr);
- ++retry;
- }
+ int ret = app_control_set_app_id(app_control_ptr.get(), app_id_str.c_str());
if (APP_CONTROL_ERROR_NONE != ret) {
- delete user_data;
-
- switch (ret) {
- case APP_CONTROL_ERROR_INVALID_PARAMETER:
- LogAndReportError(
- PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter returned."),
- &response->get<picojson::object>(),
- ("app_control_send_launch_request returns APP_CONTROL_ERROR_INVALID_PARAMETER"));
- return;
- case APP_CONTROL_ERROR_OUT_OF_MEMORY:
- LogAndReportError(
- PlatformResult(ErrorCode::UNKNOWN_ERR, "Out of memory."),
- &response->get<picojson::object>(),
- ("app_control_send_launch_request returns APP_CONTROL_ERROR_OUT_OF_MEMORY"));
- return;
- case APP_CONTROL_ERROR_LAUNCH_REJECTED:
- case APP_CONTROL_ERROR_APP_NOT_FOUND:
- LogAndReportError(
- PlatformResult(ErrorCode::NOT_FOUND_ERR, "No matched application found."),
- &response->get<picojson::object>(),
- ("app_control_send_launch_request returns APP_CONTROL_ERROR_APP_NOT_FOUND"));
- return;
- default:
- LogAndReportError(
- PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error."),
- &response->get<picojson::object>(),
- ("app_control_send_launch_request returns: %d (%s)", ret, get_error_message(ret)));
- return;
- }
+ LoggerE("Failed to set app id: %d (%s)", ret, get_error_message(ret));
+ return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed.");
}
- ReportSuccess(response->get<picojson::object>());
+ }
+
+ *app_control = app_control_ptr.release();
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+} // namespace
+void ApplicationManager::Launch(const picojson::value& args) {
+ ScopeLogger();
+
+ int callback_id = -1;
+ const auto& callback = args.get(kCallbackId);
+ if (callback.is<double>()) {
+ callback_id = static_cast<int>(callback.get<double>());
+ }
+
+ std::shared_ptr<picojson::value> response(new picojson::value(picojson::object()));
+ picojson::object& response_obj = response->get<picojson::object>();
+ response_obj.insert(
+ std::make_pair(kCallbackId, picojson::value(static_cast<double>(callback_id))));
+
+ app_control_h app_control = nullptr;
+ auto prepare_app_control_result = PrepareAppControlForLaunch(args, &app_control);
+ if (prepare_app_control_result.IsError()) {
+ AsyncResponse(LogAndCreateResult(prepare_app_control_result), &response);
+ return;
+ }
+
+ std::unique_ptr<std::remove_pointer<app_control_h>::type, decltype(&app_control_destroy)>
+ app_control_ptr(app_control, &app_control_destroy);
+
+ struct LaunchCallbackData {
+ ApplicationInstance* instance;
+ std::shared_ptr<picojson::value> response;
+ }* launch_user_data = new (std::nothrow) LaunchCallbackData{&this->instance_, response};
+
+ app_control_result_cb result_callback = [](app_control_h launch_request,
+ app_control_error_e launch_result, void* user_data) {
+ ScopeLogger("Launch result_callback");
+
+ LaunchCallbackData* callback_data = static_cast<LaunchCallbackData*>(user_data);
+
+ auto result = TranslateLaunchError(launch_result);
+
+ if (result.IsError()) {
+ LogAndReportError(result, &(callback_data->response->get<picojson::object>()));
+ } else {
+ ReportSuccess(callback_data->response->get<picojson::object>());
+ }
+
+ Instance::PostMessage(callback_data->instance, callback_data->response->serialize().c_str());
+
+ delete callback_data;
};
- launch(response);
- Instance::PostMessage(&this->instance_, response->serialize().c_str());
+ /*
+ * TODO: Observe how often app_control_send_resume_request tries to launch the application.
+ * Previous implementation, using synchronous app_control_send_launch_request,
+ * tries to launch the application 3 times, before reporting an error.
+ * New implementation, using app_control_send_resume_request makes only one attempt.
+ * If problems, such as failed application start occur, multiple attempts may solve the problem.
+ */
+ auto launch_result = TranslateLaunchError(static_cast<app_control_error_e>(
+ app_control_send_resume_request(app_control_ptr.get(), result_callback, launch_user_data)));
+
+ if (launch_result.IsError()) {
+ delete launch_user_data;
+ AsyncResponse(launch_result, &response);
+ } else {
+ LoggerD("App launched");
+ }
}
// internal impl of app_control_foreach_app_matched() for handling APP_CONTROL_ERROR_APP_NOT_FOUND
const picojson::object& app_control_obj = control.get<picojson::object>();
app_control_h app_control = nullptr;
- result = ApplicationUtils::ApplicationControlToService(app_control_obj, &app_control);
+ result = utils::ApplicationControlToService(app_control_obj, &app_control);
std::shared_ptr<std::remove_pointer<app_control_h>::type> app_control_ptr(
app_control, &app_control_destroy); // automatically release the memory
picojson::array* array = static_cast<picojson::array*>(user_data);
array->push_back(picojson::value(picojson::object()));
- ApplicationUtils::CreateApplicationInformation(handle,
- &array->back().get<picojson::object>());
+ utils::CreateApplicationInformation(handle, &array->back().get<picojson::object>());
pkgmgrinfo_appinfo_destroy_appinfo(handle);
}
picojson::array* array = static_cast<picojson::array*>(user_data);
array->push_back(picojson::value(picojson::object()));
- if (!ApplicationUtils::CreateApplicationContext(app_context,
- &array->back().get<picojson::object>())) {
+ if (!utils::CreateApplicationContext(app_context, &array->back().get<picojson::object>())) {
array->pop_back();
return false;
}
}
picojson::value result = picojson::value(picojson::object());
- ApplicationUtils::CreateApplicationContext(pid, app_id, &result.get<picojson::object>());
+ utils::CreateApplicationContext(pid, app_id, &result.get<picojson::object>());
ReportSuccess(result, *out);
}
picojson::array* array = static_cast<picojson::array*>(user_data);
array->push_back(picojson::value(picojson::object()));
- ApplicationUtils::CreateApplicationInformation(handle,
- &array->back().get<picojson::object>());
+ utils::CreateApplicationInformation(handle, &array->back().get<picojson::object>());
return 0;
};
}
picojson::value result = picojson::value(picojson::object());
- ApplicationUtils::CreateApplicationInformation(handle, &result.get<picojson::object>());
+ utils::CreateApplicationInformation(handle, &result.get<picojson::object>());
pkgmgrinfo_appinfo_destroy_appinfo(handle);
ReportSuccess(result, *out);
picojson::array* array = static_cast<picojson::array*>(user_data);
array->push_back(picojson::value(picojson::object()));
- ApplicationUtils::CreateApplicationCertificate(cert_name, cert_value,
- &array->back().get<picojson::object>());
+ utils::CreateApplicationCertificate(cert_name, cert_value,
+ &array->back().get<picojson::object>());
return true;
};
picojson::array* array = static_cast<picojson::array*>(user_data);
array->push_back(picojson::value(picojson::object()));
- ApplicationUtils::CreateApplicationMetaData(meta_key, meta_value,
- &array->back().get<picojson::object>());
+ utils::CreateApplicationMetaData(meta_key, meta_value, &array->back().get<picojson::object>());
return 0;
};
continue;
}
auto info = data_obj.insert(std::make_pair(kData, picojson::value(picojson::object())));
- ApplicationUtils::CreateApplicationInformation(
- handle, &info.first->second.get<picojson::object>());
+ utils::CreateApplicationInformation(handle, &info.first->second.get<picojson::object>());
pkgmgrinfo_appinfo_destroy_appinfo(handle);
} break;
case Event::kUninstalled:
return;
}
- ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_ALLAPP,
+ ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_APP_COMPONENT_TYPE_ALL,
ApplicationIdCallback, this);
if (PACKAGE_MANAGER_ERROR_NONE != ret) {
LoggerE("Failed to get application IDs: %d (%s)", ret, get_error_message(ret));
#include <package-manager.h>
#include <pkgmgr-info.h>
#include <functional>
-#include <functional>
#include <memory>
+#include <set>
#include <string>
#if defined(TIZEN_MOBILE)
#include <context-service/context_history.h>
#include "common/platform_result.h"
typedef std::function<void(picojson::value*)> JsonCallback;
-
namespace extension {
namespace application {
class ApplicationInstance;
+typedef struct LaunchAppControlCallbackDataStruct {
+ ApplicationInstance* instance;
+ std::shared_ptr<picojson::value> response;
+ std::string reply_callback_id;
+} LaunchAppControlCallbackData;
class ApplicationManager {
public:
void StartAppInfoEventListener(picojson::object* out);
void StopAppInfoEventListener();
void GetApplicationInformationSize(const picojson::value& args, picojson::object* out);
- void AsyncResponse(common::PlatformResult& result, std::shared_ptr<picojson::value>* response);
+ void AsyncResponse(const common::PlatformResult& result,
+ std::shared_ptr<picojson::value>* response);
void BroadcastEventHelper(const picojson::value& args, picojson::object& out, bool trusted);
common::PlatformResult StartEventListener(const std::string& event_name,
JsonCallback event_callback_;
JsonCallback status_callback_;
std::map<std::string, event_handler_h> event_handler_map_;
+ std::set<LaunchAppControlCallbackData*> launch_app_control_set;
static void OnEvent(const char* event_name, bundle* event_data, void* user_data);
static void OnStatusEvent(const char* type, const char* app_id,
app_manager_event_type_e event_type,
namespace extension {
namespace application {
+namespace utils {
-void ApplicationUtils::CreateApplicationInformation(const pkgmgrinfo_appinfo_h handle,
- picojson::object* app_info) {
+void CreateApplicationInformation(const pkgmgrinfo_appinfo_h handle, picojson::object* app_info) {
ScopeLogger();
char* tmp_str = nullptr;
// size is set at first attribute access (performance)
}
-bool ApplicationUtils::CreateApplicationContext(const app_context_h handle,
- picojson::object* app_context) {
+bool CreateApplicationContext(const app_context_h handle, picojson::object* app_context) {
ScopeLogger();
char* app_id = nullptr;
return true;
}
-void ApplicationUtils::CreateApplicationContext(pid_t pid, const std::string& app_id,
- picojson::object* app_context) {
+void CreateApplicationContext(pid_t pid, const std::string& app_id, picojson::object* app_context) {
ScopeLogger();
app_context->insert(std::make_pair("id", picojson::value(std::to_string(pid))));
app_context->insert(std::make_pair("appId", picojson::value(app_id)));
}
-void ApplicationUtils::CreateApplicationCertificate(const char* cert_type, const char* cert_value,
- picojson::object* app_certificate) {
+void CreateApplicationCertificate(const char* cert_type, const char* cert_value,
+ picojson::object* app_certificate) {
ScopeLogger();
app_certificate->insert(std::make_pair("type", picojson::value(cert_type)));
app_certificate->insert(std::make_pair("value", picojson::value(cert_value)));
}
-void ApplicationUtils::CreateApplicationMetaData(const char* key, const char* value,
- picojson::object* app_meta_data) {
+void CreateApplicationMetaData(const char* key, const char* value,
+ picojson::object* app_meta_data) {
ScopeLogger();
app_meta_data->insert(std::make_pair("key", picojson::value(key)));
app_meta_data->insert(std::make_pair("value", picojson::value(value)));
auto setter = setter_it->second;
auto result = setter(app_control, value.c_str());
- auto result_translated =
- ApplicationUtils::TranslateAppControlError(static_cast<app_control_error_e>(result));
+ auto result_translated = TranslateAppControlError(static_cast<app_control_error_e>(result));
if (result_translated.IsError()) {
LoggerD("Setting app_control's %s field failed: %s", field_name.c_str(),
}
auto result = app_control_set_launch_mode(app_control, LaunchModeStringToEnum(launch_mode_str));
- return ApplicationUtils::TranslateAppControlError(static_cast<app_control_error_e>(result));
+ return TranslateAppControlError(static_cast<app_control_error_e>(result));
}
PlatformResult SetAppControlDataField(app_control_h app_control, const picojson::array& data) {
for (auto iter = data.begin(); iter != data.end(); ++iter) {
if (iter->is<picojson::object>()) {
- PlatformResult ret = ApplicationUtils::ApplicationControlDataToServiceExtraData(
- iter->get<picojson::object>(), app_control);
+ PlatformResult ret =
+ ApplicationControlDataToServiceExtraData(iter->get<picojson::object>(), app_control);
if (ret.IsError()) {
return ret;
}
} // namespace
-PlatformResult ApplicationUtils::ApplicationControlToService(
- const picojson::object& app_control_obj, app_control_h* app_control) {
+PlatformResult ApplicationControlToService(const picojson::object& app_control_obj,
+ app_control_h* app_control) {
ScopeLogger();
const auto it_operation = app_control_obj.find(kOperationAppControlField);
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult ApplicationUtils::ApplicationControlDataToServiceExtraData(
- const picojson::object& app_control_data, app_control_h app_control) {
+PlatformResult ApplicationControlDataToServiceExtraData(const picojson::object& app_control_data,
+ app_control_h app_control) {
ScopeLogger();
const auto it_key = app_control_data.find("key");
return PlatformResult(ErrorCode::NO_ERROR);
}
-void ApplicationUtils::ServiceToApplicationControl(app_control_h app_control,
- picojson::object* app_control_obj) {
+void ServiceToApplicationControl(app_control_h app_control, picojson::object* app_control_obj) {
ScopeLogger();
int ret = 0;
app_control, &app_control_obj->find(kDataAppControlField)->second.get<picojson::array>());
}
-void ApplicationUtils::ServiceExtraDataToApplicationControlData(
- app_control_h app_control, const std::string& key, picojson::object* app_control_data) {
+void ServiceExtraDataToApplicationControlData(app_control_h app_control, const std::string& key,
+ picojson::object* app_control_data) {
ScopeLogger();
int ret = 0;
app_control_data->insert(std::make_pair("value", picojson::value(value_array)));
}
-bool ApplicationUtils::ServiceToApplicationControlDataArray(app_control_h app_control,
- picojson::array* data) {
+bool ServiceExtraDataCallback(app_control_h app_control, const char* key, void* user_data) {
+ ScopeLogger();
+ picojson::array* data = static_cast<picojson::array*>(user_data);
+
+ data->push_back(picojson::value(picojson::object()));
+ ServiceExtraDataToApplicationControlData(app_control, key, &data->back().get<picojson::object>());
+
+ return true;
+}
+
+bool ServiceToApplicationControlDataArray(app_control_h app_control, picojson::array* data) {
ScopeLogger();
int ret = app_control_foreach_extra_data(app_control, ServiceExtraDataCallback, data);
return APP_CONTROL_ERROR_NONE == ret;
}
-PlatformResult ApplicationUtils::TranslateAppControlError(app_control_error_e return_code) {
+PlatformResult TranslateAppControlError(app_control_error_e return_code) {
ScopeLogger("Return code: %d (%s)", static_cast<int>(return_code),
get_error_message(static_cast<int>(return_code)));
}
}
-bool ApplicationUtils::ServiceExtraDataCallback(app_control_h app_control, const char* key,
- void* user_data) {
- ScopeLogger();
- picojson::array* data = static_cast<picojson::array*>(user_data);
-
- data->push_back(picojson::value(picojson::object()));
- ServiceExtraDataToApplicationControlData(app_control, key, &data->back().get<picojson::object>());
-
- return true;
-}
-
+} // namespace utils
} // namespace application
} // namespace extension
namespace extension {
namespace application {
+namespace utils {
-class ApplicationUtils {
- public:
- static void CreateApplicationInformation(const pkgmgrinfo_appinfo_h handle,
- picojson::object* app_info);
+void CreateApplicationInformation(const pkgmgrinfo_appinfo_h handle, picojson::object* app_info);
- static bool CreateApplicationContext(const app_context_h handle, picojson::object* app_context);
+bool CreateApplicationContext(const app_context_h handle, picojson::object* app_context);
- static void CreateApplicationContext(pid_t pid, const std::string& app_id,
- picojson::object* app_context);
+void CreateApplicationContext(pid_t pid, const std::string& app_id, picojson::object* app_context);
- static void CreateApplicationCertificate(const char* cert_type, const char* cert_value,
- picojson::object* app_certificate);
+void CreateApplicationCertificate(const char* cert_type, const char* cert_value,
+ picojson::object* app_certificate);
- static void CreateApplicationMetaData(const char* key, const char* value,
- picojson::object* app_meta_data);
+void CreateApplicationMetaData(const char* key, const char* value, picojson::object* app_meta_data);
- static common::PlatformResult ApplicationControlToService(const picojson::object& app_control_obj,
- app_control_h* app_control);
+common::PlatformResult ApplicationControlToService(const picojson::object& app_control_obj,
+ app_control_h* app_control);
- static common::PlatformResult ApplicationControlDataToServiceExtraData(
- const picojson::object& app_control_data, app_control_h app_control);
+common::PlatformResult ApplicationControlDataToServiceExtraData(
+ const picojson::object& app_control_data, app_control_h app_control);
- static void ServiceToApplicationControl(app_control_h app_control,
- picojson::object* app_control_obj);
+void ServiceToApplicationControl(app_control_h app_control, picojson::object* app_control_obj);
- static void ServiceExtraDataToApplicationControlData(app_control_h app_control,
- const std::string& key,
- picojson::object* app_control_data);
+void ServiceExtraDataToApplicationControlData(app_control_h app_control, const std::string& key,
+ picojson::object* app_control_data);
- static bool ServiceToApplicationControlDataArray(app_control_h app_control,
- picojson::array* data);
+bool ServiceToApplicationControlDataArray(app_control_h app_control, picojson::array* data);
- static common::PlatformResult TranslateAppControlError(app_control_error_e error_code);
-
- private:
- static bool ServiceExtraDataCallback(app_control_h app_control, const char* key, void* user_data);
-};
+common::PlatformResult TranslateAppControlError(app_control_error_e error_code);
+} // namespace utils
} // namespace application
} // namespace extension
out->insert(std::make_pair("callerAppId", picojson::value(caller_app_id_)));
auto appControl =
out->insert(std::make_pair("appControl", picojson::value(picojson::object())));
- ApplicationUtils::ServiceToApplicationControl(
- app_control_.get(), &appControl.first->second.get<picojson::object>());
+ utils::ServiceToApplicationControl(app_control_.get(),
+ &appControl.first->second.get<picojson::object>());
}
}
}
// create reply
- app_control_h reply;
- app_control_create(&reply);
+ app_control_h reply = nullptr;
+ int ret = app_control_create(&reply);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "app control create failed."), out,
+ ("app control create failed: %d", ret));
+ return;
+ }
std::unique_ptr<std::remove_pointer<app_control_h>::type, int (*)(app_control_h)> reply_ptr(
reply, &app_control_destroy); // automatically release the memory
if (!data.empty()) {
for (auto iter = data.begin(); iter != data.end(); ++iter) {
- result = ApplicationUtils::ApplicationControlDataToServiceExtraData(
- iter->get<picojson::object>(), reply);
+ result =
+ utils::ApplicationControlDataToServiceExtraData(iter->get<picojson::object>(), reply);
if (result.IsError()) {
- LogAndReportError(result, out, ("Failed ApplicationControlDataToServiceExtraData()"));
+ LogAndReportError(result, out,
+ ("Failed utils::ApplicationControlDataToServiceExtraData()"));
return;
}
}
}
// send reply
- int ret =
+ ret =
app_control_reply_to_launch_request(reply, app_control_.get(), APP_CONTROL_RESULT_SUCCEEDED);
if (APP_CONTROL_ERROR_NONE != ret) {
LogAndReportError(PlatformResult(ErrorCode::NOT_FOUND_ERR, "Cannot find caller."), out,
}
// create reply
- app_control_h reply;
- app_control_create(&reply);
+ app_control_h reply = nullptr;
+ int ret = app_control_create(&reply);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "app control create failed."), out,
+ ("app control create failed: %d", ret));
+ return;
+ }
std::unique_ptr<std::remove_pointer<app_control_h>::type, int (*)(app_control_h)> reply_ptr(
reply, &app_control_destroy); // automatically release the memory
// send reply
- int ret =
- app_control_reply_to_launch_request(reply, app_control_.get(), APP_CONTROL_RESULT_FAILED);
+ ret = app_control_reply_to_launch_request(reply, app_control_.get(), APP_CONTROL_RESULT_FAILED);
if (APP_CONTROL_ERROR_NONE != ret) {
LogAndReportError(PlatformResult(ErrorCode::NOT_FOUND_ERR, "Cannot find caller."), out,
("Cannot find caller: %d (%s)", ret, get_error_message(ret)));
if (CommonFS.isCacheReady) {
return;
}
- var result = native_.callSync('Archive_fetchStorages', {});
+ var result = native_.callSync('ArchiveFetchStorages', {});
if (native_.isFailure(result)) {
privUtils_.log(
native_.addListener(ARCHIVE_ONPROGRESS_CALLBACK, ArchiveFileProgressCallback);
/**
- * The ArchiveFileEntry interface provides access to ArchiveFile member information
- * and file data.
+ * The ArchiveFileEntry interface provides access to ArchiveFile member
+ * information and file data.
* This constructor is for internal use only.
* It should be prohibited to call this constructor by user.
*/
onprogressCallbacks[opId] = args.onprogress;
}
- var result = native_.call('ArchiveFileEntry_extract', callArgs, callback);
+ var result = native_.call('ArchiveFileEntryExtract', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
/**
- * The ArchiveManager interface provides methods for global operations related to
- * ArchiveFile.
+ * The ArchiveManager interface provides methods for global operations
+ * related to ArchiveFile.
*/
/**
onprogressCallbacks[opId] = args.onprogress;
}
- var result = native_.call('ArchiveFile_add', callArgs, callback);
+ var result = native_.call('ArchiveFileAdd', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
onprogressCallbacks[opId] = args.onprogress;
}
- var result = native_.call('ArchiveFile_extractAll', callArgs, callback);
+ var result = native_.call('ArchiveFileExtractAll', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('ArchiveFile_getEntries', callArgs, callback);
+ var result = native_.call('ArchiveFileGetEntries', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
/**
- * Retrieves information about ArchiveFileEntry with the specified name in
- * ArchiveFile.
+ * Retrieves information about ArchiveFileEntry with the specified
+ * name in ArchiveFile.
*/
this.getEntryByName = function() {
var args = validator_.validateArgs(arguments, [
}
};
- var result = native_.call('ArchiveFile_getEntryByName', callArgs, callback);
+ var result = native_.call('ArchiveFileGetEntryByName', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
var handle = priv.handle;
if (priv.handle) {
delete priv.handle;
- var result = native_.callSync('ArchiveFile_close', { handle: handle });
+ var result = native_.callSync('ArchiveFileClose', { handle: handle });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
var ArchiveManager = function() {};
/**
- * Opens the archive file. After this operation, it is possible to add or get files
- * to and from the archive.
+ * Opens the archive file. After this operation, it is possible to add or get
+ * files to and from the archive.
*/
ArchiveManager.prototype.open = function() {
var args = validator_.validateArgs(arguments, [
}
};
- var result = native_.call('ArchiveManager_open', callArgs, callback);
+ var result = native_.call('ArchiveManagerOpen', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
ArchiveManager.prototype.abort = function() {
var args = validator_.validateArgs(arguments, [{ name: 'opId', type: types_.LONG }]);
- var result = native_.callSync('ArchiveManager_abort', { opId: args.opId });
+ var result = native_.callSync('ArchiveManagerAbort', { opId: args.opId });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
guint id = g_idle_add(BaseProgressCallback::callProgressCallbackCB, static_cast<void*>(ph));
if (!id) {
- LoggerE("g_idle_add fails");
+ LoggerE("g_idle_add failed");
delete ph;
ph = NULL;
}
result.message().c_str());
callback->setError(result.error_code(), result.message().c_str());
if (!g_idle_add(callErrorCallback, static_cast<void*>(callback))) {
- LoggerE("g_idle_add fails");
+ LoggerE("g_idle_add failed");
delete callback;
callback = NULL;
}
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&ArchiveInstance::x, this, _1, _2));
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&ArchiveInstance::x, this, _1, _2));
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&ArchiveInstance::M, this, _1, _2))
- REGISTER_ASYNC("ArchiveManager_open", Open);
- REGISTER_SYNC("ArchiveManager_abort", Abort);
+ REGISTER_METHOD(ArchiveManagerOpen);
+ REGISTER_METHOD(ArchiveManagerAbort);
- REGISTER_ASYNC("ArchiveFile_add", Add);
- REGISTER_ASYNC("ArchiveFile_extractAll", ExtractAll);
- REGISTER_ASYNC("ArchiveFile_getEntries", GetEntries);
- REGISTER_ASYNC("ArchiveFile_getEntryByName", GetEntryByName);
- REGISTER_SYNC("ArchiveFile_close", Close);
+ REGISTER_METHOD(ArchiveFileAdd);
+ REGISTER_METHOD(ArchiveFileExtractAll);
+ REGISTER_METHOD(ArchiveFileGetEntries);
+ REGISTER_METHOD(ArchiveFileGetEntryByName);
+ REGISTER_METHOD(ArchiveFileClose);
- REGISTER_ASYNC("ArchiveFileEntry_extract", Extract);
+ REGISTER_METHOD(ArchiveFileEntryExtract);
- REGISTER_SYNC("Archive_fetchStorages", FetchStorages);
+ REGISTER_METHOD(ArchiveFetchStorages);
-#undef REGISTER_ASYNC
-#undef REGISTER_SYNC
+#undef REGISTER_METHOD
}
ArchiveInstance::~ArchiveInstance() {
Instance::PostMessage(this, val.serialize().c_str());
}
-void ArchiveInstance::Open(const picojson::value& args, picojson::object& out) {
+void ArchiveInstance::ArchiveManagerOpen(const picojson::value& args, picojson::object& out) {
ScopeLogger("%s", args.serialize().c_str());
CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out);
}
}
-void ArchiveInstance::Abort(const picojson::value& args, picojson::object& out) {
+void ArchiveInstance::ArchiveManagerAbort(const picojson::value& args, picojson::object& out) {
ScopeLogger("%s", args.serialize().c_str());
picojson::object data = args.get<picojson::object>();
}
}
-void ArchiveInstance::Add(const picojson::value& args, picojson::object& out) {
+void ArchiveInstance::ArchiveFileAdd(const picojson::value& args, picojson::object& out) {
ScopeLogger("%s", args.serialize().c_str());
CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out);
}
}
-void ArchiveInstance::ExtractAll(const picojson::value& args, picojson::object& out) {
+void ArchiveInstance::ArchiveFileExtractAll(const picojson::value& args, picojson::object& out) {
ScopeLogger("%s", args.serialize().c_str());
CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out);
}
}
-void ArchiveInstance::GetEntries(const picojson::value& args, picojson::object& out) {
+void ArchiveInstance::ArchiveFileGetEntries(const picojson::value& args, picojson::object& out) {
ScopeLogger("%s", args.serialize().c_str());
CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemRead, &out);
}
}
-void ArchiveInstance::GetEntryByName(const picojson::value& args, picojson::object& out) {
+void ArchiveInstance::ArchiveFileGetEntryByName(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger("%s", args.serialize().c_str());
CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemRead, &out);
}
}
-void ArchiveInstance::Close(const picojson::value& args, picojson::object& out) {
+void ArchiveInstance::ArchiveFileClose(const picojson::value& args, picojson::object& out) {
ScopeLogger("%s", args.serialize().c_str());
picojson::object data = args.get<picojson::object>();
ReportSuccess(out);
}
-void ArchiveInstance::Extract(const picojson::value& args, picojson::object& out) {
+void ArchiveInstance::ArchiveFileEntryExtract(const picojson::value& args, picojson::object& out) {
ScopeLogger("%s", args.serialize().c_str());
CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out);
}
}
-void ArchiveInstance::FetchStorages(const picojson::value& args, picojson::object& out) {
+void ArchiveInstance::ArchiveFetchStorages(const picojson::value& args, picojson::object& out) {
ScopeLogger();
picojson::array storages;
ArchiveInstance(ArchiveInstance const&);
void operator=(ArchiveInstance const&);
- /* ArchiveManager methods */
- void Open(const picojson::value& args, picojson::object& out);
- void Abort(const picojson::value& args, picojson::object& out);
-
- /* ArchiveFile methods */
- void Add(const picojson::value& args, picojson::object& out);
- void ExtractAll(const picojson::value& args, picojson::object& out);
- void GetEntries(const picojson::value& args, picojson::object& out);
- void GetEntryByName(const picojson::value& args, picojson::object& out);
- void Close(const picojson::value& args, picojson::object& out);
-
- /* ArchiveFileEntry methods */
- void Extract(const picojson::value& args, picojson::object& out);
-
- /* Filesystem related method */
- void FetchStorages(const picojson::value& args, picojson::object& out);
+ void ArchiveManagerOpen(const picojson::value& args, picojson::object& out);
+ void ArchiveManagerAbort(const picojson::value& args, picojson::object& out);
+
+ void ArchiveFileAdd(const picojson::value& args, picojson::object& out);
+ void ArchiveFileExtractAll(const picojson::value& args, picojson::object& out);
+ void ArchiveFileGetEntries(const picojson::value& args, picojson::object& out);
+ void ArchiveFileGetEntryByName(const picojson::value& args, picojson::object& out);
+ void ArchiveFileClose(const picojson::value& args, picojson::object& out);
+
+ void ArchiveFileEntryExtract(const picojson::value& args, picojson::object& out);
+
+ void ArchiveFetchStorages(const picojson::value& args, picojson::object& out);
void PostError(const common::PlatformException& e, double callback_id);
void PostError(const common::PlatformResult& e, double callback_id);
);
}
- var ret = native_.callSync('BadgeManager_setBadgeCount', {
+ var ret = native_.callSync('BadgeManagerSetBadgeCount', {
appId: args.appId,
count: args.count
});
{ name: 'appId', type: types_.STRING }
]);
- var ret = native_.callSync('BadgeManager_getBadgeCount', {
+ var ret = native_.callSync('BadgeManagerGetBadgeCount', {
appId: args.appId
});
}
]);
- var result = native_.callSync('BadgeManager_addChangeListener', args);
+ var result = native_.callSync('BadgeManagerAddChangeListener', args);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
_badgeListenerRegistered = false;
}
- var result = native_.callSync('BadgeManager_removeChangeListener', args);
+ var result = native_.callSync('BadgeManagerRemoveChangeListener', args);
if (native_.isFailure(result)) throw native_.getErrorObject(result);
};
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&BadgeInstance::x, this, _1, _2));
- REGISTER_SYNC("BadgeManager_setBadgeCount", BadgeManagerSetBadgeCount);
- REGISTER_SYNC("BadgeManager_addChangeListener", BadgeManagerAddChangeListener);
- REGISTER_SYNC("BadgeManager_removeChangeListener", BadgeManagerRemoveChangeListener);
- REGISTER_SYNC("BadgeManager_getBadgeCount", BadgeManagerGetBadgeCount);
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&BadgeInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(BadgeManagerSetBadgeCount);
+ REGISTER_METHOD(BadgeManagerAddChangeListener);
+ REGISTER_METHOD(BadgeManagerRemoveChangeListener);
+ REGISTER_METHOD(BadgeManagerGetBadgeCount);
+
+#undef REGISTER_METHOD
}
BadgeInstance::~BadgeInstance() {
});
};
-//class tizen.BluetoothLEServiceData //////////////////////////
+//class tizen.BluetoothLEServiceData ///////////////////////////
tizen.BluetoothLEServiceData = function(d) {
AV.isConstructorCall(this, tizen.BluetoothLEServiceData);
var uuid_ = '';
}
};
-//class BluetoothLEAdvertiseData //////////////////////////
+//class BluetoothLEAdvertiseData ///////////////////////////
tizen.BluetoothLEAdvertiseData = function(dict) {
AV.isConstructorCall(this, tizen.BluetoothLEAdvertiseData);
var includeName_ = false;
}
};
-//class tizen.BluetoothLEManufacturerData //////////////////////////
+//class tizen.BluetoothLEManufacturerData ///////////////////////////
tizen.BluetoothLEManufacturerData = function(d) {
AV.isConstructorCall(this, tizen.BluetoothLEManufacturerData);
var id_ = '';
}
};
-// class BluetoothClass //////////////////////////
+// class BluetoothClass ///////////////////////////
var BluetoothClass = function(data) {
var services = [];
if (data) {
return BluetoothClass_hasService.apply(this, arguments);
};
-// class BluetoothSocket //////////////////////////
+// class BluetoothSocket ///////////////////////////
var _BLUETOOTH_SOCKET_STATE_CLOSED = 'CLOSED';
function BluetoothSocketListeners() {
data: args.data
};
- var result = native.callSync('BluetoothSocket_writeData', callArgs);
+ var result = native.callSync('BluetoothSocketWriteData', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
id: this._id
};
- var result = native.callSync('BluetoothSocket_readData', callArgs);
+ var result = native.callSync('BluetoothSocketReadData', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
id: this._id
};
- var result = native.callSync('BluetoothSocket_close', callArgs);
+ var result = native.callSync('BluetoothSocketClose', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
-//class BluetoothLEDevice //////////////////////////
+//class BluetoothLEDevice ///////////////////////////
var BluetoothLEDevice = function(data) {
var address = '',
name = null,
};
// Errors are handled by error callback
var result = native.call(
- 'BluetoothLEDevice_connect',
+ 'BluetoothLEDeviceConnect',
{ address: this.address },
callback
);
};
var result = native.call(
- 'BluetoothLEDevice_disconnect',
+ 'BluetoothLEDeviceDisconnect',
{ address: this.address },
callback
);
address: this.address
};
- var result = native.callSync('BluetoothLEDevice_getService', callArgs);
+ var result = native.callSync('BluetoothLEDeviceGetService', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
} else {
address: this.address
};
- var result = native.callSync('BluetoothLEDevice_getServiceAllUuids', callArgs);
+ var result = native.callSync('BluetoothLEDeviceGetServiceAllUuids', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
} else {
_bleConnectChangeListener.removeListener(args.watchID);
};
-// class BluetoothDevice //////////////////////////
+// class BluetoothDevice ///////////////////////////
var BluetoothDevice = function(data) {
var self = this;
function _getter(field) {
callArgs.address = self.address;
callArgs.field = field;
- var result = native.callSync('BluetoothDevice_getBoolValue', callArgs);
+ var result = native.callSync('BluetoothDeviceGetBoolValue', callArgs);
if (native.isFailure(result)) {
return false;
};
var result = native.call(
- 'BluetoothDevice_connectToServiceByUUID',
+ 'BluetoothDeviceConnectToServiceByUUID',
callArgs,
callback
);
}
};
-// class BluetoothServiceHandler //////////////////////////
+// class BluetoothServiceHandler ///////////////////////////
function BluetoothServiceListeners() {
var that = this;
this.serviceCallback = function(data) {
uuid: this.uuid
};
- var result = native.callSync('BluetoothAdapter_isServiceConnected', {
+ var result = native.callSync('BluetoothAdapterIsServiceConnected', {
uuid: this.uuid
});
}
};
- var result = native.call('BluetoothServiceHandler_unregister', callArgs, callback);
+ var result = native.call('BluetoothServiceHandlerUnregister', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
_bluetoothServiceListeners.removeListener(this.uuid);
};
-// class BluetoothHealthApplication //////////////////////////
+// class BluetoothHealthApplication ///////////////////////////
function BluetoothHealthApplicationListeners() {
var that = this;
this.appCallback = function(data) {
BluetoothHealthApplication.prototype.unregister = function() {
privUtils_.log('Entered BluetoothHealthApplication.unregister()');
+ privUtils_.printDeprecationWarningFor('BluetoothHealthApplication');
var args = AV.validateMethod(arguments, [
{
name: 'successCallback',
}
};
- var result = native.call('BluetoothHealthApplication_unregister', callArgs, callback);
+ var result = native.call('BluetoothHealthApplicationUnregister', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
_bluetoothHealthApplicationListeners.removeListener(this._id);
};
-// class BluetoothProfileHandler //////////////////////////
+// class BluetoothProfileHandler ///////////////////////////
var _BluetoothProfileType = {
HEALTH: 'HEALTH'
};
var BluetoothProfileHandler = function(data) {
if (data) {
+ var profileType = data.profileType;
+ function profileTypeGetter() {
+ privUtils_.printDeprecationWarningFor('profileType');
+ return profileType;
+ }
Object.defineProperties(this, {
- profileType: { value: data.profileType, writable: false, enumerable: true }
+ profileType: { enumerable: true, set: function() {}, get: profileTypeGetter }
});
}
};
-// class BluetoothHealthProfileHandler //////////////////////////
+// class BluetoothHealthProfileHandler ///////////////////////////
var BluetoothHealthProfileHandler = function(data) {
BluetoothProfileHandler.call(this, data);
};
BluetoothHealthProfileHandler.prototype.registerSinkApplication = function() {
privUtils_.log('Entered BluetoothHealthProfileHandler.registerSinkApplication()');
+ privUtils_.printDeprecationWarningFor('BluetoothHealthProfileHandler');
var args = AV.validateMethod(arguments, [
{
};
var result = native.call(
- 'BluetoothHealthProfileHandler_registerSinkApp',
+ 'BluetoothHealthProfileHandlerRegisterSinkApp',
callArgs,
callback
);
BluetoothHealthProfileHandler.prototype.connectToSource = function() {
privUtils_.log('Entered BluetoothHealthProfileHandler.connectToSource()');
+ privUtils_.printDeprecationWarningFor('BluetoothHealthProfileHandler');
var args = AV.validateMethod(arguments, [
{
};
var result = native.call(
- 'BluetoothHealthProfileHandler_connectToSource',
+ 'BluetoothHealthProfileHandlerConnectToSource',
callArgs,
callback
);
}
};
-// class BluetoothHealthChannel //////////////////////////
+// class BluetoothHealthChannel ///////////////////////////
var BluetoothHealthChannel = function(data) {
Object.defineProperties(this, {
peer: { value: data.peer, writable: false, enumerable: true },
BluetoothHealthChannel.prototype.close = function() {
privUtils_.log('Entered BluetoothHealthChannel.close()');
+ privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
if (this.isConnected) {
var callArgs = {
address: this.peer.address
};
- var result = native.callSync('BluetoothHealthChannel_close', callArgs);
+ var result = native.callSync('BluetoothHealthChannelClose', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
BluetoothHealthChannel.prototype.sendData = function() {
privUtils_.log('Entered BluetoothHealthChannel.sendData()');
+ privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
+
var args = AV.validateMethod(arguments, [
{
name: 'data',
data: args.data
};
- var result = native.callSync('BluetoothHealthChannel_sendData', callArgs);
+ var result = native.callSync('BluetoothHealthChannelSendData', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
var BluetoothHealthChannel_setListener = function() {
privUtils_.log('Entered BluetoothHealthChannel.setListener()');
+ privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
privUtils_.checkPrivilegeAccess4Ver(
'2.4',
Privilege.BLUETOOTH,
var BluetoothHealthChannel_unsetListener = function() {
privUtils_.log('Entered BluetoothHealthChannel.unsetListener ()');
+ privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
if (T.isEmptyObject(_healthListeners)) {
privUtils_.checkPrivilegeAccess4Ver(
'2.4',
};
BluetoothHealthChannel.prototype.unsetListener = function() {
+ privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
BluetoothHealthChannel_unsetListener.apply(this, arguments);
};
}
);
-//class BluetoothLEAdapter //////////////////////////
+//class BluetoothLEAdapter ///////////////////////////
var BluetoothLEAdapter = function() {};
BluetoothLEAdapter.prototype.startScan = function() {
}
]);
- var result = native.callSync('BluetoothLEAdapter_startScan', {});
+ var result = native.callSync('BluetoothLEAdapterStartScan', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
_bleScanListener.removeListener();
- var result = native.callSync('BluetoothLEAdapter_stopScan', {});
+ var result = native.callSync('BluetoothLEAdapterStopScan', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
connectable: T.isNullOrUndefined(args.connectable) ? true : args.connectable
};
- var result = native.callSync('BluetoothLEAdapter_startAdvertise', callArgs);
+ var result = native.callSync('BluetoothLEAdapterStartAdvertise', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
BluetoothLEAdapter.prototype.stopAdvertise = function() {
privUtils_.log('Entered BluetoothLEAdapter.stopAdvertise()');
- var result = native.callSync('BluetoothLEAdapter_stopAdvertise', {});
+ var result = native.callSync('BluetoothLEAdapterStopAdvertise', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
-//class BluetoothGATTService //////////////////////////
+//class BluetoothGATTService ///////////////////////////
var BluetoothGATTService = function(data, address) {
var handle_ = data.handle;
var uuid_ = data.uuid;
var address_ = address || data.address;
function servicesGetter() {
var services = [];
- var result = native.callSync('BluetoothGATTService_getServices', {
+ var result = native.callSync('BluetoothGATTServiceGetServices', {
handle: handle_,
address: address_
});
}
function characteristicsGetter() {
var characteristics = [];
- var result = native.callSync('BluetoothGATTService_getCharacteristics', {
+ var result = native.callSync('BluetoothGATTServiceGetCharacteristics', {
handle: handle_,
uuid: uuid_,
address: address_
return d;
};
-//class BluetoothGATTCharacteristic //////////////////////////
+//class BluetoothGATTCharacteristic ///////////////////////////
var BluetoothGATTCharacteristic = function(data, address) {
var handle_ = data.handle;
var descriptors_ = [];
var callArgs = { handle: handle_, address: address_ };
- var result = native.call('BluetoothGATT_readValue', callArgs, callback);
+ var result = native.call('BluetoothGATTServiceReadValue', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
address: address_
};
- var result = native.call('BluetoothGATT_writeValue', callArgs, callback);
+ var result = native.call('BluetoothGATTServiceWriteValue', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
function(listener, event) {
listener(event);
},
- 'BluetoothGATTCharacteristic_addValueChangeListener',
- 'BluetoothGATTCharacteristic_removeValueChangeListener',
+ 'BluetoothGATTServiceAddValueChangeListener',
+ 'BluetoothGATTServiceRemoveValueChangeListener',
true
);
function(listener, event) {
listener(event);
},
- 'BluetoothLEDevice_addConnectStateChangeListener',
- 'BluetoothLEDevice_removeConnectStateChangeListener'
+ 'BluetoothLEDeviceAddConnectStateChangeListener',
+ 'BluetoothLEDeviceRemoveConnectStateChangeListener'
);
-//class BluetoothGATTDescriptor //////////////////////////
+//class BluetoothGATTDescriptor ///////////////////////////
var BluetoothGATTDescriptor = function(data, address) {
var handle_ = data.handle;
//address_ is needed to control if device is still connected
var callArgs = { handle: handle_, address: address_ };
- var result = native.call('BluetoothGATT_readValue', callArgs, callback);
+ var result = native.call('BluetoothGATTServiceReadValue', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
address: address_
};
- var result = native.call('BluetoothGATT_writeValue', callArgs, callback);
+ var result = native.call('BluetoothGATTServiceWriteValue', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
};
};
-// class BluetoothAdapter //////////////////////////
+// class BluetoothAdapter ///////////////////////////
var BluetoothAdapter = function() {
function nameGetter() {
- var result = native.callSync('BluetoothAdapter_getName', {});
+ var result = native.callSync('BluetoothAdapterGetName', {});
if (native.isFailure(result)) {
return '';
}
function addressGetter() {
- var result = native.callSync('BluetoothAdapter_getAddress', {});
+ var result = native.callSync('BluetoothAdapterGetAddress', {});
if (native.isFailure(result)) {
return '';
}
function poweredGetter() {
- var result = native.callSync('BluetoothAdapter_getPowered', {});
+ var result = native.callSync('BluetoothAdapterGetPowered', {});
if (native.isFailure(result)) {
return false;
}
function visibleGetter() {
- var result = native.callSync('BluetoothAdapter_getVisible', {});
+ var result = native.callSync('BluetoothAdapterGetVisible', {});
if (native.isFailure(result)) {
return false;
}
};
- var result = native.call('BluetoothAdapter_setName', callArgs, callback);
+ var result = native.call('BluetoothAdapterSetName', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
BluetoothAdapter.prototype.setPowered = function() {
privUtils_.log('Entered BluetoothAdapter.setPowered()');
+ privUtils_.printDeprecationWarningFor('setPowered()');
privUtils_.warn(
- 'DEPRECATION WARNING: setPowered() is deprecated and will be removed from ' +
- 'next release. Let the user turn on/off Bluetooth through the Settings ' +
- 'application instead.'
+ 'Let the user turn on/off Bluetooth through the Settings application instead.'
);
var args = AV.validateMethod(arguments, [
}
};
- var result = native.call('BluetoothAdapter_setPowered', callArgs, callback);
+ var result = native.call('BluetoothAdapterSetPowered', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
-// This method is deprecated since Tizen 2.3 and will be removed in Tizen 3.0.
+// This method is deprecated since Tizen 2.3.
BluetoothAdapter.prototype.setVisible = function() {
privUtils_.log('Entered BluetoothAdapter.setVisible()');
+ privUtils_.printDeprecationWarningFor('setVisible()');
privUtils_.warn(
- 'DEPRECATION WARNING: setVisible() is deprecated and will be removed from ' +
- 'next release. Let the user change the Bluetooth visibility through the ' +
- 'Settings application instead.'
+ 'Let the user change the Bluetooth visibility through the Settings ' +
+ 'application instead.'
);
var args = AV.validateMethod(arguments, [
}
};
- var result = native.call('BluetoothAdapter_setVisible', callArgs, callback);
+ var result = native.call('BluetoothAdapterSetVisible', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
_BluetoothDiscoverDevicesErrorCallback
);
- var result = native.callSync('BluetoothAdapter_discoverDevices', {});
+ var result = native.callSync('BluetoothAdapterDiscoverDevices', {});
if (native.isFailure(result)) {
native.removeListener(
}
};
- var result = native.call('BluetoothAdapter_stopDiscovery', {}, callback);
+ var result = native.call('BluetoothAdapterStopDiscovery', {}, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
}
};
- var result = native.call('BluetoothAdapter_getKnownDevices', {}, callback);
+ var result = native.call('BluetoothAdapterGetKnownDevices', {}, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
var result = native.call(
- 'BluetoothAdapter_getDevice',
+ 'BluetoothAdapterGetDevice',
{ address: args.address },
callback
);
}
};
- var result = native.call('BluetoothAdapter_createBonding', callArgs, callback);
+ var result = native.call('BluetoothAdapterCreateBonding', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
}
};
- var result = native.call('BluetoothAdapter_destroyBonding', callArgs, callback);
+ var result = native.call('BluetoothAdapterDestroyBonding', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
var result = native.call(
- 'BluetoothAdapter_registerRFCOMMServiceByUUID',
+ 'BluetoothAdapterRegisterRFCOMMServiceByUUID',
callArgs,
callback
);
BluetoothAdapter.prototype.getBluetoothProfileHandler = function() {
privUtils_.log('Entered BluetoothAdapter.getBluetoothProfileHandler()');
-
+ privUtils_.printDeprecationWarningFor('getBluetoothProfileHandler');
var args = AV.validateMethod(arguments, [
{
name: 'profileType',
var callArgs = { profileType: args.profileType };
- var result = native.callSync('BluetoothAdapter_getBluetoothProfileHandler', callArgs);
+ var result = native.callSync('BluetoothAdapterGetBluetoothProfileHandler', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
-// class BluetoothManager //////////////////////////
+// class BluetoothManager ///////////////////////////
var BluetoothManager = function() {
Object.defineProperties(this, {
deviceMajor: {
privUtils_.log('Entered BluetoothManager.getLEAdapter()');
return BluetoothManager_getLEAdapter();
};
-// exports /////////////////////////////////////////
+// exports //////////////////////////////////////////
exports = new BluetoothManager();
ScopeLogger();
const auto& address = args.get("address").get<std::string>();
if (!IsStillConnected(address)) {
- LogAndReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR, "Device is not connected"), &out,
- ("Device with address %s is no longer connected", address.c_str()));
- return;
- }
-
- bt_gatt_h handle = (bt_gatt_h) static_cast<long>(args.get(kHandle).get<double>());
+ LoggerW("Device with address %s is no longer connected", address.c_str());
+ } else {
+ bt_gatt_h handle = (bt_gatt_h) static_cast<long>(args.get(kHandle).get<double>());
- int ret = bt_gatt_client_unset_characteristic_value_changed_cb(handle);
+ int ret = bt_gatt_client_unset_characteristic_value_changed_cb(handle);
- if (BT_ERROR_NONE != ret) {
- LogAndReportError(
- util::GetBluetoothError(ret, "Failed to unregister listener"), &out,
- ("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d (%s)", ret,
- get_error_message(ret)));
- } else {
- gatt_characteristic_.erase(
- std::remove(gatt_characteristic_.begin(), gatt_characteristic_.end(), handle),
- gatt_characteristic_.end());
- ReportSuccess(out);
+ if (BT_ERROR_NONE != ret) {
+ LoggerW("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d (%s)", ret,
+ get_error_message(ret));
+ } else {
+ gatt_characteristic_.erase(
+ std::remove(gatt_characteristic_.begin(), gatt_characteristic_.end(), handle),
+ gatt_characteristic_.end());
+ }
}
+ ReportSuccess(out);
}
common::PlatformResult BluetoothGATTService::GetServiceAllUuids(const std::string& address,
BluetoothHealthApplication::BluetoothHealthApplication(BluetoothHealthProfileHandler& handler)
: handler_(handler) {
ScopeLogger();
+ tools::PrintDeprecationWarningFor("BluetoothHealthApplication");
}
void BluetoothHealthApplication::Unregister(const picojson::value& data, picojson::object& out) {
ScopeLogger();
+ tools::PrintDeprecationWarningFor("BluetoothHealthApplication");
CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth, Privilege::kBluetoothHealth,
&out);
void BluetoothHealthApplication::ToJson(short data_type, const std::string& name, const char* id,
picojson::object* out) {
ScopeLogger();
+ tools::PrintDeprecationWarningFor("BluetoothHealthApplication");
out->insert(std::make_pair(kDataType, picojson::value(static_cast<double>(data_type))));
out->insert(std::make_pair(kName, picojson::value(name)));
out->insert(std::make_pair(kId, picojson::value(id)));
/**
* Signature: @code void unregister(successCallback, errorCallback); @endcode
+ * Deprecated since tizen version 5.5
* JSON: @code data: {method: 'BluetoothHealthApplication_unregister', args: {}} @endcode
* Invocation: @code native.call(request, result_callback); @endcode
* Return:
*/
void Unregister(const picojson::value& data, picojson::object& out);
+ /**
+ * Signature: @code static void ToJson(short, const std::string&, const char*, picojson::object*);
+ * @endcode
+ * Deprecated since tizen version 5.5
+ */
static void ToJson(short data_type, const std::string& name, const char* id,
picojson::object* out);
void BluetoothHealthChannel::Close(const picojson::value& data, picojson::object& out) {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthChannel");
CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth, Privilege::kBluetoothHealth,
&out);
void BluetoothHealthChannel::SendData(const picojson::value& data, picojson::object& out) {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthChannel");
CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth, Privilege::kBluetoothHealth,
&out);
void BluetoothHealthChannel::ToJson(unsigned int channel, bt_hdp_channel_type_e type,
picojson::object* out) {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthChannel");
const char* type_str = "UNKNOWN";
switch (type) {
bt_device_info_s* device_info, const char* app_id,
picojson::object* out) {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthChannel");
ToJson(channel, type, out);
auto& device = out->insert(std::make_pair(kPeer, picojson::value(picojson::object())))
.first->second.get<picojson::object>();
public:
/**
* Signature: @code void close(); @endcode
+ * Deprecated since tizen version 5.5
* JSON: @code data: {method: 'BluetoothHealthChannel_close', args: {}} @endcode
* Invocation: @code native.callSync(request); @endcode
* Return:
/**
* Signature: @code unsigned long sendData(data[]); @endcode
+ * Deprecated since tizen version 5.5
* JSON: @code data: {method: 'BluetoothHealthChannel_sendData', args: {data: data}} @endcode
* Invocation: @code native.callSync(request); @endcode
* Return:
*/
void SendData(const picojson::value& data, picojson::object& out);
+ /**
+ * Signature: @code void ToJson(unsigned int, bt_hdp_channel_type_e, picojson::object*); @endcode
+ * Deprecated since tizen version 5.5
+ */
static void ToJson(unsigned int channel, bt_hdp_channel_type_e type, picojson::object* out);
+ /**
+ * Signature: @code void ToJson(unsigned int, bt_hdp_channel_type_e, bt_device_info_s*,
+ * const char*, picojson::object*); @endcode
+ * Deprecated since tizen version 5.5
+ */
static void ToJson(unsigned int channel, bt_hdp_channel_type_e type,
bt_device_info_s* device_info, const char* app_id, picojson::object* out);
};
: instance_(instance) {
// initialize listeners
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthProfileHandler");
if (BT_ERROR_NONE != bt_hdp_set_connection_state_changed_cb(OnConnected, OnDisconnected, this)) {
LoggerE("bt_hdp_set_connection_state_changed_cb() failed");
}
BluetoothHealthProfileHandler::~BluetoothHealthProfileHandler() {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthProfileHandler");
bt_hdp_unset_connection_state_changed_cb();
bt_hdp_unset_data_received_cb();
const char* app_id, bt_hdp_channel_type_e type,
unsigned int channel, void* user_data) {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthProfileHandler");
BluetoothHealthProfileHandler* object = static_cast<BluetoothHealthProfileHandler*>(user_data);
void BluetoothHealthProfileHandler::OnDisconnected(int result, const char* /* remote_address */,
unsigned int channel, void* user_data) {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthProfileHandler");
BluetoothHealthProfileHandler* object = static_cast<BluetoothHealthProfileHandler*>(user_data);
void BluetoothHealthProfileHandler::OnDataReceived(unsigned int channel, const char* data,
unsigned int size, void* user_data) {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthProfileHandler");
BluetoothHealthProfileHandler* object = static_cast<BluetoothHealthProfileHandler*>(user_data);
void BluetoothHealthProfileHandler::RegisterSinkApp(const picojson::value& data,
picojson::object& out) {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthProfileHandler");
CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth, Privilege::kBluetoothHealth,
&out);
void BluetoothHealthProfileHandler::ConnectToSource(const picojson::value& data,
picojson::object& out) {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthProfileHandler");
CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth, Privilege::kBluetoothHealth,
&out);
void BluetoothHealthProfileHandler::UnregisterSinkAppAsync(const std::string& app_id,
int callback_handle) {
ScopeLogger();
+ PrintDeprecationWarningFor("BluetoothHealthProfileHandler");
auto unregister_app = [app_id, this](const std::shared_ptr<picojson::value>& response) -> void {
ScopeLogger("Entered into asynchronous function, uregister_app");
public:
/**
* Signature: @code void registerSinkApp(dataType, name, successCallback, errorCallback); @endcode
+ * Deprecated since tizen version 5.5
* JSON: @code data: {method: 'BluetoothHealthProfileHandler_registerSinkApp',
* args: {dataType: dataType, name: name}} @endcode
* Invocation: @code native.call(request, result_callback); @endcode
/**
* Signature: @code void connectToSource(peer, application, successCallback, errorCallback);
* @endcode
+ * Deprecated since tizen version 5.5
* JSON: @code data: {method: 'BluetoothHealthProfileHandler_connectToSource',
* args: {peer: peer, application: application}} @endcode
* Invocation: @code native.call(request, result_callback); @endcode
*/
void ConnectToSource(const picojson::value& data, picojson::object& out);
+ /**
+ * Signature: @code explicit BluetoothHealthProfileHandler(BluetoothInstance&); @endcode
+ * Deprecated since tizen version 5.5
+ */
explicit BluetoothHealthProfileHandler(BluetoothInstance& instance);
+
+ /**
+ * Signature: @code ~BluetoothHealthProfileHandler(); @endcode
+ * Deprecated since tizen version 5.5
+ */
~BluetoothHealthProfileHandler();
+ /**
+ * Signature: @code void UnregisterSinkAppAsync(const std::string&, int); @endcode
+ * Deprecated since tizen version 5.5
+ */
void UnregisterSinkAppAsync(const std::string& app_id, int callback_handle);
private:
BluetoothHealthProfileHandler(const BluetoothHealthProfileHandler&) = delete;
BluetoothHealthProfileHandler& operator=(const BluetoothHealthProfileHandler&) = delete;
+ /**
+ * Signature: @code static void OnConnected(int, const char*, const char*, bt_hdp_channel_type_e,
+ * unsigned int, void*); @endcode
+ * Deprecated since tizen version 5.5
+ */
static void OnConnected(int result, const char* remote_address, const char* app_id,
bt_hdp_channel_type_e type, unsigned int channel, void* user_data);
+ /**
+ * Signature: @code static void OnDisconnected(int, const char*, unsigned int, void*); @endcode
+ * Deprecated since tizen version 5.5
+ */
static void OnDisconnected(int result, const char* remote_address, unsigned int channel,
void* user_data);
+ /**
+ * Signature: @code static void OnDataReceived(unsigned int, const char*, unsigned int, void*);
+ * @endcode
+ * Deprecated since tizen version 5.5
+ */
static void OnDataReceived(unsigned int channel, const char* data, unsigned int size,
void* user_data);
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_ASYNC(c, func) RegisterSyncHandler(c, func);
-#define REGISTER_SYNC(c, func) RegisterSyncHandler(c, func);
-
- // BluetoothAdapter
- REGISTER_ASYNC("BluetoothAdapter_setName",
- std::bind(&BluetoothAdapter::SetName, &bluetooth_adapter_, _1, _2));
- REGISTER_ASYNC("BluetoothAdapter_setPowered",
- std::bind(&BluetoothAdapter::SetPowered, &bluetooth_adapter_, _1, _2));
- REGISTER_ASYNC("BluetoothAdapter_setVisible",
- std::bind(&BluetoothAdapter::SetVisible, &bluetooth_adapter_, _1, _2));
- REGISTER_SYNC("BluetoothAdapter_discoverDevices",
- std::bind(&BluetoothAdapter::DiscoverDevices, &bluetooth_adapter_, _1, _2));
- REGISTER_ASYNC("BluetoothAdapter_stopDiscovery",
- std::bind(&BluetoothAdapter::StopDiscovery, &bluetooth_adapter_, _1, _2));
- REGISTER_ASYNC("BluetoothAdapter_getKnownDevices",
- std::bind(&BluetoothAdapter::GetKnownDevices, &bluetooth_adapter_, _1, _2));
- REGISTER_ASYNC("BluetoothAdapter_getDevice",
- std::bind(&BluetoothAdapter::GetDevice, &bluetooth_adapter_, _1, _2));
- REGISTER_ASYNC("BluetoothAdapter_createBonding",
- std::bind(&BluetoothAdapter::CreateBonding, &bluetooth_adapter_, _1, _2));
- REGISTER_ASYNC("BluetoothAdapter_destroyBonding",
- std::bind(&BluetoothAdapter::DestroyBonding, &bluetooth_adapter_, _1, _2));
- REGISTER_ASYNC(
- "BluetoothAdapter_registerRFCOMMServiceByUUID",
- std::bind(&BluetoothAdapter::RegisterRFCOMMServiceByUUID, &bluetooth_adapter_, _1, _2));
- REGISTER_SYNC(
- "BluetoothAdapter_getBluetoothProfileHandler",
- std::bind(&BluetoothAdapter::GetBluetoothProfileHandler, &bluetooth_adapter_, _1, _2));
- REGISTER_SYNC("BluetoothAdapter_getName",
- std::bind(&BluetoothAdapter::GetName, &bluetooth_adapter_, _1, _2));
- REGISTER_SYNC("BluetoothAdapter_getAddress",
- std::bind(&BluetoothAdapter::GetAddress, &bluetooth_adapter_, _1, _2));
- REGISTER_SYNC("BluetoothAdapter_getPowered",
- std::bind(&BluetoothAdapter::GetPowered, &bluetooth_adapter_, _1, _2));
- REGISTER_SYNC("BluetoothAdapter_getVisible",
- std::bind(&BluetoothAdapter::GetVisible, &bluetooth_adapter_, _1, _2));
- REGISTER_SYNC("BluetoothAdapter_isServiceConnected",
- std::bind(&BluetoothAdapter::IsServiceConnected, &bluetooth_adapter_, _1, _2));
-
- // BluetoothDevice
- REGISTER_ASYNC("BluetoothDevice_connectToServiceByUUID",
- std::bind(&BluetoothDevice::ConnectToServiceByUUID, &bluetooth_device_, _1, _2));
- REGISTER_SYNC("BluetoothDevice_getBoolValue",
- std::bind(&BluetoothDevice::GetBoolValue, &bluetooth_device_, _1, _2));
-
- // BluetoothHealthApplication
- REGISTER_ASYNC(
- "BluetoothHealthApplication_unregister",
- std::bind(&BluetoothHealthApplication::Unregister, &bluetooth_health_application_, _1, _2));
-
- // BluetoothHealthChannel
- REGISTER_SYNC("BluetoothHealthChannel_close",
- std::bind(&BluetoothHealthChannel::Close, &bluetooth_health_channel_, _1, _2));
- REGISTER_SYNC("BluetoothHealthChannel_sendData",
- std::bind(&BluetoothHealthChannel::SendData, &bluetooth_health_channel_, _1, _2));
-
- // BluetoothHealthProfileHandler
- REGISTER_ASYNC("BluetoothHealthProfileHandler_registerSinkApp",
- std::bind(&BluetoothHealthProfileHandler::RegisterSinkApp,
- &bluetooth_health_profile_handler_, _1, _2));
- REGISTER_ASYNC("BluetoothHealthProfileHandler_connectToSource",
- std::bind(&BluetoothHealthProfileHandler::ConnectToSource,
- &bluetooth_health_profile_handler_, _1, _2));
-
- // BluetoothServiceHandler
- REGISTER_ASYNC(
- "BluetoothServiceHandler_unregister",
- std::bind(&BluetoothServiceHandler::Unregister, &bluetooth_service_handler_, _1, _2));
-
- // BluetoothSocket
- REGISTER_SYNC("BluetoothSocket_writeData",
- std::bind(&BluetoothSocket::WriteData, &bluetooth_socket_, _1, _2));
- REGISTER_SYNC("BluetoothSocket_readData",
- std::bind(&BluetoothSocket::ReadData, &bluetooth_socket_, _1, _2));
- REGISTER_SYNC("BluetoothSocket_close",
- std::bind(&BluetoothSocket::Close, &bluetooth_socket_, _1, _2));
-
- // BluetoothLEAdapter
- REGISTER_SYNC("BluetoothLEAdapter_startScan",
- std::bind(&BluetoothLEAdapter::StartScan, &bluetooth_le_adapter_, _1, _2));
- REGISTER_SYNC("BluetoothLEAdapter_stopScan",
- std::bind(&BluetoothLEAdapter::StopScan, &bluetooth_le_adapter_, _1, _2));
- REGISTER_SYNC("BluetoothLEAdapter_startAdvertise",
- std::bind(&BluetoothLEAdapter::StartAdvertise, &bluetooth_le_adapter_, _1, _2));
- REGISTER_SYNC("BluetoothLEAdapter_stopAdvertise",
- std::bind(&BluetoothLEAdapter::StopAdvertise, &bluetooth_le_adapter_, _1, _2));
-
- // BluetoothLEDevice
- REGISTER_ASYNC("BluetoothLEDevice_connect",
- std::bind(&BluetoothLEDevice::Connect, &bluetooth_le_device_, _1, _2));
- REGISTER_ASYNC("BluetoothLEDevice_disconnect",
- std::bind(&BluetoothLEDevice::Disconnect, &bluetooth_le_device_, _1, _2));
- REGISTER_SYNC("BluetoothLEDevice_getService",
- std::bind(&BluetoothLEDevice::GetService, &bluetooth_le_device_, _1, _2));
- REGISTER_SYNC(
- "BluetoothLEDevice_addConnectStateChangeListener",
- std::bind(&BluetoothLEDevice::AddConnectStateChangeListener, &bluetooth_le_device_, _1, _2));
- REGISTER_SYNC("BluetoothLEDevice_removeConnectStateChangeListener",
- std::bind(&BluetoothLEDevice::RemoveConnectStateChangeListener,
- &bluetooth_le_device_, _1, _2));
- REGISTER_SYNC("BluetoothLEDevice_getServiceAllUuids",
- std::bind(&BluetoothLEDevice::GetServiceAllUuids, &bluetooth_le_device_, _1, _2));
-
- // BluetoothGATTService
- REGISTER_SYNC("BluetoothGATTService_getServices",
- std::bind(&BluetoothGATTService::GetServices, &bluetooth_gatt_service_, _1, _2));
- REGISTER_SYNC(
- "BluetoothGATTService_getCharacteristics",
- std::bind(&BluetoothGATTService::GetCharacteristics, &bluetooth_gatt_service_, _1, _2));
- REGISTER_SYNC("BluetoothGATT_readValue",
- std::bind(&BluetoothGATTService::ReadValue, &bluetooth_gatt_service_, _1, _2));
- REGISTER_SYNC("BluetoothGATT_writeValue",
- std::bind(&BluetoothGATTService::WriteValue, &bluetooth_gatt_service_, _1, _2));
- REGISTER_SYNC(
- "BluetoothGATTCharacteristic_addValueChangeListener",
- std::bind(&BluetoothGATTService::AddValueChangeListener, &bluetooth_gatt_service_, _1, _2));
- REGISTER_SYNC("BluetoothGATTCharacteristic_removeValueChangeListener",
- std::bind(&BluetoothGATTService::RemoveValueChangeListener,
- &bluetooth_gatt_service_, _1, _2));
-
-#undef REGISTER_ASYNC
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&BluetoothInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(BluetoothAdapterSetName);
+ REGISTER_METHOD(BluetoothAdapterSetPowered);
+ REGISTER_METHOD(BluetoothAdapterSetVisible);
+ REGISTER_METHOD(BluetoothAdapterDiscoverDevices);
+ REGISTER_METHOD(BluetoothAdapterStopDiscovery);
+ REGISTER_METHOD(BluetoothAdapterGetKnownDevices);
+ REGISTER_METHOD(BluetoothAdapterGetDevice);
+ REGISTER_METHOD(BluetoothAdapterCreateBonding);
+ REGISTER_METHOD(BluetoothAdapterDestroyBonding);
+ REGISTER_METHOD(BluetoothAdapterRegisterRFCOMMServiceByUUID);
+ REGISTER_METHOD(BluetoothAdapterGetBluetoothProfileHandler);
+ REGISTER_METHOD(BluetoothAdapterGetName);
+ REGISTER_METHOD(BluetoothAdapterGetAddress);
+ REGISTER_METHOD(BluetoothAdapterGetPowered);
+ REGISTER_METHOD(BluetoothAdapterGetVisible);
+ REGISTER_METHOD(BluetoothAdapterIsServiceConnected);
+
+ REGISTER_METHOD(BluetoothDeviceConnectToServiceByUUID);
+ REGISTER_METHOD(BluetoothDeviceGetBoolValue);
+
+ REGISTER_METHOD(BluetoothHealthApplicationUnregister);
+
+ REGISTER_METHOD(BluetoothHealthChannelClose);
+ REGISTER_METHOD(BluetoothHealthChannelSendData);
+
+ REGISTER_METHOD(BluetoothHealthProfileHandlerRegisterSinkApp);
+ REGISTER_METHOD(BluetoothHealthProfileHandlerConnectToSource);
+
+ REGISTER_METHOD(BluetoothServiceHandlerUnregister);
+
+ REGISTER_METHOD(BluetoothSocketWriteData);
+ REGISTER_METHOD(BluetoothSocketReadData);
+ REGISTER_METHOD(BluetoothSocketClose);
+
+ REGISTER_METHOD(BluetoothLEAdapterStartScan);
+ REGISTER_METHOD(BluetoothLEAdapterStopScan);
+ REGISTER_METHOD(BluetoothLEAdapterStartAdvertise);
+ REGISTER_METHOD(BluetoothLEAdapterStopAdvertise);
+
+ REGISTER_METHOD(BluetoothLEDeviceConnect);
+ REGISTER_METHOD(BluetoothLEDeviceDisconnect);
+ REGISTER_METHOD(BluetoothLEDeviceGetService);
+ REGISTER_METHOD(BluetoothLEDeviceAddConnectStateChangeListener);
+ REGISTER_METHOD(BluetoothLEDeviceRemoveConnectStateChangeListener);
+ REGISTER_METHOD(BluetoothLEDeviceGetServiceAllUuids);
+
+ REGISTER_METHOD(BluetoothGATTServiceGetServices);
+ REGISTER_METHOD(BluetoothGATTServiceGetCharacteristics);
+ REGISTER_METHOD(BluetoothGATTServiceReadValue);
+ REGISTER_METHOD(BluetoothGATTServiceWriteValue);
+ REGISTER_METHOD(BluetoothGATTServiceAddValueChangeListener);
+ REGISTER_METHOD(BluetoothGATTServiceRemoveValueChangeListener);
+
+#undef REGISTER_METHOD
}
BluetoothInstance::~BluetoothInstance() {
FireEvent(event, *value.get());
}
+void BluetoothInstance::BluetoothAdapterSetName(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.SetName(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterSetPowered(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.SetPowered(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterSetVisible(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.SetVisible(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterDiscoverDevices(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.DiscoverDevices(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterStopDiscovery(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.StopDiscovery(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterGetKnownDevices(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.GetKnownDevices(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterGetDevice(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.GetDevice(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterCreateBonding(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.CreateBonding(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterDestroyBonding(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.DestroyBonding(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterRegisterRFCOMMServiceByUUID(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.RegisterRFCOMMServiceByUUID(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterGetBluetoothProfileHandler(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.GetBluetoothProfileHandler(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterGetName(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.GetName(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterGetAddress(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.GetAddress(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterGetPowered(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.GetPowered(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterGetVisible(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.GetVisible(args, out);
+}
+
+void BluetoothInstance::BluetoothAdapterIsServiceConnected(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_adapter_.IsServiceConnected(args, out);
+}
+
+void BluetoothInstance::BluetoothDeviceConnectToServiceByUUID(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_device_.ConnectToServiceByUUID(args, out);
+}
+
+void BluetoothInstance::BluetoothDeviceGetBoolValue(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_device_.GetBoolValue(args, out);
+}
+
+void BluetoothInstance::BluetoothHealthApplicationUnregister(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_health_application_.Unregister(args, out);
+}
+
+void BluetoothInstance::BluetoothHealthChannelClose(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_health_channel_.Close(args, out);
+}
+
+void BluetoothInstance::BluetoothHealthChannelSendData(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_health_channel_.SendData(args, out);
+}
+
+void BluetoothInstance::BluetoothHealthProfileHandlerRegisterSinkApp(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_health_profile_handler_.RegisterSinkApp(args, out);
+}
+
+void BluetoothInstance::BluetoothHealthProfileHandlerConnectToSource(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_health_profile_handler_.ConnectToSource(args, out);
+}
+
+void BluetoothInstance::BluetoothServiceHandlerUnregister(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_service_handler_.Unregister(args, out);
+}
+
+void BluetoothInstance::BluetoothSocketWriteData(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_socket_.WriteData(args, out);
+}
+
+void BluetoothInstance::BluetoothSocketReadData(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_socket_.ReadData(args, out);
+}
+
+void BluetoothInstance::BluetoothSocketClose(const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ bluetooth_socket_.Close(args, out);
+}
+
+void BluetoothInstance::BluetoothLEAdapterStartScan(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_le_adapter_.StartScan(args, out);
+}
+
+void BluetoothInstance::BluetoothLEAdapterStopScan(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_le_adapter_.StopScan(args, out);
+}
+
+void BluetoothInstance::BluetoothLEAdapterStartAdvertise(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_le_adapter_.StartAdvertise(args, out);
+}
+
+void BluetoothInstance::BluetoothLEAdapterStopAdvertise(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_le_adapter_.StopAdvertise(args, out);
+}
+
+void BluetoothInstance::BluetoothLEDeviceConnect(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_le_device_.Connect(args, out);
+}
+
+void BluetoothInstance::BluetoothLEDeviceDisconnect(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_le_device_.Disconnect(args, out);
+}
+
+void BluetoothInstance::BluetoothLEDeviceGetService(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_le_device_.GetService(args, out);
+}
+
+void BluetoothInstance::BluetoothLEDeviceAddConnectStateChangeListener(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_le_device_.AddConnectStateChangeListener(args, out);
+}
+
+void BluetoothInstance::BluetoothLEDeviceRemoveConnectStateChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ bluetooth_le_device_.RemoveConnectStateChangeListener(args, out);
+}
+
+void BluetoothInstance::BluetoothLEDeviceGetServiceAllUuids(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_le_device_.GetServiceAllUuids(args, out);
+}
+
+void BluetoothInstance::BluetoothGATTServiceGetServices(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_gatt_service_.GetServices(args, out);
+}
+
+void BluetoothInstance::BluetoothGATTServiceGetCharacteristics(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_gatt_service_.GetCharacteristics(args, out);
+}
+
+void BluetoothInstance::BluetoothGATTServiceReadValue(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_gatt_service_.ReadValue(args, out);
+}
+
+void BluetoothInstance::BluetoothGATTServiceWriteValue(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_gatt_service_.WriteValue(args, out);
+}
+
+void BluetoothInstance::BluetoothGATTServiceAddValueChangeListener(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_gatt_service_.AddValueChangeListener(args, out);
+}
+
+void BluetoothInstance::BluetoothGATTServiceRemoveValueChangeListener(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ bluetooth_gatt_service_.RemoveValueChangeListener(args, out);
+}
+
} // namespace bluetooth
} // namespace extension
void FireEvent(const std::string& event, const std::shared_ptr<picojson::value>& value);
private:
+ void BluetoothAdapterSetName(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterSetPowered(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterSetVisible(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterDiscoverDevices(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterStopDiscovery(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterGetKnownDevices(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterGetDevice(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterCreateBonding(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterDestroyBonding(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterRegisterRFCOMMServiceByUUID(const picojson::value& args,
+ picojson::object& out);
+ void BluetoothAdapterGetBluetoothProfileHandler(const picojson::value& args,
+ picojson::object& out);
+ void BluetoothAdapterGetName(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterGetAddress(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterGetPowered(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterGetVisible(const picojson::value& args, picojson::object& out);
+ void BluetoothAdapterIsServiceConnected(const picojson::value& args, picojson::object& out);
+
+ void BluetoothDeviceConnectToServiceByUUID(const picojson::value& args, picojson::object& out);
+ void BluetoothDeviceGetBoolValue(const picojson::value& args, picojson::object& out);
+
+ void BluetoothHealthApplicationUnregister(const picojson::value& args, picojson::object& out);
+ void BluetoothHealthChannelClose(const picojson::value& args, picojson::object& out);
+ void BluetoothHealthChannelSendData(const picojson::value& args, picojson::object& out);
+ void BluetoothHealthProfileHandlerRegisterSinkApp(const picojson::value& args,
+ picojson::object& out);
+ void BluetoothHealthProfileHandlerConnectToSource(const picojson::value& args,
+ picojson::object& out);
+
+ void BluetoothServiceHandlerUnregister(const picojson::value& args, picojson::object& out);
+ void BluetoothSocketWriteData(const picojson::value& args, picojson::object& out);
+ void BluetoothSocketReadData(const picojson::value& args, picojson::object& out);
+ void BluetoothSocketClose(const picojson::value& args, picojson::object& out);
+
+ void BluetoothLEAdapterStartScan(const picojson::value& args, picojson::object& out);
+ void BluetoothLEAdapterStopScan(const picojson::value& args, picojson::object& out);
+ void BluetoothLEAdapterStartAdvertise(const picojson::value& args, picojson::object& out);
+ void BluetoothLEAdapterStopAdvertise(const picojson::value& args, picojson::object& out);
+ void BluetoothLEDeviceConnect(const picojson::value& args, picojson::object& out);
+ void BluetoothLEDeviceDisconnect(const picojson::value& args, picojson::object& out);
+ void BluetoothLEDeviceGetService(const picojson::value& args, picojson::object& out);
+ void BluetoothLEDeviceAddConnectStateChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void BluetoothLEDeviceRemoveConnectStateChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void BluetoothLEDeviceGetServiceAllUuids(const picojson::value& args, picojson::object& out);
+
+ void BluetoothGATTServiceGetServices(const picojson::value& args, picojson::object& out);
+ void BluetoothGATTServiceGetCharacteristics(const picojson::value& args, picojson::object& out);
+ void BluetoothGATTServiceReadValue(const picojson::value& args, picojson::object& out);
+ void BluetoothGATTServiceWriteValue(const picojson::value& args, picojson::object& out);
+ void BluetoothGATTServiceAddValueChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void BluetoothGATTServiceRemoveValueChangeListener(const picojson::value& args,
+ picojson::object& out);
+
BluetoothAdapter bluetooth_adapter_;
BluetoothDevice bluetooth_device_;
BluetoothHealthChannel bluetooth_health_channel_;
return "Resource temporarily unavailable";
case BT_ERROR_SERVICE_NOT_FOUND:
return "Service Not Found";
+ case BT_ERROR_AUTHORIZATION_REJECTED:
+ return "Authorization rejected";
default:
return "Unknown Error";
}
]);
if (!arguments.length || args.bookmark === null) {
- var result = native_.callSync('Bookmark_removeAll');
+ var result = native_.callSync('BookmarkRemoveAll');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
-
return;
}
}
var result = native_.isFailure(
- native_.callSync('Bookmark_remove', { id: args.bookmark.id })
+ native_.callSync('BookmarkRemove', { id: args.bookmark.id })
);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
nullable: false
}
]);
- var ret = native_.callSync('Bookmark_add', {
+ var ret = native_.callSync('BookmarkAdd', {
title: args.bookmark.title,
url: String(args.bookmark.url),
parentId: args.parentId,
- type: args.bookmark instanceof tizen.BookmarkFolder ? 1 : 0
+ type: args.bookmark instanceof tizen.BookmarkFolder
});
if (native_.isFailure(ret)) {
if (arguments.length === 0 || args.id <= 0) return null;
if (args.id == this.getRootId()) return null;
- var ret = native_.callSync('Bookmark_get', {
+ var ret = native_.callSync('BookmarkGet', {
id: args.id,
- shouldGetItems: 0
+ shouldGetItems: false
});
if (native_.isFailure(ret)) {
}
]);
- var ret = native_.callSync('Bookmark_get', {
+ var ret = native_.callSync('BookmarkGet', {
id: Number(args.id),
- shouldGetItems: 1
+ shouldGetItems: true
});
if (native_.isFailure(ret)) {
};
BookmarkProvider.prototype.getRootId = function() {
- var ret = native_.callSync('Bookmark_getRootId');
+ var ret = native_.callSync('BookmarkGetRootId');
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
#include "common/logger.h"
namespace {
-const char kBookmark[] = "tizen.bookmark";
-const char kBookmarkItem[] = "tizen.BookmarkItem";
-const char kBookmarkFolder[] = "tizen.BookmarkFolder";
+constexpr char kBookmark[] = "tizen.bookmark";
+constexpr char kBookmarkItem[] = "tizen.BookmarkItem";
+constexpr char kBookmarkFolder[] = "tizen.BookmarkFolder";
}
// This will be generated from bookmark_api.js.
SetExtensionName(kBookmark);
SetJavaScriptAPI(kSource_bookmark_api);
- const char* entry_points[] = {kBookmarkItem, kBookmarkFolder, NULL};
+ const char* entry_points[] = {kBookmarkItem, kBookmarkFolder, nullptr};
SetExtraJSEntryPoints(entry_points);
-
- if (bp_bookmark_adaptor_initialize()) {
- LoggerE("Fail: Bookmark not supported");
- }
}
BookmarkExtension::~BookmarkExtension() {
- if (bp_bookmark_adaptor_deinitialize()) {
- LoggerE("Fail: Deinitialize Bookmark");
- }
}
common::Instance* BookmarkExtension::CreateInstance() {
namespace bookmark {
namespace {
-const char kId[] = "id";
-const char kTitle[] = "title";
-const char kType[] = "type";
-const char kParentId[] = "parentId";
-const char kUrl[] = "url";
-
-const std::string kPrivilegeBookmarkRead = "http://tizen.org/privilege/bookmark.read";
-const std::string kPrivilegeBookmarkWrite = "http://tizen.org/privilege/bookmark.write";
+constexpr char kId[] = "id";
+constexpr char kTitle[] = "title";
+constexpr char kType[] = "type";
+constexpr char kParentId[] = "parentId";
+constexpr char kUrl[] = "url";
+constexpr char kShouldGetItems[] = "shouldGetItems";
+
+constexpr char kPrivilegeBookmarkRead[] = "http://tizen.org/privilege/bookmark.read";
+constexpr char kPrivilegeBookmarkWrite[] = "http://tizen.org/privilege/bookmark.write";
} // namespace
BookmarkInstance::BookmarkInstance() {
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&BookmarkInstance::x, this, _1, _2));
- REGISTER_SYNC("Bookmark_get", BookmarkGet);
- REGISTER_SYNC("Bookmark_add", BookmarkAdd);
- REGISTER_SYNC("Bookmark_remove", BookmarkRemove);
- REGISTER_SYNC("Bookmark_removeAll", BookmarkRemoveAll);
- REGISTER_SYNC("Bookmark_getRootId", BookmarkGetRootId);
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&BookmarkInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(BookmarkGet);
+ REGISTER_METHOD(BookmarkAdd);
+ REGISTER_METHOD(BookmarkRemove);
+ REGISTER_METHOD(BookmarkRemoveAll);
+ REGISTER_METHOD(BookmarkGetRootId);
+
+#undef REGISTER_METHOD
+
+ if (bp_bookmark_adaptor_initialize()) {
+ LoggerE("bp_bookmark_adaptor_initialize failed.");
+ }
}
BookmarkInstance::~BookmarkInstance() {
ScopeLogger();
+ if (bp_bookmark_adaptor_deinitialize()) {
+ LoggerE("bp_bookmark_adaptor_deinitialize failed.");
+ }
}
bool BookmarkInstance::bookmark_foreach(Context& ctx, bp_bookmark_info_fmt& info) {
ScopeLogger();
int ids_count = 0;
- int* ids = NULL;
- BookmarkObject item;
+ int* ids = nullptr;
if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, -1, -1, -1, -1,
- BP_BOOKMARK_O_DATE_CREATED, 0) < 0)
+ BP_BOOKMARK_O_DATE_CREATED, 0) < 0) {
return false;
-
- if (ids_count > 0) {
- for (int i = 0; i < ids_count; i++) {
- if (bp_bookmark_adaptor_get_easy_all(ids[i], &info) < 0) {
- int errorcode = bp_bookmark_adaptor_get_errorcode();
- LoggerW("bp_bookmark_adaptor_get_easy_all for id %d returns error: %d", ids[i], errorcode);
- continue;
- }
- item.id = ids[i];
- item.bookmark_info = info;
- if ((ctx.shouldGetItems && item.bookmark_info.parent != ctx.id) ||
- (!ctx.shouldGetItems && item.id != ctx.id))
- continue;
- ctx.folders.push_back(item);
+ }
+ ctx.folders.reserve(ids_count);
+ std::unique_ptr<int, decltype(&free)> ids_ptr(ids, free);
+ for (int i = 0; i < ids_count; ++i) {
+ if (bp_bookmark_adaptor_get_easy_all(ids[i], &info) < 0) {
+ int errorcode = bp_bookmark_adaptor_get_errorcode();
+ LoggerW("bp_bookmark_adaptor_get_easy_all for id %d returns error: %d", ids[i], errorcode);
+ continue;
}
+ if ((ctx.shouldGetItems && info.parent != ctx.id) ||
+ (!ctx.shouldGetItems && ids[i] != ctx.id)) {
+ continue;
+ }
+ ctx.folders.push_back({ids[i], info});
}
- free(ids);
return true;
}
ScopeLogger();
int ids_count = 0;
int* ids = nullptr;
- char* compare_url = nullptr;
-
int ntv_ret = bp_bookmark_adaptor_get_ids_p(&ids, // ids
&ids_count, // count
-1, // limit
ErrorCode::UNKNOWN_ERR, "Failed to obtain bookmarks",
("bp_bookmark_adaptor_get_ids_p error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
}
-
- PlatformResult result{ErrorCode::NO_ERROR};
- bool url_found = false;
- for (int i = 0; (i < ids_count) && result && !url_found; ++i) {
+ std::unique_ptr<int, decltype(&free)> ids_ptr(ids, free);
+ for (int i = 0; i < ids_count; ++i) {
+ char* compare_url = nullptr;
ntv_ret = bp_bookmark_adaptor_get_url(ids[i], &compare_url);
if (ntv_ret < 0) {
- result = LogAndCreateResult(
+ PlatformResult result = LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, "Failed to obtain URL",
("bp_bookmark_adaptor_get_url error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
- } else {
- url_found = (0 == strcmp(url, compare_url));
- free(compare_url);
- compare_url = nullptr;
+ return result;
+ }
+ std::unique_ptr<char, decltype(&free)> bookmark_url(compare_url, free);
+ if (0 == strcmp(url, compare_url)) {
+ *exists = true;
+ return PlatformResult{ErrorCode::NO_ERROR};
}
}
-
- if (result) {
- *exists = url_found;
- }
-
- free(ids);
-
- return result;
+ *exists = false;
+ return PlatformResult{ErrorCode::NO_ERROR};
}
PlatformResult BookmarkInstance::BookmarkTitleExistsInParent(const char* title, int parent,
bool* exists) {
ScopeLogger();
int ids_count = 0;
- int compare_parent = -1;
int* ids = nullptr;
- char* compare_title = nullptr;
-
int ntv_ret = bp_bookmark_adaptor_get_ids_p(&ids, // ids
&ids_count, // count
-1, // limit
ErrorCode::UNKNOWN_ERR, "Failed to obtain bookmarks",
("bp_bookmark_adaptor_get_ids_p error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
}
-
- PlatformResult result{ErrorCode::NO_ERROR};
- bool title_found = false;
- for (int i = 0; (i < ids_count) && result && !title_found; ++i) {
- if ((ntv_ret = bp_bookmark_adaptor_get_parent_id(ids[i], &compare_parent)) < 0) {
- result = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to obtain parent ID",
- ("bp_bookmark_adaptor_get_parent_id error: %d (%s)", ntv_ret,
- get_error_message(ntv_ret)));
- } else if ((ntv_ret = bp_bookmark_adaptor_get_title(ids[i], &compare_title)) < 0) {
- result = LogAndCreateResult(
+ std::unique_ptr<int, decltype(&free)> ids_ptr(ids, free);
+ for (int i = 0; i < ids_count; ++i) {
+ int compare_parent = -1;
+ ntv_ret = bp_bookmark_adaptor_get_parent_id(ids[i], &compare_parent);
+ if (ntv_ret < 0) {
+ PlatformResult result =
+ LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to obtain parent ID",
+ ("bp_bookmark_adaptor_get_parent_id error: %d (%s)", ntv_ret,
+ get_error_message(ntv_ret)));
+ return result;
+ }
+ char* compare_title = nullptr;
+ ntv_ret = bp_bookmark_adaptor_get_title(ids[i], &compare_title);
+ if (ntv_ret < 0) {
+ PlatformResult result = LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, "Failed to obtain title",
("bp_bookmark_adaptor_get_title error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
- } else {
- title_found = (parent == compare_parent) && (0 == strcmp(title, compare_title));
- free(compare_title);
- compare_title = nullptr;
- compare_parent = -1;
+ return result;
+ }
+ std::unique_ptr<char, decltype(&free)> bookmark_url(compare_title, free);
+ if (parent == compare_parent && 0 == strcmp(title, compare_title)) {
+ *exists = true;
+ return PlatformResult{ErrorCode::NO_ERROR};
}
}
-
- if (result) {
- *exists = title_found;
- }
-
- free(ids);
-
- return result;
+ *exists = false;
+ return PlatformResult{ErrorCode::NO_ERROR};
}
void BookmarkInstance::BookmarkGet(const picojson::value& arg, picojson::object& o) {
Context ctx = {0};
bp_bookmark_info_fmt info = {0};
- picojson::value::array arr;
-
- ctx.shouldGetItems = arg.get("shouldGetItems").get<double>();
+ ctx.shouldGetItems = arg.get(kShouldGetItems).get<bool>();
ctx.id = arg.get(kId).get<double>();
if (!bookmark_foreach(ctx, info)) {
return;
}
- std::vector<BookmarkObject>::iterator it;
- for (it = ctx.folders.begin(); it != ctx.folders.end(); ++it) {
+ picojson::value::array arr;
+ arr.reserve(ctx.folders.size());
+ for (auto& item : ctx.folders) {
picojson::object obj;
- BookmarkObject entry = *it;
-
- obj[kTitle] = picojson::value(entry.bookmark_info.title);
- obj[kId] = picojson::value(std::to_string(entry.id));
- obj[kType] = picojson::value(std::to_string(entry.bookmark_info.type));
- obj[kParentId] = picojson::value(std::to_string(entry.bookmark_info.parent));
- if (!entry.bookmark_info.type) obj[kUrl] = picojson::value(entry.bookmark_info.url);
+ obj.emplace(kTitle, picojson::value(item.bookmark_info.title));
+ obj.emplace(kId, picojson::value(std::to_string(item.id)));
+ obj.emplace(kType, picojson::value(std::to_string(item.bookmark_info.type)));
+ obj.emplace(kParentId, picojson::value(std::to_string(item.bookmark_info.parent)));
+ if (!item.bookmark_info.type) {
+ obj.emplace(kUrl, picojson::value(item.bookmark_info.url));
+ }
- arr.push_back(picojson::value(obj));
+ arr.push_back(std::move(picojson::value(std::move(obj))));
}
- ReportSuccess(picojson::value(arr), o);
+ ReportSuccess(picojson::value(std::move(arr)), o);
}
void BookmarkInstance::BookmarkAdd(const picojson::value& arg, picojson::object& o) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeBookmarkWrite, &o);
- int saved_id = -1;
-
const auto& title = arg.get(kTitle).get<std::string>();
const int parent = static_cast<int>(arg.get(kParentId).get<double>());
- const int type = static_cast<int>(arg.get(kType).get<double>());
+ const bool is_folder = arg.get(kType).get<bool>();
const auto& url = arg.get(kUrl).get<std::string>();
- if (0 == type) { // bookmark
+ if (!is_folder) { // bookmark
bool exists = false;
auto result = BookmarkUrlExists(url.c_str(), &exists);
if (!result) {
&o);
return;
}
- }
-
- if (1 == type) { // folder
+ } else { // folder
bool exists = false;
auto result = BookmarkTitleExistsInParent(title.c_str(), parent, &exists);
if (!result) {
}
}
- int ntv_ret;
-
- ntv_ret = bp_bookmark_adaptor_create(&saved_id);
+ int saved_id = -1;
+ int ntv_ret = bp_bookmark_adaptor_create(&saved_id);
if (ntv_ret < 0) {
LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to create adaptor"), &o);
return;
}
+ std::unique_ptr<int, void (*)(int*)> bookmark(
+ &saved_id, [](int* bookmark_ptr) { bp_bookmark_adaptor_delete(*bookmark_ptr); });
ntv_ret = bp_bookmark_adaptor_set_title(saved_id, title.c_str());
if (ntv_ret < 0) {
- bp_bookmark_adaptor_delete(saved_id);
LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to set title"), &o);
return;
}
ntv_ret = bp_bookmark_adaptor_set_parent_id(saved_id, parent);
if (ntv_ret < 0) {
- bp_bookmark_adaptor_delete(saved_id);
LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to set parent id"), &o);
return;
}
- ntv_ret = bp_bookmark_adaptor_set_type(saved_id, type);
+ ntv_ret = bp_bookmark_adaptor_set_type(saved_id, static_cast<int>(is_folder));
if (ntv_ret < 0) {
- bp_bookmark_adaptor_delete(saved_id);
LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to set type"), &o);
return;
}
ntv_ret = bp_bookmark_adaptor_set_url(saved_id, url.c_str());
if (ntv_ret < 0) {
- bp_bookmark_adaptor_delete(saved_id);
LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to set url"), &o);
return;
}
+ bookmark.release();
ReportSuccess(picojson::value(std::to_string(saved_id)), o);
}
struct Context {
int id;
- int shouldGetItems;
+ bool shouldGetItems;
std::vector<BookmarkObject> folders;
};
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&CalendarInstance::x, this, _1, _2));
-
- // Calendar
- REGISTER_SYNC("Calendar_get", CalendarGet);
- REGISTER_SYNC("Calendar_add", CalendarAdd);
- REGISTER_SYNC("Calendar_update", CalendarUpdate);
- REGISTER_SYNC("Calendar_remove", CalendarRemove);
- REGISTER_SYNC("Calendar_addChangeListener", CalendarAddChangeListener);
- REGISTER_SYNC("Calendar_removeChangeListener", CalendarRemoveChangeListener);
-
- // Calendar Manager
- REGISTER_SYNC("CalendarManager_addCalendar", CalendarManagerAddCalendar);
- REGISTER_SYNC("CalendarManager_getCalendar", CalendarManagerGetCalendar);
- REGISTER_SYNC("CalendarManager_removeCalendar", CalendarManagerRemoveCalendar);
-#undef REGISTER_SYNC
-
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&CalendarInstance::x, this, _1, _2));
- REGISTER_ASYNC("Calendar_addBatch", CalendarAddBatch);
- REGISTER_ASYNC("Calendar_updateBatch", CalendarUpdateBatch);
- REGISTER_ASYNC("Calendar_removeBatch", CalendarRemoveBatch);
- REGISTER_ASYNC("Calendar_updateBatch", CalendarUpdateBatch);
- REGISTER_ASYNC("CalendarManager_getCalendars", CalendarManagerGetCalendars);
- REGISTER_ASYNC("Calendar_find", CalendarFind);
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&CalendarInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(CalendarGet);
+ REGISTER_METHOD(CalendarAdd);
+ REGISTER_METHOD(CalendarUpdate);
+ REGISTER_METHOD(CalendarRemove);
+ REGISTER_METHOD(CalendarAddChangeListener);
+ REGISTER_METHOD(CalendarRemoveChangeListener);
+
+ REGISTER_METHOD(CalendarManagerAddCalendar);
+ REGISTER_METHOD(CalendarManagerGetCalendar);
+ REGISTER_METHOD(CalendarManagerRemoveCalendar);
+
+ REGISTER_METHOD(CalendarAddBatch);
+ REGISTER_METHOD(CalendarUpdateBatch);
+ REGISTER_METHOD(CalendarRemoveBatch);
+ REGISTER_METHOD(CalendarUpdateBatch);
+ REGISTER_METHOD(CalendarManagerGetCalendars);
+ REGISTER_METHOD(CalendarFind);
+
+#undef REGISTER_METHOD
}
CalendarInstance::~CalendarInstance() {
]);
}
- var result = native_.callSync('Calendar_get', {
+ var result = native_.callSync('CalendarGet', {
calendarId: this.id,
id: args.id
});
var tmp = _itemConverter.fromTizenObject(args.item);
tmp.calendarId = this.id;
- var result = native_.callSync('Calendar_add', {
+ var result = native_.callSync('CalendarAdd', {
item: tmp,
type: this.type
});
}
var result = native_.call(
- 'Calendar_addBatch',
+ 'CalendarAddBatch',
{
type: this.type,
items: tmp
var tmp = _itemConverter.fromTizenObject(args.item);
tmp.calendarId = this.id;
- var result = native_.callSync('Calendar_update', {
+ var result = native_.callSync('CalendarUpdate', {
item: tmp,
type: this.type,
updateAllInstances: args.has.updateAllInstances
}
var result = native_.call(
- 'Calendar_updateBatch',
+ 'CalendarUpdateBatch',
{
type: this.type,
items: tmp,
]);
}
- var result = native_.callSync('Calendar_remove', {
+ var result = native_.callSync('CalendarRemove', {
type: this.type,
id: args.id
});
};
var result = native_.call(
- 'Calendar_removeBatch',
+ 'CalendarRemoveBatch',
{
type: this.type,
ids: args.ids
}
};
var result = native_.call(
- 'Calendar_find',
+ 'CalendarFind',
{
calendarId: this.id,
filter: args.filter,
var listenerId = 'CalendarChangeCallback_' + this.type;
if (!_nativeListeners.hasOwnProperty(listenerId)) {
- var result = native_.callSync('Calendar_addChangeListener', {
+ var result = native_.callSync('CalendarAddChangeListener', {
type: this.type,
listenerId: listenerId
});
if (type_.isEmptyObject(_listeners)) {
var result;
- // @todo consider listener unregister when we are not listening on
- // this.type of calendar
+ // @todo consider listener unregister when we are not listening on this.type
+ // of calendar
var fail = false;
for (var listenerId in _nativeListeners) {
if (_nativeListeners.hasOwnProperty(listenerId)) {
- result = native_.callSync('Calendar_removeChangeListener', {
+ result = native_.callSync('CalendarRemoveChangeListener', {
type: _nativeListeners[listenerId]
});
if (native_.isFailure(result)) {
//@todo Fix UTC, UTC expect duration value but according to
// documentation:
// ... the implementation may not save the duration itself,
- // rather convert it to the corresponding endDate/dueDate attribute and
- // save it. For example, if you set the startDate and the duration
- // attributes and save the item, you may see that the duration is null
- // while endDate/dueDate is non-null after retrieving it because the
+ // rather convert it to the corresponding endDate/dueDate attribute
+ // and save it.
+ // For example, if you set the startDate and the duration attributes and
+ // save the item, you may see that the duration is null while
+ // endDate/dueDate is non-null after retrieving it because the
// implementation has calculated the endDate/dueDate based on the
// duration and the startDate then saved it, not the duration.
},
}
};
- var result = native_.call('CalendarManager_getCalendars', callArgs, callback);
+ var result = native_.call('CalendarManagerGetCalendars', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
id: args.id
};
- var result = native_.callSync('CalendarManager_getCalendar', callArgs);
+ var result = native_.callSync('CalendarManagerGetCalendar', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
type: args.calendar.type
};
- var result = native_.callSync('CalendarManager_addCalendar', callArgs);
+ var result = native_.callSync('CalendarManagerAddCalendar', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
id: args.id
};
- var result = native_.callSync('CalendarManager_removeCalendar', callArgs);
+ var result = native_.callSync('CalendarManagerRemoveCalendar', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
callArgs.limit = args.limit;
callArgs.offset = args.offset;
- var result = native_.call('CallHistory_find', callArgs, callback);
+ var result = native_.call('CallHistoryFind', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
var callArgs = {};
callArgs.uid = args.entry.uid;
- var result = native_.callSync('CallHistory_remove', callArgs);
+ var result = native_.callSync('CallHistoryRemove', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
var callArgs = {};
callArgs.uid = uid;
- var result = native_.call('CallHistory_removeBatch', callArgs, callback);
+ var result = native_.call('CallHistoryRemoveBatch', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('CallHistory_removeAll', {}, callback);
+ var result = native_.call('CallHistoryRemoveAll', {}, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
]);
if (T_.isEmptyObject(callHistoryChangeListener.listeners)) {
- var result = native_.callSync('CallHistory_addChangeListener');
+ var result = native_.callSync('CallHistoryAddChangeListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
callHistoryChangeListener.removeListener(args.watchId);
if (T_.isEmptyObject(callHistoryChangeListener.listeners)) {
- var result = native_.callSync('CallHistory_removeChangeListener');
+ var result = native_.callSync('CallHistoryRemoveChangeListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
function CallHistoryEntry(data) {
function directionSetter(val) {
if (direction === 'MISSEDNEW' && val === 'MISSED') {
- var result = native_.callSync('CallHistory_setMissedDirection', {
+ var result = native_.callSync('CallHistorySetMissedDirection', {
uid: this.uid
});
if (native_.isSuccess(result)) {
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&CallHistoryInstance::x, this, _1, _2));
- REGISTER_SYNC("CallHistory_remove", Remove);
- REGISTER_SYNC("CallHistory_addChangeListener", AddChangeListener);
- REGISTER_SYNC("CallHistory_removeChangeListener", RemoveChangeListener);
- REGISTER_SYNC("CallHistory_setMissedDirection", SetMissedDirection);
-#undef REGISTER_SYNC
-#define REGISTER_ASYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&CallHistoryInstance::x, this, _1, _2));
- REGISTER_ASYNC("CallHistory_find", Find);
- REGISTER_ASYNC("CallHistory_removeBatch", RemoveBatch);
- REGISTER_ASYNC("CallHistory_removeAll", RemoveAll);
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&CallHistoryInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(CallHistoryRemove);
+ REGISTER_METHOD(CallHistoryAddChangeListener);
+ REGISTER_METHOD(CallHistoryRemoveChangeListener);
+ REGISTER_METHOD(CallHistorySetMissedDirection);
+
+ REGISTER_METHOD(CallHistoryFind);
+ REGISTER_METHOD(CallHistoryRemoveBatch);
+ REGISTER_METHOD(CallHistoryRemoveAll);
+
+#undef REGISTER_METHOD
}
CallHistoryInstance::~CallHistoryInstance() {
ScopeLogger();
}
-void CallHistoryInstance::Find(const picojson::value& args, picojson::object& out) {
+void CallHistoryInstance::CallHistoryFind(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryRead, &out);
history_.find(args.get<picojson::object>());
ReportSuccess(out);
}
-void CallHistoryInstance::Remove(const picojson::value& args, picojson::object& out) {
+void CallHistoryInstance::CallHistoryRemove(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryWrite, &out);
PlatformResult result = history_.remove(args.get<picojson::object>());
}
}
-void CallHistoryInstance::RemoveBatch(const picojson::value& args, picojson::object& out) {
+void CallHistoryInstance::CallHistoryRemoveBatch(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryWrite, &out);
PlatformResult result = history_.removeBatch(args.get<picojson::object>());
}
}
-void CallHistoryInstance::RemoveAll(const picojson::value& args, picojson::object& out) {
+void CallHistoryInstance::CallHistoryRemoveAll(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryWrite, &out);
history_.removeAll(args.get<picojson::object>());
ReportSuccess(out);
}
-void CallHistoryInstance::AddChangeListener(const picojson::value& args, picojson::object& out) {
+void CallHistoryInstance::CallHistoryAddChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryRead, &out);
PlatformResult result = history_.startCallHistoryChangeListener();
}
}
-void CallHistoryInstance::RemoveChangeListener(const picojson::value& args, picojson::object& out) {
+void CallHistoryInstance::CallHistoryRemoveChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryRead, &out);
PlatformResult result = history_.stopCallHistoryChangeListener();
}
}
-void CallHistoryInstance::SetMissedDirection(const picojson::value& args, picojson::object& out) {
+void CallHistoryInstance::CallHistorySetMissedDirection(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
if (!args.contains("uid")) {
void CallHistoryChange(picojson::object& data);
private:
- void Find(const picojson::value& args, picojson::object& out);
- void Remove(const picojson::value& args, picojson::object& out);
- void RemoveBatch(const picojson::value& args, picojson::object& out);
- void RemoveAll(const picojson::value& args, picojson::object& out);
- void AddChangeListener(const picojson::value& args, picojson::object& out);
- void RemoveChangeListener(const picojson::value& args, picojson::object& out);
- void SetMissedDirection(const picojson::value& args, picojson::object& out);
+ void CallHistoryFind(const picojson::value& args, picojson::object& out);
+ void CallHistoryRemove(const picojson::value& args, picojson::object& out);
+ void CallHistoryRemoveBatch(const picojson::value& args, picojson::object& out);
+ void CallHistoryRemoveAll(const picojson::value& args, picojson::object& out);
+ void CallHistoryAddChangeListener(const picojson::value& args, picojson::object& out);
+ void CallHistoryRemoveChangeListener(const picojson::value& args, picojson::object& out);
+ void CallHistorySetMissedDirection(const picojson::value& args, picojson::object& out);
CallHistory history_;
};
'filter-utils.cc',
'filter-utils.h',
'picojson.h',
+ 'json-utils.cc',
+ 'json-utils.h',
'utils.h',
'logger.cc',
'logger.h',
'capi-appfw-app-manager',
'capi-appfw-app-common',
'capi-appfw-package-manager',
+ 'capi-system-info',
'storage',
'security-privilege-manager',
]
}],
['tizen == 1', {
'defines': ['TIZEN'],
+ 'defines': ['U_USING_ICU_NAMESPACE=1'],
'variables': {
'packages': [
'dlog',
--- /dev/null
+{
+ 'includes':[
+ '../common/common.gypi',
+ ],
+ 'targets': [
+ {
+ 'target_name': 'webapi_common_tests',
+ 'type': 'executable',
+ 'dependencies': [
+ 'common.gyp:tizen_common'
+ ],
+ 'include_dirs': [
+ '../googletest/include/',
+ '../googletest/',
+ '../googlemock/include/',
+ '../googlemock/'
+ ],
+ 'sources': [
+ '../googletest/src/gtest-all.cc',
+ '../googlemock/src/gmock-all.cc',
+ 'ut/common_ut_extension.cc',
+ 'ut/json-utils.cc',
+ 'ut/main.cc'
+ ],
+ 'libraries': [
+ '-lbundle',
+ '-pthread'
+ ],
+ 'conditions': [
+ ['tizen == 1', {
+ 'variables': {
+ 'packages': [
+ 'capi-base-common'
+ ]
+ }
+ }]
+ ]
+ },
+ ],
+}
*/
#include "common/filesystem/filesystem_provider_deviced.h"
+#include <system_info.h>
#include <gio/gio.h>
#include <algorithm>
#include "common/logger.h"
namespace {
+
static const char* kBus = "org.tizen.system.storage";
static const char* kBlockManagerIface = "org.tizen.system.storage.BlockManager";
static const char* kPath = "/Org/Tizen/System/Storage/Block/Manager";
static const char* kDeviceChangedMethod = "DeviceChanged";
static const char* kGetDeviceListMethod = "GetDeviceList";
+static const char* kExternalStorageFeature = "http://tizen.org/feature/storage.external";
+
+bool isExternalStorageSupported() {
+ bool external_storage_support = false;
+ auto ret = system_info_get_platform_bool(kExternalStorageFeature, &external_storage_support);
+
+ if (SYSTEM_INFO_ERROR_NONE != ret) {
+ LoggerE("system_info_get_platform_bool(storage.external) check failed: %d (%s)", ret,
+ get_error_message(ret));
+ return false;
+ }
+
+ if (!external_storage_support) {
+ LoggerW("External storage not supported.");
+ return false;
+ }
+
+ return true;
+}
+
} // namespace
namespace common {
return Storages();
}
- // internal storages are gathered with storage api
Storages internal = virtual_roots_provider_.GetStorages();
- // external storages are gathered using deviced implementation
+ if (!isExternalStorageSupported()) {
+ return internal;
+ }
+
+ LoggerD("Fetching external storages.");
Storages result;
GError* error = nullptr;
GVariant* variant = g_dbus_connection_call_sync(dbus_, kBus, kPath, kBlockManagerIface,
LoggerD("GetDeviceList succeed - handling result");
result = GetStoragesFromGVariant(variant);
}
-
// merging internal and external results together, but internal on the beginning
result.insert(result.begin(), internal.begin(), internal.end());
return result;
#include "common/converter.h"
#include "common/logger.h"
+#include "tizen/tizen.h"
+
namespace common {
PlatformResult AttributeMatchFlagFromString(const std::string &str,
return PlatformResult(ErrorCode::NO_ERROR);
}
+std::string AttributeMatchFlagToString(const AttributeMatchFlag filter_match_flag) {
+ ScopeLogger();
+
+ switch (filter_match_flag) {
+ case AttributeMatchFlag::kExactly:
+ return STR_MATCH_EXACTLY;
+ case AttributeMatchFlag::kFullString:
+ return STR_MATCH_FULLSTRING;
+ case AttributeMatchFlag::kContains:
+ return STR_MATCH_CONTAINS;
+ case AttributeMatchFlag::kStartsWith:
+ return STR_MATCH_STARTSWITH;
+ case AttributeMatchFlag::kEndsWith:
+ return STR_MATCH_ENDSWITH;
+ case AttributeMatchFlag::kExists:
+ return STR_MATCH_EXISTS;
+ }
+
+ return "Invalid attribute match flag";
+}
+
PlatformResult CompositeFilterTypeFromString(const std::string &str,
CompositeFilterType *comp_filter_type) {
ScopeLogger();
PlatformResult AttributeMatchFlagFromString(const std::string& str,
AttributeMatchFlag* filter_match_flag);
+std::string AttributeMatchFlagToString(const AttributeMatchFlag filter_match_flag);
+
enum class CompositeFilterType { kUnion, kIntersection };
PlatformResult CompositeFilterTypeFromString(const std::string& str,
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "json-utils.h"
+#include <bundle.h>
+#include <bundle_internal.h>
+#include "common/logger.h"
+#include "common/picojson.h"
+
+#include <algorithm>
+
+namespace {
+
+using Octet = unsigned char;
+
+bool IsOctet(double value) {
+ return 0 <= value && value <= 255;
+}
+
+int BundleAddString(const std::string& key, const picojson::value& value, bundle* bundle_data) {
+ ScopeLogger();
+ return bundle_add_str(bundle_data, key.c_str(), value.get<std::string>().c_str());
+}
+
+std::vector<Octet> JsonArrayToByteStream(const picojson::array& jarray) {
+ ScopeLogger();
+ std::vector<Octet> bytes;
+ bytes.reserve(jarray.size());
+
+ for (const auto& elem : jarray) {
+ bytes.push_back(static_cast<Octet>(elem.get<double>()));
+ }
+
+ return bytes;
+}
+
+int BundleAddByteStream(const std::string& key, const picojson::value& value, bundle* bundle_data) {
+ ScopeLogger();
+ const picojson::array& jarray = value.get<picojson::array>();
+ auto bytes = JsonArrayToByteStream(jarray);
+ return bundle_add_byte(bundle_data, key.c_str(), bytes.data(), bytes.size());
+}
+
+int BundleAddStringArray(const std::string& key, const picojson::value& value,
+ bundle* bundle_data) {
+ ScopeLogger();
+ const auto& jarray = value.get<picojson::array>();
+
+ std::vector<const char*> cstrings;
+ cstrings.reserve(jarray.size());
+
+ for (const auto& elem : jarray) {
+ cstrings.push_back(elem.get<std::string>().c_str());
+ }
+
+ return bundle_add_str_array(bundle_data, key.c_str(), cstrings.data(), cstrings.size());
+}
+
+int BundleAddByteStreamArray(const std::string& key, const picojson::value& value,
+ bundle* bundle_data) {
+ ScopeLogger();
+ const auto& jarray = value.get<picojson::array>();
+
+ std::vector<std::vector<Octet>> bytes_array;
+ bytes_array.reserve(jarray.size());
+
+ for (const auto& elem : jarray) {
+ bytes_array.push_back(JsonArrayToByteStream(elem.get<picojson::array>()));
+ }
+
+ int ret = bundle_init_byte_array(bundle_data, key.c_str(), bytes_array.size());
+ if (BUNDLE_ERROR_NONE != ret) {
+ return ret;
+ }
+
+ for (unsigned int idx = 0; idx < bytes_array.size(); ++idx) {
+ ret = bundle_set_byte_array_element(bundle_data, key.c_str(), idx, bytes_array[idx].data(),
+ bytes_array[idx].size());
+
+ if (BUNDLE_ERROR_NONE != ret) {
+ return ret;
+ }
+ }
+
+ return BUNDLE_ERROR_NONE;
+}
+
+template <typename Type>
+bool JsonValueTypeCheck(const picojson::value& value) {
+ return value.is<Type>();
+}
+
+template <>
+bool JsonValueTypeCheck<Octet>(const picojson::value& value) {
+ return JsonValueTypeCheck<double>(value) && IsOctet(value.get<double>());
+}
+
+bundle_type GetBundleType(const picojson::value& value) {
+ ScopeLogger();
+ if (JsonValueTypeCheck<std::string>(value)) return BUNDLE_TYPE_STR;
+
+ if (!JsonValueTypeCheck<picojson::array>(value)) return BUNDLE_TYPE_ANY;
+ const auto& jarray = value.get<picojson::array>();
+
+ if (std::all_of(jarray.begin(), jarray.end(), JsonValueTypeCheck<std::string>)) {
+ return BUNDLE_TYPE_STR_ARRAY;
+ }
+
+ if (std::all_of(jarray.begin(), jarray.end(), JsonValueTypeCheck<Octet>)) {
+ return BUNDLE_TYPE_BYTE;
+ }
+
+ for (const auto& elem : jarray) {
+ if (!elem.is<picojson::array>()) {
+ return BUNDLE_TYPE_ANY;
+ }
+
+ const auto& subarray = elem.get<picojson::array>();
+ if (!std::all_of(subarray.begin(), subarray.end(), JsonValueTypeCheck<Octet>)) {
+ return BUNDLE_TYPE_ANY;
+ }
+ }
+
+ return BUNDLE_TYPE_BYTE_ARRAY;
+}
+
+int BundleAdd(const std::string& key, const picojson::value& value, bundle* bundle_data) {
+ ScopeLogger();
+ switch (GetBundleType(value)) {
+ case BUNDLE_TYPE_STR:
+ return BundleAddString(key, value, bundle_data);
+ case BUNDLE_TYPE_STR_ARRAY:
+ return BundleAddStringArray(key, value, bundle_data);
+ case BUNDLE_TYPE_BYTE:
+ return BundleAddByteStream(key, value, bundle_data);
+ case BUNDLE_TYPE_BYTE_ARRAY:
+ return BundleAddByteStreamArray(key, value, bundle_data);
+ default:
+ LoggerE("Unsupported bundle value type.");
+ return BUNDLE_ERROR_INVALID_PARAMETER;
+ }
+ return BUNDLE_ERROR_NONE;
+}
+
+} // namespace
+
+namespace common {
+
+PlatformResult JsonToBundle(const picojson::value& json, bundle** data) {
+ ScopeLogger();
+
+ if (json.is<picojson::null>()) {
+ *data = nullptr;
+ LoggerD("bundle data is null");
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+
+ if (!json.is<picojson::object>()) {
+ return PlatformResult(ErrorCode::UNKNOWN_ERR);
+ }
+
+ bundle* temp = bundle_create();
+ if (nullptr == temp) {
+ LoggerE("bundle_create() failed");
+ return PlatformResult(ErrorCode::UNKNOWN_ERR);
+ }
+
+ for (const auto& property : json.get<picojson::object>()) {
+ int ret = BundleAdd(property.first, property.second, temp);
+ if (BUNDLE_ERROR_NONE != ret) {
+ LoggerE("BundleAdd failed with error message: %s", get_error_message(ret));
+ bundle_free(temp);
+ return PlatformResult(ErrorCode::UNKNOWN_ERR);
+ }
+ }
+
+ *data = temp;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult BundleToJson(bundle* bundle_data, picojson::value* json) {
+ ScopeLogger();
+
+ if (nullptr == json) {
+ return PlatformResult(ErrorCode::UNKNOWN_ERR);
+ }
+
+ if (nullptr == bundle_data) {
+ *json = picojson::value();
+ LoggerD("bundle data is null");
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+
+ picojson::array array_data;
+ bundle_foreach(bundle_data, BundleJsonIterator, &array_data);
+
+ *json = picojson::value(picojson::object());
+ for (auto& elem : array_data) {
+ (json->get<picojson::object>())[elem.get("key").get<std::string>()] = elem.get("value");
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void BundleJsonIterator(const char* key, const int type, const bundle_keyval_t* kv, void* d) {
+ ScopeLogger();
+
+ void* basic_val = nullptr;
+ size_t basic_size = 0;
+
+ picojson::value::array* array = static_cast<picojson::value::array*>(d);
+ picojson::value::object o;
+
+ switch (bundle_keyval_get_type(const_cast<bundle_keyval_t*>(kv))) {
+ case BUNDLE_TYPE_STR:
+ bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(kv), &basic_val, &basic_size);
+ o["key"] = picojson::value(key);
+ o["value"] = picojson::value(static_cast<char*>(basic_val));
+ break;
+
+ case BUNDLE_TYPE_STR_ARRAY: {
+ picojson::value::array tab;
+ void** array_val = nullptr;
+ unsigned int array_len = 0;
+ size_t* array_elem_size = nullptr;
+
+ bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(kv), &array_val, &array_len,
+ &array_elem_size);
+
+ for (unsigned int i = 0; i < array_len; i++) {
+ tab.push_back(picojson::value(((char**)array_val)[i]));
+ }
+
+ o["key"] = picojson::value(key);
+ o["value"] = picojson::value(picojson::value(tab));
+
+ break;
+ }
+
+ case BUNDLE_TYPE_BYTE: {
+ picojson::value::array tab;
+
+ unsigned char* basic_val = nullptr;
+ size_t basic_size = 0;
+
+ bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(kv), (void**)&basic_val,
+ &basic_size);
+
+ for (unsigned int i = 0; i < basic_size; i++) {
+ tab.push_back(picojson::value(static_cast<double>(basic_val[i])));
+ }
+
+ o["key"] = picojson::value(key);
+ o["value"] = picojson::value(picojson::value(tab));
+ break;
+ }
+ case BUNDLE_TYPE_BYTE_ARRAY: {
+ picojson::value::array tab;
+
+ unsigned char** array_value = nullptr;
+ size_t* array_ele_size = nullptr;
+ unsigned int ele_nos = 0;
+
+ bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(kv), (void***)&array_value, &ele_nos,
+ &array_ele_size);
+
+ for (unsigned int i = 0; i < ele_nos; i++) {
+ picojson::value::array tab2;
+ for (unsigned int j = 0; j < array_ele_size[i]; j++) {
+ tab2.push_back(picojson::value(static_cast<double>(array_value[i][j])));
+ }
+ tab.push_back(picojson::value(tab2));
+ }
+
+ o["key"] = picojson::value(key);
+ o["value"] = picojson::value(picojson::value(tab));
+ break;
+ }
+ default:
+ o["key"] = picojson::value(key);
+ o["value"] = picojson::value();
+ break;
+ }
+ array->push_back(picojson::value(o));
+}
+
+} // namespace common
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef COMMON_JSON_UTILS_H
+#define COMMON_JSON_UTILS_H
+
+#include <bundle.h>
+#include "picojson.h"
+#include "platform_result.h"
+
+namespace common {
+
+void BundleJsonIterator(const char* key, const int type, const bundle_keyval_t* kv, void* d);
+
+PlatformResult JsonToBundle(const picojson::value& json, bundle** bundle_data);
+PlatformResult BundleToJson(bundle* bundle_data, picojson::value* json);
+
+} // namespace common;
+
+#endif // COMMON_JSON_UTILS_H
}
PlatformResult getName(NativeEnumType value, std::string* name) const {
+ if (nullptr == name) {
+ return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "output argument cannnot be nullptr");
+ }
+
auto it = rev_mapping_.find(value);
if (it != rev_mapping_.end()) {
*name = it->second;
return PlatformResult(ErrorCode::NO_ERROR);
}
+
return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "enum value not registered");
}
PlatformResult getValue(std::string name, NativeEnumType* value) const {
+ if (nullptr == value) {
+ return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "output argument cannnot be nullptr");
+ }
+
auto it = mapping_.find(name);
if (it != mapping_.end()) {
*value = it->second;
void TaskQueue::ScheduleWorkInMainThread(const std::function<void()>& work) {
QueueData<void>* d = new QueueData<void>();
d->work_callback_ = work;
- g_idle_add(WorkCallback<void>, d);
+ if (!g_idle_add(WorkCallback<void>, d)) {
+ LoggerE("g_idle_add failed");
+ }
}
} // namespace common
QueueData<T>* d = new QueueData<T>();
d->work_callback_ = work;
d->data_ = data;
- g_idle_add(WorkCallback<T>, d);
+ if (!g_idle_add(WorkCallback<T>, d)) {
+ LoggerE("g_idle_add failed");
+ }
}
} // namespace common
return CheckFileStatus(path);
}
+void PrintDeprecationWarningFor(const char* className, const char* replacement) {
+ if (nullptr == replacement) {
+ LoggerW("DEPRECATION WARNING: %s is deprecated and using it is not recommended.", className);
+ } else {
+ LoggerW(
+ "DEPRECATION WARNING: %s is deprecated and using it is not recommended. Try using %s "
+ "instead",
+ className, replacement);
+ }
+}
+
} // namespace tools
} // namespace common
PlatformResult CheckFileAvailability(const std::string& path);
+void PrintDeprecationWarningFor(const char* className, const char* replacement = nullptr);
+
} // namespace tools
} // namespace common
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "common/ut/common_ut_extension.h"
+
+common::Extension* CreateExtension() {
+ return new CommonUtExtension;
+}
+
+CommonUtExtension::CommonUtExtension() {
+ SetExtensionName("tizen");
+ SetJavaScriptAPI("");
+}
+
+CommonUtExtension::~CommonUtExtension() {
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_COMMON_UT_EXTENSION_H_
+#define TIZEN_COMMON_UT_EXTENSION_H_
+
+#include "common/extension.h"
+
+class CommonUtExtension : public common::Extension {
+ public:
+ CommonUtExtension();
+ virtual ~CommonUtExtension();
+};
+
+#endif // TIZEN_COMMON_UT_EXTENSION_H_
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "common/ut/json-utils.h"
+
+#include "bundle.h"
+#include "bundle_internal.h"
+#include "common/json-utils.h"
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+using namespace std;
+using testing::_;
+using testing::StrEq;
+
+namespace {
+
+template <typename T, typename V>
+picojson::value vec2json(vector<V> vec) {
+ picojson::array array;
+ for (auto v : vec) {
+ array.push_back(picojson::value(static_cast<T>(v)));
+ }
+ return picojson::value(array);
+}
+
+} // namespace
+
+MATCHER_P(KeyValStrEq, expected, "match keyval_t string value") {
+ auto* kv = const_cast<bundle_keyval_t*>(static_cast<const bundle_keyval_t*>(arg));
+
+ if (BUNDLE_TYPE_STR != bundle_keyval_get_type(kv)) {
+ return false;
+ }
+
+ void* untyped = nullptr;
+ size_t size = 0;
+
+ int ret = bundle_keyval_get_basic_val(kv, &untyped, &size);
+ if (BUNDLE_ERROR_NONE != ret) {
+ return false;
+ }
+
+ string value = static_cast<char*>(untyped);
+ return value == expected;
+}
+
+MATCHER_P(KeyValStrArrEq, expected, "match keyval_t string array value") {
+ auto* kv = const_cast<bundle_keyval_t*>(static_cast<const bundle_keyval_t*>(arg));
+
+ if (BUNDLE_TYPE_STR_ARRAY != bundle_keyval_get_type(kv)) {
+ return false;
+ }
+
+ void** untyped = nullptr;
+ size_t array_size = 0;
+ size_t* elem_size = nullptr;
+
+ int ret = bundle_keyval_get_array_val(kv, &untyped, &array_size, &elem_size);
+ if (BUNDLE_ERROR_NONE != ret) {
+ return false;
+ }
+
+ if (array_size != expected.size()) {
+ return false;
+ }
+
+ char** value = reinterpret_cast<char**>(untyped);
+ for (size_t i = 0; i < array_size; ++i) {
+ if (string(value[i]) != expected[i]) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+MATCHER_P(KeyValBytesEq, expected, "match keyval_t bytes value") {
+ auto* kv = const_cast<bundle_keyval_t*>(static_cast<const bundle_keyval_t*>(arg));
+
+ if (BUNDLE_TYPE_BYTE != bundle_keyval_get_type(kv)) {
+ return false;
+ }
+
+ void* untyped = nullptr;
+ size_t size = 0;
+
+ int ret = bundle_keyval_get_basic_val(kv, &untyped, &size);
+ if (BUNDLE_ERROR_NONE != ret) {
+ return false;
+ }
+
+ if (size != expected.size()) {
+ return false;
+ }
+
+ auto bytes = static_cast<unsigned char*>(untyped);
+ for (unsigned int i = 0; i < size; ++i) {
+ if (bytes[i] != expected[i]) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+MATCHER_P(KeyValBytesArrEq, expected, "match keyval_t bytes array value") {
+ auto* kv = const_cast<bundle_keyval_t*>(static_cast<const bundle_keyval_t*>(arg));
+
+ if (BUNDLE_TYPE_BYTE_ARRAY != bundle_keyval_get_type(kv)) {
+ return false;
+ }
+
+ void** untyped = nullptr;
+ size_t array_size = 0;
+ size_t* elem_size = nullptr;
+
+ int ret = bundle_keyval_get_array_val(kv, &untyped, &array_size, &elem_size);
+ if (BUNDLE_ERROR_NONE != ret) {
+ return false;
+ }
+
+ if (array_size != expected.size()) {
+ return false;
+ }
+
+ unsigned char** value = reinterpret_cast<unsigned char**>(untyped);
+ for (size_t i = 0; i < array_size; ++i) {
+ for (size_t j = 0; j < elem_size[i]; ++j) {
+ if (expected[i][j] != value[i][j]) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+class JsonToBundleTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ bundleData = nullptr;
+ }
+
+ virtual void TearDown() {
+ if (bundleData) {
+ bundle_free(bundleData);
+ }
+ }
+
+ // Replacing bundle_keyval_t with void and cast it in matcher is required because
+ // bundle_keyval_t has only public declaration, not implementation.
+ // This causes incomplete type error which I couldn't resolve in any other way.
+ using BundleIterator = void(const char*, const int, const void*, void*);
+ using BundleIteratorMock = testing::MockFunction<BundleIterator>;
+
+ void CheckBundle(bundle* b, BundleIteratorMock& mock) {
+ bundle_foreach(b,
+ [](const char* key, const int type, const bundle_keyval_t* kv, void* ud) {
+ auto* mock = static_cast<testing::MockFunction<BundleIterator>*>(ud);
+ mock->Call(key, type, kv, nullptr);
+ },
+ &mock);
+ }
+
+ bundle* bundleData;
+ BundleIteratorMock bundleIteratorMock;
+};
+
+TEST_F(JsonToBundleTest, BytesArrayConversion) {
+ vector<vector<unsigned char>> value = {{0, 1, 2}, {100, 101, 102}, {200, 201, 202}};
+
+ auto json_val = picojson::value(picojson::object());
+ auto& json = json_val.get<picojson::object>();
+
+ picojson::array array;
+ array.push_back(vec2json<double>(value[0]));
+ array.push_back(vec2json<double>(value[1]));
+ array.push_back(vec2json<double>(value[2]));
+
+ json["key"] = picojson::value(array);
+
+ auto result = common::JsonToBundle(json_val, &bundleData);
+ ASSERT_TRUE(result);
+
+ EXPECT_CALL(bundleIteratorMock,
+ Call(StrEq("key"), BUNDLE_TYPE_BYTE_ARRAY, KeyValBytesArrEq(value), nullptr));
+
+ CheckBundle(bundleData, bundleIteratorMock);
+}
+
+TEST_F(JsonToBundleTest, BytesConversion) {
+ vector<unsigned char> value = {0, 126, 255};
+
+ auto json_val = picojson::value(picojson::object());
+ auto& json = json_val.get<picojson::object>();
+
+ json["key"] = vec2json<double>(value);
+
+ auto result = common::JsonToBundle(json_val, &bundleData);
+ ASSERT_TRUE(result);
+
+ EXPECT_CALL(bundleIteratorMock,
+ Call(StrEq("key"), BUNDLE_TYPE_BYTE, KeyValBytesEq(value), nullptr));
+
+ CheckBundle(bundleData, bundleIteratorMock);
+}
+
+TEST_F(JsonToBundleTest, BytesConversionInvalidByteValue) {
+ auto json_val = picojson::value(picojson::object());
+ auto& json = json_val.get<picojson::object>();
+ json["key"] = vec2json<double>(vector<double>({1.0, 256.0, 2.0}));
+
+ auto result = common::JsonToBundle(json_val, &bundleData);
+ ASSERT_FALSE(result);
+
+ json["key"] = vec2json<double>(vector<double>({1.0, -1.0, 2.0}));
+ result = common::JsonToBundle(json_val, &bundleData);
+ ASSERT_FALSE(result);
+}
+
+TEST_F(JsonToBundleTest, StringConversion) {
+ string value = "tizen";
+
+ auto json_val = picojson::value(picojson::object());
+ auto& json = json_val.get<picojson::object>();
+
+ json["key"] = picojson::value(value);
+
+ auto result = common::JsonToBundle(json_val, &bundleData);
+ ASSERT_TRUE(result);
+
+ EXPECT_CALL(bundleIteratorMock, Call(StrEq("key"), BUNDLE_TYPE_STR, KeyValStrEq(value), nullptr));
+
+ CheckBundle(bundleData, bundleIteratorMock);
+}
+
+TEST_F(JsonToBundleTest, StringArrayConversion) {
+ vector<string> value = {"str1", "str2", "str3"};
+
+ auto json_val = picojson::value(picojson::object());
+ auto& json = json_val.get<picojson::object>();
+
+ json["key"] = picojson::value(picojson::array(
+ {picojson::value(value[0]), picojson::value(value[1]), picojson::value(value[2])}));
+
+ auto result = common::JsonToBundle(json_val, &bundleData);
+ ASSERT_TRUE(result);
+
+ EXPECT_CALL(bundleIteratorMock,
+ Call(StrEq("key"), BUNDLE_TYPE_STR_ARRAY, KeyValStrArrEq(value), nullptr));
+
+ CheckBundle(bundleData, bundleIteratorMock);
+}
+
+TEST_F(JsonToBundleTest, UnsupportedType) {
+ auto json_val = picojson::value(picojson::object());
+ auto& json = json_val.get<picojson::object>();
+
+ json["key"] = picojson::value(true);
+ auto result = common::JsonToBundle(json_val, &bundleData);
+ ASSERT_FALSE(result);
+
+ json["key"] = picojson::value(picojson::object());
+ result = common::JsonToBundle(json_val, &bundleData);
+ ASSERT_FALSE(result);
+}
+
+TEST_F(JsonToBundleTest, NullConversion) {
+ picojson::value json_val;
+ auto result = common::JsonToBundle(json_val, &bundleData);
+ ASSERT_TRUE(result);
+ ASSERT_EQ(nullptr, bundleData);
+}
+
+class BundleToJsonTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ bundleData = bundle_create();
+ }
+
+ virtual void TearDown() {
+ if (bundleData) {
+ bundle_free(bundleData);
+ }
+ }
+
+ bundle* bundleData;
+};
+
+TEST_F(BundleToJsonTest, NullConversion) {
+ bundle* data = nullptr;
+ picojson::value json;
+ auto result = common::BundleToJson(data, &json);
+ ASSERT_TRUE(result);
+ ASSERT_TRUE(json.is<picojson::null>());
+}
+
+TEST_F(BundleToJsonTest, StringConversion) {
+ string key = "key", value = "tizen";
+ ASSERT_EQ(bundle_add_str(bundleData, key.c_str(), value.c_str()), BUNDLE_ERROR_NONE);
+
+ picojson::value json;
+ auto result = common::BundleToJson(bundleData, &json);
+
+ ASSERT_TRUE(result);
+ ASSERT_TRUE(json.is<picojson::object>());
+ ASSERT_EQ(json.get<picojson::object>()[key].get<string>(), value);
+}
+
+TEST_F(BundleToJsonTest, StringArrayConversion) {
+ string key = "key";
+ vector<const char*> value = {"value1", "value2"};
+
+ ASSERT_EQ(bundle_add_str_array(bundleData, key.c_str(), value.data(), value.size()),
+ BUNDLE_ERROR_NONE);
+
+ picojson::value json;
+ auto result = common::BundleToJson(bundleData, &json);
+ ASSERT_TRUE(result);
+ ASSERT_TRUE(json.is<picojson::object>());
+
+ const auto& array = json.get<picojson::object>()[key].get<picojson::array>();
+ ASSERT_EQ(array.size(), value.size());
+ EXPECT_EQ(array[0].get<std::string>(), std::string(value[0]));
+ EXPECT_EQ(array[1].get<std::string>(), std::string(value[1]));
+}
+
+TEST_F(BundleToJsonTest, BytesConversion) {
+ string key = "key";
+ vector<unsigned char> bytes = {0, 126, 255};
+
+ ASSERT_EQ(bundle_add_byte(bundleData, key.c_str(), bytes.data(), bytes.size()),
+ BUNDLE_ERROR_NONE);
+
+ picojson::value json;
+ auto result = common::BundleToJson(bundleData, &json);
+ ASSERT_TRUE(result);
+ ASSERT_TRUE(json.is<picojson::object>());
+
+ const auto& array = json.get<picojson::object>()[key].get<picojson::array>();
+ ASSERT_EQ(array.size(), bytes.size());
+ EXPECT_EQ(array[0].get<double>(), bytes[0]);
+ EXPECT_EQ(array[1].get<double>(), bytes[1]);
+ EXPECT_EQ(array[2].get<double>(), bytes[2]);
+}
+
+TEST_F(BundleToJsonTest, BytesArrayConversion) {
+ string key = "key";
+ vector<vector<unsigned char>> value = {{0, 126, 255}, {1, 127, 254}};
+
+ ASSERT_EQ(bundle_init_byte_array(bundleData, key.c_str(), value.size()), BUNDLE_ERROR_NONE);
+ ASSERT_EQ(
+ bundle_set_byte_array_element(bundleData, key.c_str(), 0, value[0].data(), value[0].size()),
+ BUNDLE_ERROR_NONE);
+ ASSERT_EQ(
+ bundle_set_byte_array_element(bundleData, key.c_str(), 1, value[1].data(), value[1].size()),
+ BUNDLE_ERROR_NONE);
+
+ picojson::value json;
+ auto result = common::BundleToJson(bundleData, &json);
+ ASSERT_TRUE(result);
+ ASSERT_TRUE(json.is<picojson::object>());
+
+ auto& array = json.get<picojson::object>()[key].get<picojson::array>();
+ ASSERT_EQ(array.size(), value.size());
+
+ auto& bytes = array[0].get<picojson::array>();
+ ASSERT_EQ(bytes.size(), value[0].size());
+ EXPECT_EQ(bytes[0].get<double>(), value[0][0]);
+ EXPECT_EQ(bytes[1].get<double>(), value[0][1]);
+ EXPECT_EQ(bytes[2].get<double>(), value[0][2]);
+
+ bytes = array[1].get<picojson::array>();
+ ASSERT_EQ(bytes.size(), value[1].size());
+ EXPECT_EQ(bytes[0].get<double>(), value[1][0]);
+ EXPECT_EQ(bytes[1].get<double>(), value[1][1]);
+ EXPECT_EQ(bytes[2].get<double>(), value[1][2]);
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef COMMON_UT_JSON_UTILS_H
+#define COMMON_UT_JSON_UTILS_H
+
+class JsonToBundleTest;
+class BundleToJsonTest;
+
+#endif // COMMON_UT_JSON_UTILS_H
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "gtest/gtest.h"
+
+#include "common/ut/json-utils.h"
+
+#include "tizen.h"
+
+int main(int argc, char* argv[]) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&ContactInstance::x, this, _1, _2));
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&ContactInstance::x, this, _1, _2));
-
- // Contact Manager
- REGISTER_ASYNC("ContactManager_getAddressBooks", ContactManagerGetAddressBooks);
- REGISTER_SYNC("ContactManager_getAddressBook", ContactManagerGetAddressBook);
- REGISTER_SYNC("ContactManager_addAddressBook", ContactManagerAddAddressBook);
- REGISTER_SYNC("ContactManager_removeAddressBook", ContactManagerRemoveAddressBook);
- REGISTER_SYNC("ContactManager_get", ContactManagerGet);
- REGISTER_SYNC("ContactManager_update", ContactManagerUpdate);
- REGISTER_ASYNC("ContactManager_updateBatch", ContactManagerUpdateBatch);
- REGISTER_SYNC("ContactManager_remove", ContactManagerRemove);
- REGISTER_ASYNC("ContactManager_removeBatch", ContactManagerRemoveBatch);
- REGISTER_ASYNC("ContactManager_find", ContactManagerFind);
- REGISTER_ASYNC("ContactManager_findByUsageCount", ContactManagerFindByUsageCount);
- REGISTER_SYNC("ContactManager_importFromVCard", ContactManagerImportFromVCard);
- REGISTER_SYNC("ContactManager_startListening", ContactManagerStartListening);
- REGISTER_SYNC("ContactManager_stopListening", ContactManagerStopListening);
-
- // AddressBook
- REGISTER_ASYNC("AddressBook_addBatch", AddressBookAddBatch);
- REGISTER_ASYNC("AddressBook_updateBatch", AddressBookUpdateBatch);
- REGISTER_ASYNC("AddressBook_removeBatch", AddressBookRemoveBatch);
- REGISTER_SYNC("AddressBook_get", AddressBookGet);
- REGISTER_SYNC("AddressBook_add", AddressBookAdd);
- REGISTER_SYNC("AddressBook_update", AddressBookUpdate);
- REGISTER_SYNC("AddressBook_remove", AddressBookRemove);
- REGISTER_ASYNC("AddressBook_find", AddressBookFind);
- REGISTER_SYNC("AddressBook_addGroup", AddressBookAddGroup);
- REGISTER_SYNC("AddressBook_getGroup", AddressBookGetGroup);
- REGISTER_SYNC("AddressBook_updateGroup", AddressBookUpdateGroup);
- REGISTER_SYNC("AddressBook_removeGroup", AddressBookRemoveGroup);
- REGISTER_SYNC("AddressBook_getGroups", AddressBookGetGroups);
- REGISTER_SYNC("AddressBook_startListening", AddressBookStartListening);
- REGISTER_SYNC("AddressBook_stopListening", AddressBookStopListening);
-
- // Person
- REGISTER_SYNC("Person_link", PersonLink);
- REGISTER_SYNC("Person_unlink", PersonUnlink);
- REGISTER_SYNC("Person_getUsageCount", PersonGetUsageCount);
- REGISTER_SYNC("Person_resetUsageCount", PersonResetUsageCount);
-
-#undef REGISTER_SYNC
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&ContactInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(ContactManagerGetAddressBooks);
+ REGISTER_METHOD(ContactManagerGetAddressBook);
+ REGISTER_METHOD(ContactManagerAddAddressBook);
+ REGISTER_METHOD(ContactManagerRemoveAddressBook);
+ REGISTER_METHOD(ContactManagerGet);
+ REGISTER_METHOD(ContactManagerUpdate);
+ REGISTER_METHOD(ContactManagerUpdateBatch);
+ REGISTER_METHOD(ContactManagerRemove);
+ REGISTER_METHOD(ContactManagerRemoveBatch);
+ REGISTER_METHOD(ContactManagerFind);
+ REGISTER_METHOD(ContactManagerFindByUsageCount);
+ REGISTER_METHOD(ContactManagerImportFromVCard);
+ REGISTER_METHOD(ContactManagerStartListening);
+ REGISTER_METHOD(ContactManagerStopListening);
+
+ REGISTER_METHOD(AddressBookAddBatch);
+ REGISTER_METHOD(AddressBookUpdateBatch);
+ REGISTER_METHOD(AddressBookRemoveBatch);
+ REGISTER_METHOD(AddressBookGet);
+ REGISTER_METHOD(AddressBookAdd);
+ REGISTER_METHOD(AddressBookUpdate);
+ REGISTER_METHOD(AddressBookRemove);
+ REGISTER_METHOD(AddressBookFind);
+ REGISTER_METHOD(AddressBookAddGroup);
+ REGISTER_METHOD(AddressBookGetGroup);
+ REGISTER_METHOD(AddressBookUpdateGroup);
+ REGISTER_METHOD(AddressBookRemoveGroup);
+ REGISTER_METHOD(AddressBookGetGroups);
+ REGISTER_METHOD(AddressBookStartListening);
+ REGISTER_METHOD(AddressBookStopListening);
+
+ REGISTER_METHOD(PersonLink);
+ REGISTER_METHOD(PersonUnlink);
+ REGISTER_METHOD(PersonGetUsageCount);
+ REGISTER_METHOD(PersonResetUsageCount);
+
+#undef REGISTER_METHOD
}
ContactInstance::~ContactInstance() {
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var result = native_.callSync('AddressBook_get', {
+ var result = native_.callSync('AddressBookGet', {
id: args.id
});
}
]);
- var result = native_.callSync('AddressBook_add', {
+ var result = native_.callSync('AddressBookAdd', {
addressBookId: this.id,
contact: _toJsonObject(args.contact)
});
};
var result = native_.call(
- 'AddressBook_addBatch',
+ 'AddressBookAddBatch',
{
addressBookId: this.id,
batchArgs: _toJsonObject(args.contacts)
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var result = native_.callSync('AddressBook_update', {
+ var result = native_.callSync('AddressBookUpdate', {
contact: _toJsonObject(args.contact)
});
});
var result = native_.call(
- 'AddressBook_updateBatch',
+ 'AddressBookUpdateBatch',
{
batchArgs: _toJsonObject(args.contacts)
},
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var result = native_.callSync('AddressBook_remove', {
+ var result = native_.callSync('AddressBookRemove', {
id: args.id
});
};
var result = native_.call(
- 'AddressBook_removeBatch',
+ 'AddressBookRemoveBatch',
{
batchArgs: args.ids
},
};
var result = native_.call(
- 'AddressBook_find',
+ 'AddressBookFind',
{
addressBookId: this.id,
filter: utils_.repackFilter(filter),
// always on first registration checking privileges is done
if (type_.isEmptyObject(_contactCallbackMap)) {
- var result = native_.callSync('AddressBook_startListening', {});
+ var result = native_.callSync('AddressBookStartListening', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.removeListener('ContactChangeListener', _contactChangeListener);
_contactListenerRegistered = false;
- var result = native_.callSync('AddressBook_stopListening', {});
+ var result = native_.callSync('AddressBookStopListening', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var result = native_.callSync('AddressBook_getGroup', {
+ var result = native_.callSync('AddressBookGetGroup', {
addressBookId: this.id,
id: args.groupId
});
}
]);
- var result = native_.callSync('AddressBook_addGroup', {
+ var result = native_.callSync('AddressBookAddGroup', {
addressBookId: this.id,
group: args.group
});
}
]);
- var result = native_.callSync('AddressBook_updateGroup', {
+ var result = native_.callSync('AddressBookUpdateGroup', {
addressBookId: this.id,
group: args.group
});
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var result = native_.callSync('AddressBook_removeGroup', {
+ var result = native_.callSync('AddressBookRemoveGroup', {
addressBookId: this.id,
id: args.groupId
});
};
AddressBook.prototype.getGroups = function() {
- var result = native_.callSync('AddressBook_getGroups', { addressBook: this });
+ var result = native_.callSync('AddressBookGetGroups', { addressBook: this });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
var _forceEditMode = false;
if (type_.isString(data)) {
- var result = native_.callSync('ContactManager_importFromVCard', {
+ var result = native_.callSync('ContactManagerImportFromVCard', {
contact: data
});
_checkError(result);
}
};
- var result = native_.call('ContactManager_getAddressBooks', {}, callback);
+ var result = native_.call('ContactManagerGetAddressBooks', {}, callback);
_checkError(result);
};
throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
}
- var result = native_.callSync('ContactManager_getAddressBook', {
+ var result = native_.callSync('ContactManagerGetAddressBook', {
addressBookId: args.addressBookId
});
}
]);
- var result = native_.callSync('ContactManager_addAddressBook', {
+ var result = native_.callSync('ContactManagerAddAddressBook', {
addressBook: args.addressBook
});
);
}
- var result = native_.callSync('ContactManager_removeAddressBook', {
+ var result = native_.callSync('ContactManagerRemoveAddressBook', {
addressBookId: args.addressBookId
});
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var result = native_.callSync('ContactManager_get', {
+ var result = native_.callSync('ContactManagerGet', {
personId: args.personId
});
_checkError(result);
nullable: false
}
]);
- var result = native_.callSync('ContactManager_update', { person: args.person });
+ var result = native_.callSync('ContactManagerUpdate', { person: args.person });
_checkError(result);
result = native_.getResultObject(result);
};
var result = native_.call(
- 'ContactManager_updateBatch',
+ 'ContactManagerUpdateBatch',
{
addressBook: {},
batchArgs: _toJsonObject(args.persons)
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var result = native_.callSync('ContactManager_remove', { personId: args.personId });
+ var result = native_.callSync('ContactManagerRemove', { personId: args.personId });
_checkError(result);
};
};
var result = native_.call(
- 'ContactManager_removeBatch',
+ 'ContactManagerRemoveBatch',
{
addressBook: {},
batchArgs: _toJsonObject(args.personIds)
}
};
- var result = native_.call('ContactManager_find', data, callback);
+ var result = native_.call('ContactManagerFind', data, callback);
_checkError(result);
};
}
};
- var result = native_.call('ContactManager_findByUsageCount', data, callback);
+ var result = native_.call('ContactManagerFindByUsageCount', data, callback);
_checkError(result);
};
]);
if (type_.isEmptyObject(_personCallbackMap)) {
- var result = native_.callSync('ContactManager_startListening', {});
+ var result = native_.callSync('ContactManagerStartListening', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.removeListener('ContactPersonChangeListener', _personChangeListener);
_personListenerRegistered = false;
- var result = native_.callSync('ContactManager_stopListening', {});
+ var result = native_.callSync('ContactManagerStopListening', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var result = native_.callSync('Person_link', {
+ var result = native_.callSync('PersonLink', {
personId: this.id,
id: args.personId
});
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var result = native_.callSync('Person_unlink', {
+ var result = native_.callSync('PersonUnlink', {
personId: this.id,
id: args.contactId
});
var usage_type = args.usage_type === undefined ? null : args.usage_type;
- var result = native_.callSync('Person_getUsageCount', {
+ var result = native_.callSync('PersonGetUsageCount', {
personId: this.id,
usage_type: usage_type
});
var usage_type = args.usage_type === undefined ? null : args.usage_type;
- var result = native_.callSync('Person_resetUsageCount', {
+ var result = native_.callSync('PersonResetUsageCount', {
personId: this.id,
usage_type: usage_type
});
#include "common/converter.h"
#include "common/logger.h"
+#include "common/tools.h"
using common::AttributeMatchFlag;
using common::CompositeFilterType;
ScopeLogger();
auto it = attributeNameMap.find(name);
if (it != attributeNameMap.end()) {
+ if (name == "rating" || name == "description") {
+ std::string warning = "Filtering by attribute '" + name + "'";
+ common::tools::PrintDeprecationWarningFor(warning.c_str());
+ }
*result = it->second;
} else {
return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR);
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&ContentInstance::x, this, _1, _2));
-
- REGISTER_SYNC("ContentManager_find", ContentManagerFind);
- REGISTER_SYNC("ContentManager_update", ContentManagerUpdate);
- REGISTER_SYNC("ContentManager_scanFile", ContentManagerScanfile);
- REGISTER_SYNC("ContentManager_scanDirectory", ContentManagerScanDirectory);
- REGISTER_SYNC("ContentManager_cancelScanDirectory", ContentManagerCancelScanDirectory);
- REGISTER_SYNC("ContentManager_addChangeListener", ContentManagerAddChangeListener);
- REGISTER_SYNC("ContentManager_removeChangeListener", ContentManagerRemoveChangeListener);
- REGISTER_SYNC("ContentManager_unsetChangeListener", ContentManagerUnsetchangelistener);
- REGISTER_SYNC("ContentManager_setChangeListener", ContentManagerSetchangelistener);
- REGISTER_SYNC("ContentManager_getDirectories", ContentManagerGetdirectories);
- REGISTER_SYNC("ContentManager_updateBatch", ContentManagerUpdatebatch);
- REGISTER_SYNC("ContentManager_removePlaylist", ContentManagerRemoveplaylist);
- REGISTER_SYNC("ContentManager_createPlaylist", ContentManagerCreateplaylist);
- REGISTER_SYNC("ContentManager_getPlaylists", ContentManagerGetplaylists);
- REGISTER_SYNC("ContentPlaylist_add", ContentManagerPlaylistAdd);
- REGISTER_SYNC("ContentPlaylist_addBatch", ContentManagerPlaylistAddbatch);
- REGISTER_SYNC("ContentPlaylist_get", ContentManagerPlaylistGet);
- REGISTER_SYNC("ContentPlaylist_remove", ContentManagerPlaylistRemove);
- REGISTER_SYNC("ContentPlaylist_removeBatch", ContentManagerPlaylistRemovebatch);
- REGISTER_SYNC("ContentPlaylist_setOrder", ContentManagerPlaylistSetorder);
- REGISTER_SYNC("ContentPlaylist_move", ContentManagerPlaylistMove);
- REGISTER_SYNC("ContentManager_getLyrics", ContentManagerAudioGetLyrics);
-
- REGISTER_SYNC("ContentPlaylist_getName", PlaylistGetName);
- REGISTER_SYNC("ContentPlaylist_setName", PlaylistSetName);
- REGISTER_SYNC("ContentPlaylist_getThumbnailUri", PlaylistGetThumbnailUri);
- REGISTER_SYNC("ContentPlaylist_setThumbnailUri", PlaylistSetThumbnailUri);
- REGISTER_SYNC("ContentPlaylist_getNumberOfTracks", PlaylistGetNumberOfTracks);
- REGISTER_SYNC("ContentManager_createThumbnail", ContentManagerCreateThumbnail);
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&ContentInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(ContentManagerFind);
+ REGISTER_METHOD(ContentManagerUpdate);
+ REGISTER_METHOD(ContentManagerScanfile);
+ REGISTER_METHOD(ContentManagerScanDirectory);
+ REGISTER_METHOD(ContentManagerCancelScanDirectory);
+ REGISTER_METHOD(ContentManagerAddChangeListener);
+ REGISTER_METHOD(ContentManagerRemoveChangeListener);
+ REGISTER_METHOD(ContentManagerUnsetchangelistener);
+ REGISTER_METHOD(ContentManagerSetchangelistener);
+ REGISTER_METHOD(ContentManagerGetdirectories);
+ REGISTER_METHOD(ContentManagerUpdatebatch);
+ REGISTER_METHOD(ContentManagerRemoveplaylist);
+ REGISTER_METHOD(ContentManagerCreateplaylist);
+ REGISTER_METHOD(ContentManagerGetplaylists);
+ REGISTER_METHOD(ContentManagerPlaylistAdd);
+ REGISTER_METHOD(ContentManagerPlaylistAddbatch);
+ REGISTER_METHOD(ContentManagerPlaylistGet);
+ REGISTER_METHOD(ContentManagerPlaylistRemove);
+ REGISTER_METHOD(ContentManagerPlaylistRemovebatch);
+ REGISTER_METHOD(ContentManagerPlaylistSetorder);
+ REGISTER_METHOD(ContentManagerPlaylistMove);
+ REGISTER_METHOD(ContentManagerAudioGetLyrics);
+
+ REGISTER_METHOD(PlaylistGetName);
+ REGISTER_METHOD(PlaylistSetName);
+ REGISTER_METHOD(PlaylistGetThumbnailUri);
+ REGISTER_METHOD(PlaylistSetThumbnailUri);
+ REGISTER_METHOD(PlaylistGetNumberOfTracks);
+ REGISTER_METHOD(ContentManagerCreateThumbnail);
+
+#undef REGISTER_METHOD
ContentManager::getInstance()->setContentInstance(this);
}
#include "content/content_manager.h"
+#include <media_content_internal.h>
#include <metadata_extractor.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <algorithm>
#include <cstring>
int ret;
char* tmpStr = NULL;
media_content_storage_e storage_type;
- time_t tmpDate;
// id
ret = media_folder_get_folder_id(folder, &tmpStr);
}
// directoryURI
+ std::string folder_path;
ret = media_folder_get_path(folder, &tmpStr);
if (ret == MEDIA_CONTENT_ERROR_NONE) {
if (tmpStr) {
o["directoryURI"] = picojson::value(std::string(tmpStr));
+ // folder_path value kept for modifiedDate property gathering
+ folder_path = tmpStr;
free(tmpStr);
tmpStr = NULL;
}
// storageType
ret = media_folder_get_storage_type(folder, &storage_type);
+ // TODO: The function media_folder_get_storage_type is marked as deprecated since 5.0.
+ // As an alternative, it is recommended to use storage_get_type_dev function. However,
+ // this function does not work with internal storages. The media_folder_get_storage_type
+ // function should be kept or moved to internal header by Native API.
if (ret == MEDIA_CONTENT_ERROR_NONE) {
if (storage_type == MEDIA_CONTENT_STORAGE_INTERNAL) {
o["storageType"] = picojson::value(std::string("INTERNAL"));
- } else if (storage_type == MEDIA_CONTENT_STORAGE_EXTERNAL) {
+ } else {
+ LoggerD("storageType = %d, assuming EXTERNAL as storage type", storage_type);
o["storageType"] = picojson::value(std::string("EXTERNAL"));
- } else if (storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
- o["storageType"] = picojson::value(std::string("CLOUD"));
}
}
- // modifiedData
- ret = media_folder_get_modified_time(folder, &tmpDate);
- if (ret == MEDIA_CONTENT_ERROR_NONE) {
- o["modifiedDate"] = picojson::value(static_cast<double>(tmpDate));
+ // modifiedDate
+ struct stat stat_res;
+ if (stat(folder_path.c_str(), &stat_res) == 0) {
+ auto mod_time = stat_res.st_mtime;
+ o["modifiedDate"] = picojson::value(static_cast<double>(mod_time));
}
}
("Failed: media_folder_get_folder_id"));
return;
}
+ std::unique_ptr<char, decltype(&free)> id_ptr(id, &free);
ret = media_folder_get_name(folder, &name);
if (ret != MEDIA_CONTENT_ERROR_NONE) {
LogAndReportError(ContentManager::convertError(ret), out, ("Failed: media_folder_get_name"));
- free(id);
return;
}
+ std::unique_ptr<char, decltype(&free)> name_ptr(name, &free);
ret = media_folder_get_path(folder, &path);
if (ret != MEDIA_CONTENT_ERROR_NONE) {
LogAndReportError(ContentManager::convertError(ret), out, ("Failed: media_folder_get_path"));
- free(id);
- free(name);
return;
}
+ std::unique_ptr<char, decltype(&free)> path_ptr(path, &free);
- ret = media_folder_get_modified_time(folder, &date);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- LogAndReportError(ContentManager::convertError(ret), out, ("Failed: media_folder_get_path"));
- free(id);
- free(name);
- free(path);
+ struct stat stat_res;
+ ret = stat(path, &stat_res);
+ if (0 != ret) {
+ LogAndReportError(ContentManager::convertError(errno), out, ("Failed: stat"));
return;
}
+ date = stat_res.st_mtime;
ret = media_folder_get_storage_type(folder, &storageType);
+ // TODO: The function media_folder_get_storage_type is marked as deprecated since 5.0.
+ // As an alternative, it is recommended to use storage_get_type_dev function. However,
+ // this function does not work with internal storages. The media_folder_get_storage_type
+ // function should be kept or moved to internal header by Native API.
if (ret != MEDIA_CONTENT_ERROR_NONE) {
- free(id);
- free(name);
- free(path);
LogAndReportError(ContentManager::convertError(ret), out,
("Failed: media_folder_get_storage_type"));
return;
}
(*out)["modifiedDate"] = picojson::value(static_cast<double>(date));
-
- free(name);
- free(id);
- free(path);
}
static bool media_foreach_directory_cb(media_folder_h folder, void* user_data) {
}
}
-int ContentManager::update(picojson::value args) {
+int ContentManager::update(const picojson::value& args) {
ScopeLogger();
int ret;
return ret;
}
-int ContentManager::updateBatch(picojson::value args) {
+int ContentManager::updateBatch(const picojson::value& args) {
ScopeLogger();
int ret = 0;
std::vector<picojson::value> contents = args.get("contents").get<picojson::array>();
ScopeLogger();
media_playlist_h playlist = NULL;
media_content_order_e order = MEDIA_CONTENT_ORDER_ASC;
- const std::string playOrder("play_order");
+ const std::string playOrder("playlist_member_order");
SCOPE_EXIT {
if (playlist) {
void getDirectories(const std::shared_ptr<ReplyCallbackData>& user_data);
void find(const std::shared_ptr<ReplyCallbackData>& user_data);
- int update(picojson::value args);
- int updateBatch(picojson::value args);
+ int update(const picojson::value& args);
+ int updateBatch(const picojson::value& args);
int scanFile(std::string& uri);
common::PlatformResult scanDirectory(media_scan_completed_cb callback, ReplyCallbackData* cbData);
var types_ = validator_.Types;
var native_ = new xwalk.utils.NativeManager(extension);
+var isEarlierThan55 = utils_.isAppVersionEarlierThan('5.5');
+
var EditManager = function() {
this.isAllowed = false;
};
},
storageType: {
get: function() {
+ utils_.printDeprecationWarningFor('ContentDirectoryStorageType');
return storageType;
},
set: function(v) {
}
function Content(data) {
- var editableAttributes = ['name', 'rating', 'description', 'isFavorite'];
+ var editableAttributes = ['isFavorite'];
+ // since 5.5 these attributes are readonly, it is disallowed to modify them,
+ // but for applications developed for earlier versions backward compatibility
+ // is kept
+ if (isEarlierThan55) {
+ editableAttributes.push('name');
+ editableAttributes.push('rating');
+ editableAttributes.push('description');
+ }
var id;
var name;
var type;
return name;
},
set: function(v) {
- if (!type_.isNull(v)) {
- name = converter_.toString(v, false);
+ // since 5.5 this attribute is readonly, it is disallowed to modify it,
+ // but for applications developed for earlier versions backward
+ // compatibility is kept
+ if (isEarlierThan55 || edit_.isAllowed) {
+ if (!type_.isNull(v)) {
+ name = converter_.toString(v, false);
+ }
+ } else {
+ utils_.warn(
+ 'Since 5.5 "name" attribute is readonly, modifying it has no ' +
+ 'effect.'
+ );
}
},
enumerable: true
return description;
},
set: function(v) {
- description = converter_.toString(v, true);
+ // since 5.5 this attribute is readonly, it is disallowed to modify it,
+ // but for applications developed for earlier versions backward
+ // compatibility is kept
+ if (isEarlierThan55 || edit_.isAllowed) {
+ description = converter_.toString(v, true);
+ } else {
+ utils_.warn(
+ 'Since 5.5 "description" attribute is readonly, modifying it ' +
+ 'has no effect.'
+ );
+ }
},
enumerable: true
},
return rating;
},
set: function(v) {
- if (!type_.isNull(v) && v >= 0 && v <= 10) {
- rating = converter_.toUnsignedLong(v, false);
+ // since 5.5 this attribute is readonly, it is disallowed to modify it,
+ // but for applications developed for earlier versions backward
+ // compatibility is kept
+ if (isEarlierThan55 || edit_.isAllowed) {
+ if (!type_.isNull(v) && v >= 0 && v <= 10) {
+ rating = converter_.toUnsignedLong(v, false);
+ }
+ } else {
+ utils_.warn(
+ 'Since 5.5 "rating" attribute is readonly, modifying it has no ' +
+ 'effect.'
+ );
}
},
enumerable: true
Content.call(this, data);
var editableAttributes = this.editableAttributes;
- editableAttributes.push('geolocation');
+ // since 5.5 this attribute is readonly, it is disallowed to modify it,
+ // but for applications developed for earlier versions backward compatibility
+ // is kept
+ if (isEarlierThan55) {
+ editableAttributes.push('geolocation');
+ }
var geolocation;
var album;
},
geolocation: {
get: function() {
- return geolocation;
+ if (isEarlierThan55) {
+ return geolocation;
+ } else {
+ // for keep geolocation's latitude and longitude readonly
+ // we need to return copy of this object
+ return new tizen.SimpleCoordinates(
+ geolocation.latitude,
+ geolocation.longitude
+ );
+ }
},
set: function(v) {
- if (!type_.isNull(v)) {
- var latitude = converter_.toDouble(v.latitude, false);
- var longitude = converter_.toDouble(v.longitude, false);
- geolocation = new tizen.SimpleCoordinates(latitude, longitude);
+ // since 5.5 this attribute is readonly, it is disallowed to modify it,
+ // but for applications developed for earlier versions backward
+ // compatibility is kept
+ if (isEarlierThan55 || edit_.isAllowed) {
+ if (!type_.isNull(v)) {
+ var latitude = converter_.toDouble(v.latitude, false);
+ var longitude = converter_.toDouble(v.longitude, false);
+ geolocation = new tizen.SimpleCoordinates(latitude, longitude);
+ }
+ } else {
+ utils_.warn(
+ 'Since 5.5 "geolocation" attribute is readonly, modifying it ' +
+ 'has no effect.'
+ );
}
},
enumerable: true
contentURI: convertUriToPath_(this.contentURI)
};
- var result = native_.callSync('ContentManager_getLyrics', data);
+ var result = native_.callSync('ContentManagerAudioGetLyrics', data);
if (native_.isFailure(result)) {
utils_.log('Getting lyrics failed for ' + data.contentURI);
Content.call(this, data);
var editableAttributes = this.editableAttributes;
- editableAttributes.push('geolocation');
- editableAttributes.push('orientation');
+ // since 5.5 these attributes are readonly, it is disallowed to modify them,
+ // but for applications developed for earlier versions backward compatibility
+ // is kept
+ if (isEarlierThan55) {
+ editableAttributes.push('geolocation');
+ editableAttributes.push('orientation');
+ }
var geolocation;
var width;
},
geolocation: {
get: function() {
- return geolocation;
+ if (isEarlierThan55) {
+ return geolocation;
+ } else {
+ // for keep geolocation's latitude and longitude readonly
+ // we need to return copy of this object
+ return new tizen.SimpleCoordinates(
+ geolocation.latitude,
+ geolocation.longitude
+ );
+ }
},
set: function(v) {
- if (!type_.isNull(v)) {
- var latitude = converter_.toDouble(v.latitude, false);
- var longitude = converter_.toDouble(v.longitude, false);
- geolocation = new tizen.SimpleCoordinates(latitude, longitude);
+ // since 5.5 this attribute is readonly, it is disallowed to modify it,
+ // but for applications developed for earlier versions backward
+ // compatibility is kept
+ if (isEarlierThan55 || edit_.isAllowed) {
+ if (!type_.isNull(v)) {
+ var latitude = converter_.toDouble(v.latitude, false);
+ var longitude = converter_.toDouble(v.longitude, false);
+ geolocation = new tizen.SimpleCoordinates(latitude, longitude);
+ }
+ } else {
+ utils_.warn(
+ 'Since 5.5 "geolocation" attribute is readonly, modifying it ' +
+ 'has no effect.'
+ );
}
},
enumerable: true
return orientation;
},
set: function(v) {
- if (!type_.isNull(v)) {
- orientation = converter_.toEnum(
- v,
- Object.keys(ImageContentOrientation),
- false
+ // since 5.5 this attribute is readonly, it is disallowed to modify it,
+ // but for applications developed for earlier versions backward
+ // compatibility is kept
+ if (isEarlierThan55 || edit_.isAllowed) {
+ if (!type_.isNull(v)) {
+ orientation = converter_.toEnum(
+ v,
+ Object.keys(ImageContentOrientation),
+ false
+ );
+ }
+ } else {
+ utils_.warn(
+ 'Since 5.5 "orientation" attribute is readonly, modifying it ' +
+ 'has no effect.'
);
}
},
_ContentListenersManager.prototype.addChangeListener = function(changeCallback) {
if (T_.isEmptyObject(this.listeners)) {
- var result = native_.callSync('ContentManager_addChangeListener');
+ var result = native_.callSync('ContentManagerAddChangeListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
delete this.listeners[listenerId];
if (T_.isEmptyObject(this.listeners)) {
- var result = native_.callSync('ContentManager_removeChangeListener');
+ var result = native_.callSync('ContentManagerRemoveChangeListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
content: args.content
};
- var result = native_.callSync('ContentManager_update', data);
+ var result = native_.callSync('ContentManagerUpdate', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback);
};
- var result = native_.call('ContentManager_updateBatch', data, callback);
+ var result = native_.call('ContentManagerUpdatebatch', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback, out);
};
- var result = native_.call('ContentManager_getDirectories', null, callback);
+ var result = native_.call('ContentManagerGetdirectories', null, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback, out);
};
- var result = native_.call('ContentManager_find', data, callback);
+ var result = native_.call('ContentManagerFind', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback, args.contentURI);
};
- var result = native_.call('ContentManager_scanFile', data, callback);
+ var result = native_.call('ContentManagerScanfile', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback, args.contentDirURI);
};
- var result = native_.call('ContentManager_scanDirectory', data, callback);
+ var result = native_.call('ContentManagerScanDirectory', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
contentDirURI: convertUriToPath_(path)
};
- var result = native_.callSync('ContentManager_cancelScanDirectory', data);
+ var result = native_.callSync('ContentManagerCancelScanDirectory', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
oncontentdirremoved: args.changeCallback.oncontentdirremoved
};
- var result = native_.callSync('ContentManager_setChangeListener', data);
+ var result = native_.callSync('ContentManagerSetchangelistener', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
var data = {};
- var result = native_.callSync('ContentManager_unsetChangeListener', data);
+ var result = native_.callSync('ContentManagerUnsetchangelistener', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback, out);
};
- var result = native_.call('ContentManager_getPlaylists', data, callback);
+ var result = native_.call('ContentManagerGetplaylists', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
);
};
- var result = native_.call('ContentManager_createPlaylist', data, callback);
+ var result = native_.call('ContentManagerCreateplaylist', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback);
};
- var result = native_.call('ContentManager_removePlaylist', data, callback);
+ var result = native_.call('ContentManagerRemoveplaylist', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
args.successCallback(native_.getResultObject(result));
};
- var result = native_.call('ContentManager_createThumbnail', data, callback);
+ var result = native_.call('ContentManagerCreateThumbnail', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
},
name: {
get: function() {
- var result = native_.callSync('ContentPlaylist_getName', {
+ var result = native_.callSync('PlaylistGetName', {
id: Number(id)
});
if (native_.isFailure(result)) {
set: function(v) {
if (!type_.isNull(v)) {
var name = converter_.toString(v, false);
- var result = native_.callSync('ContentPlaylist_setName', {
+ var result = native_.callSync('PlaylistSetName', {
id: Number(id),
name: name
});
},
numberOfTracks: {
get: function() {
- var result = native_.callSync('ContentPlaylist_getNumberOfTracks', {
+ var result = native_.callSync('PlaylistGetNumberOfTracks', {
id: Number(id)
});
if (native_.isFailure(result)) {
},
thumbnailURI: {
get: function() {
- var result = native_.callSync('ContentPlaylist_getThumbnailUri', {
+ var result = native_.callSync('PlaylistGetThumbnailUri', {
id: Number(id)
});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
var res = native_.getResultObject(result);
- //CoreAPI not support empty thumbnail, so one space must be used instead
- //null thumbnail
+ //CoreAPI not support empty thumbnail, so one space must be used
+ // instead null thumbnail
return res === ' ' ? null : res;
},
set: function(v) {
var thumbnailURI = converter_.toString(v, true);
if (type_.isNullOrUndefined(thumbnailURI)) {
//CoreAPI not support empty thumbnail, so one space must be used
- //instead null thumbnail
+ // instead null thumbnail
thumbnailURI = ' ';
}
- //TODO probably thumbnailURI should be converted here to absolute uri
- //in case of virtual
- var result = native_.callSync('ContentPlaylist_setThumbnailUri', {
+ //TODO probably thumbnailURI should be converted here to absolute
+ // uri in case of virtual
+ var result = native_.callSync('PlaylistSetThumbnailUri', {
id: Number(id),
uri: thumbnailURI
});
playlistId: this.id
};
- var result = native_.callSync('ContentPlaylist_add', data);
+ var result = native_.callSync('ContentManagerPlaylistAdd', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
native_.callIfPossible(args.successCallback);
};
- var result = native_.call('ContentPlaylist_addBatch', data, callback);
+ var result = native_.call('ContentManagerPlaylistAddbatch', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
playlistId: this.id,
memberId: args.item.content.memberId
};
- var result = native_.callSync('ContentPlaylist_remove', data);
+ var result = native_.callSync('ContentManagerPlaylistRemove', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback);
};
- var result = native_.call('ContentPlaylist_removeBatch', data, callback);
+ var result = native_.call('ContentManagerPlaylistRemovebatch', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback, out);
};
- var result = native_.call('ContentPlaylist_get', data, callback);
+ var result = native_.call('ContentManagerPlaylistGet', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback);
};
- var result = native_.call('ContentPlaylist_setOrder', data, callback);
+ var result = native_.call('ContentManagerPlaylistSetorder', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback);
};
- var result = native_.call('ContentPlaylist_move', data, callback);
+ var result = native_.call('ContentManagerPlaylistMove', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
var converter_ = xwalk.utils.converter;
var types_ = validator_.Types;
var type_ = xwalk.utils.type;
+var privUtils_ = xwalk.utils;
var native_ = new xwalk.utils.NativeManager(extension);
var DATA_CONTROL_MANAGER_LISTENER_ID = 'DataControlManagerChangeCallback';
}
};
var result = native_.call(
- 'DataControlConsumerObject_addChangeListener',
+ 'DataControlConsumerObjectAddChangeListener',
{
providerId: providerId,
dataId: dataId,
}
}
} else {
- console.log('Type invalid or listener was not added');
+ privUtils_.log('Type invalid or listener was not added');
return;
}
if (0 != _realWatchId) {
- native_.call('DataControlConsumerObject_removeChangeListener', {
+ native_.call('DataControlConsumerObjectRemoveChangeListener', {
watchId: _realWatchId
});
insertionData: args.insertionData
};
- var syncResult = native_.call('SQLDataControlConsumer_insert', nativeParam, function(
+ var syncResult = native_.call('SQLDataControlConsumerInsert', nativeParam, function(
result
) {
if (result.status == 'success') {
updateData: args.updateData
};
- var syncResult = native_.call('SQLDataControlConsumer_update', nativeParam, function(
+ var syncResult = native_.call('SQLDataControlConsumerUpdate', nativeParam, function(
result
) {
if (result.status == 'success') {
where: args.where
};
- var syncResult = native_.call('SQLDataControlConsumer_remove', nativeParam, function(
+ var syncResult = native_.call('SQLDataControlConsumerRemove', nativeParam, function(
result
) {
if (result.status == 'success') {
nativeParam['order'] = args.order;
}
- var syncResult = native_.call('SQLDataControlConsumer_select', nativeParam, function(
+ var syncResult = native_.call('SQLDataControlConsumerSelect', nativeParam, function(
result
) {
if (result.status == 'success') {
};
var syncResult = native_.call(
- 'MappedDataControlConsumer_addValue',
+ 'MappedDataControlConsumerAddValue',
nativeParam,
function(result) {
if (result.status == 'success') {
};
var syncResult = native_.call(
- 'MappedDataControlConsumer_removeValue',
+ 'MappedDataControlConsumerRemoveValue',
nativeParam,
function(result) {
if (result.status == 'success') {
};
var syncResult = native_.call(
- 'MappedDataControlConsumer_getValue',
+ 'MappedDataControlConsumerGetValue',
nativeParam,
function(result) {
if (result.status == 'success') {
};
var syncResult = native_.call(
- 'MappedDataControlConsumer_updateValue',
+ 'MappedDataControlConsumerUpdateValue',
nativeParam,
function(result) {
if (result.status == 'success') {
ScopeLogger();
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&DatacontrolInstance::x, this, _1, _2));
- REGISTER_SYNC("SQLDataControlConsumer_update", SQLDataControlConsumerUpdate);
- REGISTER_SYNC("MappedDataControlConsumer_addValue", MappedDataControlConsumerAddvalue);
- REGISTER_SYNC("SQLDataControlConsumer_select", SQLDataControlConsumerSelect);
- REGISTER_SYNC("SQLDataControlConsumer_remove", SQLDataControlConsumerRemove);
- REGISTER_SYNC("MappedDataControlConsumer_removeValue", MappedDataControlConsumerRemovevalue);
- REGISTER_SYNC("MappedDataControlConsumer_updateValue", MappedDataControlConsumerUpdatevalue);
- REGISTER_SYNC("DataControlManager_getDataControlConsumer",
- DataControlManagerGetdatacontrolconsumer);
- REGISTER_SYNC("SQLDataControlConsumer_insert", SQLDataControlConsumerInsert);
- REGISTER_SYNC("MappedDataControlConsumer_getValue", MappedDataControlConsumerGetvalue);
- REGISTER_SYNC("DataControlConsumerObject_removeChangeListener", RemoveChangeListener);
-#undef REGISTER_SYNC
-#define REGISTER_ASYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&DatacontrolInstance::x, this, _1, _2));
- REGISTER_ASYNC("DataControlConsumerObject_addChangeListener", AddChangeListener);
-#undef REGISTER_ASYNC
+
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&DatacontrolInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(SQLDataControlConsumerUpdate);
+ REGISTER_METHOD(MappedDataControlConsumerAddValue);
+ REGISTER_METHOD(SQLDataControlConsumerSelect);
+ REGISTER_METHOD(SQLDataControlConsumerRemove);
+ REGISTER_METHOD(MappedDataControlConsumerRemoveValue);
+ REGISTER_METHOD(MappedDataControlConsumerUpdateValue);
+ REGISTER_METHOD(DataControlManagerGetConsumer);
+ REGISTER_METHOD(SQLDataControlConsumerInsert);
+ REGISTER_METHOD(MappedDataControlConsumerGetValue);
+ REGISTER_METHOD(DataControlConsumerObjectRemoveChangeListener);
+ REGISTER_METHOD(DataControlConsumerObjectAddChangeListener);
+
+#undef REGISTER_METHOD
}
DatacontrolInstance::~DatacontrolInstance() {
LoggerD("Deleting callback number %d", item.first);
int result = ::data_control_remove_data_change_cb(handle, watch_id);
if (DATA_CONTROL_ERROR_NONE != result) {
- LoggerE("RemoveChangeListener %d failed: %d (%s)", watch_id, result,
+ LoggerE("data_control_remove_data_change_cb %d failed: %d (%s)", watch_id, result,
get_error_message(result));
}
}
return; \
}
-void DatacontrolInstance::DataControlManagerGetdatacontrolconsumer(const picojson::value& args,
- picojson::object& out) {
+void DatacontrolInstance::DataControlManagerGetConsumer(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeDatacontrol, &out);
}
}
}
-void DatacontrolInstance::MappedDataControlConsumerAddvalue(const picojson::value& args,
+void DatacontrolInstance::MappedDataControlConsumerAddValue(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeDatacontrol, &out);
}
}
}
-void DatacontrolInstance::MappedDataControlConsumerRemovevalue(const picojson::value& args,
+void DatacontrolInstance::MappedDataControlConsumerRemoveValue(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeDatacontrol, &out);
}
}
}
-void DatacontrolInstance::MappedDataControlConsumerGetvalue(const picojson::value& args,
+void DatacontrolInstance::MappedDataControlConsumerGetValue(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeDatacontrol, &out);
}
}
}
-void DatacontrolInstance::MappedDataControlConsumerUpdatevalue(const picojson::value& args,
+void DatacontrolInstance::MappedDataControlConsumerUpdateValue(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeDatacontrol, &out);
obj.insert(std::make_pair("callbackId", picojson::value(std::to_string(data->callbackId))));
// According to native documentation only IOError can be returned to webapi, other errors are
// handled earlier
- LogAndReportError(IOException("AddChangeListener failed"), obj);
+ LogAndReportError(IOException("DataControlConsumerObjectAddChangeListener failed"), obj);
Instance::PostMessage(data->_instance, event.serialize().c_str());
if (0 != callback_id) {
data->_instance->EraseMap(callback_id);
}
}
-void DatacontrolInstance::AddChangeListener(const picojson::value& args, picojson::object& out) {
+void DatacontrolInstance::DataControlConsumerObjectAddChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeDatasharing, &out);
}
if (DATA_CONTROL_ERROR_NONE != result) {
- LogAndReportError(ServiceNotAvailableException("AddChangeListener failed"), out,
- ("AddChangeListener failed: %d (%s)", result, get_error_message(result)));
+ LogAndReportError(
+ ServiceNotAvailableException("DataControlConsumerObjectAddChangeListener failed"), out,
+ ("DataControlConsumerObjectAddChangeListener failed: %d (%s)", result,
+ get_error_message(result)));
return;
}
user_data.get(), &watch_id);
if (DATA_CONTROL_ERROR_NONE != result) {
- LogAndReportError(ServiceNotAvailableException("AddChangeListener failed"), out,
- ("AddChangeListener failed: %d (%s)", result, get_error_message(result)));
+ LogAndReportError(
+ ServiceNotAvailableException("DataControlConsumerObjectAddChangeListener failed"), out,
+ ("DataControlConsumerObjectAddChangeListener failed: %d (%s)", result,
+ get_error_message(result)));
return;
}
ReportSuccess(return_value, out);
}
-void DatacontrolInstance::RemoveChangeListener(const picojson::value& args, picojson::object& out) {
+void DatacontrolInstance::DataControlConsumerObjectRemoveChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeDatasharing, &out);
int watch_id = static_cast<int>(args.get("watchId").get<double>());
if (reply_map.end() == reply_map.find(watch_id)) {
- LogAndReportError(IOException("RemoveChangeListener failed"), out,
- ("RemoveChangeListener failed, watch_id: %d", watch_id));
+ LogAndReportError(
+ IOException("DataControlConsumerObjectRemoveChangeListener failed"), out,
+ ("DataControlConsumerObjectRemoveChangeListener failed, watch_id: %d", watch_id));
return;
}
data_control_h handle = reply_map[watch_id]->handle;
if (DATA_CONTROL_ERROR_NONE != result) {
// According to native documentation only IOError can be returned to webapi, other errors are
// handled earlier
- LogAndReportError(IOException("RemoveChangeListener failed"), out,
- ("RemoveChangeListener failed: %d (%s)", result, get_error_message(result)));
+ LogAndReportError(IOException("DataControlConsumerObjectRemoveChangeListener failed"), out,
+ ("DataControlConsumerObjectRemoveChangeListener failed: %d (%s)", result,
+ get_error_message(result)));
return;
}
std::string* type);
private:
- void DataControlManagerGetdatacontrolconsumer(const picojson::value& args, picojson::object& out);
+ void DataControlManagerGetConsumer(const picojson::value& args, picojson::object& out);
void SQLDataControlConsumerInsert(const picojson::value& args, picojson::object& out);
void SQLDataControlConsumerUpdate(const picojson::value& args, picojson::object& out);
void SQLDataControlConsumerRemove(const picojson::value& args, picojson::object& out);
void SQLDataControlConsumerSelect(const picojson::value& args, picojson::object& out);
- void MappedDataControlConsumerAddvalue(const picojson::value& args, picojson::object& out);
- void MappedDataControlConsumerRemovevalue(const picojson::value& args, picojson::object& out);
- void MappedDataControlConsumerGetvalue(const picojson::value& args, picojson::object& out);
- void MappedDataControlConsumerUpdatevalue(const picojson::value& args, picojson::object& out);
- void AddChangeListener(const picojson::value& args, picojson::object& out);
- void RemoveChangeListener(const picojson::value& args, picojson::object& out);
+ void MappedDataControlConsumerAddValue(const picojson::value& args, picojson::object& out);
+ void MappedDataControlConsumerRemoveValue(const picojson::value& args, picojson::object& out);
+ void MappedDataControlConsumerGetValue(const picojson::value& args, picojson::object& out);
+ void MappedDataControlConsumerUpdateValue(const picojson::value& args, picojson::object& out);
+ void DataControlConsumerObjectAddChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void DataControlConsumerObjectRemoveChangeListener(const picojson::value& args,
+ picojson::object& out);
ReplyCallbackDataMap reply_map;
};
} else if (result.status == 'canceled') {
if (callback.oncanceled) {
callback.oncanceled(result.downloadId);
- delete callbacks[result.downloadId];
}
} else if (result.status == 'completed') {
if (callback.oncompleted) {
} else if (result.status == 'error') {
if (callback.onfailed) {
callback.onfailed(result.downloadId, new WebAPIException(result.error));
- delete callbacks[result.downloadId];
}
}
}, 0);
PAUSED: 'PAUSED',
CANCELED: 'CANCELED',
COMPLETED: 'COMPLETED',
- FAILED: 'FAILED'
+ FAILED: 'FAILED',
+ ABANDONED: 'ABANDONED'
};
var DownloadNetworkType = {
this.setListener(nativeParam.downloadId, args.downloadCallback);
}
- var result = native_.callSync('DownloadManager_start', nativeParam);
+ var result = native_.callSync('DownloadManagerStart', nativeParam);
if (native_.isFailure(result)) {
if ('NetworkError' === result.error.name) {
'the identifier does not match any download operation in progress'
);
- var result = native_.callSync('DownloadManager_cancel', nativeParam);
+ var result = native_.callSync('DownloadManagerCancel', nativeParam);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
'the identifier does not match any download operation in progress'
);
- var result = native_.callSync('DownloadManager_pause', nativeParam);
+ var result = native_.callSync('DownloadManagerPause', nativeParam);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
+DownloadManager.prototype.abandon = function() {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'downloadId', type: types_.LONG, nullable: false, optional: false }
+ ]);
+
+ var nativeParam = {
+ downloadId: args.downloadId
+ };
+
+ if (typeof requests[args.downloadId] === 'undefined')
+ throw new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'the identifier does not match any download operation in progress'
+ );
+
+ var result = native_.callSync('DownloadManagerAbandon', nativeParam);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ delete callbacks[args.downloadId];
+};
+
DownloadManager.prototype.resume = function() {
var args = validator_.validateArgs(arguments, [
{ name: 'downloadId', type: types_.LONG, nullable: false, optional: false }
'the identifier does not match any download operation in progress'
);
- var result = native_.callSync('DownloadManager_resume', nativeParam);
+ var result = native_.callSync('DownloadManagerResume', nativeParam);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
'the identifier does not match any download operation in progress'
);
- var result = native_.callSync('DownloadManager_getState', nativeParam);
+ var result = native_.callSync('DownloadManagerGetState', nativeParam);
if (native_.isSuccess(result)) {
return native_.getResultObject(result);
'the identifier does not match any download operation in progress'
);
- var result = native_.callSync('DownloadManager_getMIMEType', nativeParam);
+ var result = native_.callSync('DownloadManagerGetMimeType', nativeParam);
if (native_.isSuccess(result)) {
return native_.getResultObject(result);
ScopeLogger();
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&DownloadInstance::x, this, _1, _2));
- REGISTER_SYNC("DownloadManager_pause", DownloadManagerPause);
- REGISTER_SYNC("DownloadManager_getMIMEType", DownloadManagerGetmimetype);
- REGISTER_SYNC("DownloadManager_start", DownloadManagerStart);
- REGISTER_SYNC("DownloadManager_cancel", DownloadManagerCancel);
- REGISTER_SYNC("DownloadManager_resume", DownloadManagerResume);
- REGISTER_SYNC("DownloadManager_getState", DownloadManagerGetstate);
-#undef REGISTER_SYNC
+
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&DownloadInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(DownloadManagerGetMimeType);
+ REGISTER_METHOD(DownloadManagerStart);
+ REGISTER_METHOD(DownloadManagerCancel);
+ REGISTER_METHOD(DownloadManagerPause);
+ REGISTER_METHOD(DownloadManagerAbandon);
+ REGISTER_METHOD(DownloadManagerResume);
+ REGISTER_METHOD(DownloadManagerGetState);
+
+#undef REGISTER_METHOD
std::lock_guard<std::mutex> lock(instances_mutex_);
instances_.push_back(this);
OnStart(download_id, user_data);
break;
case DOWNLOAD_STATE_PAUSED:
- g_idle_add(OnPaused, down_cb_ptr);
+ if (!g_idle_add(OnPaused, down_cb_ptr)) {
+ LoggerE("g_idle_add failed");
+ }
break;
case DOWNLOAD_STATE_COMPLETED:
- g_idle_add(OnFinished, down_cb_ptr);
+ if (!g_idle_add(OnFinished, down_cb_ptr)) {
+ LoggerE("g_idle_add failed");
+ }
break;
case DOWNLOAD_STATE_CANCELED:
- g_idle_add(OnCanceled, down_cb_ptr);
+ if (!g_idle_add(OnCanceled, down_cb_ptr)) {
+ LoggerE("g_idle_add failed");
+ }
break;
case DOWNLOAD_STATE_FAILED:
- g_idle_add(OnFailed, down_cb_ptr);
+ if (!g_idle_add(OnFailed, down_cb_ptr)) {
+ LoggerE("g_idle_add failed");
+ }
break;
default:
LoggerD("Unexpected download state: %d", state);
LoggerE("%s", get_error_message(ret));
}
- ret = download_destroy(di_ptr->native_download_id);
- if (ret != DOWNLOAD_ERROR_NONE) {
- LoggerE("%s", get_error_message(ret));
- }
-
picojson::value::object out;
out["status"] = picojson::value("canceled");
out["downloadId"] = picojson::value(static_cast<double>(download_id));
LoggerE("%s", get_error_message(ret));
}
- ret = download_destroy(di_ptr->native_download_id);
- if (DOWNLOAD_ERROR_NONE != ret) {
- LoggerE("%s", get_error_message(ret));
- }
-
out["downloadId"] = picojson::value(static_cast<double>(down_cb_ptr->download_id));
out["listenerId"] = picojson::value(kDownloadManagerListenerId);
down_cb_ptr->received = received;
down_cb_ptr->native_download_id = download_id;
- g_idle_add(OnProgressChanged, down_cb_ptr);
+ if (!g_idle_add(OnProgressChanged, down_cb_ptr)) {
+ LoggerE("g_idle_add failed");
+ }
}
#define CHECK_CONNECTION_ERROR(ret) \
if (!GetDownloadID(callbackId, downloadId)) {
LogAndReportError(
- common::PlatformResult(common::ErrorCode::NOT_FOUND_ERR,
+ common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
"The identifier does not match any download operation in progress"),
- &out, ("The identifier %d does not match any download operation in progress", downloadId));
+ &out, ("downloadId: %d, found in WEB Api but missing in native API", callbackId));
return;
}
if (!GetDownloadID(callbackId, downloadId)) {
LogAndReportError(
- common::PlatformResult(common::ErrorCode::NOT_FOUND_ERR,
+ common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
"The identifier does not match any download operation in progress"),
- &out, ("The identifier %d does not match any download operation in progress", downloadId));
+ &out, ("downloadId: %d, found in WEB Api but missing in native API", downloadId));
return;
}
}
}
+void DownloadInstance::DownloadManagerAbandon(const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ CHECK_EXIST(args, "downloadId", out)
+ int callbackId, nativeDownloadId, ret;
+ callbackId = static_cast<int>(args.get("downloadId").get<double>());
+
+ if (!GetDownloadID(callbackId, nativeDownloadId)) {
+ LogAndReportError(
+ common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ "The identifier does not match any download operation in progress"),
+ &out, ("downloadId: %d, found in WEB Api but missing in native API", callbackId));
+ return;
+ }
+
+ ret = download_destroy(nativeDownloadId);
+ if (ret == DOWNLOAD_ERROR_NONE) {
+ if (di_map.find(callbackId) != di_map.end()) {
+ di_map.find(callbackId)->second->abandoned = true;
+ }
+ ReportSuccess(out);
+ } else {
+ LogAndReportError(convertError(ret), &out,
+ ("download_destroy error: %d (%s)", ret, get_error_message(ret)));
+ }
+}
+
void DownloadInstance::DownloadManagerResume(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_EXIST(args, "downloadId", out)
- int downloadId, ret;
+ int nativeDownloadId, ret;
int callbackId = static_cast<int>(args.get("downloadId").get<double>());
- if (!GetDownloadID(callbackId, downloadId)) {
+ if ((di_map.end() != di_map.find(callbackId)) && (di_map.find(callbackId)->second->abandoned)) {
LogAndReportError(
- common::PlatformResult(common::ErrorCode::NOT_FOUND_ERR,
+ common::PlatformResult(common::ErrorCode::INVALID_VALUES_ERR,
+ "The download operation with given identifier has been abandoned "
+ "and can not be resumed"),
+ &out,
+ ("The download operation with identifier: %d has been abandoned and can not be resumed",
+ callbackId));
+ return;
+ }
+
+ if (!GetDownloadID(callbackId, nativeDownloadId)) {
+ LogAndReportError(
+ common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
"The identifier does not match any download operation in progress"),
- &out, ("The identifier %d does not match any download operation in progress", downloadId));
+ &out, ("downloadId: %d, found in WEB Api but missing in native API", callbackId));
return;
}
- ret = download_start(downloadId);
+ download_state_e state;
+ ret = download_get_state(nativeDownloadId, &state);
+
+ if (ret == DOWNLOAD_ERROR_NONE) {
+ switch (state) {
+ case DOWNLOAD_STATE_QUEUED:
+ case DOWNLOAD_STATE_DOWNLOADING:
+ case DOWNLOAD_STATE_COMPLETED:
+ ReportSuccess(out);
+ return;
+ default:
+ LoggerD("Download state: %d", state);
+ }
+ }
+
+ ret = download_set_state_changed_cb(nativeDownloadId, OnStateChanged,
+ static_cast<void*>(download_callbacks[callbackId]));
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LogAndReportError(convertError(ret), &out, ("download_set_state_changed_cb error: %d (%s)", ret,
+ get_error_message(ret)));
+ return;
+ }
+
+ ret = download_set_progress_cb(nativeDownloadId, progress_changed_cb,
+ static_cast<void*>(download_callbacks[callbackId]));
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LogAndReportError(convertError(ret), &out,
+ ("download_set_progress_cb error: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ ret = download_start(nativeDownloadId);
if (ret == DOWNLOAD_ERROR_NONE) {
ReportSuccess(out);
}
}
-void DownloadInstance::DownloadManagerGetstate(const picojson::value& args, picojson::object& out) {
+void DownloadInstance::DownloadManagerGetState(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_EXIST(args, "downloadId", out)
int downloadId, ret;
int callbackId = static_cast<int>(args.get("downloadId").get<double>());
+ if (di_map.find(callbackId)->second->abandoned) {
+ stateValue = "ABANDONED";
+ ReportSuccess(picojson::value(stateValue), out);
+ return;
+ }
+
if (!GetDownloadID(callbackId, downloadId)) {
LogAndReportError(
common::PlatformResult(common::ErrorCode::NOT_FOUND_ERR,
}
}
-void DownloadInstance::DownloadManagerGetmimetype(const picojson::value& args,
+void DownloadInstance::DownloadManagerGetMimeType(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
CHECK_EXIST(args, "downloadId", out)
int native_download_id;
long long unsigned file_size;
+ bool abandoned = false;
};
struct DownloadCallback {
void DownloadManagerStart(const picojson::value& args, picojson::object& out);
void DownloadManagerCancel(const picojson::value& args, picojson::object& out);
void DownloadManagerPause(const picojson::value& args, picojson::object& out);
+ void DownloadManagerAbandon(const picojson::value& args, picojson::object& out);
void DownloadManagerResume(const picojson::value& args, picojson::object& out);
- void DownloadManagerGetstate(const picojson::value& args, picojson::object& out);
- void DownloadManagerGetmimetype(const picojson::value& args, picojson::object& out);
+ void DownloadManagerGetState(const picojson::value& args, picojson::object& out);
+ void DownloadManagerGetMimeType(const picojson::value& args, picojson::object& out);
bool GetDownloadID(const int download_id, int& native_download_id);
}
};
- var result = native_.call('ExifManager_getExifInfo', { uri: args.uri }, callback);
+ var result = native_.call('ExifManagerGetExifInfo', { uri: args.uri }, callback);
if (native_.isFailure(result)) {
// since tizen 5.0 the only possible error type here is SecurityError
}
};
- var result = native_.call('ExifManager_saveExifInfo', json, callback);
+ var result = native_.call('ExifManagerSaveExifInfo', json, callback);
if (native_.isFailure(result)) {
// since tizen 5.0 the only possible error type here is SecurityError
}
};
- var result = native_.call('ExifManager_getThumbnail', { uri: args.uri }, _callback);
+ var result = native_.call('ExifManagerGetThumbnail', { uri: args.uri }, _callback);
if (native_.isFailure(result)) {
// since tizen 5.0 the only possible error type here is SecurityError
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&ExifInstance::x, this, _1, _2));
- REGISTER_ASYNC("ExifManager_getExifInfo", ExifManagerGetExifInfo);
- REGISTER_ASYNC("ExifManager_saveExifInfo", ExifManagerSaveExifInfo);
- REGISTER_ASYNC("ExifManager_getThumbnail", ExifManagerGetThumbnail);
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&ExifInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(ExifManagerGetExifInfo);
+ REGISTER_METHOD(ExifManagerSaveExifInfo);
+ REGISTER_METHOD(ExifManagerGetThumbnail);
+
+#undef REGISTER_METHOD
}
ExifInstance::~ExifInstance() {
{ name: 'type', type: types_.ENUM, values: Object.keys(FeedbackType) }
]);
- var result = native_.callSync('FeedbackManager_isPatternSupported', args);
+ var result = native_.callSync('FeedbackManagerIsPatternSupported', args);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
type: args.type ? args.type : 'any'
};
- var result = native_.callSync('FeedbackManager_play', nativeParam);
+ var result = native_.callSync('FeedbackManagerPlay', nativeParam);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
FeedbackManager.prototype.stop = function() {
var args = validator_.validateArgs(arguments, []);
- var result = native_.callSync('FeedbackManager_stop', args);
+ var result = native_.callSync('FeedbackManagerStop', args);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
ScopeLogger();
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&FeedbackInstance::x, this, _1, _2));
- REGISTER_SYNC("FeedbackManager_isPatternSupported", IsPatternSupported);
- REGISTER_SYNC("FeedbackManager_play", Play);
- REGISTER_SYNC("FeedbackManager_stop", Stop);
-#undef REGISTER_SYNC
+
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&FeedbackInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(FeedbackManagerIsPatternSupported);
+ REGISTER_METHOD(FeedbackManagerPlay);
+ REGISTER_METHOD(FeedbackManagerStop);
+
+#undef REGISTER_METHOD
}
FeedbackInstance::~FeedbackInstance() {
ScopeLogger();
}
-void FeedbackInstance::IsPatternSupported(const picojson::value& args, picojson::object& out) {
+void FeedbackInstance::FeedbackManagerIsPatternSupported(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
const auto pattern = args.get("pattern").get<std::string>();
}
}
-void FeedbackInstance::Play(const picojson::value& args, picojson::object& out) {
+void FeedbackInstance::FeedbackManagerPlay(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeHaptic, &out);
}
}
-void FeedbackInstance::Stop(const picojson::value& args, picojson::object& out) {
+void FeedbackInstance::FeedbackManagerStop(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeHaptic, &out);
private:
std::shared_ptr<FeedbackMaps> m_feedbackMapsPtr;
std::unique_ptr<FeedbackManager> m_feedbackManagerPtr;
- void IsPatternSupported(const picojson::value& args, picojson::object& out);
- void Play(const picojson::value& args, picojson::object& out);
- void Stop(const picojson::value& args, picojson::object& out);
+ void FeedbackManagerIsPatternSupported(const picojson::value& args, picojson::object& out);
+ void FeedbackManagerPlay(const picojson::value& args, picojson::object& out);
+ void FeedbackManagerStop(const picojson::value& args, picojson::object& out);
};
} // namespace feedback
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&FilesystemInstance::x, this, _1, _2));
-
- REGISTER_SYNC("File_stat", FileStat);
- REGISTER_SYNC("File_statSync", FileStatSync);
- REGISTER_SYNC("File_createSync", FileCreateSync);
- REGISTER_SYNC("File_readDir", ReadDir);
- REGISTER_SYNC("File_rename", FileRename);
- REGISTER_SYNC("File_readBytes", FileReadBytes);
- REGISTER_SYNC("File_readString", FileReadString);
- REGISTER_SYNC("File_writeBytes", FileWriteBytes);
- REGISTER_SYNC("File_writeBase64", FileWriteBase64);
- REGISTER_SYNC("File_writeString", FileWriteString);
- REGISTER_SYNC("Filesystem_fetchAllStorages", FilesystemFetchAllStorages)
- REGISTER_SYNC("FileSystemManager_addStorageStateChangeListener", StartListening);
- REGISTER_SYNC("FileSystemManager_removeStorageStateChangeListener", StopListening);
- REGISTER_SYNC("FileSystemManager_fetchStorages", FileSystemManagerFetchStorages);
- REGISTER_SYNC("FileSystemManager_mkdir", FileSystemManagerMakeDirectory);
- REGISTER_SYNC("FileSystemManager_mkdirSync", FileSystemManagerMakeDirectorySync);
- REGISTER_SYNC("File_unlinkFile", UnlinkFile);
- REGISTER_SYNC("File_removeDirectory", RemoveDirectory);
- REGISTER_SYNC("File_copyTo", CopyTo);
- REGISTER_SYNC("FileSystemManager_getCanonicalPath", FileSystemManagerGetCanonicalPath);
-
- REGISTER_SYNC("FileSystemManager_openFile", FileSystemManagerOpenFile);
- REGISTER_SYNC("FileSystemManager_createDirectory", FileSystemManagerCreateDirectory);
- REGISTER_SYNC("FileSystemManager_deleteFile", FileSystemManagerDeleteFile);
- REGISTER_SYNC("FileSystemManager_deleteDirectory", FileSystemManagerDeleteDirectory);
- REGISTER_SYNC("FileSystemManager_copyFile", FileSystemManagerCopyFile);
- REGISTER_SYNC("FileSystemManager_copyDirectory", FileSystemManagerCopyDirectory);
- REGISTER_SYNC("FileSystemManager_moveFile", FileSystemManagerMoveFile);
- REGISTER_SYNC("FileSystemManager_moveDirectory", FileSystemManagerMoveDirectory);
- REGISTER_SYNC("FileSystemManager_rename", FileSystemManagerRename);
- REGISTER_SYNC("FileSystemManager_listDirectory", FileSystemManagerListDirectory);
- REGISTER_SYNC("FileSystemManager_isFile", FileSystemManagerIsFile);
- REGISTER_SYNC("FileSystemManager_isDirectory", FileSystemManagerIsDirectory);
- REGISTER_SYNC("FileSystemManager_pathExists", FileSystemManagerPathExists);
- REGISTER_SYNC("FileSystemManager_getLimits", FileSystemManagerGetLimits);
-
- REGISTER_SYNC("FileHandle_seek", FileHandleSeek);
- REGISTER_SYNC("FileHandle_readString", FileHandleReadString);
- REGISTER_SYNC("FileHandle_writeString", FileHandleWriteString);
- REGISTER_SYNC("FileHandle_readData", FileHandleReadData);
- REGISTER_SYNC("FileHandle_writeData", FileHandleWriteData);
- REGISTER_SYNC("FileHandle_flush", FileHandleFlush);
- REGISTER_SYNC("FileHandle_sync", FileHandleSync);
- REGISTER_SYNC("FileHandle_close", FileHandleClose);
-
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&FilesystemInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(FileStat);
+ REGISTER_METHOD(FileStatSync);
+ REGISTER_METHOD(FileCreateSync);
+ REGISTER_METHOD(FileReadDir);
+ REGISTER_METHOD(FileRename);
+ REGISTER_METHOD(FileReadBytes);
+ REGISTER_METHOD(FileReadString);
+ REGISTER_METHOD(FileWriteBytes);
+ REGISTER_METHOD(FileWriteBase64);
+ REGISTER_METHOD(FileWriteString);
+ REGISTER_METHOD(FilesystemFetchAllStorages);
+ REGISTER_METHOD(FileSystemManagerAddStorageStateChangeListener);
+ REGISTER_METHOD(FileSystemManagerRemoveStorageStateChangeListener);
+ REGISTER_METHOD(FileSystemManagerFetchStorages);
+ REGISTER_METHOD(FileSystemManagerMakeDirectory);
+ REGISTER_METHOD(FileSystemManagerMakeDirectorySync);
+ REGISTER_METHOD(FileUnlinkFile);
+ REGISTER_METHOD(FileRemoveDirectory);
+ REGISTER_METHOD(FileCopyTo);
+ REGISTER_METHOD(FileSystemManagerGetCanonicalPath);
+
+ REGISTER_METHOD(FileSystemManagerOpenFile);
+ REGISTER_METHOD(FileSystemManagerCreateDirectory);
+ REGISTER_METHOD(FileSystemManagerDeleteFile);
+ REGISTER_METHOD(FileSystemManagerDeleteDirectory);
+ REGISTER_METHOD(FileSystemManagerCopyFile);
+ REGISTER_METHOD(FileSystemManagerCopyDirectory);
+ REGISTER_METHOD(FileSystemManagerMoveFile);
+ REGISTER_METHOD(FileSystemManagerMoveDirectory);
+ REGISTER_METHOD(FileSystemManagerRename);
+ REGISTER_METHOD(FileSystemManagerListDirectory);
+ REGISTER_METHOD(FileSystemManagerIsFile);
+ REGISTER_METHOD(FileSystemManagerIsDirectory);
+ REGISTER_METHOD(FileSystemManagerPathExists);
+ REGISTER_METHOD(FileSystemManagerGetLimits);
+
+ REGISTER_METHOD(FileHandleSeek);
+ REGISTER_METHOD(FileHandleReadString);
+ REGISTER_METHOD(FileHandleWriteString);
+ REGISTER_METHOD(FileHandleReadData);
+ REGISTER_METHOD(FileHandleWriteData);
+ REGISTER_METHOD(FileHandleFlush);
+ REGISTER_METHOD(FileHandleSync);
+ REGISTER_METHOD(FileHandleClose);
+
+#undef REGISTER_METHOD
+
FilesystemManager::GetInstance().AddListener(this);
}
FilesystemManager::GetInstance().FetchStorages(onSuccess, onError);
}
-void FilesystemInstance::StartListening(const picojson::value& args, picojson::object& out) {
+void FilesystemInstance::FileSystemManagerAddStorageStateChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out);
FilesystemManager::GetInstance().StartListening();
ReportSuccess(out);
}
-void FilesystemInstance::StopListening(const picojson::value& args, picojson::object& out) {
+void FilesystemInstance::FileSystemManagerRemoveStorageStateChangeListener(
+ const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out);
FilesystemManager::GetInstance().StopListening();
FilesystemManager::GetInstance().MakeDirectory(location, onResult);
}
-void FilesystemInstance::ReadDir(const picojson::value& args, picojson::object& out) {
+void FilesystemInstance::FileReadDir(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: File.listFiles() is deprecated since Tizen 5.0. Use "
std::bind(&FilesystemManager::ReadDir, &fm, pathToDir, onSuccess, onError));
}
-void FilesystemInstance::UnlinkFile(const picojson::value& args, picojson::object& out) {
+void FilesystemInstance::FileUnlinkFile(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: File.deleteFile() is deprecated since Tizen 5.0. Use "
std::bind(&FilesystemManager::UnlinkFile, &fm, pathToFile, onSuccess, onError));
}
-void FilesystemInstance::RemoveDirectory(const picojson::value& args, picojson::object& out) {
+void FilesystemInstance::FileRemoveDirectory(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: File.deleteDirectory() is deprecated since Tizen 5.0. Use "
std::bind(&FilesystemManager::RemoveDirectory, &fm, pathToDelete, onSuccess, onError));
}
-void FilesystemInstance::CopyTo(const picojson::value& args, picojson::object& out) {
+void FilesystemInstance::FileCopyTo(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: File.copyTo() is deprecated since Tizen 5.0. Use "
void FileSystemManagerFetchStorages(const picojson::value& args, picojson::object& out);
void FileSystemManagerMakeDirectory(const picojson::value& args, picojson::object& out);
void FileSystemManagerMakeDirectorySync(const picojson::value& args, picojson::object& out);
- void ReadDir(const picojson::value& args, picojson::object& out);
- void UnlinkFile(const picojson::value& args, picojson::object& out);
- void RemoveDirectory(const picojson::value& args, picojson::object& out);
- void StartListening(const picojson::value& args, picojson::object& out);
- void StopListening(const picojson::value& args, picojson::object& out);
- void CopyTo(const picojson::value& args, picojson::object& out);
+ void FileReadDir(const picojson::value& args, picojson::object& out);
+ void FileUnlinkFile(const picojson::value& args, picojson::object& out);
+ void FileRemoveDirectory(const picojson::value& args, picojson::object& out);
+ void FileSystemManagerAddStorageStateChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void FileSystemManagerRemoveStorageStateChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void FileCopyTo(const picojson::value& args, picojson::object& out);
void onFilesystemStateChangeErrorCallback();
void onFilesystemStateChangeSuccessCallback(const common::Storage& storage);
void PrepareError(const FilesystemError& error, picojson::object& out);
*/
#include "filesystem/filesystem_manager.h"
-
#include <app_manager.h>
#include <dirent.h>
#include <fcntl.h>
SCOPE_EXIT {
(void)closedir(dp);
};
- errno = 0;
- struct dirent* entry = nullptr;
- while (nullptr != (entry = readdir(dp))) {
- if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue;
+
+ while (true) {
+ errno = 0;
+ struct dirent* entry = readdir(dp);
+ int readdir_errno = errno;
+ if (0 != readdir_errno) {
+ LoggerE("readdir() error message: %s", GetErrorString(readdir_errno).c_str());
+ return FilesystemError::Other;
+ }
+
+ if (nullptr == entry) {
+ LoggerD("No more entries in the directory");
+ break;
+ }
+
+ if (std::strcmp(entry->d_name, ".") == 0 || std::strcmp(entry->d_name, "..") == 0) {
+ LoggerD("Skipping %s directory", entry->d_name);
+ continue;
+ }
std::string oldLocation = originPath + std::string("/") + std::string(entry->d_name);
std::string newLocation = destPath + std::string("/") + std::string(entry->d_name);
+
FilesystemError fstatus = FilesystemError::None;
if (entry->d_type == DT_DIR) {
fstatus = copyDirectory(oldLocation, newLocation);
}
}
- if (0 != errno) {
- LoggerE("error occured");
- return FilesystemError::Other;
- }
return FilesystemError::None;
}
LoggerW("closedir failed");
}
});
- errno = 0;
- for (dirent* entry; (entry = ::readdir(d));) {
+ while (true) {
+ errno = 0;
+ dirent* entry = ::readdir(d);
+ int readdir_errno = errno;
+ if (0 != readdir_errno) {
+ throw std::system_error{errno, std::generic_category(),
+ "Failed to read directory: "s + GetErrorString(readdir_errno)};
+ }
+
+ if (entry == nullptr) {
+ break;
+ }
+
if (0 == std::strcmp(entry->d_name, ".") || 0 == std::strcmp(entry->d_name, "..")) {
continue;
}
next(entry->d_name, entry->d_type);
}
-
- if (0 != errno) {
- throw std::system_error{errno, std::generic_category(),
- "Failed to read directory: "s + GetErrorString(errno)};
- }
}
void RemoveDirectoryRecursively(const std::string& path) {
if (cacheReady) {
return;
}
- var result = native_.callSync('Filesystem_fetchAllStorages', {});
+ var result = native_.callSync('FilesystemFetchAllStorages', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
// (global paths usage issue workaround)
initHomeDir();
- var result = native_.callSync('FileSystemManager_fetchStorages', {});
+ var result = native_.callSync('FileSystemManagerFetchStorages', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
function toCanonicalPath(path) {
- var result = native_.callSync('FileSystemManager_getCanonicalPath', {
+ var result = native_.callSync('FileSystemManagerGetCanonicalPath', {
path: path
});
if (native_.isFailure(result)) {
function File(data) {
function fileSizeGetter() {
var _realPath = commonFS_.toRealPath(this.fullPath);
- var _result = native_.callSync('File_statSync', { location: _realPath });
+ var _result = native_.callSync('FileStatSync', { location: _realPath });
var _aStatObj = native_.getResultObject(_result);
return _aStatObj.isFile ? _aStatObj.size : undefined;
}
// prevent recursive - only one parent
var _parentPath = data.path;
var _location = { location: commonFS_.toRealPath(_parentPath) };
- var _result = native_.callSync('File_statSync', _location);
+ var _result = native_.callSync('FileStatSync', _location);
var _statObj = native_.getResultObject(_result);
var _info = commonFS_.getFileInfo(_statObj, true);
return new File(_info);
if (str === '') {
return new RegExp(_regString + '$', 'i');
}
- // single '\' sign is not visible in JS string, escaping % wildcard need to
- // be done by '\\%'
+ // single '\' sign is not visible in JS string, escaping % wildcard
+ // need to be done by '\\%'
str = str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
var _percentTokens = str.split('%');
native_.callIfPossible(args.onsuccess, _result);
};
- native_.call('File_readDir', data, callback);
+ native_.call('FileReadDir', data, callback);
}
File.prototype.listFiles = function() {
args.encoding = _checkEncoding(args.encoding);
var _realPath = commonFS_.toRealPath(this.fullPath);
- var _result = native_.callSync('File_statSync', { location: _realPath });
+ var _result = native_.callSync('FileStatSync', { location: _realPath });
if (native_.isFailure(_result)) {
setTimeout(function() {
native_.callIfPossible(
function readFile() {
var result;
- result = native_.callSync('File_readString', data);
+ result = native_.callSync('FileReadString', data);
if (native_.isFailure(result)) {
setTimeout(function() {
native_.callIfPossible(args.onerror, native_.getErrorObject(result));
return;
}
- var resultOldPath = native_.callSync('File_statSync', {
+ var resultOldPath = native_.callSync('FileStatSync', {
location: _realOriginalPath
});
if (native_.isFailure(resultOldPath)) {
var addFileName = false;
var lastChar = _realDestinationPath.substr(_realDestinationPath.length - 1);
- var resultNewPath = native_.callSync('File_statSync', {
+ var resultNewPath = native_.callSync('FileStatSync', {
location: _realDestinationPath
});
if (native_.isSuccess(resultNewPath)) {
_realDestinationPath.lastIndexOf('/') + 1
);
- var resultDestinationDirectory = native_.callSync('File_statSync', {
+ var resultDestinationDirectory = native_.callSync('FileStatSync', {
location: destinationDirectoryPath
});
if (native_.isFailure(resultDestinationDirectory)) {
}
if (!args.overwrite) {
- var resultPath = native_.callSync('File_statSync', {
+ var resultPath = native_.callSync('FileStatSync', {
location: _realDestinationPath
});
if (native_.isSuccess(resultPath)) {
native_.callIfPossible(args.onsuccess);
};
- native_.call('File_copyTo', data, callback);
+ native_.call('FileCopyTo', data, callback);
}
File.prototype.copyTo = function() {
return;
}
- var resultOldPath = native_.callSync('File_statSync', {
+ var resultOldPath = native_.callSync('FileStatSync', {
location: _realOriginalPath
});
if (native_.isFailure(resultOldPath)) {
}
if (!args.overwrite) {
- var resultNewPath = native_.callSync('File_statSync', {
+ var resultNewPath = native_.callSync('FileStatSync', {
location: _realDestinationPath
});
if (native_.isSuccess(resultNewPath)) {
native_.callIfPossible(args.onsuccess);
};
- native_.call('File_rename', data, callback);
+ native_.call('FileRename', data, callback);
}
File.prototype.moveTo = function() {
);
}
- var _resultExist = native_.callSync('File_statSync', { location: _realNewPath });
+ var _resultExist = native_.callSync('FileStatSync', { location: _realNewPath });
if (native_.isSuccess(_resultExist)) {
throw new WebAPIException(
WebAPIException.INVALID_VALUES_ERR,
);
}
- var result = native_.callSync('FileSystemManager_mkdirSync', {
+ var result = native_.callSync('FileSystemManagerMakeDirectorySync', {
location: _realNewPath
});
if (native_.isFailure(result)) {
);
}
- var _result = native_.callSync('File_statSync', { location: _realNewPath });
+ var _result = native_.callSync('FileStatSync', { location: _realNewPath });
_statObj = native_.getResultObject(_result);
_fileInfo = commonFS_.getFileInfo(_statObj, false, this.mode);
);
}
- var _resultExist = native_.callSync('File_statSync', { location: _outputRealPath });
+ var _resultExist = native_.callSync('FileStatSync', { location: _outputRealPath });
if (native_.isSuccess(_resultExist)) {
throw new WebAPIException(WebAPIException.IO_ERR, 'Overwrite is not allowed');
}
- var result = native_.callSync('File_createSync', { location: _outputRealPath });
+ var result = native_.callSync('FileCreateSync', { location: _outputRealPath });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
- var _result = native_.callSync('File_statSync', { location: _outputRealPath });
+ var _result = native_.callSync('FileStatSync', { location: _outputRealPath });
var _statObj = native_.getResultObject(_result);
var _fileInfo = commonFS_.getFileInfo(_statObj, false, this.mode);
);
}
- var _result = native_.callSync('File_statSync', { location: _realPath });
+ var _result = native_.callSync('FileStatSync', { location: _realPath });
if (native_.isFailure(_result)) {
throw new WebAPIException(
WebAPIException.NOT_FOUND_ERR,
return;
}
- var _result = native_.callSync('File_statSync', { location: _myPath });
+ var _result = native_.callSync('FileStatSync', { location: _myPath });
if (native_.isFailure(_result)) {
setTimeout(function() {
native_.callIfPossible(
native_.callIfPossible(args.onsuccess);
};
- native_.call('File_removeDirectory', data, callback);
+ native_.call('FileRemoveDirectory', data, callback);
},
function() {
native_.callIfPossible(
var _fileRealPath = commonFS_.toRealPath(args.filePath);
- var _result = native_.callSync('File_statSync', { location: _fileRealPath });
+ var _result = native_.callSync('FileStatSync', { location: _fileRealPath });
if (native_.isFailure(_result)) {
setTimeout(function() {
native_.callIfPossible(
native_.callIfPossible(args.onsuccess);
};
- native_.call('File_unlinkFile', data, callback);
+ native_.call('FileUnlinkFile', data, callback);
}
File.prototype.deleteFile = function() {
} else {
data.whence = args.whence;
}
- var result = native_.callSync('FileHandle_seek', data);
+ var result = native_.callSync('FileHandleSeek', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('FileHandle_seek', data, callback);
+ var result = native_.call('FileHandleSeek', data, callback);
if (native_.isFailure(result)) {
setTimeout(function() {
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
if (!type_.isNullOrUndefined(args.count)) {
data.count = args.count;
}
- var result = native_.callSync('FileHandle_readString', data);
+ var result = native_.callSync('FileHandleReadString', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
- var result = native_.call('FileHandle_readString', data, callback);
+ var result = native_.call('FileHandleReadString', data, callback);
if (native_.isFailure(result)) {
var err = native_.getErrorObject(result);
);
}
var data = { id: this.id, string: args.string, encoding: args.outputEncoding };
- var result = native_.callSync('FileHandle_writeString', data);
+ var result = native_.callSync('FileHandleWriteString', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
- var result = native_.call('FileHandle_writeString', data, callback);
+ var result = native_.call('FileHandleWriteString', data, callback);
if (native_.isFailure(result)) {
var err = native_.getErrorObject(result);
if (!type_.isNullOrUndefined(args.size)) {
data.size = args.size;
}
- var result = native_.call('FileHandle_readData', data);
+ var result = native_.call('FileHandleReadData', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
- var result = native_.call('FileHandle_readData', data, callback);
+ var result = native_.call('FileHandleReadData', data, callback);
if (native_.isFailure(result)) {
var err = native_.getErrorObject(result);
var encodedData = ArrayToString(blobToUint8Array(args.blob));
var data = { id: this.id, data: encodedData };
- var result = native_.callSync('FileHandle_writeData', data);
+ var result = native_.callSync('FileHandleWriteData', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('FileHandle_writeData', data, callback);
+ var result = native_.call('FileHandleWriteData', data, callback);
// Only IOError is possible to be returned synchronously, so it is passed to
// errorCallback in each case.
if (!type_.isNullOrUndefined(args.size)) {
data.size = args.size;
}
- var result = native_.callSync('FileHandle_readData', data);
+ var result = native_.callSync('FileHandleReadData', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
- var result = native_.call('FileHandle_readData', data, callback);
+ var result = native_.call('FileHandleReadData', data, callback);
if (native_.isFailure(result)) {
var err = native_.getErrorObject(result);
}
var encodedData = ArrayToString(args.data);
var data = { id: this.id, data: encodedData };
- var result = native_.callSync('FileHandle_writeData', data);
+ var result = native_.callSync('FileHandleWriteData', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
- var result = native_.call('FileHandle_writeData', data, callback);
+ var result = native_.call('FileHandleWriteData', data, callback);
// Only IOError is possible to be returned synchronously, so it is passed to
// errorCallback in each case.
);
}
var data = { id: this.id };
- var result = native_.callSync('FileHandle_flush', data);
+ var result = native_.callSync('FileHandleFlush', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
- var result = native_.call('FileHandle_flush', data, callback);
+ var result = native_.call('FileHandleFlush', data, callback);
// Only IOError is possible to be returned synchronously, so it is passed to
// errorCallback in each case.
}
var data = { id: this.id };
- var result = native_.callSync('FileHandle_sync', data);
+ var result = native_.callSync('FileHandleSync', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
- var result = native_.call('FileHandle_sync', data, callback);
+ var result = native_.call('FileHandleSync', data, callback);
// Only IOError is possible to be returned synchronously, so it is passed to
// errorCallback in each case.
throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened');
}
var data = { id: this.id };
- var result = native_.callSync('FileHandle_close', data);
+ var result = native_.callSync('FileHandleClose', data);
this.state = 'closed';
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
- var result = native_.call('FileHandle_close', data, callback);
+ var result = native_.call('FileHandleClose', data, callback);
this.state = 'closed';
// Only IOError is possible to be returned synchronously, so it is passed to
length: args.charCount > _count ? _count : args.charCount
};
- var result = native_.callSync('File_readString', data);
+ var result = native_.callSync('FileReadString', data);
if (native_.isFailure(result)) {
throw new WebAPIException(WebAPIException.IO_ERR, 'Could not read');
}
length: args.byteCount > _count ? _count : args.byteCount
};
- var result = native_.callSync('File_readBytes', data);
+ var result = native_.callSync('FileReadBytes', data);
if (native_.isFailure(result)) {
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Could not read');
}
check_characters_outside_latin1(data.data);
}
- var result = native_.callSync('File_writeString', data);
+ var result = native_.callSync('FileWriteString', data);
if (native_.isFailure(result)) {
throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write');
truncate: this._truncate
};
- var result = native_.callSync('File_writeBytes', data);
+ var result = native_.callSync('FileWriteBytes', data);
if (native_.isFailure(result)) {
throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write');
truncate: this._truncate
};
- var result = native_.callSync('File_writeBase64', data);
+ var result = native_.callSync('FileWriteBase64', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
var fileStreamManager = new FileStreamManager();
function FileSystemManager() {
- var limits = native_.getResultObject(native_.callSync('FileSystemManager_getLimits'));
+ var limits = native_.getResultObject(native_.callSync('FileSystemManagerGetLimits'));
Object.defineProperties(this, {
maxNameLength: { value: limits[0], writable: false, enumerable: true },
maxPathLength: { value: limits[1], writable: false, enumerable: true }
);
}
- var result = native_.callSync('FileSystemManager_openFile', data);
+ var result = native_.callSync('FileSystemManagerOpenFile', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
} else {
}
};
- var result = native_.call('FileSystemManager_createDirectory', data, callback);
+ var result = native_.call('FileSystemManagerCreateDirectory', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('FileSystemManager_deleteFile', data, callback);
+ var result = native_.call('FileSystemManagerDeleteFile', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('FileSystemManager_deleteDirectory', data, callback);
+ var result = native_.call('FileSystemManagerDeleteDirectory', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('FileSystemManager_copyFile', data, callback);
+ var result = native_.call('FileSystemManagerCopyFile', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('FileSystemManager_copyDirectory', data, callback);
+ var result = native_.call('FileSystemManagerCopyDirectory', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('FileSystemManager_moveFile', data, callback);
+ var result = native_.call('FileSystemManagerMoveFile', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('FileSystemManager_moveDirectory', data, callback);
+ var result = native_.call('FileSystemManagerMoveDirectory', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('FileSystemManager_rename', data, callback);
+ var result = native_.call('FileSystemManagerRename', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
};
- var result = native_.call('FileSystemManager_listDirectory', data, callback);
+ var result = native_.call('FileSystemManagerListDirectory', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
var data = { path: realPath };
- var result = native_.callSync('FileSystemManager_isFile', data);
+ var result = native_.callSync('FileSystemManagerIsFile', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
} else {
var data = { path: realPath };
- var result = native_.callSync('FileSystemManager_isDirectory', data);
+ var result = native_.callSync('FileSystemManagerIsDirectory', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
} else {
}
var data = { path: realPath };
- var result = native_.callSync('FileSystemManager_pathExists', data);
+ var result = native_.callSync('FileSystemManagerPathExists', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
} else {
}
};
- var ret = native_.call('File_stat', data, callback);
+ var ret = native_.call('FileStat', data, callback);
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
if (register) {
native_.addListener('StorageStateChangeListener', _StorageStateChangeListener);
var result = native_.callSync(
- 'FileSystemManager_addStorageStateChangeListener',
+ 'FileSystemManagerAddStorageStateChangeListener',
{}
);
var id = args.watchId;
if (type_.isNullOrUndefined(callbacks[id])) {
- throw new WebAPIException(WebAPIException.NOT_FOUND_ERR, 'Watch ID not found.');
+ return;
}
delete callbacks[id];
if (type_.isEmptyObject(callbacks)) {
var result = native_.callSync(
- 'FileSystemManager_removeStorageStateChangeListener',
+ 'FileSystemManagerRemoveStorageStateChangeListener',
{}
);
if (native_.isFailure(result)) {
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements some commonly used actions.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
+
+#ifndef _WIN32_WCE
+# include <errno.h>
+#endif
+
+#include <algorithm>
+#include <functional>
+#include <memory>
+#include <string>
+#include <type_traits>
+#include <utility>
+
+#include "gmock/internal/gmock-internal-utils.h"
+#include "gmock/internal/gmock-port.h"
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable:4100)
+#endif
+
+namespace testing {
+
+// To implement an action Foo, define:
+// 1. a class FooAction that implements the ActionInterface interface, and
+// 2. a factory function that creates an Action object from a
+// const FooAction*.
+//
+// The two-level delegation design follows that of Matcher, providing
+// consistency for extension developers. It also eases ownership
+// management as Action objects can now be copied like plain values.
+
+namespace internal {
+
+// BuiltInDefaultValueGetter<T, true>::Get() returns a
+// default-constructed T value. BuiltInDefaultValueGetter<T,
+// false>::Get() crashes with an error.
+//
+// This primary template is used when kDefaultConstructible is true.
+template <typename T, bool kDefaultConstructible>
+struct BuiltInDefaultValueGetter {
+ static T Get() { return T(); }
+};
+template <typename T>
+struct BuiltInDefaultValueGetter<T, false> {
+ static T Get() {
+ Assert(false, __FILE__, __LINE__,
+ "Default action undefined for the function return type.");
+ return internal::Invalid<T>();
+ // The above statement will never be reached, but is required in
+ // order for this function to compile.
+ }
+};
+
+// BuiltInDefaultValue<T>::Get() returns the "built-in" default value
+// for type T, which is NULL when T is a raw pointer type, 0 when T is
+// a numeric type, false when T is bool, or "" when T is string or
+// std::string. In addition, in C++11 and above, it turns a
+// default-constructed T value if T is default constructible. For any
+// other type T, the built-in default T value is undefined, and the
+// function will abort the process.
+template <typename T>
+class BuiltInDefaultValue {
+ public:
+ // This function returns true iff type T has a built-in default value.
+ static bool Exists() {
+ return ::std::is_default_constructible<T>::value;
+ }
+
+ static T Get() {
+ return BuiltInDefaultValueGetter<
+ T, ::std::is_default_constructible<T>::value>::Get();
+ }
+};
+
+// This partial specialization says that we use the same built-in
+// default value for T and const T.
+template <typename T>
+class BuiltInDefaultValue<const T> {
+ public:
+ static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
+ static T Get() { return BuiltInDefaultValue<T>::Get(); }
+};
+
+// This partial specialization defines the default values for pointer
+// types.
+template <typename T>
+class BuiltInDefaultValue<T*> {
+ public:
+ static bool Exists() { return true; }
+ static T* Get() { return nullptr; }
+};
+
+// The following specializations define the default values for
+// specific types we care about.
+#define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
+ template <> \
+ class BuiltInDefaultValue<type> { \
+ public: \
+ static bool Exists() { return true; } \
+ static type Get() { return value; } \
+ }
+
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
+
+// There's no need for a default action for signed wchar_t, as that
+// type is the same as wchar_t for gcc, and invalid for MSVC.
+//
+// There's also no need for a default action for unsigned wchar_t, as
+// that type is the same as unsigned int for gcc, and invalid for
+// MSVC.
+#if GMOCK_WCHAR_T_IS_NATIVE_
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT
+#endif
+
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
+
+#undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
+
+} // namespace internal
+
+// When an unexpected function call is encountered, Google Mock will
+// let it return a default value if the user has specified one for its
+// return type, or if the return type has a built-in default value;
+// otherwise Google Mock won't know what value to return and will have
+// to abort the process.
+//
+// The DefaultValue<T> class allows a user to specify the
+// default value for a type T that is both copyable and publicly
+// destructible (i.e. anything that can be used as a function return
+// type). The usage is:
+//
+// // Sets the default value for type T to be foo.
+// DefaultValue<T>::Set(foo);
+template <typename T>
+class DefaultValue {
+ public:
+ // Sets the default value for type T; requires T to be
+ // copy-constructable and have a public destructor.
+ static void Set(T x) {
+ delete producer_;
+ producer_ = new FixedValueProducer(x);
+ }
+
+ // Provides a factory function to be called to generate the default value.
+ // This method can be used even if T is only move-constructible, but it is not
+ // limited to that case.
+ typedef T (*FactoryFunction)();
+ static void SetFactory(FactoryFunction factory) {
+ delete producer_;
+ producer_ = new FactoryValueProducer(factory);
+ }
+
+ // Unsets the default value for type T.
+ static void Clear() {
+ delete producer_;
+ producer_ = nullptr;
+ }
+
+ // Returns true iff the user has set the default value for type T.
+ static bool IsSet() { return producer_ != nullptr; }
+
+ // Returns true if T has a default return value set by the user or there
+ // exists a built-in default value.
+ static bool Exists() {
+ return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
+ }
+
+ // Returns the default value for type T if the user has set one;
+ // otherwise returns the built-in default value. Requires that Exists()
+ // is true, which ensures that the return value is well-defined.
+ static T Get() {
+ return producer_ == nullptr ? internal::BuiltInDefaultValue<T>::Get()
+ : producer_->Produce();
+ }
+
+ private:
+ class ValueProducer {
+ public:
+ virtual ~ValueProducer() {}
+ virtual T Produce() = 0;
+ };
+
+ class FixedValueProducer : public ValueProducer {
+ public:
+ explicit FixedValueProducer(T value) : value_(value) {}
+ T Produce() override { return value_; }
+
+ private:
+ const T value_;
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer);
+ };
+
+ class FactoryValueProducer : public ValueProducer {
+ public:
+ explicit FactoryValueProducer(FactoryFunction factory)
+ : factory_(factory) {}
+ T Produce() override { return factory_(); }
+
+ private:
+ const FactoryFunction factory_;
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer);
+ };
+
+ static ValueProducer* producer_;
+};
+
+// This partial specialization allows a user to set default values for
+// reference types.
+template <typename T>
+class DefaultValue<T&> {
+ public:
+ // Sets the default value for type T&.
+ static void Set(T& x) { // NOLINT
+ address_ = &x;
+ }
+
+ // Unsets the default value for type T&.
+ static void Clear() { address_ = nullptr; }
+
+ // Returns true iff the user has set the default value for type T&.
+ static bool IsSet() { return address_ != nullptr; }
+
+ // Returns true if T has a default return value set by the user or there
+ // exists a built-in default value.
+ static bool Exists() {
+ return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
+ }
+
+ // Returns the default value for type T& if the user has set one;
+ // otherwise returns the built-in default value if there is one;
+ // otherwise aborts the process.
+ static T& Get() {
+ return address_ == nullptr ? internal::BuiltInDefaultValue<T&>::Get()
+ : *address_;
+ }
+
+ private:
+ static T* address_;
+};
+
+// This specialization allows DefaultValue<void>::Get() to
+// compile.
+template <>
+class DefaultValue<void> {
+ public:
+ static bool Exists() { return true; }
+ static void Get() {}
+};
+
+// Points to the user-set default value for type T.
+template <typename T>
+typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = nullptr;
+
+// Points to the user-set default value for type T&.
+template <typename T>
+T* DefaultValue<T&>::address_ = nullptr;
+
+// Implement this interface to define an action for function type F.
+template <typename F>
+class ActionInterface {
+ public:
+ typedef typename internal::Function<F>::Result Result;
+ typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
+
+ ActionInterface() {}
+ virtual ~ActionInterface() {}
+
+ // Performs the action. This method is not const, as in general an
+ // action can have side effects and be stateful. For example, a
+ // get-the-next-element-from-the-collection action will need to
+ // remember the current element.
+ virtual Result Perform(const ArgumentTuple& args) = 0;
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
+};
+
+// An Action<F> is a copyable and IMMUTABLE (except by assignment)
+// object that represents an action to be taken when a mock function
+// of type F is called. The implementation of Action<T> is just a
+// std::shared_ptr to const ActionInterface<T>. Don't inherit from Action!
+// You can view an object implementing ActionInterface<F> as a
+// concrete action (including its current state), and an Action<F>
+// object as a handle to it.
+template <typename F>
+class Action {
+ // Adapter class to allow constructing Action from a legacy ActionInterface.
+ // New code should create Actions from functors instead.
+ struct ActionAdapter {
+ // Adapter must be copyable to satisfy std::function requirements.
+ ::std::shared_ptr<ActionInterface<F>> impl_;
+
+ template <typename... Args>
+ typename internal::Function<F>::Result operator()(Args&&... args) {
+ return impl_->Perform(
+ ::std::forward_as_tuple(::std::forward<Args>(args)...));
+ }
+ };
+
+ public:
+ typedef typename internal::Function<F>::Result Result;
+ typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
+
+ // Constructs a null Action. Needed for storing Action objects in
+ // STL containers.
+ Action() {}
+
+ // Construct an Action from a specified callable.
+ // This cannot take std::function directly, because then Action would not be
+ // directly constructible from lambda (it would require two conversions).
+ template <typename G,
+ typename = typename ::std::enable_if<
+ ::std::is_constructible<::std::function<F>, G>::value>::type>
+ Action(G&& fun) : fun_(::std::forward<G>(fun)) {} // NOLINT
+
+ // Constructs an Action from its implementation.
+ explicit Action(ActionInterface<F>* impl)
+ : fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(impl)}) {}
+
+ // This constructor allows us to turn an Action<Func> object into an
+ // Action<F>, as long as F's arguments can be implicitly converted
+ // to Func's and Func's return type can be implicitly converted to F's.
+ template <typename Func>
+ explicit Action(const Action<Func>& action) : fun_(action.fun_) {}
+
+ // Returns true iff this is the DoDefault() action.
+ bool IsDoDefault() const { return fun_ == nullptr; }
+
+ // Performs the action. Note that this method is const even though
+ // the corresponding method in ActionInterface is not. The reason
+ // is that a const Action<F> means that it cannot be re-bound to
+ // another concrete action, not that the concrete action it binds to
+ // cannot change state. (Think of the difference between a const
+ // pointer and a pointer to const.)
+ Result Perform(ArgumentTuple args) const {
+ if (IsDoDefault()) {
+ internal::IllegalDoDefault(__FILE__, __LINE__);
+ }
+ return internal::Apply(fun_, ::std::move(args));
+ }
+
+ private:
+ template <typename G>
+ friend class Action;
+
+ // fun_ is an empty function iff this is the DoDefault() action.
+ ::std::function<F> fun_;
+};
+
+// The PolymorphicAction class template makes it easy to implement a
+// polymorphic action (i.e. an action that can be used in mock
+// functions of than one type, e.g. Return()).
+//
+// To define a polymorphic action, a user first provides a COPYABLE
+// implementation class that has a Perform() method template:
+//
+// class FooAction {
+// public:
+// template <typename Result, typename ArgumentTuple>
+// Result Perform(const ArgumentTuple& args) const {
+// // Processes the arguments and returns a result, using
+// // std::get<N>(args) to get the N-th (0-based) argument in the tuple.
+// }
+// ...
+// };
+//
+// Then the user creates the polymorphic action using
+// MakePolymorphicAction(object) where object has type FooAction. See
+// the definition of Return(void) and SetArgumentPointee<N>(value) for
+// complete examples.
+template <typename Impl>
+class PolymorphicAction {
+ public:
+ explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
+
+ template <typename F>
+ operator Action<F>() const {
+ return Action<F>(new MonomorphicImpl<F>(impl_));
+ }
+
+ private:
+ template <typename F>
+ class MonomorphicImpl : public ActionInterface<F> {
+ public:
+ typedef typename internal::Function<F>::Result Result;
+ typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
+
+ explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
+
+ Result Perform(const ArgumentTuple& args) override {
+ return impl_.template Perform<Result>(args);
+ }
+
+ private:
+ Impl impl_;
+
+ GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
+ };
+
+ Impl impl_;
+
+ GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
+};
+
+// Creates an Action from its implementation and returns it. The
+// created Action object owns the implementation.
+template <typename F>
+Action<F> MakeAction(ActionInterface<F>* impl) {
+ return Action<F>(impl);
+}
+
+// Creates a polymorphic action from its implementation. This is
+// easier to use than the PolymorphicAction<Impl> constructor as it
+// doesn't require you to explicitly write the template argument, e.g.
+//
+// MakePolymorphicAction(foo);
+// vs
+// PolymorphicAction<TypeOfFoo>(foo);
+template <typename Impl>
+inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
+ return PolymorphicAction<Impl>(impl);
+}
+
+namespace internal {
+
+// Helper struct to specialize ReturnAction to execute a move instead of a copy
+// on return. Useful for move-only types, but could be used on any type.
+template <typename T>
+struct ByMoveWrapper {
+ explicit ByMoveWrapper(T value) : payload(std::move(value)) {}
+ T payload;
+};
+
+// Implements the polymorphic Return(x) action, which can be used in
+// any function that returns the type of x, regardless of the argument
+// types.
+//
+// Note: The value passed into Return must be converted into
+// Function<F>::Result when this action is cast to Action<F> rather than
+// when that action is performed. This is important in scenarios like
+//
+// MOCK_METHOD1(Method, T(U));
+// ...
+// {
+// Foo foo;
+// X x(&foo);
+// EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
+// }
+//
+// In the example above the variable x holds reference to foo which leaves
+// scope and gets destroyed. If copying X just copies a reference to foo,
+// that copy will be left with a hanging reference. If conversion to T
+// makes a copy of foo, the above code is safe. To support that scenario, we
+// need to make sure that the type conversion happens inside the EXPECT_CALL
+// statement, and conversion of the result of Return to Action<T(U)> is a
+// good place for that.
+//
+// The real life example of the above scenario happens when an invocation
+// of gtl::Container() is passed into Return.
+//
+template <typename R>
+class ReturnAction {
+ public:
+ // Constructs a ReturnAction object from the value to be returned.
+ // 'value' is passed by value instead of by const reference in order
+ // to allow Return("string literal") to compile.
+ explicit ReturnAction(R value) : value_(new R(std::move(value))) {}
+
+ // This template type conversion operator allows Return(x) to be
+ // used in ANY function that returns x's type.
+ template <typename F>
+ operator Action<F>() const { // NOLINT
+ // Assert statement belongs here because this is the best place to verify
+ // conditions on F. It produces the clearest error messages
+ // in most compilers.
+ // Impl really belongs in this scope as a local class but can't
+ // because MSVC produces duplicate symbols in different translation units
+ // in this case. Until MS fixes that bug we put Impl into the class scope
+ // and put the typedef both here (for use in assert statement) and
+ // in the Impl class. But both definitions must be the same.
+ typedef typename Function<F>::Result Result;
+ GTEST_COMPILE_ASSERT_(
+ !is_reference<Result>::value,
+ use_ReturnRef_instead_of_Return_to_return_a_reference);
+ static_assert(!std::is_void<Result>::value,
+ "Can't use Return() on an action expected to return `void`.");
+ return Action<F>(new Impl<R, F>(value_));
+ }
+
+ private:
+ // Implements the Return(x) action for a particular function type F.
+ template <typename R_, typename F>
+ class Impl : public ActionInterface<F> {
+ public:
+ typedef typename Function<F>::Result Result;
+ typedef typename Function<F>::ArgumentTuple ArgumentTuple;
+
+ // The implicit cast is necessary when Result has more than one
+ // single-argument constructor (e.g. Result is std::vector<int>) and R
+ // has a type conversion operator template. In that case, value_(value)
+ // won't compile as the compiler doesn't known which constructor of
+ // Result to call. ImplicitCast_ forces the compiler to convert R to
+ // Result without considering explicit constructors, thus resolving the
+ // ambiguity. value_ is then initialized using its copy constructor.
+ explicit Impl(const std::shared_ptr<R>& value)
+ : value_before_cast_(*value),
+ value_(ImplicitCast_<Result>(value_before_cast_)) {}
+
+ Result Perform(const ArgumentTuple&) override { return value_; }
+
+ private:
+ GTEST_COMPILE_ASSERT_(!is_reference<Result>::value,
+ Result_cannot_be_a_reference_type);
+ // We save the value before casting just in case it is being cast to a
+ // wrapper type.
+ R value_before_cast_;
+ Result value_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
+ };
+
+ // Partially specialize for ByMoveWrapper. This version of ReturnAction will
+ // move its contents instead.
+ template <typename R_, typename F>
+ class Impl<ByMoveWrapper<R_>, F> : public ActionInterface<F> {
+ public:
+ typedef typename Function<F>::Result Result;
+ typedef typename Function<F>::ArgumentTuple ArgumentTuple;
+
+ explicit Impl(const std::shared_ptr<R>& wrapper)
+ : performed_(false), wrapper_(wrapper) {}
+
+ Result Perform(const ArgumentTuple&) override {
+ GTEST_CHECK_(!performed_)
+ << "A ByMove() action should only be performed once.";
+ performed_ = true;
+ return std::move(wrapper_->payload);
+ }
+
+ private:
+ bool performed_;
+ const std::shared_ptr<R> wrapper_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ const std::shared_ptr<R> value_;
+
+ GTEST_DISALLOW_ASSIGN_(ReturnAction);
+};
+
+// Implements the ReturnNull() action.
+class ReturnNullAction {
+ public:
+ // Allows ReturnNull() to be used in any pointer-returning function. In C++11
+ // this is enforced by returning nullptr, and in non-C++11 by asserting a
+ // pointer type on compile time.
+ template <typename Result, typename ArgumentTuple>
+ static Result Perform(const ArgumentTuple&) {
+ return nullptr;
+ }
+};
+
+// Implements the Return() action.
+class ReturnVoidAction {
+ public:
+ // Allows Return() to be used in any void-returning function.
+ template <typename Result, typename ArgumentTuple>
+ static void Perform(const ArgumentTuple&) {
+ CompileAssertTypesEqual<void, Result>();
+ }
+};
+
+// Implements the polymorphic ReturnRef(x) action, which can be used
+// in any function that returns a reference to the type of x,
+// regardless of the argument types.
+template <typename T>
+class ReturnRefAction {
+ public:
+ // Constructs a ReturnRefAction object from the reference to be returned.
+ explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT
+
+ // This template type conversion operator allows ReturnRef(x) to be
+ // used in ANY function that returns a reference to x's type.
+ template <typename F>
+ operator Action<F>() const {
+ typedef typename Function<F>::Result Result;
+ // Asserts that the function return type is a reference. This
+ // catches the user error of using ReturnRef(x) when Return(x)
+ // should be used, and generates some helpful error message.
+ GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value,
+ use_Return_instead_of_ReturnRef_to_return_a_value);
+ return Action<F>(new Impl<F>(ref_));
+ }
+
+ private:
+ // Implements the ReturnRef(x) action for a particular function type F.
+ template <typename F>
+ class Impl : public ActionInterface<F> {
+ public:
+ typedef typename Function<F>::Result Result;
+ typedef typename Function<F>::ArgumentTuple ArgumentTuple;
+
+ explicit Impl(T& ref) : ref_(ref) {} // NOLINT
+
+ Result Perform(const ArgumentTuple&) override { return ref_; }
+
+ private:
+ T& ref_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ T& ref_;
+
+ GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
+};
+
+// Implements the polymorphic ReturnRefOfCopy(x) action, which can be
+// used in any function that returns a reference to the type of x,
+// regardless of the argument types.
+template <typename T>
+class ReturnRefOfCopyAction {
+ public:
+ // Constructs a ReturnRefOfCopyAction object from the reference to
+ // be returned.
+ explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT
+
+ // This template type conversion operator allows ReturnRefOfCopy(x) to be
+ // used in ANY function that returns a reference to x's type.
+ template <typename F>
+ operator Action<F>() const {
+ typedef typename Function<F>::Result Result;
+ // Asserts that the function return type is a reference. This
+ // catches the user error of using ReturnRefOfCopy(x) when Return(x)
+ // should be used, and generates some helpful error message.
+ GTEST_COMPILE_ASSERT_(
+ internal::is_reference<Result>::value,
+ use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
+ return Action<F>(new Impl<F>(value_));
+ }
+
+ private:
+ // Implements the ReturnRefOfCopy(x) action for a particular function type F.
+ template <typename F>
+ class Impl : public ActionInterface<F> {
+ public:
+ typedef typename Function<F>::Result Result;
+ typedef typename Function<F>::ArgumentTuple ArgumentTuple;
+
+ explicit Impl(const T& value) : value_(value) {} // NOLINT
+
+ Result Perform(const ArgumentTuple&) override { return value_; }
+
+ private:
+ T value_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ const T value_;
+
+ GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
+};
+
+// Implements the polymorphic DoDefault() action.
+class DoDefaultAction {
+ public:
+ // This template type conversion operator allows DoDefault() to be
+ // used in any function.
+ template <typename F>
+ operator Action<F>() const { return Action<F>(); } // NOLINT
+};
+
+// Implements the Assign action to set a given pointer referent to a
+// particular value.
+template <typename T1, typename T2>
+class AssignAction {
+ public:
+ AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
+
+ template <typename Result, typename ArgumentTuple>
+ void Perform(const ArgumentTuple& /* args */) const {
+ *ptr_ = value_;
+ }
+
+ private:
+ T1* const ptr_;
+ const T2 value_;
+
+ GTEST_DISALLOW_ASSIGN_(AssignAction);
+};
+
+#if !GTEST_OS_WINDOWS_MOBILE
+
+// Implements the SetErrnoAndReturn action to simulate return from
+// various system calls and libc functions.
+template <typename T>
+class SetErrnoAndReturnAction {
+ public:
+ SetErrnoAndReturnAction(int errno_value, T result)
+ : errno_(errno_value),
+ result_(result) {}
+ template <typename Result, typename ArgumentTuple>
+ Result Perform(const ArgumentTuple& /* args */) const {
+ errno = errno_;
+ return result_;
+ }
+
+ private:
+ const int errno_;
+ const T result_;
+
+ GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
+};
+
+#endif // !GTEST_OS_WINDOWS_MOBILE
+
+// Implements the SetArgumentPointee<N>(x) action for any function
+// whose N-th argument (0-based) is a pointer to x's type.
+template <size_t N, typename A, typename = void>
+struct SetArgumentPointeeAction {
+ A value;
+
+ template <typename... Args>
+ void operator()(const Args&... args) const {
+ *::std::get<N>(std::tie(args...)) = value;
+ }
+};
+
+// Implements the Invoke(object_ptr, &Class::Method) action.
+template <class Class, typename MethodPtr>
+struct InvokeMethodAction {
+ Class* const obj_ptr;
+ const MethodPtr method_ptr;
+
+ template <typename... Args>
+ auto operator()(Args&&... args) const
+ -> decltype((obj_ptr->*method_ptr)(std::forward<Args>(args)...)) {
+ return (obj_ptr->*method_ptr)(std::forward<Args>(args)...);
+ }
+};
+
+// Implements the InvokeWithoutArgs(f) action. The template argument
+// FunctionImpl is the implementation type of f, which can be either a
+// function pointer or a functor. InvokeWithoutArgs(f) can be used as an
+// Action<F> as long as f's type is compatible with F.
+template <typename FunctionImpl>
+struct InvokeWithoutArgsAction {
+ FunctionImpl function_impl;
+
+ // Allows InvokeWithoutArgs(f) to be used as any action whose type is
+ // compatible with f.
+ template <typename... Args>
+ auto operator()(const Args&...) -> decltype(function_impl()) {
+ return function_impl();
+ }
+};
+
+// Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
+template <class Class, typename MethodPtr>
+struct InvokeMethodWithoutArgsAction {
+ Class* const obj_ptr;
+ const MethodPtr method_ptr;
+
+ using ReturnType = typename std::result_of<MethodPtr(Class*)>::type;
+
+ template <typename... Args>
+ ReturnType operator()(const Args&...) const {
+ return (obj_ptr->*method_ptr)();
+ }
+};
+
+// Implements the IgnoreResult(action) action.
+template <typename A>
+class IgnoreResultAction {
+ public:
+ explicit IgnoreResultAction(const A& action) : action_(action) {}
+
+ template <typename F>
+ operator Action<F>() const {
+ // Assert statement belongs here because this is the best place to verify
+ // conditions on F. It produces the clearest error messages
+ // in most compilers.
+ // Impl really belongs in this scope as a local class but can't
+ // because MSVC produces duplicate symbols in different translation units
+ // in this case. Until MS fixes that bug we put Impl into the class scope
+ // and put the typedef both here (for use in assert statement) and
+ // in the Impl class. But both definitions must be the same.
+ typedef typename internal::Function<F>::Result Result;
+
+ // Asserts at compile time that F returns void.
+ CompileAssertTypesEqual<void, Result>();
+
+ return Action<F>(new Impl<F>(action_));
+ }
+
+ private:
+ template <typename F>
+ class Impl : public ActionInterface<F> {
+ public:
+ typedef typename internal::Function<F>::Result Result;
+ typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
+
+ explicit Impl(const A& action) : action_(action) {}
+
+ void Perform(const ArgumentTuple& args) override {
+ // Performs the action and ignores its result.
+ action_.Perform(args);
+ }
+
+ private:
+ // Type OriginalFunction is the same as F except that its return
+ // type is IgnoredValue.
+ typedef typename internal::Function<F>::MakeResultIgnoredValue
+ OriginalFunction;
+
+ const Action<OriginalFunction> action_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ const A action_;
+
+ GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
+};
+
+template <typename InnerAction, size_t... I>
+struct WithArgsAction {
+ InnerAction action;
+
+ // The inner action could be anything convertible to Action<X>.
+ // We use the conversion operator to detect the signature of the inner Action.
+ template <typename R, typename... Args>
+ operator Action<R(Args...)>() const { // NOLINT
+ Action<R(typename std::tuple_element<I, std::tuple<Args...>>::type...)>
+ converted(action);
+
+ return [converted](Args... args) -> R {
+ return converted.Perform(std::forward_as_tuple(
+ std::get<I>(std::forward_as_tuple(std::forward<Args>(args)...))...));
+ };
+ }
+};
+
+template <typename... Actions>
+struct DoAllAction {
+ private:
+ template <typename... Args, size_t... I>
+ std::vector<Action<void(Args...)>> Convert(IndexSequence<I...>) const {
+ return {std::get<I>(actions)...};
+ }
+
+ public:
+ std::tuple<Actions...> actions;
+
+ template <typename R, typename... Args>
+ operator Action<R(Args...)>() const { // NOLINT
+ struct Op {
+ std::vector<Action<void(Args...)>> converted;
+ Action<R(Args...)> last;
+ R operator()(Args... args) const {
+ auto tuple_args = std::forward_as_tuple(std::forward<Args>(args)...);
+ for (auto& a : converted) {
+ a.Perform(tuple_args);
+ }
+ return last.Perform(tuple_args);
+ }
+ };
+ return Op{Convert<Args...>(MakeIndexSequence<sizeof...(Actions) - 1>()),
+ std::get<sizeof...(Actions) - 1>(actions)};
+ }
+};
+
+} // namespace internal
+
+// An Unused object can be implicitly constructed from ANY value.
+// This is handy when defining actions that ignore some or all of the
+// mock function arguments. For example, given
+//
+// MOCK_METHOD3(Foo, double(const string& label, double x, double y));
+// MOCK_METHOD3(Bar, double(int index, double x, double y));
+//
+// instead of
+//
+// double DistanceToOriginWithLabel(const string& label, double x, double y) {
+// return sqrt(x*x + y*y);
+// }
+// double DistanceToOriginWithIndex(int index, double x, double y) {
+// return sqrt(x*x + y*y);
+// }
+// ...
+// EXPECT_CALL(mock, Foo("abc", _, _))
+// .WillOnce(Invoke(DistanceToOriginWithLabel));
+// EXPECT_CALL(mock, Bar(5, _, _))
+// .WillOnce(Invoke(DistanceToOriginWithIndex));
+//
+// you could write
+//
+// // We can declare any uninteresting argument as Unused.
+// double DistanceToOrigin(Unused, double x, double y) {
+// return sqrt(x*x + y*y);
+// }
+// ...
+// EXPECT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
+// EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
+typedef internal::IgnoredValue Unused;
+
+// Creates an action that does actions a1, a2, ..., sequentially in
+// each invocation.
+template <typename... Action>
+internal::DoAllAction<typename std::decay<Action>::type...> DoAll(
+ Action&&... action) {
+ return {std::forward_as_tuple(std::forward<Action>(action)...)};
+}
+
+// WithArg<k>(an_action) creates an action that passes the k-th
+// (0-based) argument of the mock function to an_action and performs
+// it. It adapts an action accepting one argument to one that accepts
+// multiple arguments. For convenience, we also provide
+// WithArgs<k>(an_action) (defined below) as a synonym.
+template <size_t k, typename InnerAction>
+internal::WithArgsAction<typename std::decay<InnerAction>::type, k>
+WithArg(InnerAction&& action) {
+ return {std::forward<InnerAction>(action)};
+}
+
+// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
+// the selected arguments of the mock function to an_action and
+// performs it. It serves as an adaptor between actions with
+// different argument lists.
+template <size_t k, size_t... ks, typename InnerAction>
+internal::WithArgsAction<typename std::decay<InnerAction>::type, k, ks...>
+WithArgs(InnerAction&& action) {
+ return {std::forward<InnerAction>(action)};
+}
+
+// WithoutArgs(inner_action) can be used in a mock function with a
+// non-empty argument list to perform inner_action, which takes no
+// argument. In other words, it adapts an action accepting no
+// argument to one that accepts (and ignores) arguments.
+template <typename InnerAction>
+internal::WithArgsAction<typename std::decay<InnerAction>::type>
+WithoutArgs(InnerAction&& action) {
+ return {std::forward<InnerAction>(action)};
+}
+
+// Creates an action that returns 'value'. 'value' is passed by value
+// instead of const reference - otherwise Return("string literal")
+// will trigger a compiler error about using array as initializer.
+template <typename R>
+internal::ReturnAction<R> Return(R value) {
+ return internal::ReturnAction<R>(std::move(value));
+}
+
+// Creates an action that returns NULL.
+inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
+ return MakePolymorphicAction(internal::ReturnNullAction());
+}
+
+// Creates an action that returns from a void function.
+inline PolymorphicAction<internal::ReturnVoidAction> Return() {
+ return MakePolymorphicAction(internal::ReturnVoidAction());
+}
+
+// Creates an action that returns the reference to a variable.
+template <typename R>
+inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT
+ return internal::ReturnRefAction<R>(x);
+}
+
+// Creates an action that returns the reference to a copy of the
+// argument. The copy is created when the action is constructed and
+// lives as long as the action.
+template <typename R>
+inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
+ return internal::ReturnRefOfCopyAction<R>(x);
+}
+
+// Modifies the parent action (a Return() action) to perform a move of the
+// argument instead of a copy.
+// Return(ByMove()) actions can only be executed once and will assert this
+// invariant.
+template <typename R>
+internal::ByMoveWrapper<R> ByMove(R x) {
+ return internal::ByMoveWrapper<R>(std::move(x));
+}
+
+// Creates an action that does the default action for the give mock function.
+inline internal::DoDefaultAction DoDefault() {
+ return internal::DoDefaultAction();
+}
+
+// Creates an action that sets the variable pointed by the N-th
+// (0-based) function argument to 'value'.
+template <size_t N, typename T>
+internal::SetArgumentPointeeAction<N, T> SetArgPointee(T x) {
+ return {std::move(x)};
+}
+
+// The following version is DEPRECATED.
+template <size_t N, typename T>
+internal::SetArgumentPointeeAction<N, T> SetArgumentPointee(T x) {
+ return {std::move(x)};
+}
+
+// Creates an action that sets a pointer referent to a given value.
+template <typename T1, typename T2>
+PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
+ return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
+}
+
+#if !GTEST_OS_WINDOWS_MOBILE
+
+// Creates an action that sets errno and returns the appropriate error.
+template <typename T>
+PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
+SetErrnoAndReturn(int errval, T result) {
+ return MakePolymorphicAction(
+ internal::SetErrnoAndReturnAction<T>(errval, result));
+}
+
+#endif // !GTEST_OS_WINDOWS_MOBILE
+
+// Various overloads for Invoke().
+
+// Legacy function.
+// Actions can now be implicitly constructed from callables. No need to create
+// wrapper objects.
+// This function exists for backwards compatibility.
+template <typename FunctionImpl>
+typename std::decay<FunctionImpl>::type Invoke(FunctionImpl&& function_impl) {
+ return std::forward<FunctionImpl>(function_impl);
+}
+
+// Creates an action that invokes the given method on the given object
+// with the mock function's arguments.
+template <class Class, typename MethodPtr>
+internal::InvokeMethodAction<Class, MethodPtr> Invoke(Class* obj_ptr,
+ MethodPtr method_ptr) {
+ return {obj_ptr, method_ptr};
+}
+
+// Creates an action that invokes 'function_impl' with no argument.
+template <typename FunctionImpl>
+internal::InvokeWithoutArgsAction<typename std::decay<FunctionImpl>::type>
+InvokeWithoutArgs(FunctionImpl function_impl) {
+ return {std::move(function_impl)};
+}
+
+// Creates an action that invokes the given method on the given object
+// with no argument.
+template <class Class, typename MethodPtr>
+internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> InvokeWithoutArgs(
+ Class* obj_ptr, MethodPtr method_ptr) {
+ return {obj_ptr, method_ptr};
+}
+
+// Creates an action that performs an_action and throws away its
+// result. In other words, it changes the return type of an_action to
+// void. an_action MUST NOT return void, or the code won't compile.
+template <typename A>
+inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
+ return internal::IgnoreResultAction<A>(an_action);
+}
+
+// Creates a reference wrapper for the given L-value. If necessary,
+// you can explicitly specify the type of the reference. For example,
+// suppose 'derived' is an object of type Derived, ByRef(derived)
+// would wrap a Derived&. If you want to wrap a const Base& instead,
+// where Base is a base class of Derived, just write:
+//
+// ByRef<const Base>(derived)
+//
+// N.B. ByRef is redundant with std::ref, std::cref and std::reference_wrapper.
+// However, it may still be used for consistency with ByMove().
+template <typename T>
+inline ::std::reference_wrapper<T> ByRef(T& l_value) { // NOLINT
+ return ::std::reference_wrapper<T>(l_value);
+}
+
+} // namespace testing
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements some commonly used cardinalities. More
+// cardinalities can be defined by the user implementing the
+// CardinalityInterface interface if necessary.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
+
+#include <limits.h>
+#include <memory>
+#include <ostream> // NOLINT
+#include "gmock/internal/gmock-port.h"
+#include "gtest/gtest.h"
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
+/* class A needs to have dll-interface to be used by clients of class B */)
+
+namespace testing {
+
+// To implement a cardinality Foo, define:
+// 1. a class FooCardinality that implements the
+// CardinalityInterface interface, and
+// 2. a factory function that creates a Cardinality object from a
+// const FooCardinality*.
+//
+// The two-level delegation design follows that of Matcher, providing
+// consistency for extension developers. It also eases ownership
+// management as Cardinality objects can now be copied like plain values.
+
+// The implementation of a cardinality.
+class CardinalityInterface {
+ public:
+ virtual ~CardinalityInterface() {}
+
+ // Conservative estimate on the lower/upper bound of the number of
+ // calls allowed.
+ virtual int ConservativeLowerBound() const { return 0; }
+ virtual int ConservativeUpperBound() const { return INT_MAX; }
+
+ // Returns true iff call_count calls will satisfy this cardinality.
+ virtual bool IsSatisfiedByCallCount(int call_count) const = 0;
+
+ // Returns true iff call_count calls will saturate this cardinality.
+ virtual bool IsSaturatedByCallCount(int call_count) const = 0;
+
+ // Describes self to an ostream.
+ virtual void DescribeTo(::std::ostream* os) const = 0;
+};
+
+// A Cardinality is a copyable and IMMUTABLE (except by assignment)
+// object that specifies how many times a mock function is expected to
+// be called. The implementation of Cardinality is just a std::shared_ptr
+// to const CardinalityInterface. Don't inherit from Cardinality!
+class GTEST_API_ Cardinality {
+ public:
+ // Constructs a null cardinality. Needed for storing Cardinality
+ // objects in STL containers.
+ Cardinality() {}
+
+ // Constructs a Cardinality from its implementation.
+ explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {}
+
+ // Conservative estimate on the lower/upper bound of the number of
+ // calls allowed.
+ int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); }
+ int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); }
+
+ // Returns true iff call_count calls will satisfy this cardinality.
+ bool IsSatisfiedByCallCount(int call_count) const {
+ return impl_->IsSatisfiedByCallCount(call_count);
+ }
+
+ // Returns true iff call_count calls will saturate this cardinality.
+ bool IsSaturatedByCallCount(int call_count) const {
+ return impl_->IsSaturatedByCallCount(call_count);
+ }
+
+ // Returns true iff call_count calls will over-saturate this
+ // cardinality, i.e. exceed the maximum number of allowed calls.
+ bool IsOverSaturatedByCallCount(int call_count) const {
+ return impl_->IsSaturatedByCallCount(call_count) &&
+ !impl_->IsSatisfiedByCallCount(call_count);
+ }
+
+ // Describes self to an ostream
+ void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
+
+ // Describes the given actual call count to an ostream.
+ static void DescribeActualCallCountTo(int actual_call_count,
+ ::std::ostream* os);
+
+ private:
+ std::shared_ptr<const CardinalityInterface> impl_;
+};
+
+// Creates a cardinality that allows at least n calls.
+GTEST_API_ Cardinality AtLeast(int n);
+
+// Creates a cardinality that allows at most n calls.
+GTEST_API_ Cardinality AtMost(int n);
+
+// Creates a cardinality that allows any number of calls.
+GTEST_API_ Cardinality AnyNumber();
+
+// Creates a cardinality that allows between min and max calls.
+GTEST_API_ Cardinality Between(int min, int max);
+
+// Creates a cardinality that allows exactly n calls.
+GTEST_API_ Cardinality Exactly(int n);
+
+// Creates a cardinality from its implementation.
+inline Cardinality MakeCardinality(const CardinalityInterface* c) {
+ return Cardinality(c);
+}
+
+} // namespace testing
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
--- /dev/null
+#ifndef THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT
+#define THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT
+
+#include "gmock/gmock-generated-function-mockers.h" // NOLINT
+#include "gmock/internal/gmock-pp.h"
+
+#define MOCK_METHOD(...) \
+ GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__)
+
+#define GMOCK_INTERNAL_MOCK_METHOD_ARG_1(...) \
+ GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
+
+#define GMOCK_INTERNAL_MOCK_METHOD_ARG_2(...) \
+ GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
+
+#define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \
+ GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ())
+
+#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \
+ GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \
+ GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \
+ GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \
+ GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \
+ GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \
+ GMOCK_INTERNAL_MOCK_METHOD_IMPL( \
+ GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \
+ GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \
+ GMOCK_INTERNAL_HAS_NOEXCEPT(_Spec), GMOCK_INTERNAL_GET_CALLTYPE(_Spec), \
+ (GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)))
+
+#define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \
+ GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
+
+#define GMOCK_INTERNAL_MOCK_METHOD_ARG_6(...) \
+ GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
+
+#define GMOCK_INTERNAL_MOCK_METHOD_ARG_7(...) \
+ GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
+
+#define GMOCK_INTERNAL_WRONG_ARITY(...) \
+ static_assert( \
+ false, \
+ "MOCK_METHOD must be called with 3 or 4 arguments. _Ret, " \
+ "_MethodName, _Args and optionally _Spec. _Args and _Spec must be " \
+ "enclosed in parentheses. If _Ret is a type with unprotected commas, " \
+ "it must also be enclosed in parentheses.")
+
+#define GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Tuple) \
+ static_assert( \
+ GMOCK_PP_IS_ENCLOSED_PARENS(_Tuple), \
+ GMOCK_PP_STRINGIZE(_Tuple) " should be enclosed in parentheses.")
+
+#define GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE(_N, ...) \
+ static_assert( \
+ std::is_function<__VA_ARGS__>::value, \
+ "Signature must be a function type, maybe return type contains " \
+ "unprotected comma."); \
+ static_assert( \
+ ::testing::tuple_size<typename ::testing::internal::Function< \
+ __VA_ARGS__>::ArgumentTuple>::value == _N, \
+ "This method does not take " GMOCK_PP_STRINGIZE( \
+ _N) " arguments. Parenthesize all types with unproctected commas.")
+
+#define GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \
+ GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT, ~, _Spec)
+
+#define GMOCK_INTERNAL_MOCK_METHOD_IMPL(_N, _MethodName, _Constness, \
+ _Override, _Final, _Noexcept, \
+ _CallType, _Signature) \
+ typename ::testing::internal::Function<GMOCK_PP_REMOVE_PARENS( \
+ _Signature)>::Result \
+ GMOCK_INTERNAL_EXPAND(_CallType) \
+ _MethodName(GMOCK_PP_REPEAT(GMOCK_INTERNAL_PARAMETER, _Signature, _N)) \
+ GMOCK_PP_IF(_Constness, const, ) GMOCK_PP_IF(_Noexcept, noexcept, ) \
+ GMOCK_PP_IF(_Override, override, ) \
+ GMOCK_PP_IF(_Final, final, ) { \
+ GMOCK_MOCKER_(_N, _Constness, _MethodName) \
+ .SetOwnerAndName(this, #_MethodName); \
+ return GMOCK_MOCKER_(_N, _Constness, _MethodName) \
+ .Invoke(GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, _Signature, _N)); \
+ } \
+ ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \
+ GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_PARAMETER, _Signature, _N)) \
+ GMOCK_PP_IF(_Constness, const, ) { \
+ GMOCK_MOCKER_(_N, _Constness, _MethodName).RegisterOwner(this); \
+ return GMOCK_MOCKER_(_N, _Constness, _MethodName) \
+ .With(GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_ARGUMENT, , _N)); \
+ } \
+ ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \
+ const ::testing::internal::WithoutMatchers&, \
+ GMOCK_PP_IF(_Constness, const, )::testing::internal::Function< \
+ GMOCK_PP_REMOVE_PARENS(_Signature)>*) \
+ const GMOCK_PP_IF(_Noexcept, noexcept, ) { \
+ return GMOCK_PP_CAT(::testing::internal::AdjustConstness_, \
+ GMOCK_PP_IF(_Constness, const, ))(this) \
+ ->gmock_##_MethodName(GMOCK_PP_REPEAT( \
+ GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \
+ } \
+ mutable ::testing::FunctionMocker<GMOCK_PP_REMOVE_PARENS(_Signature)> \
+ GMOCK_MOCKER_(_N, _Constness, _MethodName)
+
+#define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__
+
+// Five Valid modifiers.
+#define GMOCK_INTERNAL_HAS_CONST(_Tuple) \
+ GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple))
+
+#define GMOCK_INTERNAL_HAS_OVERRIDE(_Tuple) \
+ GMOCK_PP_HAS_COMMA( \
+ GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_OVERRIDE, ~, _Tuple))
+
+#define GMOCK_INTERNAL_HAS_FINAL(_Tuple) \
+ GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_FINAL, ~, _Tuple))
+
+#define GMOCK_INTERNAL_HAS_NOEXCEPT(_Tuple) \
+ GMOCK_PP_HAS_COMMA( \
+ GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_NOEXCEPT, ~, _Tuple))
+
+#define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \
+ GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple)
+
+#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \
+ static_assert( \
+ (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \
+ GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \
+ GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \
+ GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \
+ GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \
+ GMOCK_PP_STRINGIZE( \
+ _elem) " cannot be recognized as a valid specification modifier.");
+
+// Modifiers implementation.
+#define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \
+ GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CONST_I_, _elem)
+
+#define GMOCK_INTERNAL_DETECT_CONST_I_const ,
+
+#define GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem) \
+ GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_OVERRIDE_I_, _elem)
+
+#define GMOCK_INTERNAL_DETECT_OVERRIDE_I_override ,
+
+#define GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem) \
+ GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_FINAL_I_, _elem)
+
+#define GMOCK_INTERNAL_DETECT_FINAL_I_final ,
+
+// TODO(iserna): Maybe noexcept should accept an argument here as well.
+#define GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem) \
+ GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_NOEXCEPT_I_, _elem)
+
+#define GMOCK_INTERNAL_DETECT_NOEXCEPT_I_noexcept ,
+
+#define GMOCK_INTERNAL_GET_CALLTYPE_IMPL(_i, _, _elem) \
+ GMOCK_PP_IF(GMOCK_INTERNAL_IS_CALLTYPE(_elem), \
+ GMOCK_INTERNAL_GET_VALUE_CALLTYPE, GMOCK_PP_EMPTY) \
+ (_elem)
+
+// TODO(iserna): GMOCK_INTERNAL_IS_CALLTYPE and
+// GMOCK_INTERNAL_GET_VALUE_CALLTYPE needed more expansions to work on windows
+// maybe they can be simplified somehow.
+#define GMOCK_INTERNAL_IS_CALLTYPE(_arg) \
+ GMOCK_INTERNAL_IS_CALLTYPE_I( \
+ GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg))
+#define GMOCK_INTERNAL_IS_CALLTYPE_I(_arg) GMOCK_PP_IS_ENCLOSED_PARENS(_arg)
+
+#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE(_arg) \
+ GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \
+ GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg))
+#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I(_arg) \
+ GMOCK_PP_CAT(GMOCK_PP_IDENTITY, _arg)
+
+#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype
+
+#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
+ GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), GMOCK_PP_REMOVE_PARENS, \
+ GMOCK_PP_IDENTITY) \
+ (_Ret)(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
+
+#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \
+ GMOCK_PP_COMMA_IF(_i) \
+ GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_elem), GMOCK_PP_REMOVE_PARENS, \
+ GMOCK_PP_IDENTITY) \
+ (_elem)
+
+#define GMOCK_INTERNAL_PARAMETER(_i, _Signature, _) \
+ GMOCK_PP_COMMA_IF(_i) \
+ GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \
+ GMOCK_PP_REMOVE_PARENS(_Signature)) \
+ gmock_a##_i
+
+#define GMOCK_INTERNAL_FORWARD_ARG(_i, _Signature, _) \
+ GMOCK_PP_COMMA_IF(_i) \
+ ::std::forward<GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \
+ GMOCK_PP_REMOVE_PARENS(_Signature))>( \
+ gmock_a##_i)
+
+#define GMOCK_INTERNAL_MATCHER_PARAMETER(_i, _Signature, _) \
+ GMOCK_PP_COMMA_IF(_i) \
+ GMOCK_INTERNAL_MATCHER_O(typename, GMOCK_PP_INC(_i), \
+ GMOCK_PP_REMOVE_PARENS(_Signature)) \
+ gmock_a##_i
+
+#define GMOCK_INTERNAL_MATCHER_ARGUMENT(_i, _1, _2) \
+ GMOCK_PP_COMMA_IF(_i) \
+ gmock_a##_i
+
+#define GMOCK_INTERNAL_A_MATCHER_ARGUMENT(_i, _Signature, _) \
+ GMOCK_PP_COMMA_IF(_i) \
+ ::testing::A<GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \
+ GMOCK_PP_REMOVE_PARENS(_Signature))>()
+
+#define GMOCK_INTERNAL_ARG_O(_tn, _i, ...) GMOCK_ARG_(_tn, _i, __VA_ARGS__)
+
+#define GMOCK_INTERNAL_MATCHER_O(_tn, _i, ...) \
+ GMOCK_MATCHER_(_tn, _i, __VA_ARGS__)
+
+#endif // THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_
--- /dev/null
+// This file was GENERATED by command:
+// pump.py gmock-generated-actions.h.pump
+// DO NOT EDIT BY HAND!!!
+
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements some commonly used variadic actions.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
+
+#include <memory>
+#include <utility>
+
+#include "gmock/gmock-actions.h"
+#include "gmock/internal/gmock-port.h"
+
+namespace testing {
+namespace internal {
+
+// A macro from the ACTION* family (defined later in this file)
+// defines an action that can be used in a mock function. Typically,
+// these actions only care about a subset of the arguments of the mock
+// function. For example, if such an action only uses the second
+// argument, it can be used in any mock function that takes >= 2
+// arguments where the type of the second argument is compatible.
+//
+// Therefore, the action implementation must be prepared to take more
+// arguments than it needs. The ExcessiveArg type is used to
+// represent those excessive arguments. In order to keep the compiler
+// error messages tractable, we define it in the testing namespace
+// instead of testing::internal. However, this is an INTERNAL TYPE
+// and subject to change without notice, so a user MUST NOT USE THIS
+// TYPE DIRECTLY.
+struct ExcessiveArg {};
+
+// A helper class needed for implementing the ACTION* macros.
+template <typename Result, class Impl>
+class ActionHelper {
+ public:
+ static Result Perform(Impl* impl, const ::std::tuple<>& args) {
+ return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
+ ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
+ ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
+ ExcessiveArg());
+ }
+
+ template <typename A0>
+ static Result Perform(Impl* impl, const ::std::tuple<A0>& args) {
+ return impl->template gmock_PerformImpl<A0>(args, std::get<0>(args),
+ ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
+ ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
+ ExcessiveArg());
+ }
+
+ template <typename A0, typename A1>
+ static Result Perform(Impl* impl, const ::std::tuple<A0, A1>& args) {
+ return impl->template gmock_PerformImpl<A0, A1>(args, std::get<0>(args),
+ std::get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
+ ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
+ ExcessiveArg());
+ }
+
+ template <typename A0, typename A1, typename A2>
+ static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2>& args) {
+ return impl->template gmock_PerformImpl<A0, A1, A2>(args,
+ std::get<0>(args), std::get<1>(args), std::get<2>(args),
+ ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
+ ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
+ }
+
+ template <typename A0, typename A1, typename A2, typename A3>
+ static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3>& args) {
+ return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args,
+ std::get<0>(args), std::get<1>(args), std::get<2>(args),
+ std::get<3>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
+ ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
+ }
+
+ template <typename A0, typename A1, typename A2, typename A3, typename A4>
+ static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3,
+ A4>& args) {
+ return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
+ std::get<0>(args), std::get<1>(args), std::get<2>(args),
+ std::get<3>(args), std::get<4>(args), ExcessiveArg(), ExcessiveArg(),
+ ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
+ }
+
+ template <typename A0, typename A1, typename A2, typename A3, typename A4,
+ typename A5>
+ static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4,
+ A5>& args) {
+ return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
+ std::get<0>(args), std::get<1>(args), std::get<2>(args),
+ std::get<3>(args), std::get<4>(args), std::get<5>(args),
+ ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
+ }
+
+ template <typename A0, typename A1, typename A2, typename A3, typename A4,
+ typename A5, typename A6>
+ static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
+ A6>& args) {
+ return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
+ std::get<0>(args), std::get<1>(args), std::get<2>(args),
+ std::get<3>(args), std::get<4>(args), std::get<5>(args),
+ std::get<6>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
+ }
+
+ template <typename A0, typename A1, typename A2, typename A3, typename A4,
+ typename A5, typename A6, typename A7>
+ static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
+ A6, A7>& args) {
+ return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
+ A7>(args, std::get<0>(args), std::get<1>(args), std::get<2>(args),
+ std::get<3>(args), std::get<4>(args), std::get<5>(args),
+ std::get<6>(args), std::get<7>(args), ExcessiveArg(), ExcessiveArg());
+ }
+
+ template <typename A0, typename A1, typename A2, typename A3, typename A4,
+ typename A5, typename A6, typename A7, typename A8>
+ static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
+ A6, A7, A8>& args) {
+ return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
+ A8>(args, std::get<0>(args), std::get<1>(args), std::get<2>(args),
+ std::get<3>(args), std::get<4>(args), std::get<5>(args),
+ std::get<6>(args), std::get<7>(args), std::get<8>(args),
+ ExcessiveArg());
+ }
+
+ template <typename A0, typename A1, typename A2, typename A3, typename A4,
+ typename A5, typename A6, typename A7, typename A8, typename A9>
+ static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
+ A6, A7, A8, A9>& args) {
+ return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
+ A9>(args, std::get<0>(args), std::get<1>(args), std::get<2>(args),
+ std::get<3>(args), std::get<4>(args), std::get<5>(args),
+ std::get<6>(args), std::get<7>(args), std::get<8>(args),
+ std::get<9>(args));
+ }
+};
+
+} // namespace internal
+} // namespace testing
+
+// The ACTION* family of macros can be used in a namespace scope to
+// define custom actions easily. The syntax:
+//
+// ACTION(name) { statements; }
+//
+// will define an action with the given name that executes the
+// statements. The value returned by the statements will be used as
+// the return value of the action. Inside the statements, you can
+// refer to the K-th (0-based) argument of the mock function by
+// 'argK', and refer to its type by 'argK_type'. For example:
+//
+// ACTION(IncrementArg1) {
+// arg1_type temp = arg1;
+// return ++(*temp);
+// }
+//
+// allows you to write
+//
+// ...WillOnce(IncrementArg1());
+//
+// You can also refer to the entire argument tuple and its type by
+// 'args' and 'args_type', and refer to the mock function type and its
+// return type by 'function_type' and 'return_type'.
+//
+// Note that you don't need to specify the types of the mock function
+// arguments. However rest assured that your code is still type-safe:
+// you'll get a compiler error if *arg1 doesn't support the ++
+// operator, or if the type of ++(*arg1) isn't compatible with the
+// mock function's return type, for example.
+//
+// Sometimes you'll want to parameterize the action. For that you can use
+// another macro:
+//
+// ACTION_P(name, param_name) { statements; }
+//
+// For example:
+//
+// ACTION_P(Add, n) { return arg0 + n; }
+//
+// will allow you to write:
+//
+// ...WillOnce(Add(5));
+//
+// Note that you don't need to provide the type of the parameter
+// either. If you need to reference the type of a parameter named
+// 'foo', you can write 'foo_type'. For example, in the body of
+// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
+// of 'n'.
+//
+// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
+// multi-parameter actions.
+//
+// For the purpose of typing, you can view
+//
+// ACTION_Pk(Foo, p1, ..., pk) { ... }
+//
+// as shorthand for
+//
+// template <typename p1_type, ..., typename pk_type>
+// FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
+//
+// In particular, you can provide the template type arguments
+// explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
+// although usually you can rely on the compiler to infer the types
+// for you automatically. You can assign the result of expression
+// Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
+// pk_type>. This can be useful when composing actions.
+//
+// You can also overload actions with different numbers of parameters:
+//
+// ACTION_P(Plus, a) { ... }
+// ACTION_P2(Plus, a, b) { ... }
+//
+// While it's tempting to always use the ACTION* macros when defining
+// a new action, you should also consider implementing ActionInterface
+// or using MakePolymorphicAction() instead, especially if you need to
+// use the action a lot. While these approaches require more work,
+// they give you more control on the types of the mock function
+// arguments and the action parameters, which in general leads to
+// better compiler error messages that pay off in the long run. They
+// also allow overloading actions based on parameter types (as opposed
+// to just based on the number of parameters).
+//
+// CAVEAT:
+//
+// ACTION*() can only be used in a namespace scope. The reason is
+// that C++ doesn't yet allow function-local types to be used to
+// instantiate templates. The up-coming C++0x standard will fix this.
+// Once that's done, we'll consider supporting using ACTION*() inside
+// a function.
+//
+// MORE INFORMATION:
+//
+// To learn more about using these macros, please search for 'ACTION' on
+// https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
+
+// An internal macro needed for implementing ACTION*().
+#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
+ const args_type& args GTEST_ATTRIBUTE_UNUSED_, \
+ const arg0_type& arg0 GTEST_ATTRIBUTE_UNUSED_, \
+ const arg1_type& arg1 GTEST_ATTRIBUTE_UNUSED_, \
+ const arg2_type& arg2 GTEST_ATTRIBUTE_UNUSED_, \
+ const arg3_type& arg3 GTEST_ATTRIBUTE_UNUSED_, \
+ const arg4_type& arg4 GTEST_ATTRIBUTE_UNUSED_, \
+ const arg5_type& arg5 GTEST_ATTRIBUTE_UNUSED_, \
+ const arg6_type& arg6 GTEST_ATTRIBUTE_UNUSED_, \
+ const arg7_type& arg7 GTEST_ATTRIBUTE_UNUSED_, \
+ const arg8_type& arg8 GTEST_ATTRIBUTE_UNUSED_, \
+ const arg9_type& arg9 GTEST_ATTRIBUTE_UNUSED_
+
+// Sometimes you want to give an action explicit template parameters
+// that cannot be inferred from its value parameters. ACTION() and
+// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
+// and can be viewed as an extension to ACTION() and ACTION_P*().
+//
+// The syntax:
+//
+// ACTION_TEMPLATE(ActionName,
+// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
+// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
+//
+// defines an action template that takes m explicit template
+// parameters and n value parameters. name_i is the name of the i-th
+// template parameter, and kind_i specifies whether it's a typename,
+// an integral constant, or a template. p_i is the name of the i-th
+// value parameter.
+//
+// Example:
+//
+// // DuplicateArg<k, T>(output) converts the k-th argument of the mock
+// // function to type T and copies it to *output.
+// ACTION_TEMPLATE(DuplicateArg,
+// HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
+// AND_1_VALUE_PARAMS(output)) {
+// *output = T(::std::get<k>(args));
+// }
+// ...
+// int n;
+// EXPECT_CALL(mock, Foo(_, _))
+// .WillOnce(DuplicateArg<1, unsigned char>(&n));
+//
+// To create an instance of an action template, write:
+//
+// ActionName<t1, ..., t_m>(v1, ..., v_n)
+//
+// where the ts are the template arguments and the vs are the value
+// arguments. The value argument types are inferred by the compiler.
+// If you want to explicitly specify the value argument types, you can
+// provide additional template arguments:
+//
+// ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
+//
+// where u_i is the desired type of v_i.
+//
+// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
+// number of value parameters, but not on the number of template
+// parameters. Without the restriction, the meaning of the following
+// is unclear:
+//
+// OverloadedAction<int, bool>(x);
+//
+// Are we using a single-template-parameter action where 'bool' refers
+// to the type of x, or are we using a two-template-parameter action
+// where the compiler is asked to infer the type of x?
+//
+// Implementation notes:
+//
+// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
+// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
+// implementing ACTION_TEMPLATE. The main trick we use is to create
+// new macro invocations when expanding a macro. For example, we have
+//
+// #define ACTION_TEMPLATE(name, template_params, value_params)
+// ... GMOCK_INTERNAL_DECL_##template_params ...
+//
+// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
+// to expand to
+//
+// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
+//
+// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
+// preprocessor will continue to expand it to
+//
+// ... typename T ...
+//
+// This technique conforms to the C++ standard and is portable. It
+// allows us to implement action templates using O(N) code, where N is
+// the maximum number of template/value parameters supported. Without
+// using it, we'd have to devote O(N^2) amount of code to implement all
+// combinations of m and n.
+
+// Declares the template parameters.
+#define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
+#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
+ name1) kind0 name0, kind1 name1
+#define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2) kind0 name0, kind1 name1, kind2 name2
+#define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \
+ kind3 name3
+#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \
+ kind2 name2, kind3 name3, kind4 name4
+#define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \
+ kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
+#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
+ name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
+ kind5 name5, kind6 name6
+#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
+ kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \
+ kind4 name4, kind5 name5, kind6 name6, kind7 name7
+#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
+ kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \
+ kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \
+ kind8 name8
+#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
+ name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
+ name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \
+ kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \
+ kind6 name6, kind7 name7, kind8 name8, kind9 name9
+
+// Lists the template parameters.
+#define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
+#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
+ name1) name0, name1
+#define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2) name0, name1, name2
+#define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3) name0, name1, name2, name3
+#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \
+ name4
+#define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \
+ name2, name3, name4, name5
+#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
+ name6) name0, name1, name2, name3, name4, name5, name6
+#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
+ kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7
+#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
+ kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
+ kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \
+ name6, name7, name8
+#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
+ name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
+ name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \
+ name3, name4, name5, name6, name7, name8, name9
+
+// Declares the types of value parameters.
+#define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
+#define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
+#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \
+ typename p0##_type, typename p1##_type
+#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \
+ typename p0##_type, typename p1##_type, typename p2##_type
+#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
+ typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type
+#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
+ typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type
+#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
+ typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type
+#define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6) , typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type
+#define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type
+#define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type
+#define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \
+ typename p2##_type, typename p3##_type, typename p4##_type, \
+ typename p5##_type, typename p6##_type, typename p7##_type, \
+ typename p8##_type, typename p9##_type
+
+// Initializes the value parameters.
+#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
+ ()
+#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
+ (p0##_type gmock_p0) : p0(::std::move(gmock_p0))
+#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
+ (p0##_type gmock_p0, p1##_type gmock_p1) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1))
+#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
+ (p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2))
+#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
+ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3))
+#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
+ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4))
+#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
+ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
+ p5(::std::move(gmock_p5))
+#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
+ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
+ p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6))
+#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
+ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6, p7##_type gmock_p7) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
+ p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
+ p7(::std::move(gmock_p7))
+#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7, p8)\
+ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6, p7##_type gmock_p7, \
+ p8##_type gmock_p8) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
+ p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
+ p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8))
+#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7, p8, p9)\
+ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
+ p9##_type gmock_p9) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
+ p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
+ p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \
+ p9(::std::move(gmock_p9))
+
+// Declares the fields for storing the value parameters.
+#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
+#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
+#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \
+ p1##_type p1;
+#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \
+ p1##_type p1; p2##_type p2;
+#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \
+ p1##_type p1; p2##_type p2; p3##_type p3;
+#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
+ p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4;
+#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
+ p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
+ p5##_type p5;
+#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
+ p5##_type p5; p6##_type p6;
+#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
+ p5##_type p5; p6##_type p6; p7##_type p7;
+#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
+ p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8;
+#define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
+ p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \
+ p9##_type p9;
+
+// Lists the value parameters.
+#define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
+#define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
+#define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
+#define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
+#define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
+#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \
+ p2, p3, p4
+#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \
+ p1, p2, p3, p4, p5
+#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6) p0, p1, p2, p3, p4, p5, p6
+#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7) p0, p1, p2, p3, p4, p5, p6, p7
+#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8
+#define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
+
+// Lists the value parameter types.
+#define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
+#define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
+#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \
+ p1##_type
+#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \
+ p1##_type, p2##_type
+#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
+ p0##_type, p1##_type, p2##_type, p3##_type
+#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
+ p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
+#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
+ p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
+#define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
+ p6##_type
+#define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type, p6##_type, p7##_type
+#define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type, p6##_type, p7##_type, p8##_type
+#define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type, p6##_type, p7##_type, p8##_type, p9##_type
+
+// Declares the value parameters.
+#define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
+#define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
+#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \
+ p1##_type p1
+#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \
+ p1##_type p1, p2##_type p2
+#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \
+ p1##_type p1, p2##_type p2, p3##_type p3
+#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
+ p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
+#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
+ p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
+ p5##_type p5
+#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
+ p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
+ p5##_type p5, p6##_type p6
+#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
+ p5##_type p5, p6##_type p6, p7##_type p7
+#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
+ p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
+#define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
+ p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
+ p9##_type p9
+
+// The suffix of the class template implementing the action template.
+#define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
+#define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
+#define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
+#define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
+#define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
+#define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
+#define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
+#define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
+#define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7) P8
+#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7, p8) P9
+#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
+ p7, p8, p9) P10
+
+// The name of the class template implementing the action template.
+#define GMOCK_ACTION_CLASS_(name, value_params)\
+ GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
+
+#define ACTION_TEMPLATE(name, template_params, value_params)\
+ template <GMOCK_INTERNAL_DECL_##template_params\
+ GMOCK_INTERNAL_DECL_TYPE_##value_params>\
+ class GMOCK_ACTION_CLASS_(name, value_params) {\
+ public:\
+ explicit GMOCK_ACTION_CLASS_(name, value_params)\
+ GMOCK_INTERNAL_INIT_##value_params {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ GMOCK_INTERNAL_DEFN_##value_params\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(\
+ new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
+ }\
+ GMOCK_INTERNAL_DEFN_##value_params\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
+ };\
+ template <GMOCK_INTERNAL_DECL_##template_params\
+ GMOCK_INTERNAL_DECL_TYPE_##value_params>\
+ inline GMOCK_ACTION_CLASS_(name, value_params)<\
+ GMOCK_INTERNAL_LIST_##template_params\
+ GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
+ GMOCK_INTERNAL_DECL_##value_params) {\
+ return GMOCK_ACTION_CLASS_(name, value_params)<\
+ GMOCK_INTERNAL_LIST_##template_params\
+ GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
+ GMOCK_INTERNAL_LIST_##value_params);\
+ }\
+ template <GMOCK_INTERNAL_DECL_##template_params\
+ GMOCK_INTERNAL_DECL_TYPE_##value_params>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ GMOCK_ACTION_CLASS_(name, value_params)<\
+ GMOCK_INTERNAL_LIST_##template_params\
+ GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
+ gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION(name)\
+ class name##Action {\
+ public:\
+ name##Action() {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ gmock_Impl() {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>());\
+ }\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##Action);\
+ };\
+ inline name##Action name() {\
+ return name##Action();\
+ }\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##Action::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION_P(name, p0)\
+ template <typename p0##_type>\
+ class name##ActionP {\
+ public:\
+ explicit name##ActionP(p0##_type gmock_p0) : \
+ p0(::std::forward<p0##_type>(gmock_p0)) {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ explicit gmock_Impl(p0##_type gmock_p0) : \
+ p0(::std::forward<p0##_type>(gmock_p0)) {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ p0##_type p0;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>(p0));\
+ }\
+ p0##_type p0;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##ActionP);\
+ };\
+ template <typename p0##_type>\
+ inline name##ActionP<p0##_type> name(p0##_type p0) {\
+ return name##ActionP<p0##_type>(p0);\
+ }\
+ template <typename p0##_type>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION_P2(name, p0, p1)\
+ template <typename p0##_type, typename p1##_type>\
+ class name##ActionP2 {\
+ public:\
+ name##ActionP2(p0##_type gmock_p0, \
+ p1##_type gmock_p1) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)) {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ gmock_Impl(p0##_type gmock_p0, \
+ p1##_type gmock_p1) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)) {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ p0##_type p0;\
+ p1##_type p1;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
+ }\
+ p0##_type p0;\
+ p1##_type p1;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##ActionP2);\
+ };\
+ template <typename p0##_type, typename p1##_type>\
+ inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
+ p1##_type p1) {\
+ return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
+ }\
+ template <typename p0##_type, typename p1##_type>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION_P3(name, p0, p1, p2)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type>\
+ class name##ActionP3 {\
+ public:\
+ name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)) {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)) {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
+ }\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##ActionP3);\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type>\
+ inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
+ p1##_type p1, p2##_type p2) {\
+ return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##ActionP3<p0##_type, p1##_type, \
+ p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION_P4(name, p0, p1, p2, p3)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type>\
+ class name##ActionP4 {\
+ public:\
+ name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, \
+ p3##_type gmock_p3) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)) {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)) {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
+ }\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##ActionP4);\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type>\
+ inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
+ p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
+ p3##_type p3) {\
+ return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \
+ p2, p3);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##ActionP4<p0##_type, p1##_type, p2##_type, \
+ p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION_P5(name, p0, p1, p2, p3, p4)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type>\
+ class name##ActionP5 {\
+ public:\
+ name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, \
+ p4##_type gmock_p4) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)) {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, \
+ p4##_type gmock_p4) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)) {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
+ }\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##ActionP5);\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type>\
+ inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
+ p4##_type p4) {\
+ return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type>(p0, p1, p2, p3, p4);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type>\
+ class name##ActionP6 {\
+ public:\
+ name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)), \
+ p5(::std::forward<p5##_type>(gmock_p5)) {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)), \
+ p5(::std::forward<p5##_type>(gmock_p5)) {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ p5##_type p5;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
+ }\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ p5##_type p5;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##ActionP6);\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type>\
+ inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
+ p3##_type p3, p4##_type p4, p5##_type p5) {\
+ return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type>\
+ class name##ActionP7 {\
+ public:\
+ name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5, \
+ p6##_type gmock_p6) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)), \
+ p5(::std::forward<p5##_type>(gmock_p5)), \
+ p6(::std::forward<p6##_type>(gmock_p6)) {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)), \
+ p5(::std::forward<p5##_type>(gmock_p5)), \
+ p6(::std::forward<p6##_type>(gmock_p6)) {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ p5##_type p5;\
+ p6##_type p6;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
+ p6));\
+ }\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ p5##_type p5;\
+ p6##_type p6;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##ActionP7);\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type>\
+ inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
+ p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
+ p6##_type p6) {\
+ return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type>\
+ class name##ActionP8 {\
+ public:\
+ name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5, p6##_type gmock_p6, \
+ p7##_type gmock_p7) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)), \
+ p5(::std::forward<p5##_type>(gmock_p5)), \
+ p6(::std::forward<p6##_type>(gmock_p6)), \
+ p7(::std::forward<p7##_type>(gmock_p7)) {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6, \
+ p7##_type gmock_p7) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)), \
+ p5(::std::forward<p5##_type>(gmock_p5)), \
+ p6(::std::forward<p6##_type>(gmock_p6)), \
+ p7(::std::forward<p7##_type>(gmock_p7)) {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ p5##_type p5;\
+ p6##_type p6;\
+ p7##_type p7;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
+ p6, p7));\
+ }\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ p5##_type p5;\
+ p6##_type p6;\
+ p7##_type p7;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##ActionP8);\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type>\
+ inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
+ p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
+ p6##_type p6, p7##_type p7) {\
+ return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
+ p6, p7);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type, p6##_type, \
+ p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type>\
+ class name##ActionP9 {\
+ public:\
+ name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
+ p8##_type gmock_p8) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)), \
+ p5(::std::forward<p5##_type>(gmock_p5)), \
+ p6(::std::forward<p6##_type>(gmock_p6)), \
+ p7(::std::forward<p7##_type>(gmock_p7)), \
+ p8(::std::forward<p8##_type>(gmock_p8)) {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6, p7##_type gmock_p7, \
+ p8##_type gmock_p8) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)), \
+ p5(::std::forward<p5##_type>(gmock_p5)), \
+ p6(::std::forward<p6##_type>(gmock_p6)), \
+ p7(::std::forward<p7##_type>(gmock_p7)), \
+ p8(::std::forward<p8##_type>(gmock_p8)) {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ p5##_type p5;\
+ p6##_type p6;\
+ p7##_type p7;\
+ p8##_type p8;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
+ p6, p7, p8));\
+ }\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ p5##_type p5;\
+ p6##_type p6;\
+ p7##_type p7;\
+ p8##_type p8;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##ActionP9);\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type>\
+ inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, \
+ p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
+ p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
+ p8##_type p8) {\
+ return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
+ p3, p4, p5, p6, p7, p8);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type, p6##_type, p7##_type, \
+ p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+#define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type, \
+ typename p9##_type>\
+ class name##ActionP10 {\
+ public:\
+ name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
+ p8##_type gmock_p8, \
+ p9##_type gmock_p9) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)), \
+ p5(::std::forward<p5##_type>(gmock_p5)), \
+ p6(::std::forward<p6##_type>(gmock_p6)), \
+ p7(::std::forward<p7##_type>(gmock_p7)), \
+ p8(::std::forward<p8##_type>(gmock_p8)), \
+ p9(::std::forward<p9##_type>(gmock_p9)) {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
+ p9##_type gmock_p9) : p0(::std::forward<p0##_type>(gmock_p0)), \
+ p1(::std::forward<p1##_type>(gmock_p1)), \
+ p2(::std::forward<p2##_type>(gmock_p2)), \
+ p3(::std::forward<p3##_type>(gmock_p3)), \
+ p4(::std::forward<p4##_type>(gmock_p4)), \
+ p5(::std::forward<p5##_type>(gmock_p5)), \
+ p6(::std::forward<p6##_type>(gmock_p6)), \
+ p7(::std::forward<p7##_type>(gmock_p7)), \
+ p8(::std::forward<p8##_type>(gmock_p8)), \
+ p9(::std::forward<p9##_type>(gmock_p9)) {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ return_type gmock_PerformImpl(const args_type& args, \
+ const arg0_type& arg0, const arg1_type& arg1, \
+ const arg2_type& arg2, const arg3_type& arg3, \
+ const arg4_type& arg4, const arg5_type& arg5, \
+ const arg6_type& arg6, const arg7_type& arg7, \
+ const arg8_type& arg8, const arg9_type& arg9) const;\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ p5##_type p5;\
+ p6##_type p6;\
+ p7##_type p7;\
+ p8##_type p8;\
+ p9##_type p9;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
+ p6, p7, p8, p9));\
+ }\
+ p0##_type p0;\
+ p1##_type p1;\
+ p2##_type p2;\
+ p3##_type p3;\
+ p4##_type p4;\
+ p5##_type p5;\
+ p6##_type p6;\
+ p7##_type p7;\
+ p8##_type p8;\
+ p9##_type p9;\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(name##ActionP10);\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type, \
+ typename p9##_type>\
+ inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
+ p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
+ p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
+ p9##_type p9) {\
+ return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
+ p1, p2, p3, p4, p5, p6, p7, p8, p9);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type, \
+ typename p9##_type>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type, p6##_type, p7##_type, p8##_type, \
+ p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+namespace testing {
+
+
+// The ACTION*() macros trigger warning C4100 (unreferenced formal
+// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
+// the macro definition, as the warnings are generated when the macro
+// is expanded and macro expansion cannot contain #pragma. Therefore
+// we suppress them here.
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable:4100)
+#endif
+
+// Various overloads for InvokeArgument<N>().
+//
+// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
+// (0-based) argument, which must be a k-ary callable, of the mock
+// function, with arguments a1, a2, ..., a_k.
+//
+// Notes:
+//
+// 1. The arguments are passed by value by default. If you need to
+// pass an argument by reference, wrap it inside ByRef(). For
+// example,
+//
+// InvokeArgument<1>(5, string("Hello"), ByRef(foo))
+//
+// passes 5 and string("Hello") by value, and passes foo by
+// reference.
+//
+// 2. If the callable takes an argument by reference but ByRef() is
+// not used, it will receive the reference to a copy of the value,
+// instead of the original value. For example, when the 0-th
+// argument of the mock function takes a const string&, the action
+//
+// InvokeArgument<0>(string("Hello"))
+//
+// makes a copy of the temporary string("Hello") object and passes a
+// reference of the copy, instead of the original temporary object,
+// to the callable. This makes it easy for a user to define an
+// InvokeArgument action from temporary values and have it performed
+// later.
+
+namespace internal {
+namespace invoke_argument {
+
+// Appears in InvokeArgumentAdl's argument list to help avoid
+// accidental calls to user functions of the same name.
+struct AdlTag {};
+
+// InvokeArgumentAdl - a helper for InvokeArgument.
+// The basic overloads are provided here for generic functors.
+// Overloads for other custom-callables are provided in the
+// internal/custom/callback-actions.h header.
+
+template <typename R, typename F>
+R InvokeArgumentAdl(AdlTag, F f) {
+ return f();
+}
+template <typename R, typename F, typename A1>
+R InvokeArgumentAdl(AdlTag, F f, A1 a1) {
+ return f(a1);
+}
+template <typename R, typename F, typename A1, typename A2>
+R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2) {
+ return f(a1, a2);
+}
+template <typename R, typename F, typename A1, typename A2, typename A3>
+R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3) {
+ return f(a1, a2, a3);
+}
+template <typename R, typename F, typename A1, typename A2, typename A3,
+ typename A4>
+R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4) {
+ return f(a1, a2, a3, a4);
+}
+template <typename R, typename F, typename A1, typename A2, typename A3,
+ typename A4, typename A5>
+R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
+ return f(a1, a2, a3, a4, a5);
+}
+template <typename R, typename F, typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6>
+R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
+ return f(a1, a2, a3, a4, a5, a6);
+}
+template <typename R, typename F, typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6, typename A7>
+R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
+ A7 a7) {
+ return f(a1, a2, a3, a4, a5, a6, a7);
+}
+template <typename R, typename F, typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6, typename A7, typename A8>
+R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
+ A7 a7, A8 a8) {
+ return f(a1, a2, a3, a4, a5, a6, a7, a8);
+}
+template <typename R, typename F, typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6, typename A7, typename A8,
+ typename A9>
+R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
+ A7 a7, A8 a8, A9 a9) {
+ return f(a1, a2, a3, a4, a5, a6, a7, a8, a9);
+}
+template <typename R, typename F, typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6, typename A7, typename A8,
+ typename A9, typename A10>
+R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
+ A7 a7, A8 a8, A9 a9, A10 a10) {
+ return f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
+}
+} // namespace invoke_argument
+} // namespace internal
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_0_VALUE_PARAMS()) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args));
+}
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_1_VALUE_PARAMS(p0)) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args), p0);
+}
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_2_VALUE_PARAMS(p0, p1)) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args), p0, p1);
+}
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_3_VALUE_PARAMS(p0, p1, p2)) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args), p0, p1, p2);
+}
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args), p0, p1, p2, p3);
+}
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args), p0, p1, p2, p3, p4);
+}
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args), p0, p1, p2, p3, p4, p5);
+}
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
+}
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
+}
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8);
+}
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
+}
+
+// Various overloads for ReturnNew<T>().
+//
+// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
+// instance of type T, constructed on the heap with constructor arguments
+// a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_0_VALUE_PARAMS()) {
+ return new T();
+}
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_1_VALUE_PARAMS(p0)) {
+ return new T(p0);
+}
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_2_VALUE_PARAMS(p0, p1)) {
+ return new T(p0, p1);
+}
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_3_VALUE_PARAMS(p0, p1, p2)) {
+ return new T(p0, p1, p2);
+}
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
+ return new T(p0, p1, p2, p3);
+}
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
+ return new T(p0, p1, p2, p3, p4);
+}
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
+ return new T(p0, p1, p2, p3, p4, p5);
+}
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
+ return new T(p0, p1, p2, p3, p4, p5, p6);
+}
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
+ return new T(p0, p1, p2, p3, p4, p5, p6, p7);
+}
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
+ return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8);
+}
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
+ return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
+}
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+} // namespace testing
+
+// Include any custom callback actions added by the local installation.
+// We must include this header at the end to make sure it can use the
+// declarations from this file.
+#include "gmock/internal/custom/gmock-generated-actions.h"
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
--- /dev/null
+$$ -*- mode: c++; -*-
+$$ This is a Pump source file. Please use Pump to convert it to
+$$ gmock-generated-actions.h.
+$$
+$var n = 10 $$ The maximum arity we support.
+$$}} This meta comment fixes auto-indentation in editors.
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements some commonly used variadic actions.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
+
+#include <memory>
+#include <utility>
+
+#include "gmock/gmock-actions.h"
+#include "gmock/internal/gmock-port.h"
+
+namespace testing {
+namespace internal {
+
+// A macro from the ACTION* family (defined later in this file)
+// defines an action that can be used in a mock function. Typically,
+// these actions only care about a subset of the arguments of the mock
+// function. For example, if such an action only uses the second
+// argument, it can be used in any mock function that takes >= 2
+// arguments where the type of the second argument is compatible.
+//
+// Therefore, the action implementation must be prepared to take more
+// arguments than it needs. The ExcessiveArg type is used to
+// represent those excessive arguments. In order to keep the compiler
+// error messages tractable, we define it in the testing namespace
+// instead of testing::internal. However, this is an INTERNAL TYPE
+// and subject to change without notice, so a user MUST NOT USE THIS
+// TYPE DIRECTLY.
+struct ExcessiveArg {};
+
+// A helper class needed for implementing the ACTION* macros.
+template <typename Result, class Impl>
+class ActionHelper {
+ public:
+$range i 0..n
+$for i
+
+[[
+$var template = [[$if i==0 [[]] $else [[
+$range j 0..i-1
+ template <$for j, [[typename A$j]]>
+]]]]
+$range j 0..i-1
+$var As = [[$for j, [[A$j]]]]
+$var as = [[$for j, [[std::get<$j>(args)]]]]
+$range k 1..n-i
+$var eas = [[$for k, [[ExcessiveArg()]]]]
+$var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]]
+$template
+ static Result Perform(Impl* impl, const ::std::tuple<$As>& args) {
+ return impl->template gmock_PerformImpl<$As>(args, $arg_list);
+ }
+
+]]
+};
+
+} // namespace internal
+} // namespace testing
+
+// The ACTION* family of macros can be used in a namespace scope to
+// define custom actions easily. The syntax:
+//
+// ACTION(name) { statements; }
+//
+// will define an action with the given name that executes the
+// statements. The value returned by the statements will be used as
+// the return value of the action. Inside the statements, you can
+// refer to the K-th (0-based) argument of the mock function by
+// 'argK', and refer to its type by 'argK_type'. For example:
+//
+// ACTION(IncrementArg1) {
+// arg1_type temp = arg1;
+// return ++(*temp);
+// }
+//
+// allows you to write
+//
+// ...WillOnce(IncrementArg1());
+//
+// You can also refer to the entire argument tuple and its type by
+// 'args' and 'args_type', and refer to the mock function type and its
+// return type by 'function_type' and 'return_type'.
+//
+// Note that you don't need to specify the types of the mock function
+// arguments. However rest assured that your code is still type-safe:
+// you'll get a compiler error if *arg1 doesn't support the ++
+// operator, or if the type of ++(*arg1) isn't compatible with the
+// mock function's return type, for example.
+//
+// Sometimes you'll want to parameterize the action. For that you can use
+// another macro:
+//
+// ACTION_P(name, param_name) { statements; }
+//
+// For example:
+//
+// ACTION_P(Add, n) { return arg0 + n; }
+//
+// will allow you to write:
+//
+// ...WillOnce(Add(5));
+//
+// Note that you don't need to provide the type of the parameter
+// either. If you need to reference the type of a parameter named
+// 'foo', you can write 'foo_type'. For example, in the body of
+// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
+// of 'n'.
+//
+// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P$n to support
+// multi-parameter actions.
+//
+// For the purpose of typing, you can view
+//
+// ACTION_Pk(Foo, p1, ..., pk) { ... }
+//
+// as shorthand for
+//
+// template <typename p1_type, ..., typename pk_type>
+// FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
+//
+// In particular, you can provide the template type arguments
+// explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
+// although usually you can rely on the compiler to infer the types
+// for you automatically. You can assign the result of expression
+// Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
+// pk_type>. This can be useful when composing actions.
+//
+// You can also overload actions with different numbers of parameters:
+//
+// ACTION_P(Plus, a) { ... }
+// ACTION_P2(Plus, a, b) { ... }
+//
+// While it's tempting to always use the ACTION* macros when defining
+// a new action, you should also consider implementing ActionInterface
+// or using MakePolymorphicAction() instead, especially if you need to
+// use the action a lot. While these approaches require more work,
+// they give you more control on the types of the mock function
+// arguments and the action parameters, which in general leads to
+// better compiler error messages that pay off in the long run. They
+// also allow overloading actions based on parameter types (as opposed
+// to just based on the number of parameters).
+//
+// CAVEAT:
+//
+// ACTION*() can only be used in a namespace scope. The reason is
+// that C++ doesn't yet allow function-local types to be used to
+// instantiate templates. The up-coming C++0x standard will fix this.
+// Once that's done, we'll consider supporting using ACTION*() inside
+// a function.
+//
+// MORE INFORMATION:
+//
+// To learn more about using these macros, please search for 'ACTION' on
+// https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
+
+$range i 0..n
+$range k 0..n-1
+
+// An internal macro needed for implementing ACTION*().
+#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
+ const args_type& args GTEST_ATTRIBUTE_UNUSED_
+$for k [[, \
+ const arg$k[[]]_type& arg$k GTEST_ATTRIBUTE_UNUSED_]]
+
+
+// Sometimes you want to give an action explicit template parameters
+// that cannot be inferred from its value parameters. ACTION() and
+// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
+// and can be viewed as an extension to ACTION() and ACTION_P*().
+//
+// The syntax:
+//
+// ACTION_TEMPLATE(ActionName,
+// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
+// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
+//
+// defines an action template that takes m explicit template
+// parameters and n value parameters. name_i is the name of the i-th
+// template parameter, and kind_i specifies whether it's a typename,
+// an integral constant, or a template. p_i is the name of the i-th
+// value parameter.
+//
+// Example:
+//
+// // DuplicateArg<k, T>(output) converts the k-th argument of the mock
+// // function to type T and copies it to *output.
+// ACTION_TEMPLATE(DuplicateArg,
+// HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
+// AND_1_VALUE_PARAMS(output)) {
+// *output = T(::std::get<k>(args));
+// }
+// ...
+// int n;
+// EXPECT_CALL(mock, Foo(_, _))
+// .WillOnce(DuplicateArg<1, unsigned char>(&n));
+//
+// To create an instance of an action template, write:
+//
+// ActionName<t1, ..., t_m>(v1, ..., v_n)
+//
+// where the ts are the template arguments and the vs are the value
+// arguments. The value argument types are inferred by the compiler.
+// If you want to explicitly specify the value argument types, you can
+// provide additional template arguments:
+//
+// ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
+//
+// where u_i is the desired type of v_i.
+//
+// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
+// number of value parameters, but not on the number of template
+// parameters. Without the restriction, the meaning of the following
+// is unclear:
+//
+// OverloadedAction<int, bool>(x);
+//
+// Are we using a single-template-parameter action where 'bool' refers
+// to the type of x, or are we using a two-template-parameter action
+// where the compiler is asked to infer the type of x?
+//
+// Implementation notes:
+//
+// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
+// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
+// implementing ACTION_TEMPLATE. The main trick we use is to create
+// new macro invocations when expanding a macro. For example, we have
+//
+// #define ACTION_TEMPLATE(name, template_params, value_params)
+// ... GMOCK_INTERNAL_DECL_##template_params ...
+//
+// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
+// to expand to
+//
+// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
+//
+// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
+// preprocessor will continue to expand it to
+//
+// ... typename T ...
+//
+// This technique conforms to the C++ standard and is portable. It
+// allows us to implement action templates using O(N) code, where N is
+// the maximum number of template/value parameters supported. Without
+// using it, we'd have to devote O(N^2) amount of code to implement all
+// combinations of m and n.
+
+// Declares the template parameters.
+
+$range j 1..n
+$for j [[
+$range m 0..j-1
+#define GMOCK_INTERNAL_DECL_HAS_$j[[]]
+_TEMPLATE_PARAMS($for m, [[kind$m, name$m]]) $for m, [[kind$m name$m]]
+
+
+]]
+
+// Lists the template parameters.
+
+$for j [[
+$range m 0..j-1
+#define GMOCK_INTERNAL_LIST_HAS_$j[[]]
+_TEMPLATE_PARAMS($for m, [[kind$m, name$m]]) $for m, [[name$m]]
+
+
+]]
+
+// Declares the types of value parameters.
+
+$for i [[
+$range j 0..i-1
+#define GMOCK_INTERNAL_DECL_TYPE_AND_$i[[]]
+_VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]]
+
+
+]]
+
+// Initializes the value parameters.
+
+$for i [[
+$range j 0..i-1
+#define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\
+ ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(::std::move(gmock_p$j))]]
+
+
+]]
+
+// Declares the fields for storing the value parameters.
+
+$for i [[
+$range j 0..i-1
+#define GMOCK_INTERNAL_DEFN_AND_$i[[]]
+_VALUE_PARAMS($for j, [[p$j]]) $for j [[p$j##_type p$j; ]]
+
+
+]]
+
+// Lists the value parameters.
+
+$for i [[
+$range j 0..i-1
+#define GMOCK_INTERNAL_LIST_AND_$i[[]]
+_VALUE_PARAMS($for j, [[p$j]]) $for j, [[p$j]]
+
+
+]]
+
+// Lists the value parameter types.
+
+$for i [[
+$range j 0..i-1
+#define GMOCK_INTERNAL_LIST_TYPE_AND_$i[[]]
+_VALUE_PARAMS($for j, [[p$j]]) $for j [[, p$j##_type]]
+
+
+]]
+
+// Declares the value parameters.
+
+$for i [[
+$range j 0..i-1
+#define GMOCK_INTERNAL_DECL_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]]) [[]]
+$for j, [[p$j##_type p$j]]
+
+
+]]
+
+// The suffix of the class template implementing the action template.
+$for i [[
+
+
+$range j 0..i-1
+#define GMOCK_INTERNAL_COUNT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]]) [[]]
+$if i==1 [[P]] $elif i>=2 [[P$i]]
+]]
+
+
+// The name of the class template implementing the action template.
+#define GMOCK_ACTION_CLASS_(name, value_params)\
+ GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
+
+$range k 0..n-1
+
+#define ACTION_TEMPLATE(name, template_params, value_params)\
+ template <GMOCK_INTERNAL_DECL_##template_params\
+ GMOCK_INTERNAL_DECL_TYPE_##value_params>\
+ class GMOCK_ACTION_CLASS_(name, value_params) {\
+ public:\
+ explicit GMOCK_ACTION_CLASS_(name, value_params)\
+ GMOCK_INTERNAL_INIT_##value_params {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <$for k, [[typename arg$k[[]]_type]]>\
+ return_type gmock_PerformImpl(const args_type& args[[]]
+$for k [[, const arg$k[[]]_type& arg$k]]) const;\
+ GMOCK_INTERNAL_DEFN_##value_params\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(\
+ new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
+ }\
+ GMOCK_INTERNAL_DEFN_##value_params\
+ private:\
+ GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
+ };\
+ template <GMOCK_INTERNAL_DECL_##template_params\
+ GMOCK_INTERNAL_DECL_TYPE_##value_params>\
+ inline GMOCK_ACTION_CLASS_(name, value_params)<\
+ GMOCK_INTERNAL_LIST_##template_params\
+ GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
+ GMOCK_INTERNAL_DECL_##value_params) {\
+ return GMOCK_ACTION_CLASS_(name, value_params)<\
+ GMOCK_INTERNAL_LIST_##template_params\
+ GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
+ GMOCK_INTERNAL_LIST_##value_params);\
+ }\
+ template <GMOCK_INTERNAL_DECL_##template_params\
+ GMOCK_INTERNAL_DECL_TYPE_##value_params>\
+ template <typename F>\
+ template <typename arg0_type, typename arg1_type, typename arg2_type, \
+ typename arg3_type, typename arg4_type, typename arg5_type, \
+ typename arg6_type, typename arg7_type, typename arg8_type, \
+ typename arg9_type>\
+ typename ::testing::internal::Function<F>::Result\
+ GMOCK_ACTION_CLASS_(name, value_params)<\
+ GMOCK_INTERNAL_LIST_##template_params\
+ GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
+ gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+
+$for i
+
+[[
+$var template = [[$if i==0 [[]] $else [[
+$range j 0..i-1
+
+ template <$for j, [[typename p$j##_type]]>\
+]]]]
+$var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]]
+ $else [[P$i]]]]]]
+$range j 0..i-1
+$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
+$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
+$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::forward<p$j##_type>(gmock_p$j))]]]]]]
+$var param_field_decls = [[$for j
+[[
+
+ p$j##_type p$j;\
+]]]]
+$var param_field_decls2 = [[$for j
+[[
+
+ p$j##_type p$j;\
+]]]]
+$var params = [[$for j, [[p$j]]]]
+$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
+$var typename_arg_types = [[$for k, [[typename arg$k[[]]_type]]]]
+$var arg_types_and_names = [[$for k, [[const arg$k[[]]_type& arg$k]]]]
+$var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]]
+ $else [[ACTION_P$i]]]]
+
+#define $macro_name(name$for j [[, p$j]])\$template
+ class $class_name {\
+ public:\
+ [[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {}\
+ template <typename F>\
+ class gmock_Impl : public ::testing::ActionInterface<F> {\
+ public:\
+ typedef F function_type;\
+ typedef typename ::testing::internal::Function<F>::Result return_type;\
+ typedef typename ::testing::internal::Function<F>::ArgumentTuple\
+ args_type;\
+ [[$if i==1 [[explicit ]]]]gmock_Impl($ctor_param_list)$inits {}\
+ virtual return_type Perform(const args_type& args) {\
+ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
+ Perform(this, args);\
+ }\
+ template <$typename_arg_types>\
+ return_type gmock_PerformImpl(const args_type& args, [[]]
+$arg_types_and_names) const;\$param_field_decls
+ private:\
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
+ };\
+ template <typename F> operator ::testing::Action<F>() const {\
+ return ::testing::Action<F>(new gmock_Impl<F>($params));\
+ }\$param_field_decls2
+ private:\
+ GTEST_DISALLOW_ASSIGN_($class_name);\
+ };\$template
+ inline $class_name$param_types name($param_types_and_names) {\
+ return $class_name$param_types($params);\
+ }\$template
+ template <typename F>\
+ template <$typename_arg_types>\
+ typename ::testing::internal::Function<F>::Result\
+ $class_name$param_types::gmock_Impl<F>::gmock_PerformImpl(\
+ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
+]]
+$$ } // This meta comment fixes auto-indentation in Emacs. It won't
+$$ // show up in the generated code.
+
+
+namespace testing {
+
+
+// The ACTION*() macros trigger warning C4100 (unreferenced formal
+// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
+// the macro definition, as the warnings are generated when the macro
+// is expanded and macro expansion cannot contain #pragma. Therefore
+// we suppress them here.
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable:4100)
+#endif
+
+// Various overloads for InvokeArgument<N>().
+//
+// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
+// (0-based) argument, which must be a k-ary callable, of the mock
+// function, with arguments a1, a2, ..., a_k.
+//
+// Notes:
+//
+// 1. The arguments are passed by value by default. If you need to
+// pass an argument by reference, wrap it inside ByRef(). For
+// example,
+//
+// InvokeArgument<1>(5, string("Hello"), ByRef(foo))
+//
+// passes 5 and string("Hello") by value, and passes foo by
+// reference.
+//
+// 2. If the callable takes an argument by reference but ByRef() is
+// not used, it will receive the reference to a copy of the value,
+// instead of the original value. For example, when the 0-th
+// argument of the mock function takes a const string&, the action
+//
+// InvokeArgument<0>(string("Hello"))
+//
+// makes a copy of the temporary string("Hello") object and passes a
+// reference of the copy, instead of the original temporary object,
+// to the callable. This makes it easy for a user to define an
+// InvokeArgument action from temporary values and have it performed
+// later.
+
+namespace internal {
+namespace invoke_argument {
+
+// Appears in InvokeArgumentAdl's argument list to help avoid
+// accidental calls to user functions of the same name.
+struct AdlTag {};
+
+// InvokeArgumentAdl - a helper for InvokeArgument.
+// The basic overloads are provided here for generic functors.
+// Overloads for other custom-callables are provided in the
+// internal/custom/callback-actions.h header.
+
+$range i 0..n
+$for i
+[[
+$range j 1..i
+
+template <typename R, typename F[[$for j [[, typename A$j]]]]>
+R InvokeArgumentAdl(AdlTag, F f[[$for j [[, A$j a$j]]]]) {
+ return f([[$for j, [[a$j]]]]);
+}
+]]
+
+} // namespace invoke_argument
+} // namespace internal
+
+$range i 0..n
+$for i [[
+$range j 0..i-1
+
+ACTION_TEMPLATE(InvokeArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])) {
+ using internal::invoke_argument::InvokeArgumentAdl;
+ return InvokeArgumentAdl<return_type>(
+ internal::invoke_argument::AdlTag(),
+ ::std::get<k>(args)$for j [[, p$j]]);
+}
+
+]]
+
+// Various overloads for ReturnNew<T>().
+//
+// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
+// instance of type T, constructed on the heap with constructor arguments
+// a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
+$range i 0..n
+$for i [[
+$range j 0..i-1
+$var ps = [[$for j, [[p$j]]]]
+
+ACTION_TEMPLATE(ReturnNew,
+ HAS_1_TEMPLATE_PARAMS(typename, T),
+ AND_$i[[]]_VALUE_PARAMS($ps)) {
+ return new T($ps);
+}
+
+]]
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+} // namespace testing
+
+// Include any custom callback actions added by the local installation.
+// We must include this header at the end to make sure it can use the
+// declarations from this file.
+#include "gmock/internal/custom/gmock-generated-actions.h"
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
--- /dev/null
+// This file was GENERATED by command:
+// pump.py gmock-generated-function-mockers.h.pump
+// DO NOT EDIT BY HAND!!!
+
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements function mockers of various arities.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
+
+#include <functional>
+#include <utility>
+
+#include "gmock/gmock-spec-builders.h"
+#include "gmock/internal/gmock-internal-utils.h"
+
+namespace testing {
+namespace internal {
+// Removes the given pointer; this is a helper for the expectation setter method
+// for parameterless matchers.
+//
+// We want to make sure that the user cannot set a parameterless expectation on
+// overloaded methods, including methods which are overloaded on const. Example:
+//
+// class MockClass {
+// MOCK_METHOD0(GetName, string&());
+// MOCK_CONST_METHOD0(GetName, const string&());
+// };
+//
+// TEST() {
+// // This should be an error, as it's not clear which overload is expected.
+// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value));
+// }
+//
+// Here are the generated expectation-setter methods:
+//
+// class MockClass {
+// // Overload 1
+// MockSpec<string&()> gmock_GetName() { ... }
+// // Overload 2. Declared const so that the compiler will generate an
+// // error when trying to resolve between this and overload 4 in
+// // 'gmock_GetName(WithoutMatchers(), nullptr)'.
+// MockSpec<string&()> gmock_GetName(
+// const WithoutMatchers&, const Function<string&()>*) const {
+// // Removes const from this, calls overload 1
+// return AdjustConstness_(this)->gmock_GetName();
+// }
+//
+// // Overload 3
+// const string& gmock_GetName() const { ... }
+// // Overload 4
+// MockSpec<const string&()> gmock_GetName(
+// const WithoutMatchers&, const Function<const string&()>*) const {
+// // Does not remove const, calls overload 3
+// return AdjustConstness_const(this)->gmock_GetName();
+// }
+// }
+//
+template <typename MockType>
+const MockType* AdjustConstness_const(const MockType* mock) {
+ return mock;
+}
+
+// Removes const from and returns the given pointer; this is a helper for the
+// expectation setter method for parameterless matchers.
+template <typename MockType>
+MockType* AdjustConstness_(const MockType* mock) {
+ return const_cast<MockType*>(mock);
+}
+
+} // namespace internal
+
+// The style guide prohibits "using" statements in a namespace scope
+// inside a header file. However, the FunctionMocker class template
+// is meant to be defined in the ::testing namespace. The following
+// line is just a trick for working around a bug in MSVC 8.0, which
+// cannot handle it if we define FunctionMocker in ::testing.
+using internal::FunctionMocker;
+
+// GMOCK_RESULT_(tn, F) expands to the result type of function type F.
+// We define this as a variadic macro in case F contains unprotected
+// commas (the same reason that we use variadic macros in other places
+// in this file).
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_RESULT_(tn, ...) \
+ tn ::testing::internal::Function<__VA_ARGS__>::Result
+
+// The type of argument N of the given function type.
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_ARG_(tn, N, ...) \
+ tn ::testing::internal::Function<__VA_ARGS__>::template Arg<N-1>::type
+
+// The matcher type for argument N of the given function type.
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_MATCHER_(tn, N, ...) \
+ const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>&
+
+// The variable for mocking the given method.
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_MOCKER_(arity, constness, Method) \
+ GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \
+ static_assert(0 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ ) constness { \
+ GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(0, constness, Method).Invoke(); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method() constness { \
+ GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(0, constness, Method).With(); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \
+ Method)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \
+ static_assert(1 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
+ GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(1, constness, \
+ Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
+ __VA_ARGS__)>(gmock_a1)); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
+ GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>()); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \
+ Method)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \
+ static_assert(2 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
+ __VA_ARGS__) gmock_a2) constness { \
+ GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(2, constness, \
+ Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
+ __VA_ARGS__)>(gmock_a1), \
+ ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2)); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
+ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
+ GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>()); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \
+ Method)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \
+ static_assert(3 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
+ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, \
+ __VA_ARGS__) gmock_a3) constness { \
+ GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(3, constness, \
+ Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
+ __VA_ARGS__)>(gmock_a1), \
+ ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
+ ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3)); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
+ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
+ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
+ GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \
+ gmock_a3); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>()); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \
+ Method)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \
+ static_assert(4 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
+ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
+ GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(4, constness, \
+ Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
+ __VA_ARGS__)>(gmock_a1), \
+ ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
+ ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
+ ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4)); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
+ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
+ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
+ GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \
+ gmock_a3, gmock_a4); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>()); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \
+ Method)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \
+ static_assert(5 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
+ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
+ __VA_ARGS__) gmock_a5) constness { \
+ GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(5, constness, \
+ Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
+ __VA_ARGS__)>(gmock_a1), \
+ ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
+ ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
+ ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
+ ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5)); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
+ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
+ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
+ GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
+ GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \
+ gmock_a3, gmock_a4, gmock_a5); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>()); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \
+ Method)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \
+ static_assert(6 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
+ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
+ __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, \
+ __VA_ARGS__) gmock_a6) constness { \
+ GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(6, constness, \
+ Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
+ __VA_ARGS__)>(gmock_a1), \
+ ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
+ ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
+ ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
+ ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
+ ::std::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6)); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
+ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
+ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
+ GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
+ GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
+ GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \
+ gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>()); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \
+ Method)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \
+ static_assert(7 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
+ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
+ __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
+ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
+ GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(7, constness, \
+ Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
+ __VA_ARGS__)>(gmock_a1), \
+ ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
+ ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
+ ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
+ ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
+ ::std::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
+ ::std::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7)); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
+ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
+ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
+ GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
+ GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
+ GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
+ GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \
+ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>()); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \
+ Method)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \
+ static_assert(8 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
+ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
+ __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
+ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \
+ __VA_ARGS__) gmock_a8) constness { \
+ GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(8, constness, \
+ Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
+ __VA_ARGS__)>(gmock_a1), \
+ ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
+ ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
+ ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
+ ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
+ ::std::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
+ ::std::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \
+ ::std::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8)); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
+ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
+ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
+ GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
+ GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
+ GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
+ GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
+ GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \
+ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 8, __VA_ARGS__)>()); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \
+ Method)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \
+ static_assert(9 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
+ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
+ __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
+ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \
+ __VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, \
+ __VA_ARGS__) gmock_a9) constness { \
+ GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(9, constness, \
+ Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
+ __VA_ARGS__)>(gmock_a1), \
+ ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
+ ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
+ ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
+ ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
+ ::std::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
+ ::std::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \
+ ::std::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8), \
+ ::std::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(gmock_a9)); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
+ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
+ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
+ GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
+ GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
+ GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
+ GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
+ GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
+ GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \
+ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
+ gmock_a9); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 9, __VA_ARGS__)>()); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \
+ Method)
+
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \
+ static_assert(10 == \
+ ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
+ "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
+ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
+ __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
+ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \
+ __VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \
+ GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
+ GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_(10, constness, \
+ Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
+ __VA_ARGS__)>(gmock_a1), \
+ ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
+ ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
+ ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
+ ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
+ ::std::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
+ ::std::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \
+ ::std::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8), \
+ ::std::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(gmock_a9), \
+ ::std::forward<GMOCK_ARG_(tn, 10, __VA_ARGS__)>(gmock_a10)); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
+ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
+ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
+ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
+ GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
+ GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
+ GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
+ GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
+ GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \
+ GMOCK_MATCHER_(tn, 10, \
+ __VA_ARGS__) gmock_a10) constness { \
+ GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \
+ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
+ gmock_a10); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(), \
+ ::testing::A<GMOCK_ARG_(tn, 10, __VA_ARGS__)>()); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \
+ Method)
+
+#define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__)
+#define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__)
+#define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__)
+#define MOCK_METHOD3(m, ...) GMOCK_METHOD3_(, , , m, __VA_ARGS__)
+#define MOCK_METHOD4(m, ...) GMOCK_METHOD4_(, , , m, __VA_ARGS__)
+#define MOCK_METHOD5(m, ...) GMOCK_METHOD5_(, , , m, __VA_ARGS__)
+#define MOCK_METHOD6(m, ...) GMOCK_METHOD6_(, , , m, __VA_ARGS__)
+#define MOCK_METHOD7(m, ...) GMOCK_METHOD7_(, , , m, __VA_ARGS__)
+#define MOCK_METHOD8(m, ...) GMOCK_METHOD8_(, , , m, __VA_ARGS__)
+#define MOCK_METHOD9(m, ...) GMOCK_METHOD9_(, , , m, __VA_ARGS__)
+#define MOCK_METHOD10(m, ...) GMOCK_METHOD10_(, , , m, __VA_ARGS__)
+
+#define MOCK_CONST_METHOD0(m, ...) GMOCK_METHOD0_(, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD1(m, ...) GMOCK_METHOD1_(, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD2(m, ...) GMOCK_METHOD2_(, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD3(m, ...) GMOCK_METHOD3_(, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD4(m, ...) GMOCK_METHOD4_(, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD5(m, ...) GMOCK_METHOD5_(, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD6(m, ...) GMOCK_METHOD6_(, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD7(m, ...) GMOCK_METHOD7_(, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD8(m, ...) GMOCK_METHOD8_(, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD9(m, ...) GMOCK_METHOD9_(, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD10(m, ...) GMOCK_METHOD10_(, const, , m, __VA_ARGS__)
+
+#define MOCK_METHOD0_T(m, ...) GMOCK_METHOD0_(typename, , , m, __VA_ARGS__)
+#define MOCK_METHOD1_T(m, ...) GMOCK_METHOD1_(typename, , , m, __VA_ARGS__)
+#define MOCK_METHOD2_T(m, ...) GMOCK_METHOD2_(typename, , , m, __VA_ARGS__)
+#define MOCK_METHOD3_T(m, ...) GMOCK_METHOD3_(typename, , , m, __VA_ARGS__)
+#define MOCK_METHOD4_T(m, ...) GMOCK_METHOD4_(typename, , , m, __VA_ARGS__)
+#define MOCK_METHOD5_T(m, ...) GMOCK_METHOD5_(typename, , , m, __VA_ARGS__)
+#define MOCK_METHOD6_T(m, ...) GMOCK_METHOD6_(typename, , , m, __VA_ARGS__)
+#define MOCK_METHOD7_T(m, ...) GMOCK_METHOD7_(typename, , , m, __VA_ARGS__)
+#define MOCK_METHOD8_T(m, ...) GMOCK_METHOD8_(typename, , , m, __VA_ARGS__)
+#define MOCK_METHOD9_T(m, ...) GMOCK_METHOD9_(typename, , , m, __VA_ARGS__)
+#define MOCK_METHOD10_T(m, ...) GMOCK_METHOD10_(typename, , , m, __VA_ARGS__)
+
+#define MOCK_CONST_METHOD0_T(m, ...) \
+ GMOCK_METHOD0_(typename, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD1_T(m, ...) \
+ GMOCK_METHOD1_(typename, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD2_T(m, ...) \
+ GMOCK_METHOD2_(typename, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD3_T(m, ...) \
+ GMOCK_METHOD3_(typename, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD4_T(m, ...) \
+ GMOCK_METHOD4_(typename, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD5_T(m, ...) \
+ GMOCK_METHOD5_(typename, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD6_T(m, ...) \
+ GMOCK_METHOD6_(typename, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD7_T(m, ...) \
+ GMOCK_METHOD7_(typename, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD8_T(m, ...) \
+ GMOCK_METHOD8_(typename, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD9_T(m, ...) \
+ GMOCK_METHOD9_(typename, const, , m, __VA_ARGS__)
+#define MOCK_CONST_METHOD10_T(m, ...) \
+ GMOCK_METHOD10_(typename, const, , m, __VA_ARGS__)
+
+#define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD0_(, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD1_(, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD2_(, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD3_(, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD4_(, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD5_(, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD6_(, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD7_(, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD8_(, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD9_(, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD10_(, , ct, m, __VA_ARGS__)
+
+#define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD0_(, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD1_(, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD2_(, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD3_(, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD4_(, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD5_(, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD6_(, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD7_(, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD8_(, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD9_(, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD10_(, const, ct, m, __VA_ARGS__)
+
+#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD0_(typename, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD1_(typename, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD2_(typename, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD3_(typename, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD4_(typename, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD5_(typename, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD6_(typename, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD7_(typename, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD8_(typename, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD9_(typename, , ct, m, __VA_ARGS__)
+#define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD10_(typename, , ct, m, __VA_ARGS__)
+
+#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD0_(typename, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD1_(typename, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD2_(typename, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD3_(typename, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD4_(typename, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD5_(typename, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD6_(typename, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD7_(typename, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD8_(typename, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD9_(typename, const, ct, m, __VA_ARGS__)
+#define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD10_(typename, const, ct, m, __VA_ARGS__)
+
+} // namespace testing
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
--- /dev/null
+$$ -*- mode: c++; -*-
+$$ This is a Pump source file. Please use Pump to convert
+$$ it to gmock-generated-function-mockers.h.
+$$
+$var n = 10 $$ The maximum arity we support.
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements function mockers of various arities.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
+
+#include <functional>
+#include <utility>
+
+#include "gmock/gmock-spec-builders.h"
+#include "gmock/internal/gmock-internal-utils.h"
+
+namespace testing {
+namespace internal {
+
+$range i 0..n
+// Removes the given pointer; this is a helper for the expectation setter method
+// for parameterless matchers.
+//
+// We want to make sure that the user cannot set a parameterless expectation on
+// overloaded methods, including methods which are overloaded on const. Example:
+//
+// class MockClass {
+// MOCK_METHOD0(GetName, string&());
+// MOCK_CONST_METHOD0(GetName, const string&());
+// };
+//
+// TEST() {
+// // This should be an error, as it's not clear which overload is expected.
+// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value));
+// }
+//
+// Here are the generated expectation-setter methods:
+//
+// class MockClass {
+// // Overload 1
+// MockSpec<string&()> gmock_GetName() { ... }
+// // Overload 2. Declared const so that the compiler will generate an
+// // error when trying to resolve between this and overload 4 in
+// // 'gmock_GetName(WithoutMatchers(), nullptr)'.
+// MockSpec<string&()> gmock_GetName(
+// const WithoutMatchers&, const Function<string&()>*) const {
+// // Removes const from this, calls overload 1
+// return AdjustConstness_(this)->gmock_GetName();
+// }
+//
+// // Overload 3
+// const string& gmock_GetName() const { ... }
+// // Overload 4
+// MockSpec<const string&()> gmock_GetName(
+// const WithoutMatchers&, const Function<const string&()>*) const {
+// // Does not remove const, calls overload 3
+// return AdjustConstness_const(this)->gmock_GetName();
+// }
+// }
+//
+template <typename MockType>
+const MockType* AdjustConstness_const(const MockType* mock) {
+ return mock;
+}
+
+// Removes const from and returns the given pointer; this is a helper for the
+// expectation setter method for parameterless matchers.
+template <typename MockType>
+MockType* AdjustConstness_(const MockType* mock) {
+ return const_cast<MockType*>(mock);
+}
+
+} // namespace internal
+
+// The style guide prohibits "using" statements in a namespace scope
+// inside a header file. However, the FunctionMocker class template
+// is meant to be defined in the ::testing namespace. The following
+// line is just a trick for working around a bug in MSVC 8.0, which
+// cannot handle it if we define FunctionMocker in ::testing.
+using internal::FunctionMocker;
+
+// GMOCK_RESULT_(tn, F) expands to the result type of function type F.
+// We define this as a variadic macro in case F contains unprotected
+// commas (the same reason that we use variadic macros in other places
+// in this file).
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_RESULT_(tn, ...) \
+ tn ::testing::internal::Function<__VA_ARGS__>::Result
+
+// The type of argument N of the given function type.
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_ARG_(tn, N, ...) \
+ tn ::testing::internal::Function<__VA_ARGS__>::template Arg<N-1>::type
+
+// The matcher type for argument N of the given function type.
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_MATCHER_(tn, N, ...) \
+ const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>&
+
+// The variable for mocking the given method.
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_MOCKER_(arity, constness, Method) \
+ GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
+
+
+$for i [[
+$range j 1..i
+$var arg_as = [[$for j, [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
+$var as = [[$for j, \
+ [[::std::forward<GMOCK_ARG_(tn, $j, __VA_ARGS__)>(gmock_a$j)]]]]
+$var matcher_arg_as = [[$for j, \
+ [[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
+$var matcher_as = [[$for j, [[gmock_a$j]]]]
+$var anything_matchers = [[$for j, \
+ [[::testing::A<GMOCK_ARG_(tn, $j, __VA_ARGS__)>()]]]]
+// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
+#define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \
+ static_assert($i == ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, "MOCK_METHOD<N> must match argument count.");\
+ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+ $arg_as) constness { \
+ GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \
+ return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> \
+ gmock_##Method($matcher_arg_as) constness { \
+ GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \
+ return GMOCK_MOCKER_($i, constness, Method).With($matcher_as); \
+ } \
+ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
+ const ::testing::internal::WithoutMatchers&, \
+ constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
+ return ::testing::internal::AdjustConstness_##constness(this)-> \
+ gmock_##Method($anything_matchers); \
+ } \
+ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method)
+
+
+]]
+$for i [[
+#define MOCK_METHOD$i(m, ...) GMOCK_METHOD$i[[]]_(, , , m, __VA_ARGS__)
+
+]]
+
+
+$for i [[
+#define MOCK_CONST_METHOD$i(m, ...) GMOCK_METHOD$i[[]]_(, const, , m, __VA_ARGS__)
+
+]]
+
+
+$for i [[
+#define MOCK_METHOD$i[[]]_T(m, ...) GMOCK_METHOD$i[[]]_(typename, , , m, __VA_ARGS__)
+
+]]
+
+
+$for i [[
+#define MOCK_CONST_METHOD$i[[]]_T(m, ...) \
+ GMOCK_METHOD$i[[]]_(typename, const, , m, __VA_ARGS__)
+
+]]
+
+
+$for i [[
+#define MOCK_METHOD$i[[]]_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD$i[[]]_(, , ct, m, __VA_ARGS__)
+
+]]
+
+
+$for i [[
+#define MOCK_CONST_METHOD$i[[]]_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD$i[[]]_(, const, ct, m, __VA_ARGS__)
+
+]]
+
+
+$for i [[
+#define MOCK_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD$i[[]]_(typename, , ct, m, __VA_ARGS__)
+
+]]
+
+
+$for i [[
+#define MOCK_CONST_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, ...) \
+ GMOCK_METHOD$i[[]]_(typename, const, ct, m, __VA_ARGS__)
+
+]]
+
+} // namespace testing
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
--- /dev/null
+// This file was GENERATED by command:
+// pump.py gmock-generated-matchers.h.pump
+// DO NOT EDIT BY HAND!!!
+
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements some commonly used variadic matchers.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
+
+#include <iterator>
+#include <sstream>
+#include <string>
+#include <utility>
+#include <vector>
+#include "gmock/gmock-matchers.h"
+
+// The MATCHER* family of macros can be used in a namespace scope to
+// define custom matchers easily.
+//
+// Basic Usage
+// ===========
+//
+// The syntax
+//
+// MATCHER(name, description_string) { statements; }
+//
+// defines a matcher with the given name that executes the statements,
+// which must return a bool to indicate if the match succeeds. Inside
+// the statements, you can refer to the value being matched by 'arg',
+// and refer to its type by 'arg_type'.
+//
+// The description string documents what the matcher does, and is used
+// to generate the failure message when the match fails. Since a
+// MATCHER() is usually defined in a header file shared by multiple
+// C++ source files, we require the description to be a C-string
+// literal to avoid possible side effects. It can be empty, in which
+// case we'll use the sequence of words in the matcher name as the
+// description.
+//
+// For example:
+//
+// MATCHER(IsEven, "") { return (arg % 2) == 0; }
+//
+// allows you to write
+//
+// // Expects mock_foo.Bar(n) to be called where n is even.
+// EXPECT_CALL(mock_foo, Bar(IsEven()));
+//
+// or,
+//
+// // Verifies that the value of some_expression is even.
+// EXPECT_THAT(some_expression, IsEven());
+//
+// If the above assertion fails, it will print something like:
+//
+// Value of: some_expression
+// Expected: is even
+// Actual: 7
+//
+// where the description "is even" is automatically calculated from the
+// matcher name IsEven.
+//
+// Argument Type
+// =============
+//
+// Note that the type of the value being matched (arg_type) is
+// determined by the context in which you use the matcher and is
+// supplied to you by the compiler, so you don't need to worry about
+// declaring it (nor can you). This allows the matcher to be
+// polymorphic. For example, IsEven() can be used to match any type
+// where the value of "(arg % 2) == 0" can be implicitly converted to
+// a bool. In the "Bar(IsEven())" example above, if method Bar()
+// takes an int, 'arg_type' will be int; if it takes an unsigned long,
+// 'arg_type' will be unsigned long; and so on.
+//
+// Parameterizing Matchers
+// =======================
+//
+// Sometimes you'll want to parameterize the matcher. For that you
+// can use another macro:
+//
+// MATCHER_P(name, param_name, description_string) { statements; }
+//
+// For example:
+//
+// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
+//
+// will allow you to write:
+//
+// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
+//
+// which may lead to this message (assuming n is 10):
+//
+// Value of: Blah("a")
+// Expected: has absolute value 10
+// Actual: -9
+//
+// Note that both the matcher description and its parameter are
+// printed, making the message human-friendly.
+//
+// In the matcher definition body, you can write 'foo_type' to
+// reference the type of a parameter named 'foo'. For example, in the
+// body of MATCHER_P(HasAbsoluteValue, value) above, you can write
+// 'value_type' to refer to the type of 'value'.
+//
+// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
+// support multi-parameter matchers.
+//
+// Describing Parameterized Matchers
+// =================================
+//
+// The last argument to MATCHER*() is a string-typed expression. The
+// expression can reference all of the matcher's parameters and a
+// special bool-typed variable named 'negation'. When 'negation' is
+// false, the expression should evaluate to the matcher's description;
+// otherwise it should evaluate to the description of the negation of
+// the matcher. For example,
+//
+// using testing::PrintToString;
+//
+// MATCHER_P2(InClosedRange, low, hi,
+// std::string(negation ? "is not" : "is") + " in range [" +
+// PrintToString(low) + ", " + PrintToString(hi) + "]") {
+// return low <= arg && arg <= hi;
+// }
+// ...
+// EXPECT_THAT(3, InClosedRange(4, 6));
+// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
+//
+// would generate two failures that contain the text:
+//
+// Expected: is in range [4, 6]
+// ...
+// Expected: is not in range [2, 4]
+//
+// If you specify "" as the description, the failure message will
+// contain the sequence of words in the matcher name followed by the
+// parameter values printed as a tuple. For example,
+//
+// MATCHER_P2(InClosedRange, low, hi, "") { ... }
+// ...
+// EXPECT_THAT(3, InClosedRange(4, 6));
+// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
+//
+// would generate two failures that contain the text:
+//
+// Expected: in closed range (4, 6)
+// ...
+// Expected: not (in closed range (2, 4))
+//
+// Types of Matcher Parameters
+// ===========================
+//
+// For the purpose of typing, you can view
+//
+// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
+//
+// as shorthand for
+//
+// template <typename p1_type, ..., typename pk_type>
+// FooMatcherPk<p1_type, ..., pk_type>
+// Foo(p1_type p1, ..., pk_type pk) { ... }
+//
+// When you write Foo(v1, ..., vk), the compiler infers the types of
+// the parameters v1, ..., and vk for you. If you are not happy with
+// the result of the type inference, you can specify the types by
+// explicitly instantiating the template, as in Foo<long, bool>(5,
+// false). As said earlier, you don't get to (or need to) specify
+// 'arg_type' as that's determined by the context in which the matcher
+// is used. You can assign the result of expression Foo(p1, ..., pk)
+// to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
+// can be useful when composing matchers.
+//
+// While you can instantiate a matcher template with reference types,
+// passing the parameters by pointer usually makes your code more
+// readable. If, however, you still want to pass a parameter by
+// reference, be aware that in the failure message generated by the
+// matcher you will see the value of the referenced object but not its
+// address.
+//
+// Explaining Match Results
+// ========================
+//
+// Sometimes the matcher description alone isn't enough to explain why
+// the match has failed or succeeded. For example, when expecting a
+// long string, it can be very helpful to also print the diff between
+// the expected string and the actual one. To achieve that, you can
+// optionally stream additional information to a special variable
+// named result_listener, whose type is a pointer to class
+// MatchResultListener:
+//
+// MATCHER_P(EqualsLongString, str, "") {
+// if (arg == str) return true;
+//
+// *result_listener << "the difference: "
+/// << DiffStrings(str, arg);
+// return false;
+// }
+//
+// Overloading Matchers
+// ====================
+//
+// You can overload matchers with different numbers of parameters:
+//
+// MATCHER_P(Blah, a, description_string1) { ... }
+// MATCHER_P2(Blah, a, b, description_string2) { ... }
+//
+// Caveats
+// =======
+//
+// When defining a new matcher, you should also consider implementing
+// MatcherInterface or using MakePolymorphicMatcher(). These
+// approaches require more work than the MATCHER* macros, but also
+// give you more control on the types of the value being matched and
+// the matcher parameters, which may leads to better compiler error
+// messages when the matcher is used wrong. They also allow
+// overloading matchers based on parameter types (as opposed to just
+// based on the number of parameters).
+//
+// MATCHER*() can only be used in a namespace scope. The reason is
+// that C++ doesn't yet allow function-local types to be used to
+// instantiate templates. The up-coming C++0x standard will fix this.
+// Once that's done, we'll consider supporting using MATCHER*() inside
+// a function.
+//
+// More Information
+// ================
+//
+// To learn more about using these macros, please search for 'MATCHER'
+// on
+// https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
+
+#define MATCHER(name, description)\
+ class name##Matcher {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ gmock_Impl()\
+ {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<>()));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>());\
+ }\
+ name##Matcher() {\
+ }\
+ private:\
+ };\
+ inline name##Matcher name() {\
+ return name##Matcher();\
+ }\
+ template <typename arg_type>\
+ bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#define MATCHER_P(name, p0, description)\
+ template <typename p0##_type>\
+ class name##MatcherP {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ explicit gmock_Impl(p0##_type gmock_p0)\
+ : p0(::std::move(gmock_p0)) {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ p0##_type const p0;\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<p0##_type>(p0)));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>(p0));\
+ }\
+ explicit name##MatcherP(p0##_type gmock_p0) : p0(::std::move(gmock_p0)) {\
+ }\
+ p0##_type const p0;\
+ private:\
+ };\
+ template <typename p0##_type>\
+ inline name##MatcherP<p0##_type> name(p0##_type p0) {\
+ return name##MatcherP<p0##_type>(p0);\
+ }\
+ template <typename p0##_type>\
+ template <typename arg_type>\
+ bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#define MATCHER_P2(name, p0, p1, description)\
+ template <typename p0##_type, typename p1##_type>\
+ class name##MatcherP2 {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
+ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)) {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<p0##_type, p1##_type>(p0, p1)));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>(p0, p1));\
+ }\
+ name##MatcherP2(p0##_type gmock_p0, \
+ p1##_type gmock_p1) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)) {\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ private:\
+ };\
+ template <typename p0##_type, typename p1##_type>\
+ inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
+ p1##_type p1) {\
+ return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
+ }\
+ template <typename p0##_type, typename p1##_type>\
+ template <typename arg_type>\
+ bool name##MatcherP2<p0##_type, \
+ p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#define MATCHER_P3(name, p0, p1, p2, description)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type>\
+ class name##MatcherP3 {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
+ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
+ p2(::std::move(gmock_p2)) {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, p2)));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>(p0, p1, p2));\
+ }\
+ name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)) {\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ private:\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type>\
+ inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
+ p1##_type p1, p2##_type p2) {\
+ return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type>\
+ template <typename arg_type>\
+ bool name##MatcherP3<p0##_type, p1##_type, \
+ p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#define MATCHER_P4(name, p0, p1, p2, p3, description)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type>\
+ class name##MatcherP4 {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3)\
+ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
+ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)) {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
+ p1, p2, p3)));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>(p0, p1, p2, p3));\
+ }\
+ name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)) {\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ private:\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type>\
+ inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
+ p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
+ p3##_type p3) {\
+ return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
+ p1, p2, p3);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type>\
+ template <typename arg_type>\
+ bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \
+ p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type>\
+ class name##MatcherP5 {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4)\
+ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
+ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
+ p4(::std::move(gmock_p4)) {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type>(p0, p1, p2, p3, p4)));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4));\
+ }\
+ name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, \
+ p4##_type gmock_p4) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)) {\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ private:\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type>\
+ inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
+ p4##_type p4) {\
+ return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type>(p0, p1, p2, p3, p4);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type>\
+ template <typename arg_type>\
+ bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type>\
+ class name##MatcherP6 {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\
+ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
+ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
+ p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)) {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ p5##_type const p5;\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5));\
+ }\
+ name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
+ p5(::std::move(gmock_p5)) {\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ p5##_type const p5;\
+ private:\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type>\
+ inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
+ p3##_type p3, p4##_type p4, p5##_type p5) {\
+ return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type>\
+ template <typename arg_type>\
+ bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type>\
+ class name##MatcherP7 {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6)\
+ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
+ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
+ p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
+ p6(::std::move(gmock_p6)) {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ p5##_type const p5;\
+ p6##_type const p6;\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
+ p6)));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6));\
+ }\
+ name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5, p6##_type gmock_p6) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
+ p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)) {\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ p5##_type const p5;\
+ p6##_type const p6;\
+ private:\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type>\
+ inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
+ p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
+ p6##_type p6) {\
+ return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type>\
+ template <typename arg_type>\
+ bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type>\
+ class name##MatcherP8 {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6, p7##_type gmock_p7)\
+ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
+ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
+ p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
+ p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)) {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ p5##_type const p5;\
+ p6##_type const p6;\
+ p7##_type const p7;\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
+ p3, p4, p5, p6, p7)));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7));\
+ }\
+ name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5, p6##_type gmock_p6, \
+ p7##_type gmock_p7) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
+ p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
+ p7(::std::move(gmock_p7)) {\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ p5##_type const p5;\
+ p6##_type const p6;\
+ p7##_type const p7;\
+ private:\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type>\
+ inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
+ p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
+ p6##_type p6, p7##_type p7) {\
+ return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
+ p6, p7);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type>\
+ template <typename arg_type>\
+ bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type, p6##_type, \
+ p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type>\
+ class name##MatcherP9 {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\
+ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
+ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
+ p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
+ p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \
+ p8(::std::move(gmock_p8)) {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ p5##_type const p5;\
+ p6##_type const p6;\
+ p7##_type const p7;\
+ p8##_type const p8;\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, \
+ p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
+ }\
+ name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
+ p8##_type gmock_p8) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
+ p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
+ p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)) {\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ p5##_type const p5;\
+ p6##_type const p6;\
+ p7##_type const p7;\
+ p8##_type const p8;\
+ private:\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type>\
+ inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, \
+ p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
+ p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
+ p8##_type p8) {\
+ return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
+ p3, p4, p5, p6, p7, p8);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type>\
+ template <typename arg_type>\
+ bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
+ p5##_type, p6##_type, p7##_type, \
+ p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type, \
+ typename p9##_type>\
+ class name##MatcherP10 {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
+ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
+ p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
+ p9##_type gmock_p9)\
+ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
+ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
+ p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
+ p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \
+ p8(::std::move(gmock_p8)), p9(::std::move(gmock_p9)) {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ p5##_type const p5;\
+ p6##_type const p6;\
+ p7##_type const p7;\
+ p8##_type const p8;\
+ p9##_type const p9;\
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
+ p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
+ }\
+ name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
+ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
+ p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
+ p8##_type gmock_p8, p9##_type gmock_p9) : p0(::std::move(gmock_p0)), \
+ p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
+ p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
+ p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
+ p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \
+ p9(::std::move(gmock_p9)) {\
+ }\
+ p0##_type const p0;\
+ p1##_type const p1;\
+ p2##_type const p2;\
+ p3##_type const p3;\
+ p4##_type const p4;\
+ p5##_type const p5;\
+ p6##_type const p6;\
+ p7##_type const p7;\
+ p8##_type const p8;\
+ p9##_type const p9;\
+ private:\
+ };\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type, \
+ typename p9##_type>\
+ inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
+ p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
+ p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
+ p9##_type p9) {\
+ return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
+ p1, p2, p3, p4, p5, p6, p7, p8, p9);\
+ }\
+ template <typename p0##_type, typename p1##_type, typename p2##_type, \
+ typename p3##_type, typename p4##_type, typename p5##_type, \
+ typename p6##_type, typename p7##_type, typename p8##_type, \
+ typename p9##_type>\
+ template <typename arg_type>\
+ bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
+ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
+ p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
--- /dev/null
+$$ -*- mode: c++; -*-
+$$ This is a Pump source file. Please use Pump to convert
+$$ it to gmock-generated-matchers.h.
+$$
+$var n = 10 $$ The maximum arity we support.
+$$ }} This line fixes auto-indentation of the following code in Emacs.
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements some commonly used variadic matchers.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
+
+#include <iterator>
+#include <sstream>
+#include <string>
+#include <utility>
+#include <vector>
+#include "gmock/gmock-matchers.h"
+
+// The MATCHER* family of macros can be used in a namespace scope to
+// define custom matchers easily.
+//
+// Basic Usage
+// ===========
+//
+// The syntax
+//
+// MATCHER(name, description_string) { statements; }
+//
+// defines a matcher with the given name that executes the statements,
+// which must return a bool to indicate if the match succeeds. Inside
+// the statements, you can refer to the value being matched by 'arg',
+// and refer to its type by 'arg_type'.
+//
+// The description string documents what the matcher does, and is used
+// to generate the failure message when the match fails. Since a
+// MATCHER() is usually defined in a header file shared by multiple
+// C++ source files, we require the description to be a C-string
+// literal to avoid possible side effects. It can be empty, in which
+// case we'll use the sequence of words in the matcher name as the
+// description.
+//
+// For example:
+//
+// MATCHER(IsEven, "") { return (arg % 2) == 0; }
+//
+// allows you to write
+//
+// // Expects mock_foo.Bar(n) to be called where n is even.
+// EXPECT_CALL(mock_foo, Bar(IsEven()));
+//
+// or,
+//
+// // Verifies that the value of some_expression is even.
+// EXPECT_THAT(some_expression, IsEven());
+//
+// If the above assertion fails, it will print something like:
+//
+// Value of: some_expression
+// Expected: is even
+// Actual: 7
+//
+// where the description "is even" is automatically calculated from the
+// matcher name IsEven.
+//
+// Argument Type
+// =============
+//
+// Note that the type of the value being matched (arg_type) is
+// determined by the context in which you use the matcher and is
+// supplied to you by the compiler, so you don't need to worry about
+// declaring it (nor can you). This allows the matcher to be
+// polymorphic. For example, IsEven() can be used to match any type
+// where the value of "(arg % 2) == 0" can be implicitly converted to
+// a bool. In the "Bar(IsEven())" example above, if method Bar()
+// takes an int, 'arg_type' will be int; if it takes an unsigned long,
+// 'arg_type' will be unsigned long; and so on.
+//
+// Parameterizing Matchers
+// =======================
+//
+// Sometimes you'll want to parameterize the matcher. For that you
+// can use another macro:
+//
+// MATCHER_P(name, param_name, description_string) { statements; }
+//
+// For example:
+//
+// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
+//
+// will allow you to write:
+//
+// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
+//
+// which may lead to this message (assuming n is 10):
+//
+// Value of: Blah("a")
+// Expected: has absolute value 10
+// Actual: -9
+//
+// Note that both the matcher description and its parameter are
+// printed, making the message human-friendly.
+//
+// In the matcher definition body, you can write 'foo_type' to
+// reference the type of a parameter named 'foo'. For example, in the
+// body of MATCHER_P(HasAbsoluteValue, value) above, you can write
+// 'value_type' to refer to the type of 'value'.
+//
+// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P$n to
+// support multi-parameter matchers.
+//
+// Describing Parameterized Matchers
+// =================================
+//
+// The last argument to MATCHER*() is a string-typed expression. The
+// expression can reference all of the matcher's parameters and a
+// special bool-typed variable named 'negation'. When 'negation' is
+// false, the expression should evaluate to the matcher's description;
+// otherwise it should evaluate to the description of the negation of
+// the matcher. For example,
+//
+// using testing::PrintToString;
+//
+// MATCHER_P2(InClosedRange, low, hi,
+// std::string(negation ? "is not" : "is") + " in range [" +
+// PrintToString(low) + ", " + PrintToString(hi) + "]") {
+// return low <= arg && arg <= hi;
+// }
+// ...
+// EXPECT_THAT(3, InClosedRange(4, 6));
+// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
+//
+// would generate two failures that contain the text:
+//
+// Expected: is in range [4, 6]
+// ...
+// Expected: is not in range [2, 4]
+//
+// If you specify "" as the description, the failure message will
+// contain the sequence of words in the matcher name followed by the
+// parameter values printed as a tuple. For example,
+//
+// MATCHER_P2(InClosedRange, low, hi, "") { ... }
+// ...
+// EXPECT_THAT(3, InClosedRange(4, 6));
+// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
+//
+// would generate two failures that contain the text:
+//
+// Expected: in closed range (4, 6)
+// ...
+// Expected: not (in closed range (2, 4))
+//
+// Types of Matcher Parameters
+// ===========================
+//
+// For the purpose of typing, you can view
+//
+// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
+//
+// as shorthand for
+//
+// template <typename p1_type, ..., typename pk_type>
+// FooMatcherPk<p1_type, ..., pk_type>
+// Foo(p1_type p1, ..., pk_type pk) { ... }
+//
+// When you write Foo(v1, ..., vk), the compiler infers the types of
+// the parameters v1, ..., and vk for you. If you are not happy with
+// the result of the type inference, you can specify the types by
+// explicitly instantiating the template, as in Foo<long, bool>(5,
+// false). As said earlier, you don't get to (or need to) specify
+// 'arg_type' as that's determined by the context in which the matcher
+// is used. You can assign the result of expression Foo(p1, ..., pk)
+// to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
+// can be useful when composing matchers.
+//
+// While you can instantiate a matcher template with reference types,
+// passing the parameters by pointer usually makes your code more
+// readable. If, however, you still want to pass a parameter by
+// reference, be aware that in the failure message generated by the
+// matcher you will see the value of the referenced object but not its
+// address.
+//
+// Explaining Match Results
+// ========================
+//
+// Sometimes the matcher description alone isn't enough to explain why
+// the match has failed or succeeded. For example, when expecting a
+// long string, it can be very helpful to also print the diff between
+// the expected string and the actual one. To achieve that, you can
+// optionally stream additional information to a special variable
+// named result_listener, whose type is a pointer to class
+// MatchResultListener:
+//
+// MATCHER_P(EqualsLongString, str, "") {
+// if (arg == str) return true;
+//
+// *result_listener << "the difference: "
+/// << DiffStrings(str, arg);
+// return false;
+// }
+//
+// Overloading Matchers
+// ====================
+//
+// You can overload matchers with different numbers of parameters:
+//
+// MATCHER_P(Blah, a, description_string1) { ... }
+// MATCHER_P2(Blah, a, b, description_string2) { ... }
+//
+// Caveats
+// =======
+//
+// When defining a new matcher, you should also consider implementing
+// MatcherInterface or using MakePolymorphicMatcher(). These
+// approaches require more work than the MATCHER* macros, but also
+// give you more control on the types of the value being matched and
+// the matcher parameters, which may leads to better compiler error
+// messages when the matcher is used wrong. They also allow
+// overloading matchers based on parameter types (as opposed to just
+// based on the number of parameters).
+//
+// MATCHER*() can only be used in a namespace scope. The reason is
+// that C++ doesn't yet allow function-local types to be used to
+// instantiate templates. The up-coming C++0x standard will fix this.
+// Once that's done, we'll consider supporting using MATCHER*() inside
+// a function.
+//
+// More Information
+// ================
+//
+// To learn more about using these macros, please search for 'MATCHER'
+// on
+// https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
+
+$range i 0..n
+$for i
+
+[[
+$var macro_name = [[$if i==0 [[MATCHER]] $elif i==1 [[MATCHER_P]]
+ $else [[MATCHER_P$i]]]]
+$var class_name = [[name##Matcher[[$if i==0 [[]] $elif i==1 [[P]]
+ $else [[P$i]]]]]]
+$range j 0..i-1
+$var template = [[$if i==0 [[]] $else [[
+
+ template <$for j, [[typename p$j##_type]]>\
+]]]]
+$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
+$var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
+$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::move(gmock_p$j))]]]]]]
+$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::move(gmock_p$j))]]]]]]
+$var params = [[$for j, [[p$j]]]]
+$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
+$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
+$var param_field_decls = [[$for j
+[[
+
+ p$j##_type const p$j;\
+]]]]
+$var param_field_decls2 = [[$for j
+[[
+
+ p$j##_type const p$j;\
+]]]]
+
+#define $macro_name(name$for j [[, p$j]], description)\$template
+ class $class_name {\
+ public:\
+ template <typename arg_type>\
+ class gmock_Impl : public ::testing::MatcherInterface<\
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
+ public:\
+ [[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\
+ $impl_inits {}\
+ virtual bool MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener) const;\
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(false);\
+ }\
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ *gmock_os << FormatDescription(true);\
+ }\$param_field_decls
+ private:\
+ ::std::string FormatDescription(bool negation) const {\
+ ::std::string gmock_description = (description);\
+ if (!gmock_description.empty()) {\
+ return gmock_description;\
+ }\
+ return ::testing::internal::FormatMatcherDescription(\
+ negation, #name, \
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
+ ::std::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\
+ }\
+ };\
+ template <typename arg_type>\
+ operator ::testing::Matcher<arg_type>() const {\
+ return ::testing::Matcher<arg_type>(\
+ new gmock_Impl<arg_type>($params));\
+ }\
+ [[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {\
+ }\$param_field_decls2
+ private:\
+ };\$template
+ inline $class_name$param_types name($param_types_and_names) {\
+ return $class_name$param_types($params);\
+ }\$template
+ template <typename arg_type>\
+ bool $class_name$param_types::gmock_Impl<arg_type>::MatchAndExplain(\
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
+ const
+]]
+
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements some commonly used argument matchers. More
+// matchers can be defined by the user implementing the
+// MatcherInterface<T> interface if necessary.
+//
+// See googletest/include/gtest/gtest-matchers.h for the definition of class
+// Matcher, class MatcherInterface, and others.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
+
+#include <math.h>
+#include <algorithm>
+#include <initializer_list>
+#include <iterator>
+#include <limits>
+#include <memory>
+#include <ostream> // NOLINT
+#include <sstream>
+#include <string>
+#include <type_traits>
+#include <utility>
+#include <vector>
+#include "gmock/internal/gmock-internal-utils.h"
+#include "gmock/internal/gmock-port.h"
+#include "gtest/gtest.h"
+
+// MSVC warning C5046 is new as of VS2017 version 15.8.
+#if defined(_MSC_VER) && _MSC_VER >= 1915
+#define GMOCK_MAYBE_5046_ 5046
+#else
+#define GMOCK_MAYBE_5046_
+#endif
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(
+ 4251 GMOCK_MAYBE_5046_ /* class A needs to have dll-interface to be used by
+ clients of class B */
+ /* Symbol involving type with internal linkage not defined */)
+
+namespace testing {
+
+// To implement a matcher Foo for type T, define:
+// 1. a class FooMatcherImpl that implements the
+// MatcherInterface<T> interface, and
+// 2. a factory function that creates a Matcher<T> object from a
+// FooMatcherImpl*.
+//
+// The two-level delegation design makes it possible to allow a user
+// to write "v" instead of "Eq(v)" where a Matcher is expected, which
+// is impossible if we pass matchers by pointers. It also eases
+// ownership management as Matcher objects can now be copied like
+// plain values.
+
+// A match result listener that stores the explanation in a string.
+class StringMatchResultListener : public MatchResultListener {
+ public:
+ StringMatchResultListener() : MatchResultListener(&ss_) {}
+
+ // Returns the explanation accumulated so far.
+ std::string str() const { return ss_.str(); }
+
+ // Clears the explanation accumulated so far.
+ void Clear() { ss_.str(""); }
+
+ private:
+ ::std::stringstream ss_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
+};
+
+// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
+// and MUST NOT BE USED IN USER CODE!!!
+namespace internal {
+
+// The MatcherCastImpl class template is a helper for implementing
+// MatcherCast(). We need this helper in order to partially
+// specialize the implementation of MatcherCast() (C++ allows
+// class/struct templates to be partially specialized, but not
+// function templates.).
+
+// This general version is used when MatcherCast()'s argument is a
+// polymorphic matcher (i.e. something that can be converted to a
+// Matcher but is not one yet; for example, Eq(value)) or a value (for
+// example, "hello").
+template <typename T, typename M>
+class MatcherCastImpl {
+ public:
+ static Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
+ // M can be a polymorphic matcher, in which case we want to use
+ // its conversion operator to create Matcher<T>. Or it can be a value
+ // that should be passed to the Matcher<T>'s constructor.
+ //
+ // We can't call Matcher<T>(polymorphic_matcher_or_value) when M is a
+ // polymorphic matcher because it'll be ambiguous if T has an implicit
+ // constructor from M (this usually happens when T has an implicit
+ // constructor from any type).
+ //
+ // It won't work to unconditionally implict_cast
+ // polymorphic_matcher_or_value to Matcher<T> because it won't trigger
+ // a user-defined conversion from M to T if one exists (assuming M is
+ // a value).
+ return CastImpl(
+ polymorphic_matcher_or_value,
+ BooleanConstant<
+ std::is_convertible<M, Matcher<T> >::value>(),
+ BooleanConstant<
+ std::is_convertible<M, T>::value>());
+ }
+
+ private:
+ template <bool Ignore>
+ static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
+ BooleanConstant<true> /* convertible_to_matcher */,
+ BooleanConstant<Ignore>) {
+ // M is implicitly convertible to Matcher<T>, which means that either
+ // M is a polymorphic matcher or Matcher<T> has an implicit constructor
+ // from M. In both cases using the implicit conversion will produce a
+ // matcher.
+ //
+ // Even if T has an implicit constructor from M, it won't be called because
+ // creating Matcher<T> would require a chain of two user-defined conversions
+ // (first to create T from M and then to create Matcher<T> from T).
+ return polymorphic_matcher_or_value;
+ }
+
+ // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
+ // matcher. It's a value of a type implicitly convertible to T. Use direct
+ // initialization to create a matcher.
+ static Matcher<T> CastImpl(
+ const M& value, BooleanConstant<false> /* convertible_to_matcher */,
+ BooleanConstant<true> /* convertible_to_T */) {
+ return Matcher<T>(ImplicitCast_<T>(value));
+ }
+
+ // M can't be implicitly converted to either Matcher<T> or T. Attempt to use
+ // polymorphic matcher Eq(value) in this case.
+ //
+ // Note that we first attempt to perform an implicit cast on the value and
+ // only fall back to the polymorphic Eq() matcher afterwards because the
+ // latter calls bool operator==(const Lhs& lhs, const Rhs& rhs) in the end
+ // which might be undefined even when Rhs is implicitly convertible to Lhs
+ // (e.g. std::pair<const int, int> vs. std::pair<int, int>).
+ //
+ // We don't define this method inline as we need the declaration of Eq().
+ static Matcher<T> CastImpl(
+ const M& value, BooleanConstant<false> /* convertible_to_matcher */,
+ BooleanConstant<false> /* convertible_to_T */);
+};
+
+// This more specialized version is used when MatcherCast()'s argument
+// is already a Matcher. This only compiles when type T can be
+// statically converted to type U.
+template <typename T, typename U>
+class MatcherCastImpl<T, Matcher<U> > {
+ public:
+ static Matcher<T> Cast(const Matcher<U>& source_matcher) {
+ return Matcher<T>(new Impl(source_matcher));
+ }
+
+ private:
+ class Impl : public MatcherInterface<T> {
+ public:
+ explicit Impl(const Matcher<U>& source_matcher)
+ : source_matcher_(source_matcher) {}
+
+ // We delegate the matching logic to the source matcher.
+ bool MatchAndExplain(T x, MatchResultListener* listener) const override {
+ using FromType = typename std::remove_cv<typename std::remove_pointer<
+ typename std::remove_reference<T>::type>::type>::type;
+ using ToType = typename std::remove_cv<typename std::remove_pointer<
+ typename std::remove_reference<U>::type>::type>::type;
+ // Do not allow implicitly converting base*/& to derived*/&.
+ static_assert(
+ // Do not trigger if only one of them is a pointer. That implies a
+ // regular conversion and not a down_cast.
+ (std::is_pointer<typename std::remove_reference<T>::type>::value !=
+ std::is_pointer<typename std::remove_reference<U>::type>::value) ||
+ std::is_same<FromType, ToType>::value ||
+ !std::is_base_of<FromType, ToType>::value,
+ "Can't implicitly convert from <base> to <derived>");
+
+ return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
+ }
+
+ void DescribeTo(::std::ostream* os) const override {
+ source_matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ source_matcher_.DescribeNegationTo(os);
+ }
+
+ private:
+ const Matcher<U> source_matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+};
+
+// This even more specialized version is used for efficiently casting
+// a matcher to its own type.
+template <typename T>
+class MatcherCastImpl<T, Matcher<T> > {
+ public:
+ static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
+};
+
+} // namespace internal
+
+// In order to be safe and clear, casting between different matcher
+// types is done explicitly via MatcherCast<T>(m), which takes a
+// matcher m and returns a Matcher<T>. It compiles only when T can be
+// statically converted to the argument type of m.
+template <typename T, typename M>
+inline Matcher<T> MatcherCast(const M& matcher) {
+ return internal::MatcherCastImpl<T, M>::Cast(matcher);
+}
+
+// Implements SafeMatcherCast().
+//
+// FIXME: The intermediate SafeMatcherCastImpl class was introduced as a
+// workaround for a compiler bug, and can now be removed.
+template <typename T>
+class SafeMatcherCastImpl {
+ public:
+ // This overload handles polymorphic matchers and values only since
+ // monomorphic matchers are handled by the next one.
+ template <typename M>
+ static inline Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
+ return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value);
+ }
+
+ // This overload handles monomorphic matchers.
+ //
+ // In general, if type T can be implicitly converted to type U, we can
+ // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
+ // contravariant): just keep a copy of the original Matcher<U>, convert the
+ // argument from type T to U, and then pass it to the underlying Matcher<U>.
+ // The only exception is when U is a reference and T is not, as the
+ // underlying Matcher<U> may be interested in the argument's address, which
+ // is not preserved in the conversion from T to U.
+ template <typename U>
+ static inline Matcher<T> Cast(const Matcher<U>& matcher) {
+ // Enforce that T can be implicitly converted to U.
+ GTEST_COMPILE_ASSERT_((std::is_convertible<T, U>::value),
+ "T must be implicitly convertible to U");
+ // Enforce that we are not converting a non-reference type T to a reference
+ // type U.
+ GTEST_COMPILE_ASSERT_(
+ internal::is_reference<T>::value || !internal::is_reference<U>::value,
+ cannot_convert_non_reference_arg_to_reference);
+ // In case both T and U are arithmetic types, enforce that the
+ // conversion is not lossy.
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
+ const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
+ const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
+ GTEST_COMPILE_ASSERT_(
+ kTIsOther || kUIsOther ||
+ (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
+ conversion_of_arithmetic_types_must_be_lossless);
+ return MatcherCast<T>(matcher);
+ }
+};
+
+template <typename T, typename M>
+inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
+ return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
+}
+
+// A<T>() returns a matcher that matches any value of type T.
+template <typename T>
+Matcher<T> A();
+
+// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
+// and MUST NOT BE USED IN USER CODE!!!
+namespace internal {
+
+// If the explanation is not empty, prints it to the ostream.
+inline void PrintIfNotEmpty(const std::string& explanation,
+ ::std::ostream* os) {
+ if (explanation != "" && os != nullptr) {
+ *os << ", " << explanation;
+ }
+}
+
+// Returns true if the given type name is easy to read by a human.
+// This is used to decide whether printing the type of a value might
+// be helpful.
+inline bool IsReadableTypeName(const std::string& type_name) {
+ // We consider a type name readable if it's short or doesn't contain
+ // a template or function type.
+ return (type_name.length() <= 20 ||
+ type_name.find_first_of("<(") == std::string::npos);
+}
+
+// Matches the value against the given matcher, prints the value and explains
+// the match result to the listener. Returns the match result.
+// 'listener' must not be NULL.
+// Value cannot be passed by const reference, because some matchers take a
+// non-const argument.
+template <typename Value, typename T>
+bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
+ MatchResultListener* listener) {
+ if (!listener->IsInterested()) {
+ // If the listener is not interested, we do not need to construct the
+ // inner explanation.
+ return matcher.Matches(value);
+ }
+
+ StringMatchResultListener inner_listener;
+ const bool match = matcher.MatchAndExplain(value, &inner_listener);
+
+ UniversalPrint(value, listener->stream());
+#if GTEST_HAS_RTTI
+ const std::string& type_name = GetTypeName<Value>();
+ if (IsReadableTypeName(type_name))
+ *listener->stream() << " (of type " << type_name << ")";
+#endif
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
+
+ return match;
+}
+
+// An internal helper class for doing compile-time loop on a tuple's
+// fields.
+template <size_t N>
+class TuplePrefix {
+ public:
+ // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true
+ // iff the first N fields of matcher_tuple matches the first N
+ // fields of value_tuple, respectively.
+ template <typename MatcherTuple, typename ValueTuple>
+ static bool Matches(const MatcherTuple& matcher_tuple,
+ const ValueTuple& value_tuple) {
+ return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple) &&
+ std::get<N - 1>(matcher_tuple).Matches(std::get<N - 1>(value_tuple));
+ }
+
+ // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os)
+ // describes failures in matching the first N fields of matchers
+ // against the first N fields of values. If there is no failure,
+ // nothing will be streamed to os.
+ template <typename MatcherTuple, typename ValueTuple>
+ static void ExplainMatchFailuresTo(const MatcherTuple& matchers,
+ const ValueTuple& values,
+ ::std::ostream* os) {
+ // First, describes failures in the first N - 1 fields.
+ TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
+
+ // Then describes the failure (if any) in the (N - 1)-th (0-based)
+ // field.
+ typename std::tuple_element<N - 1, MatcherTuple>::type matcher =
+ std::get<N - 1>(matchers);
+ typedef typename std::tuple_element<N - 1, ValueTuple>::type Value;
+ const Value& value = std::get<N - 1>(values);
+ StringMatchResultListener listener;
+ if (!matcher.MatchAndExplain(value, &listener)) {
+ *os << " Expected arg #" << N - 1 << ": ";
+ std::get<N - 1>(matchers).DescribeTo(os);
+ *os << "\n Actual: ";
+ // We remove the reference in type Value to prevent the
+ // universal printer from printing the address of value, which
+ // isn't interesting to the user most of the time. The
+ // matcher's MatchAndExplain() method handles the case when
+ // the address is interesting.
+ internal::UniversalPrint(value, os);
+ PrintIfNotEmpty(listener.str(), os);
+ *os << "\n";
+ }
+ }
+};
+
+// The base case.
+template <>
+class TuplePrefix<0> {
+ public:
+ template <typename MatcherTuple, typename ValueTuple>
+ static bool Matches(const MatcherTuple& /* matcher_tuple */,
+ const ValueTuple& /* value_tuple */) {
+ return true;
+ }
+
+ template <typename MatcherTuple, typename ValueTuple>
+ static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */,
+ const ValueTuple& /* values */,
+ ::std::ostream* /* os */) {}
+};
+
+// TupleMatches(matcher_tuple, value_tuple) returns true iff all
+// matchers in matcher_tuple match the corresponding fields in
+// value_tuple. It is a compiler error if matcher_tuple and
+// value_tuple have different number of fields or incompatible field
+// types.
+template <typename MatcherTuple, typename ValueTuple>
+bool TupleMatches(const MatcherTuple& matcher_tuple,
+ const ValueTuple& value_tuple) {
+ // Makes sure that matcher_tuple and value_tuple have the same
+ // number of fields.
+ GTEST_COMPILE_ASSERT_(std::tuple_size<MatcherTuple>::value ==
+ std::tuple_size<ValueTuple>::value,
+ matcher_and_value_have_different_numbers_of_fields);
+ return TuplePrefix<std::tuple_size<ValueTuple>::value>::Matches(matcher_tuple,
+ value_tuple);
+}
+
+// Describes failures in matching matchers against values. If there
+// is no failure, nothing will be streamed to os.
+template <typename MatcherTuple, typename ValueTuple>
+void ExplainMatchFailureTupleTo(const MatcherTuple& matchers,
+ const ValueTuple& values,
+ ::std::ostream* os) {
+ TuplePrefix<std::tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo(
+ matchers, values, os);
+}
+
+// TransformTupleValues and its helper.
+//
+// TransformTupleValuesHelper hides the internal machinery that
+// TransformTupleValues uses to implement a tuple traversal.
+template <typename Tuple, typename Func, typename OutIter>
+class TransformTupleValuesHelper {
+ private:
+ typedef ::std::tuple_size<Tuple> TupleSize;
+
+ public:
+ // For each member of tuple 't', taken in order, evaluates '*out++ = f(t)'.
+ // Returns the final value of 'out' in case the caller needs it.
+ static OutIter Run(Func f, const Tuple& t, OutIter out) {
+ return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out);
+ }
+
+ private:
+ template <typename Tup, size_t kRemainingSize>
+ struct IterateOverTuple {
+ OutIter operator() (Func f, const Tup& t, OutIter out) const {
+ *out++ = f(::std::get<TupleSize::value - kRemainingSize>(t));
+ return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out);
+ }
+ };
+ template <typename Tup>
+ struct IterateOverTuple<Tup, 0> {
+ OutIter operator() (Func /* f */, const Tup& /* t */, OutIter out) const {
+ return out;
+ }
+ };
+};
+
+// Successively invokes 'f(element)' on each element of the tuple 't',
+// appending each result to the 'out' iterator. Returns the final value
+// of 'out'.
+template <typename Tuple, typename Func, typename OutIter>
+OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
+ return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out);
+}
+
+// Implements A<T>().
+template <typename T>
+class AnyMatcherImpl : public MatcherInterface<const T&> {
+ public:
+ bool MatchAndExplain(const T& /* x */,
+ MatchResultListener* /* listener */) const override {
+ return true;
+ }
+ void DescribeTo(::std::ostream* os) const override { *os << "is anything"; }
+ void DescribeNegationTo(::std::ostream* os) const override {
+ // This is mostly for completeness' safe, as it's not very useful
+ // to write Not(A<bool>()). However we cannot completely rule out
+ // such a possibility, and it doesn't hurt to be prepared.
+ *os << "never matches";
+ }
+};
+
+// Implements _, a matcher that matches any value of any
+// type. This is a polymorphic matcher, so we need a template type
+// conversion operator to make it appearing as a Matcher<T> for any
+// type T.
+class AnythingMatcher {
+ public:
+ template <typename T>
+ operator Matcher<T>() const { return A<T>(); }
+};
+
+// Implements the polymorphic IsNull() matcher, which matches any raw or smart
+// pointer that is NULL.
+class IsNullMatcher {
+ public:
+ template <typename Pointer>
+ bool MatchAndExplain(const Pointer& p,
+ MatchResultListener* /* listener */) const {
+ return p == nullptr;
+ }
+
+ void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "isn't NULL";
+ }
+};
+
+// Implements the polymorphic NotNull() matcher, which matches any raw or smart
+// pointer that is not NULL.
+class NotNullMatcher {
+ public:
+ template <typename Pointer>
+ bool MatchAndExplain(const Pointer& p,
+ MatchResultListener* /* listener */) const {
+ return p != nullptr;
+ }
+
+ void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "is NULL";
+ }
+};
+
+// Ref(variable) matches any argument that is a reference to
+// 'variable'. This matcher is polymorphic as it can match any
+// super type of the type of 'variable'.
+//
+// The RefMatcher template class implements Ref(variable). It can
+// only be instantiated with a reference type. This prevents a user
+// from mistakenly using Ref(x) to match a non-reference function
+// argument. For example, the following will righteously cause a
+// compiler error:
+//
+// int n;
+// Matcher<int> m1 = Ref(n); // This won't compile.
+// Matcher<int&> m2 = Ref(n); // This will compile.
+template <typename T>
+class RefMatcher;
+
+template <typename T>
+class RefMatcher<T&> {
+ // Google Mock is a generic framework and thus needs to support
+ // mocking any function types, including those that take non-const
+ // reference arguments. Therefore the template parameter T (and
+ // Super below) can be instantiated to either a const type or a
+ // non-const type.
+ public:
+ // RefMatcher() takes a T& instead of const T&, as we want the
+ // compiler to catch using Ref(const_value) as a matcher for a
+ // non-const reference.
+ explicit RefMatcher(T& x) : object_(x) {} // NOLINT
+
+ template <typename Super>
+ operator Matcher<Super&>() const {
+ // By passing object_ (type T&) to Impl(), which expects a Super&,
+ // we make sure that Super is a super type of T. In particular,
+ // this catches using Ref(const_value) as a matcher for a
+ // non-const reference, as you cannot implicitly convert a const
+ // reference to a non-const reference.
+ return MakeMatcher(new Impl<Super>(object_));
+ }
+
+ private:
+ template <typename Super>
+ class Impl : public MatcherInterface<Super&> {
+ public:
+ explicit Impl(Super& x) : object_(x) {} // NOLINT
+
+ // MatchAndExplain() takes a Super& (as opposed to const Super&)
+ // in order to match the interface MatcherInterface<Super&>.
+ bool MatchAndExplain(Super& x,
+ MatchResultListener* listener) const override {
+ *listener << "which is located @" << static_cast<const void*>(&x);
+ return &x == &object_;
+ }
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "references the variable ";
+ UniversalPrinter<Super&>::Print(object_, os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "does not reference the variable ";
+ UniversalPrinter<Super&>::Print(object_, os);
+ }
+
+ private:
+ const Super& object_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ T& object_;
+
+ GTEST_DISALLOW_ASSIGN_(RefMatcher);
+};
+
+// Polymorphic helper functions for narrow and wide string matchers.
+inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) {
+ return String::CaseInsensitiveCStringEquals(lhs, rhs);
+}
+
+inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs,
+ const wchar_t* rhs) {
+ return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
+}
+
+// String comparison for narrow or wide strings that can have embedded NUL
+// characters.
+template <typename StringType>
+bool CaseInsensitiveStringEquals(const StringType& s1,
+ const StringType& s2) {
+ // Are the heads equal?
+ if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) {
+ return false;
+ }
+
+ // Skip the equal heads.
+ const typename StringType::value_type nul = 0;
+ const size_t i1 = s1.find(nul), i2 = s2.find(nul);
+
+ // Are we at the end of either s1 or s2?
+ if (i1 == StringType::npos || i2 == StringType::npos) {
+ return i1 == i2;
+ }
+
+ // Are the tails equal?
+ return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1));
+}
+
+// String matchers.
+
+// Implements equality-based string matchers like StrEq, StrCaseNe, and etc.
+template <typename StringType>
+class StrEqualityMatcher {
+ public:
+ StrEqualityMatcher(const StringType& str, bool expect_eq,
+ bool case_sensitive)
+ : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
+
+#if GTEST_HAS_ABSL
+ bool MatchAndExplain(const absl::string_view& s,
+ MatchResultListener* listener) const {
+ // This should fail to compile if absl::string_view is used with wide
+ // strings.
+ const StringType& str = std::string(s);
+ return MatchAndExplain(str, listener);
+ }
+#endif // GTEST_HAS_ABSL
+
+ // Accepts pointer types, particularly:
+ // const char*
+ // char*
+ // const wchar_t*
+ // wchar_t*
+ template <typename CharType>
+ bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
+ if (s == nullptr) {
+ return !expect_eq_;
+ }
+ return MatchAndExplain(StringType(s), listener);
+ }
+
+ // Matches anything that can convert to StringType.
+ //
+ // This is a template, not just a plain function with const StringType&,
+ // because absl::string_view has some interfering non-explicit constructors.
+ template <typename MatcheeStringType>
+ bool MatchAndExplain(const MatcheeStringType& s,
+ MatchResultListener* /* listener */) const {
+ const StringType& s2(s);
+ const bool eq = case_sensitive_ ? s2 == string_ :
+ CaseInsensitiveStringEquals(s2, string_);
+ return expect_eq_ == eq;
+ }
+
+ void DescribeTo(::std::ostream* os) const {
+ DescribeToHelper(expect_eq_, os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const {
+ DescribeToHelper(!expect_eq_, os);
+ }
+
+ private:
+ void DescribeToHelper(bool expect_eq, ::std::ostream* os) const {
+ *os << (expect_eq ? "is " : "isn't ");
+ *os << "equal to ";
+ if (!case_sensitive_) {
+ *os << "(ignoring case) ";
+ }
+ UniversalPrint(string_, os);
+ }
+
+ const StringType string_;
+ const bool expect_eq_;
+ const bool case_sensitive_;
+
+ GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher);
+};
+
+// Implements the polymorphic HasSubstr(substring) matcher, which
+// can be used as a Matcher<T> as long as T can be converted to a
+// string.
+template <typename StringType>
+class HasSubstrMatcher {
+ public:
+ explicit HasSubstrMatcher(const StringType& substring)
+ : substring_(substring) {}
+
+#if GTEST_HAS_ABSL
+ bool MatchAndExplain(const absl::string_view& s,
+ MatchResultListener* listener) const {
+ // This should fail to compile if absl::string_view is used with wide
+ // strings.
+ const StringType& str = std::string(s);
+ return MatchAndExplain(str, listener);
+ }
+#endif // GTEST_HAS_ABSL
+
+ // Accepts pointer types, particularly:
+ // const char*
+ // char*
+ // const wchar_t*
+ // wchar_t*
+ template <typename CharType>
+ bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
+ return s != nullptr && MatchAndExplain(StringType(s), listener);
+ }
+
+ // Matches anything that can convert to StringType.
+ //
+ // This is a template, not just a plain function with const StringType&,
+ // because absl::string_view has some interfering non-explicit constructors.
+ template <typename MatcheeStringType>
+ bool MatchAndExplain(const MatcheeStringType& s,
+ MatchResultListener* /* listener */) const {
+ const StringType& s2(s);
+ return s2.find(substring_) != StringType::npos;
+ }
+
+ // Describes what this matcher matches.
+ void DescribeTo(::std::ostream* os) const {
+ *os << "has substring ";
+ UniversalPrint(substring_, os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "has no substring ";
+ UniversalPrint(substring_, os);
+ }
+
+ private:
+ const StringType substring_;
+
+ GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher);
+};
+
+// Implements the polymorphic StartsWith(substring) matcher, which
+// can be used as a Matcher<T> as long as T can be converted to a
+// string.
+template <typename StringType>
+class StartsWithMatcher {
+ public:
+ explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
+ }
+
+#if GTEST_HAS_ABSL
+ bool MatchAndExplain(const absl::string_view& s,
+ MatchResultListener* listener) const {
+ // This should fail to compile if absl::string_view is used with wide
+ // strings.
+ const StringType& str = std::string(s);
+ return MatchAndExplain(str, listener);
+ }
+#endif // GTEST_HAS_ABSL
+
+ // Accepts pointer types, particularly:
+ // const char*
+ // char*
+ // const wchar_t*
+ // wchar_t*
+ template <typename CharType>
+ bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
+ return s != nullptr && MatchAndExplain(StringType(s), listener);
+ }
+
+ // Matches anything that can convert to StringType.
+ //
+ // This is a template, not just a plain function with const StringType&,
+ // because absl::string_view has some interfering non-explicit constructors.
+ template <typename MatcheeStringType>
+ bool MatchAndExplain(const MatcheeStringType& s,
+ MatchResultListener* /* listener */) const {
+ const StringType& s2(s);
+ return s2.length() >= prefix_.length() &&
+ s2.substr(0, prefix_.length()) == prefix_;
+ }
+
+ void DescribeTo(::std::ostream* os) const {
+ *os << "starts with ";
+ UniversalPrint(prefix_, os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "doesn't start with ";
+ UniversalPrint(prefix_, os);
+ }
+
+ private:
+ const StringType prefix_;
+
+ GTEST_DISALLOW_ASSIGN_(StartsWithMatcher);
+};
+
+// Implements the polymorphic EndsWith(substring) matcher, which
+// can be used as a Matcher<T> as long as T can be converted to a
+// string.
+template <typename StringType>
+class EndsWithMatcher {
+ public:
+ explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
+
+#if GTEST_HAS_ABSL
+ bool MatchAndExplain(const absl::string_view& s,
+ MatchResultListener* listener) const {
+ // This should fail to compile if absl::string_view is used with wide
+ // strings.
+ const StringType& str = std::string(s);
+ return MatchAndExplain(str, listener);
+ }
+#endif // GTEST_HAS_ABSL
+
+ // Accepts pointer types, particularly:
+ // const char*
+ // char*
+ // const wchar_t*
+ // wchar_t*
+ template <typename CharType>
+ bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
+ return s != nullptr && MatchAndExplain(StringType(s), listener);
+ }
+
+ // Matches anything that can convert to StringType.
+ //
+ // This is a template, not just a plain function with const StringType&,
+ // because absl::string_view has some interfering non-explicit constructors.
+ template <typename MatcheeStringType>
+ bool MatchAndExplain(const MatcheeStringType& s,
+ MatchResultListener* /* listener */) const {
+ const StringType& s2(s);
+ return s2.length() >= suffix_.length() &&
+ s2.substr(s2.length() - suffix_.length()) == suffix_;
+ }
+
+ void DescribeTo(::std::ostream* os) const {
+ *os << "ends with ";
+ UniversalPrint(suffix_, os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "doesn't end with ";
+ UniversalPrint(suffix_, os);
+ }
+
+ private:
+ const StringType suffix_;
+
+ GTEST_DISALLOW_ASSIGN_(EndsWithMatcher);
+};
+
+// Implements a matcher that compares the two fields of a 2-tuple
+// using one of the ==, <=, <, etc, operators. The two fields being
+// compared don't have to have the same type.
+//
+// The matcher defined here is polymorphic (for example, Eq() can be
+// used to match a std::tuple<int, short>, a std::tuple<const long&, double>,
+// etc). Therefore we use a template type conversion operator in the
+// implementation.
+template <typename D, typename Op>
+class PairMatchBase {
+ public:
+ template <typename T1, typename T2>
+ operator Matcher<::std::tuple<T1, T2>>() const {
+ return Matcher<::std::tuple<T1, T2>>(new Impl<const ::std::tuple<T1, T2>&>);
+ }
+ template <typename T1, typename T2>
+ operator Matcher<const ::std::tuple<T1, T2>&>() const {
+ return MakeMatcher(new Impl<const ::std::tuple<T1, T2>&>);
+ }
+
+ private:
+ static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT
+ return os << D::Desc();
+ }
+
+ template <typename Tuple>
+ class Impl : public MatcherInterface<Tuple> {
+ public:
+ bool MatchAndExplain(Tuple args,
+ MatchResultListener* /* listener */) const override {
+ return Op()(::std::get<0>(args), ::std::get<1>(args));
+ }
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "are " << GetDesc;
+ }
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "aren't " << GetDesc;
+ }
+ };
+};
+
+class Eq2Matcher : public PairMatchBase<Eq2Matcher, AnyEq> {
+ public:
+ static const char* Desc() { return "an equal pair"; }
+};
+class Ne2Matcher : public PairMatchBase<Ne2Matcher, AnyNe> {
+ public:
+ static const char* Desc() { return "an unequal pair"; }
+};
+class Lt2Matcher : public PairMatchBase<Lt2Matcher, AnyLt> {
+ public:
+ static const char* Desc() { return "a pair where the first < the second"; }
+};
+class Gt2Matcher : public PairMatchBase<Gt2Matcher, AnyGt> {
+ public:
+ static const char* Desc() { return "a pair where the first > the second"; }
+};
+class Le2Matcher : public PairMatchBase<Le2Matcher, AnyLe> {
+ public:
+ static const char* Desc() { return "a pair where the first <= the second"; }
+};
+class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
+ public:
+ static const char* Desc() { return "a pair where the first >= the second"; }
+};
+
+// Implements the Not(...) matcher for a particular argument type T.
+// We do not nest it inside the NotMatcher class template, as that
+// will prevent different instantiations of NotMatcher from sharing
+// the same NotMatcherImpl<T> class.
+template <typename T>
+class NotMatcherImpl : public MatcherInterface<const T&> {
+ public:
+ explicit NotMatcherImpl(const Matcher<T>& matcher)
+ : matcher_(matcher) {}
+
+ bool MatchAndExplain(const T& x,
+ MatchResultListener* listener) const override {
+ return !matcher_.MatchAndExplain(x, listener);
+ }
+
+ void DescribeTo(::std::ostream* os) const override {
+ matcher_.DescribeNegationTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ matcher_.DescribeTo(os);
+ }
+
+ private:
+ const Matcher<T> matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(NotMatcherImpl);
+};
+
+// Implements the Not(m) matcher, which matches a value that doesn't
+// match matcher m.
+template <typename InnerMatcher>
+class NotMatcher {
+ public:
+ explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
+
+ // This template type conversion operator allows Not(m) to be used
+ // to match any type m can match.
+ template <typename T>
+ operator Matcher<T>() const {
+ return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
+ }
+
+ private:
+ InnerMatcher matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(NotMatcher);
+};
+
+// Implements the AllOf(m1, m2) matcher for a particular argument type
+// T. We do not nest it inside the BothOfMatcher class template, as
+// that will prevent different instantiations of BothOfMatcher from
+// sharing the same BothOfMatcherImpl<T> class.
+template <typename T>
+class AllOfMatcherImpl : public MatcherInterface<const T&> {
+ public:
+ explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers)
+ : matchers_(std::move(matchers)) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "(";
+ for (size_t i = 0; i < matchers_.size(); ++i) {
+ if (i != 0) *os << ") and (";
+ matchers_[i].DescribeTo(os);
+ }
+ *os << ")";
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "(";
+ for (size_t i = 0; i < matchers_.size(); ++i) {
+ if (i != 0) *os << ") or (";
+ matchers_[i].DescribeNegationTo(os);
+ }
+ *os << ")";
+ }
+
+ bool MatchAndExplain(const T& x,
+ MatchResultListener* listener) const override {
+ // If either matcher1_ or matcher2_ doesn't match x, we only need
+ // to explain why one of them fails.
+ std::string all_match_result;
+
+ for (size_t i = 0; i < matchers_.size(); ++i) {
+ StringMatchResultListener slistener;
+ if (matchers_[i].MatchAndExplain(x, &slistener)) {
+ if (all_match_result.empty()) {
+ all_match_result = slistener.str();
+ } else {
+ std::string result = slistener.str();
+ if (!result.empty()) {
+ all_match_result += ", and ";
+ all_match_result += result;
+ }
+ }
+ } else {
+ *listener << slistener.str();
+ return false;
+ }
+ }
+
+ // Otherwise we need to explain why *both* of them match.
+ *listener << all_match_result;
+ return true;
+ }
+
+ private:
+ const std::vector<Matcher<T> > matchers_;
+
+ GTEST_DISALLOW_ASSIGN_(AllOfMatcherImpl);
+};
+
+// VariadicMatcher is used for the variadic implementation of
+// AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
+// CombiningMatcher<T> is used to recursively combine the provided matchers
+// (of type Args...).
+template <template <typename T> class CombiningMatcher, typename... Args>
+class VariadicMatcher {
+ public:
+ VariadicMatcher(const Args&... matchers) // NOLINT
+ : matchers_(matchers...) {
+ static_assert(sizeof...(Args) > 0, "Must have at least one matcher.");
+ }
+
+ // This template type conversion operator allows an
+ // VariadicMatcher<Matcher1, Matcher2...> object to match any type that
+ // all of the provided matchers (Matcher1, Matcher2, ...) can match.
+ template <typename T>
+ operator Matcher<T>() const {
+ std::vector<Matcher<T> > values;
+ CreateVariadicMatcher<T>(&values, std::integral_constant<size_t, 0>());
+ return Matcher<T>(new CombiningMatcher<T>(std::move(values)));
+ }
+
+ private:
+ template <typename T, size_t I>
+ void CreateVariadicMatcher(std::vector<Matcher<T> >* values,
+ std::integral_constant<size_t, I>) const {
+ values->push_back(SafeMatcherCast<T>(std::get<I>(matchers_)));
+ CreateVariadicMatcher<T>(values, std::integral_constant<size_t, I + 1>());
+ }
+
+ template <typename T>
+ void CreateVariadicMatcher(
+ std::vector<Matcher<T> >*,
+ std::integral_constant<size_t, sizeof...(Args)>) const {}
+
+ std::tuple<Args...> matchers_;
+
+ GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
+};
+
+template <typename... Args>
+using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>;
+
+// Implements the AnyOf(m1, m2) matcher for a particular argument type
+// T. We do not nest it inside the AnyOfMatcher class template, as
+// that will prevent different instantiations of AnyOfMatcher from
+// sharing the same EitherOfMatcherImpl<T> class.
+template <typename T>
+class AnyOfMatcherImpl : public MatcherInterface<const T&> {
+ public:
+ explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers)
+ : matchers_(std::move(matchers)) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "(";
+ for (size_t i = 0; i < matchers_.size(); ++i) {
+ if (i != 0) *os << ") or (";
+ matchers_[i].DescribeTo(os);
+ }
+ *os << ")";
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "(";
+ for (size_t i = 0; i < matchers_.size(); ++i) {
+ if (i != 0) *os << ") and (";
+ matchers_[i].DescribeNegationTo(os);
+ }
+ *os << ")";
+ }
+
+ bool MatchAndExplain(const T& x,
+ MatchResultListener* listener) const override {
+ std::string no_match_result;
+
+ // If either matcher1_ or matcher2_ matches x, we just need to
+ // explain why *one* of them matches.
+ for (size_t i = 0; i < matchers_.size(); ++i) {
+ StringMatchResultListener slistener;
+ if (matchers_[i].MatchAndExplain(x, &slistener)) {
+ *listener << slistener.str();
+ return true;
+ } else {
+ if (no_match_result.empty()) {
+ no_match_result = slistener.str();
+ } else {
+ std::string result = slistener.str();
+ if (!result.empty()) {
+ no_match_result += ", and ";
+ no_match_result += result;
+ }
+ }
+ }
+ }
+
+ // Otherwise we need to explain why *both* of them fail.
+ *listener << no_match_result;
+ return false;
+ }
+
+ private:
+ const std::vector<Matcher<T> > matchers_;
+
+ GTEST_DISALLOW_ASSIGN_(AnyOfMatcherImpl);
+};
+
+// AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
+template <typename... Args>
+using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>;
+
+// Wrapper for implementation of Any/AllOfArray().
+template <template <class> class MatcherImpl, typename T>
+class SomeOfArrayMatcher {
+ public:
+ // Constructs the matcher from a sequence of element values or
+ // element matchers.
+ template <typename Iter>
+ SomeOfArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
+
+ template <typename U>
+ operator Matcher<U>() const { // NOLINT
+ using RawU = typename std::decay<U>::type;
+ std::vector<Matcher<RawU>> matchers;
+ for (const auto& matcher : matchers_) {
+ matchers.push_back(MatcherCast<RawU>(matcher));
+ }
+ return Matcher<U>(new MatcherImpl<RawU>(std::move(matchers)));
+ }
+
+ private:
+ const ::std::vector<T> matchers_;
+
+ GTEST_DISALLOW_ASSIGN_(SomeOfArrayMatcher);
+};
+
+template <typename T>
+using AllOfArrayMatcher = SomeOfArrayMatcher<AllOfMatcherImpl, T>;
+
+template <typename T>
+using AnyOfArrayMatcher = SomeOfArrayMatcher<AnyOfMatcherImpl, T>;
+
+// Used for implementing Truly(pred), which turns a predicate into a
+// matcher.
+template <typename Predicate>
+class TrulyMatcher {
+ public:
+ explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
+
+ // This method template allows Truly(pred) to be used as a matcher
+ // for type T where T is the argument type of predicate 'pred'. The
+ // argument is passed by reference as the predicate may be
+ // interested in the address of the argument.
+ template <typename T>
+ bool MatchAndExplain(T& x, // NOLINT
+ MatchResultListener* /* listener */) const {
+ // Without the if-statement, MSVC sometimes warns about converting
+ // a value to bool (warning 4800).
+ //
+ // We cannot write 'return !!predicate_(x);' as that doesn't work
+ // when predicate_(x) returns a class convertible to bool but
+ // having no operator!().
+ if (predicate_(x))
+ return true;
+ return false;
+ }
+
+ void DescribeTo(::std::ostream* os) const {
+ *os << "satisfies the given predicate";
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "doesn't satisfy the given predicate";
+ }
+
+ private:
+ Predicate predicate_;
+
+ GTEST_DISALLOW_ASSIGN_(TrulyMatcher);
+};
+
+// Used for implementing Matches(matcher), which turns a matcher into
+// a predicate.
+template <typename M>
+class MatcherAsPredicate {
+ public:
+ explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
+
+ // This template operator() allows Matches(m) to be used as a
+ // predicate on type T where m is a matcher on type T.
+ //
+ // The argument x is passed by reference instead of by value, as
+ // some matcher may be interested in its address (e.g. as in
+ // Matches(Ref(n))(x)).
+ template <typename T>
+ bool operator()(const T& x) const {
+ // We let matcher_ commit to a particular type here instead of
+ // when the MatcherAsPredicate object was constructed. This
+ // allows us to write Matches(m) where m is a polymorphic matcher
+ // (e.g. Eq(5)).
+ //
+ // If we write Matcher<T>(matcher_).Matches(x) here, it won't
+ // compile when matcher_ has type Matcher<const T&>; if we write
+ // Matcher<const T&>(matcher_).Matches(x) here, it won't compile
+ // when matcher_ has type Matcher<T>; if we just write
+ // matcher_.Matches(x), it won't compile when matcher_ is
+ // polymorphic, e.g. Eq(5).
+ //
+ // MatcherCast<const T&>() is necessary for making the code work
+ // in all of the above situations.
+ return MatcherCast<const T&>(matcher_).Matches(x);
+ }
+
+ private:
+ M matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate);
+};
+
+// For implementing ASSERT_THAT() and EXPECT_THAT(). The template
+// argument M must be a type that can be converted to a matcher.
+template <typename M>
+class PredicateFormatterFromMatcher {
+ public:
+ explicit PredicateFormatterFromMatcher(M m) : matcher_(std::move(m)) {}
+
+ // This template () operator allows a PredicateFormatterFromMatcher
+ // object to act as a predicate-formatter suitable for using with
+ // Google Test's EXPECT_PRED_FORMAT1() macro.
+ template <typename T>
+ AssertionResult operator()(const char* value_text, const T& x) const {
+ // We convert matcher_ to a Matcher<const T&> *now* instead of
+ // when the PredicateFormatterFromMatcher object was constructed,
+ // as matcher_ may be polymorphic (e.g. NotNull()) and we won't
+ // know which type to instantiate it to until we actually see the
+ // type of x here.
+ //
+ // We write SafeMatcherCast<const T&>(matcher_) instead of
+ // Matcher<const T&>(matcher_), as the latter won't compile when
+ // matcher_ has type Matcher<T> (e.g. An<int>()).
+ // We don't write MatcherCast<const T&> either, as that allows
+ // potentially unsafe downcasting of the matcher argument.
+ const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
+
+ // The expected path here is that the matcher should match (i.e. that most
+ // tests pass) so optimize for this case.
+ if (matcher.Matches(x)) {
+ return AssertionSuccess();
+ }
+
+ ::std::stringstream ss;
+ ss << "Value of: " << value_text << "\n"
+ << "Expected: ";
+ matcher.DescribeTo(&ss);
+
+ // Rerun the matcher to "PrintAndExain" the failure.
+ StringMatchResultListener listener;
+ if (MatchPrintAndExplain(x, matcher, &listener)) {
+ ss << "\n The matcher failed on the initial attempt; but passed when "
+ "rerun to generate the explanation.";
+ }
+ ss << "\n Actual: " << listener.str();
+ return AssertionFailure() << ss.str();
+ }
+
+ private:
+ const M matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher);
+};
+
+// A helper function for converting a matcher to a predicate-formatter
+// without the user needing to explicitly write the type. This is
+// used for implementing ASSERT_THAT() and EXPECT_THAT().
+// Implementation detail: 'matcher' is received by-value to force decaying.
+template <typename M>
+inline PredicateFormatterFromMatcher<M>
+MakePredicateFormatterFromMatcher(M matcher) {
+ return PredicateFormatterFromMatcher<M>(std::move(matcher));
+}
+
+// Implements the polymorphic floating point equality matcher, which matches
+// two float values using ULP-based approximation or, optionally, a
+// user-specified epsilon. The template is meant to be instantiated with
+// FloatType being either float or double.
+template <typename FloatType>
+class FloatingEqMatcher {
+ public:
+ // Constructor for FloatingEqMatcher.
+ // The matcher's input will be compared with expected. The matcher treats two
+ // NANs as equal if nan_eq_nan is true. Otherwise, under IEEE standards,
+ // equality comparisons between NANs will always return false. We specify a
+ // negative max_abs_error_ term to indicate that ULP-based approximation will
+ // be used for comparison.
+ FloatingEqMatcher(FloatType expected, bool nan_eq_nan) :
+ expected_(expected), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) {
+ }
+
+ // Constructor that supports a user-specified max_abs_error that will be used
+ // for comparison instead of ULP-based approximation. The max absolute
+ // should be non-negative.
+ FloatingEqMatcher(FloatType expected, bool nan_eq_nan,
+ FloatType max_abs_error)
+ : expected_(expected),
+ nan_eq_nan_(nan_eq_nan),
+ max_abs_error_(max_abs_error) {
+ GTEST_CHECK_(max_abs_error >= 0)
+ << ", where max_abs_error is" << max_abs_error;
+ }
+
+ // Implements floating point equality matcher as a Matcher<T>.
+ template <typename T>
+ class Impl : public MatcherInterface<T> {
+ public:
+ Impl(FloatType expected, bool nan_eq_nan, FloatType max_abs_error)
+ : expected_(expected),
+ nan_eq_nan_(nan_eq_nan),
+ max_abs_error_(max_abs_error) {}
+
+ bool MatchAndExplain(T value,
+ MatchResultListener* listener) const override {
+ const FloatingPoint<FloatType> actual(value), expected(expected_);
+
+ // Compares NaNs first, if nan_eq_nan_ is true.
+ if (actual.is_nan() || expected.is_nan()) {
+ if (actual.is_nan() && expected.is_nan()) {
+ return nan_eq_nan_;
+ }
+ // One is nan; the other is not nan.
+ return false;
+ }
+ if (HasMaxAbsError()) {
+ // We perform an equality check so that inf will match inf, regardless
+ // of error bounds. If the result of value - expected_ would result in
+ // overflow or if either value is inf, the default result is infinity,
+ // which should only match if max_abs_error_ is also infinity.
+ if (value == expected_) {
+ return true;
+ }
+
+ const FloatType diff = value - expected_;
+ if (fabs(diff) <= max_abs_error_) {
+ return true;
+ }
+
+ if (listener->IsInterested()) {
+ *listener << "which is " << diff << " from " << expected_;
+ }
+ return false;
+ } else {
+ return actual.AlmostEquals(expected);
+ }
+ }
+
+ void DescribeTo(::std::ostream* os) const override {
+ // os->precision() returns the previously set precision, which we
+ // store to restore the ostream to its original configuration
+ // after outputting.
+ const ::std::streamsize old_precision = os->precision(
+ ::std::numeric_limits<FloatType>::digits10 + 2);
+ if (FloatingPoint<FloatType>(expected_).is_nan()) {
+ if (nan_eq_nan_) {
+ *os << "is NaN";
+ } else {
+ *os << "never matches";
+ }
+ } else {
+ *os << "is approximately " << expected_;
+ if (HasMaxAbsError()) {
+ *os << " (absolute error <= " << max_abs_error_ << ")";
+ }
+ }
+ os->precision(old_precision);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ // As before, get original precision.
+ const ::std::streamsize old_precision = os->precision(
+ ::std::numeric_limits<FloatType>::digits10 + 2);
+ if (FloatingPoint<FloatType>(expected_).is_nan()) {
+ if (nan_eq_nan_) {
+ *os << "isn't NaN";
+ } else {
+ *os << "is anything";
+ }
+ } else {
+ *os << "isn't approximately " << expected_;
+ if (HasMaxAbsError()) {
+ *os << " (absolute error > " << max_abs_error_ << ")";
+ }
+ }
+ // Restore original precision.
+ os->precision(old_precision);
+ }
+
+ private:
+ bool HasMaxAbsError() const {
+ return max_abs_error_ >= 0;
+ }
+
+ const FloatType expected_;
+ const bool nan_eq_nan_;
+ // max_abs_error will be used for value comparison when >= 0.
+ const FloatType max_abs_error_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ // The following 3 type conversion operators allow FloatEq(expected) and
+ // NanSensitiveFloatEq(expected) to be used as a Matcher<float>, a
+ // Matcher<const float&>, or a Matcher<float&>, but nothing else.
+ // (While Google's C++ coding style doesn't allow arguments passed
+ // by non-const reference, we may see them in code not conforming to
+ // the style. Therefore Google Mock needs to support them.)
+ operator Matcher<FloatType>() const {
+ return MakeMatcher(
+ new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_));
+ }
+
+ operator Matcher<const FloatType&>() const {
+ return MakeMatcher(
+ new Impl<const FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
+ }
+
+ operator Matcher<FloatType&>() const {
+ return MakeMatcher(
+ new Impl<FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
+ }
+
+ private:
+ const FloatType expected_;
+ const bool nan_eq_nan_;
+ // max_abs_error will be used for value comparison when >= 0.
+ const FloatType max_abs_error_;
+
+ GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher);
+};
+
+// A 2-tuple ("binary") wrapper around FloatingEqMatcher:
+// FloatingEq2Matcher() matches (x, y) by matching FloatingEqMatcher(x, false)
+// against y, and FloatingEq2Matcher(e) matches FloatingEqMatcher(x, false, e)
+// against y. The former implements "Eq", the latter "Near". At present, there
+// is no version that compares NaNs as equal.
+template <typename FloatType>
+class FloatingEq2Matcher {
+ public:
+ FloatingEq2Matcher() { Init(-1, false); }
+
+ explicit FloatingEq2Matcher(bool nan_eq_nan) { Init(-1, nan_eq_nan); }
+
+ explicit FloatingEq2Matcher(FloatType max_abs_error) {
+ Init(max_abs_error, false);
+ }
+
+ FloatingEq2Matcher(FloatType max_abs_error, bool nan_eq_nan) {
+ Init(max_abs_error, nan_eq_nan);
+ }
+
+ template <typename T1, typename T2>
+ operator Matcher<::std::tuple<T1, T2>>() const {
+ return MakeMatcher(
+ new Impl<::std::tuple<T1, T2>>(max_abs_error_, nan_eq_nan_));
+ }
+ template <typename T1, typename T2>
+ operator Matcher<const ::std::tuple<T1, T2>&>() const {
+ return MakeMatcher(
+ new Impl<const ::std::tuple<T1, T2>&>(max_abs_error_, nan_eq_nan_));
+ }
+
+ private:
+ static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT
+ return os << "an almost-equal pair";
+ }
+
+ template <typename Tuple>
+ class Impl : public MatcherInterface<Tuple> {
+ public:
+ Impl(FloatType max_abs_error, bool nan_eq_nan) :
+ max_abs_error_(max_abs_error),
+ nan_eq_nan_(nan_eq_nan) {}
+
+ bool MatchAndExplain(Tuple args,
+ MatchResultListener* listener) const override {
+ if (max_abs_error_ == -1) {
+ FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_);
+ return static_cast<Matcher<FloatType>>(fm).MatchAndExplain(
+ ::std::get<1>(args), listener);
+ } else {
+ FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_,
+ max_abs_error_);
+ return static_cast<Matcher<FloatType>>(fm).MatchAndExplain(
+ ::std::get<1>(args), listener);
+ }
+ }
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "are " << GetDesc;
+ }
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "aren't " << GetDesc;
+ }
+
+ private:
+ FloatType max_abs_error_;
+ const bool nan_eq_nan_;
+ };
+
+ void Init(FloatType max_abs_error_val, bool nan_eq_nan_val) {
+ max_abs_error_ = max_abs_error_val;
+ nan_eq_nan_ = nan_eq_nan_val;
+ }
+ FloatType max_abs_error_;
+ bool nan_eq_nan_;
+};
+
+// Implements the Pointee(m) matcher for matching a pointer whose
+// pointee matches matcher m. The pointer can be either raw or smart.
+template <typename InnerMatcher>
+class PointeeMatcher {
+ public:
+ explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {}
+
+ // This type conversion operator template allows Pointee(m) to be
+ // used as a matcher for any pointer type whose pointee type is
+ // compatible with the inner matcher, where type Pointer can be
+ // either a raw pointer or a smart pointer.
+ //
+ // The reason we do this instead of relying on
+ // MakePolymorphicMatcher() is that the latter is not flexible
+ // enough for implementing the DescribeTo() method of Pointee().
+ template <typename Pointer>
+ operator Matcher<Pointer>() const {
+ return Matcher<Pointer>(new Impl<const Pointer&>(matcher_));
+ }
+
+ private:
+ // The monomorphic implementation that works for a particular pointer type.
+ template <typename Pointer>
+ class Impl : public MatcherInterface<Pointer> {
+ public:
+ typedef typename PointeeOf<GTEST_REMOVE_CONST_( // NOLINT
+ GTEST_REMOVE_REFERENCE_(Pointer))>::type Pointee;
+
+ explicit Impl(const InnerMatcher& matcher)
+ : matcher_(MatcherCast<const Pointee&>(matcher)) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "points to a value that ";
+ matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "does not point to a value that ";
+ matcher_.DescribeTo(os);
+ }
+
+ bool MatchAndExplain(Pointer pointer,
+ MatchResultListener* listener) const override {
+ if (GetRawPointer(pointer) == nullptr) return false;
+
+ *listener << "which points to ";
+ return MatchPrintAndExplain(*pointer, matcher_, listener);
+ }
+
+ private:
+ const Matcher<const Pointee&> matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ const InnerMatcher matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(PointeeMatcher);
+};
+
+#if GTEST_HAS_RTTI
+// Implements the WhenDynamicCastTo<T>(m) matcher that matches a pointer or
+// reference that matches inner_matcher when dynamic_cast<T> is applied.
+// The result of dynamic_cast<To> is forwarded to the inner matcher.
+// If To is a pointer and the cast fails, the inner matcher will receive NULL.
+// If To is a reference and the cast fails, this matcher returns false
+// immediately.
+template <typename To>
+class WhenDynamicCastToMatcherBase {
+ public:
+ explicit WhenDynamicCastToMatcherBase(const Matcher<To>& matcher)
+ : matcher_(matcher) {}
+
+ void DescribeTo(::std::ostream* os) const {
+ GetCastTypeDescription(os);
+ matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const {
+ GetCastTypeDescription(os);
+ matcher_.DescribeNegationTo(os);
+ }
+
+ protected:
+ const Matcher<To> matcher_;
+
+ static std::string GetToName() {
+ return GetTypeName<To>();
+ }
+
+ private:
+ static void GetCastTypeDescription(::std::ostream* os) {
+ *os << "when dynamic_cast to " << GetToName() << ", ";
+ }
+
+ GTEST_DISALLOW_ASSIGN_(WhenDynamicCastToMatcherBase);
+};
+
+// Primary template.
+// To is a pointer. Cast and forward the result.
+template <typename To>
+class WhenDynamicCastToMatcher : public WhenDynamicCastToMatcherBase<To> {
+ public:
+ explicit WhenDynamicCastToMatcher(const Matcher<To>& matcher)
+ : WhenDynamicCastToMatcherBase<To>(matcher) {}
+
+ template <typename From>
+ bool MatchAndExplain(From from, MatchResultListener* listener) const {
+ To to = dynamic_cast<To>(from);
+ return MatchPrintAndExplain(to, this->matcher_, listener);
+ }
+};
+
+// Specialize for references.
+// In this case we return false if the dynamic_cast fails.
+template <typename To>
+class WhenDynamicCastToMatcher<To&> : public WhenDynamicCastToMatcherBase<To&> {
+ public:
+ explicit WhenDynamicCastToMatcher(const Matcher<To&>& matcher)
+ : WhenDynamicCastToMatcherBase<To&>(matcher) {}
+
+ template <typename From>
+ bool MatchAndExplain(From& from, MatchResultListener* listener) const {
+ // We don't want an std::bad_cast here, so do the cast with pointers.
+ To* to = dynamic_cast<To*>(&from);
+ if (to == nullptr) {
+ *listener << "which cannot be dynamic_cast to " << this->GetToName();
+ return false;
+ }
+ return MatchPrintAndExplain(*to, this->matcher_, listener);
+ }
+};
+#endif // GTEST_HAS_RTTI
+
+// Implements the Field() matcher for matching a field (i.e. member
+// variable) of an object.
+template <typename Class, typename FieldType>
+class FieldMatcher {
+ public:
+ FieldMatcher(FieldType Class::*field,
+ const Matcher<const FieldType&>& matcher)
+ : field_(field), matcher_(matcher), whose_field_("whose given field ") {}
+
+ FieldMatcher(const std::string& field_name, FieldType Class::*field,
+ const Matcher<const FieldType&>& matcher)
+ : field_(field),
+ matcher_(matcher),
+ whose_field_("whose field `" + field_name + "` ") {}
+
+ void DescribeTo(::std::ostream* os) const {
+ *os << "is an object " << whose_field_;
+ matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "is an object " << whose_field_;
+ matcher_.DescribeNegationTo(os);
+ }
+
+ template <typename T>
+ bool MatchAndExplain(const T& value, MatchResultListener* listener) const {
+ // FIXME: The dispatch on std::is_pointer was introduced as a workaround for
+ // a compiler bug, and can now be removed.
+ return MatchAndExplainImpl(
+ typename std::is_pointer<GTEST_REMOVE_CONST_(T)>::type(), value,
+ listener);
+ }
+
+ private:
+ bool MatchAndExplainImpl(std::false_type /* is_not_pointer */,
+ const Class& obj,
+ MatchResultListener* listener) const {
+ *listener << whose_field_ << "is ";
+ return MatchPrintAndExplain(obj.*field_, matcher_, listener);
+ }
+
+ bool MatchAndExplainImpl(std::true_type /* is_pointer */, const Class* p,
+ MatchResultListener* listener) const {
+ if (p == nullptr) return false;
+
+ *listener << "which points to an object ";
+ // Since *p has a field, it must be a class/struct/union type and
+ // thus cannot be a pointer. Therefore we pass false_type() as
+ // the first argument.
+ return MatchAndExplainImpl(std::false_type(), *p, listener);
+ }
+
+ const FieldType Class::*field_;
+ const Matcher<const FieldType&> matcher_;
+
+ // Contains either "whose given field " if the name of the field is unknown
+ // or "whose field `name_of_field` " if the name is known.
+ const std::string whose_field_;
+
+ GTEST_DISALLOW_ASSIGN_(FieldMatcher);
+};
+
+// Implements the Property() matcher for matching a property
+// (i.e. return value of a getter method) of an object.
+//
+// Property is a const-qualified member function of Class returning
+// PropertyType.
+template <typename Class, typename PropertyType, typename Property>
+class PropertyMatcher {
+ public:
+ typedef const PropertyType& RefToConstProperty;
+
+ PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher)
+ : property_(property),
+ matcher_(matcher),
+ whose_property_("whose given property ") {}
+
+ PropertyMatcher(const std::string& property_name, Property property,
+ const Matcher<RefToConstProperty>& matcher)
+ : property_(property),
+ matcher_(matcher),
+ whose_property_("whose property `" + property_name + "` ") {}
+
+ void DescribeTo(::std::ostream* os) const {
+ *os << "is an object " << whose_property_;
+ matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "is an object " << whose_property_;
+ matcher_.DescribeNegationTo(os);
+ }
+
+ template <typename T>
+ bool MatchAndExplain(const T&value, MatchResultListener* listener) const {
+ return MatchAndExplainImpl(
+ typename std::is_pointer<GTEST_REMOVE_CONST_(T)>::type(), value,
+ listener);
+ }
+
+ private:
+ bool MatchAndExplainImpl(std::false_type /* is_not_pointer */,
+ const Class& obj,
+ MatchResultListener* listener) const {
+ *listener << whose_property_ << "is ";
+ // Cannot pass the return value (for example, int) to MatchPrintAndExplain,
+ // which takes a non-const reference as argument.
+ RefToConstProperty result = (obj.*property_)();
+ return MatchPrintAndExplain(result, matcher_, listener);
+ }
+
+ bool MatchAndExplainImpl(std::true_type /* is_pointer */, const Class* p,
+ MatchResultListener* listener) const {
+ if (p == nullptr) return false;
+
+ *listener << "which points to an object ";
+ // Since *p has a property method, it must be a class/struct/union
+ // type and thus cannot be a pointer. Therefore we pass
+ // false_type() as the first argument.
+ return MatchAndExplainImpl(std::false_type(), *p, listener);
+ }
+
+ Property property_;
+ const Matcher<RefToConstProperty> matcher_;
+
+ // Contains either "whose given property " if the name of the property is
+ // unknown or "whose property `name_of_property` " if the name is known.
+ const std::string whose_property_;
+
+ GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
+};
+
+// Type traits specifying various features of different functors for ResultOf.
+// The default template specifies features for functor objects.
+template <typename Functor>
+struct CallableTraits {
+ typedef Functor StorageType;
+
+ static void CheckIsValid(Functor /* functor */) {}
+
+ template <typename T>
+ static auto Invoke(Functor f, T arg) -> decltype(f(arg)) { return f(arg); }
+};
+
+// Specialization for function pointers.
+template <typename ArgType, typename ResType>
+struct CallableTraits<ResType(*)(ArgType)> {
+ typedef ResType ResultType;
+ typedef ResType(*StorageType)(ArgType);
+
+ static void CheckIsValid(ResType(*f)(ArgType)) {
+ GTEST_CHECK_(f != nullptr)
+ << "NULL function pointer is passed into ResultOf().";
+ }
+ template <typename T>
+ static ResType Invoke(ResType(*f)(ArgType), T arg) {
+ return (*f)(arg);
+ }
+};
+
+// Implements the ResultOf() matcher for matching a return value of a
+// unary function of an object.
+template <typename Callable, typename InnerMatcher>
+class ResultOfMatcher {
+ public:
+ ResultOfMatcher(Callable callable, InnerMatcher matcher)
+ : callable_(std::move(callable)), matcher_(std::move(matcher)) {
+ CallableTraits<Callable>::CheckIsValid(callable_);
+ }
+
+ template <typename T>
+ operator Matcher<T>() const {
+ return Matcher<T>(new Impl<T>(callable_, matcher_));
+ }
+
+ private:
+ typedef typename CallableTraits<Callable>::StorageType CallableStorageType;
+
+ template <typename T>
+ class Impl : public MatcherInterface<T> {
+ using ResultType = decltype(CallableTraits<Callable>::template Invoke<T>(
+ std::declval<CallableStorageType>(), std::declval<T>()));
+
+ public:
+ template <typename M>
+ Impl(const CallableStorageType& callable, const M& matcher)
+ : callable_(callable), matcher_(MatcherCast<ResultType>(matcher)) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "is mapped by the given callable to a value that ";
+ matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "is mapped by the given callable to a value that ";
+ matcher_.DescribeNegationTo(os);
+ }
+
+ bool MatchAndExplain(T obj, MatchResultListener* listener) const override {
+ *listener << "which is mapped by the given callable to ";
+ // Cannot pass the return value directly to MatchPrintAndExplain, which
+ // takes a non-const reference as argument.
+ // Also, specifying template argument explicitly is needed because T could
+ // be a non-const reference (e.g. Matcher<Uncopyable&>).
+ ResultType result =
+ CallableTraits<Callable>::template Invoke<T>(callable_, obj);
+ return MatchPrintAndExplain(result, matcher_, listener);
+ }
+
+ private:
+ // Functors often define operator() as non-const method even though
+ // they are actually stateless. But we need to use them even when
+ // 'this' is a const pointer. It's the user's responsibility not to
+ // use stateful callables with ResultOf(), which doesn't guarantee
+ // how many times the callable will be invoked.
+ mutable CallableStorageType callable_;
+ const Matcher<ResultType> matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ }; // class Impl
+
+ const CallableStorageType callable_;
+ const InnerMatcher matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(ResultOfMatcher);
+};
+
+// Implements a matcher that checks the size of an STL-style container.
+template <typename SizeMatcher>
+class SizeIsMatcher {
+ public:
+ explicit SizeIsMatcher(const SizeMatcher& size_matcher)
+ : size_matcher_(size_matcher) {
+ }
+
+ template <typename Container>
+ operator Matcher<Container>() const {
+ return Matcher<Container>(new Impl<const Container&>(size_matcher_));
+ }
+
+ template <typename Container>
+ class Impl : public MatcherInterface<Container> {
+ public:
+ using SizeType = decltype(std::declval<Container>().size());
+ explicit Impl(const SizeMatcher& size_matcher)
+ : size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "size ";
+ size_matcher_.DescribeTo(os);
+ }
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "size ";
+ size_matcher_.DescribeNegationTo(os);
+ }
+
+ bool MatchAndExplain(Container container,
+ MatchResultListener* listener) const override {
+ SizeType size = container.size();
+ StringMatchResultListener size_listener;
+ const bool result = size_matcher_.MatchAndExplain(size, &size_listener);
+ *listener
+ << "whose size " << size << (result ? " matches" : " doesn't match");
+ PrintIfNotEmpty(size_listener.str(), listener->stream());
+ return result;
+ }
+
+ private:
+ const Matcher<SizeType> size_matcher_;
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ private:
+ const SizeMatcher size_matcher_;
+ GTEST_DISALLOW_ASSIGN_(SizeIsMatcher);
+};
+
+// Implements a matcher that checks the begin()..end() distance of an STL-style
+// container.
+template <typename DistanceMatcher>
+class BeginEndDistanceIsMatcher {
+ public:
+ explicit BeginEndDistanceIsMatcher(const DistanceMatcher& distance_matcher)
+ : distance_matcher_(distance_matcher) {}
+
+ template <typename Container>
+ operator Matcher<Container>() const {
+ return Matcher<Container>(new Impl<const Container&>(distance_matcher_));
+ }
+
+ template <typename Container>
+ class Impl : public MatcherInterface<Container> {
+ public:
+ typedef internal::StlContainerView<
+ GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
+ typedef typename std::iterator_traits<
+ typename ContainerView::type::const_iterator>::difference_type
+ DistanceType;
+ explicit Impl(const DistanceMatcher& distance_matcher)
+ : distance_matcher_(MatcherCast<DistanceType>(distance_matcher)) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "distance between begin() and end() ";
+ distance_matcher_.DescribeTo(os);
+ }
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "distance between begin() and end() ";
+ distance_matcher_.DescribeNegationTo(os);
+ }
+
+ bool MatchAndExplain(Container container,
+ MatchResultListener* listener) const override {
+ using std::begin;
+ using std::end;
+ DistanceType distance = std::distance(begin(container), end(container));
+ StringMatchResultListener distance_listener;
+ const bool result =
+ distance_matcher_.MatchAndExplain(distance, &distance_listener);
+ *listener << "whose distance between begin() and end() " << distance
+ << (result ? " matches" : " doesn't match");
+ PrintIfNotEmpty(distance_listener.str(), listener->stream());
+ return result;
+ }
+
+ private:
+ const Matcher<DistanceType> distance_matcher_;
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ private:
+ const DistanceMatcher distance_matcher_;
+ GTEST_DISALLOW_ASSIGN_(BeginEndDistanceIsMatcher);
+};
+
+// Implements an equality matcher for any STL-style container whose elements
+// support ==. This matcher is like Eq(), but its failure explanations provide
+// more detailed information that is useful when the container is used as a set.
+// The failure message reports elements that are in one of the operands but not
+// the other. The failure messages do not report duplicate or out-of-order
+// elements in the containers (which don't properly matter to sets, but can
+// occur if the containers are vectors or lists, for example).
+//
+// Uses the container's const_iterator, value_type, operator ==,
+// begin(), and end().
+template <typename Container>
+class ContainerEqMatcher {
+ public:
+ typedef internal::StlContainerView<Container> View;
+ typedef typename View::type StlContainer;
+ typedef typename View::const_reference StlContainerReference;
+
+ // We make a copy of expected in case the elements in it are modified
+ // after this matcher is created.
+ explicit ContainerEqMatcher(const Container& expected)
+ : expected_(View::Copy(expected)) {
+ // Makes sure the user doesn't instantiate this class template
+ // with a const or reference type.
+ (void)testing::StaticAssertTypeEq<Container,
+ GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>();
+ }
+
+ void DescribeTo(::std::ostream* os) const {
+ *os << "equals ";
+ UniversalPrint(expected_, os);
+ }
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "does not equal ";
+ UniversalPrint(expected_, os);
+ }
+
+ template <typename LhsContainer>
+ bool MatchAndExplain(const LhsContainer& lhs,
+ MatchResultListener* listener) const {
+ // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
+ // that causes LhsContainer to be a const type sometimes.
+ typedef internal::StlContainerView<GTEST_REMOVE_CONST_(LhsContainer)>
+ LhsView;
+ typedef typename LhsView::type LhsStlContainer;
+ StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
+ if (lhs_stl_container == expected_)
+ return true;
+
+ ::std::ostream* const os = listener->stream();
+ if (os != nullptr) {
+ // Something is different. Check for extra values first.
+ bool printed_header = false;
+ for (typename LhsStlContainer::const_iterator it =
+ lhs_stl_container.begin();
+ it != lhs_stl_container.end(); ++it) {
+ if (internal::ArrayAwareFind(expected_.begin(), expected_.end(), *it) ==
+ expected_.end()) {
+ if (printed_header) {
+ *os << ", ";
+ } else {
+ *os << "which has these unexpected elements: ";
+ printed_header = true;
+ }
+ UniversalPrint(*it, os);
+ }
+ }
+
+ // Now check for missing values.
+ bool printed_header2 = false;
+ for (typename StlContainer::const_iterator it = expected_.begin();
+ it != expected_.end(); ++it) {
+ if (internal::ArrayAwareFind(
+ lhs_stl_container.begin(), lhs_stl_container.end(), *it) ==
+ lhs_stl_container.end()) {
+ if (printed_header2) {
+ *os << ", ";
+ } else {
+ *os << (printed_header ? ",\nand" : "which")
+ << " doesn't have these expected elements: ";
+ printed_header2 = true;
+ }
+ UniversalPrint(*it, os);
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private:
+ const StlContainer expected_;
+
+ GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher);
+};
+
+// A comparator functor that uses the < operator to compare two values.
+struct LessComparator {
+ template <typename T, typename U>
+ bool operator()(const T& lhs, const U& rhs) const { return lhs < rhs; }
+};
+
+// Implements WhenSortedBy(comparator, container_matcher).
+template <typename Comparator, typename ContainerMatcher>
+class WhenSortedByMatcher {
+ public:
+ WhenSortedByMatcher(const Comparator& comparator,
+ const ContainerMatcher& matcher)
+ : comparator_(comparator), matcher_(matcher) {}
+
+ template <typename LhsContainer>
+ operator Matcher<LhsContainer>() const {
+ return MakeMatcher(new Impl<LhsContainer>(comparator_, matcher_));
+ }
+
+ template <typename LhsContainer>
+ class Impl : public MatcherInterface<LhsContainer> {
+ public:
+ typedef internal::StlContainerView<
+ GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
+ typedef typename LhsView::type LhsStlContainer;
+ typedef typename LhsView::const_reference LhsStlContainerReference;
+ // Transforms std::pair<const Key, Value> into std::pair<Key, Value>
+ // so that we can match associative containers.
+ typedef typename RemoveConstFromKey<
+ typename LhsStlContainer::value_type>::type LhsValue;
+
+ Impl(const Comparator& comparator, const ContainerMatcher& matcher)
+ : comparator_(comparator), matcher_(matcher) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "(when sorted) ";
+ matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "(when sorted) ";
+ matcher_.DescribeNegationTo(os);
+ }
+
+ bool MatchAndExplain(LhsContainer lhs,
+ MatchResultListener* listener) const override {
+ LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
+ ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
+ lhs_stl_container.end());
+ ::std::sort(
+ sorted_container.begin(), sorted_container.end(), comparator_);
+
+ if (!listener->IsInterested()) {
+ // If the listener is not interested, we do not need to
+ // construct the inner explanation.
+ return matcher_.Matches(sorted_container);
+ }
+
+ *listener << "which is ";
+ UniversalPrint(sorted_container, listener->stream());
+ *listener << " when sorted";
+
+ StringMatchResultListener inner_listener;
+ const bool match = matcher_.MatchAndExplain(sorted_container,
+ &inner_listener);
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
+ return match;
+ }
+
+ private:
+ const Comparator comparator_;
+ const Matcher<const ::std::vector<LhsValue>&> matcher_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
+ };
+
+ private:
+ const Comparator comparator_;
+ const ContainerMatcher matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(WhenSortedByMatcher);
+};
+
+// Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher
+// must be able to be safely cast to Matcher<std::tuple<const T1&, const
+// T2&> >, where T1 and T2 are the types of elements in the LHS
+// container and the RHS container respectively.
+template <typename TupleMatcher, typename RhsContainer>
+class PointwiseMatcher {
+ GTEST_COMPILE_ASSERT_(
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>::value,
+ use_UnorderedPointwise_with_hash_tables);
+
+ public:
+ typedef internal::StlContainerView<RhsContainer> RhsView;
+ typedef typename RhsView::type RhsStlContainer;
+ typedef typename RhsStlContainer::value_type RhsValue;
+
+ // Like ContainerEq, we make a copy of rhs in case the elements in
+ // it are modified after this matcher is created.
+ PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs)
+ : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {
+ // Makes sure the user doesn't instantiate this class template
+ // with a const or reference type.
+ (void)testing::StaticAssertTypeEq<RhsContainer,
+ GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>();
+ }
+
+ template <typename LhsContainer>
+ operator Matcher<LhsContainer>() const {
+ GTEST_COMPILE_ASSERT_(
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value,
+ use_UnorderedPointwise_with_hash_tables);
+
+ return Matcher<LhsContainer>(
+ new Impl<const LhsContainer&>(tuple_matcher_, rhs_));
+ }
+
+ template <typename LhsContainer>
+ class Impl : public MatcherInterface<LhsContainer> {
+ public:
+ typedef internal::StlContainerView<
+ GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
+ typedef typename LhsView::type LhsStlContainer;
+ typedef typename LhsView::const_reference LhsStlContainerReference;
+ typedef typename LhsStlContainer::value_type LhsValue;
+ // We pass the LHS value and the RHS value to the inner matcher by
+ // reference, as they may be expensive to copy. We must use tuple
+ // instead of pair here, as a pair cannot hold references (C++ 98,
+ // 20.2.2 [lib.pairs]).
+ typedef ::std::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg;
+
+ Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs)
+ // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher.
+ : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)),
+ rhs_(rhs) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "contains " << rhs_.size()
+ << " values, where each value and its corresponding value in ";
+ UniversalPrinter<RhsStlContainer>::Print(rhs_, os);
+ *os << " ";
+ mono_tuple_matcher_.DescribeTo(os);
+ }
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "doesn't contain exactly " << rhs_.size()
+ << " values, or contains a value x at some index i"
+ << " where x and the i-th value of ";
+ UniversalPrint(rhs_, os);
+ *os << " ";
+ mono_tuple_matcher_.DescribeNegationTo(os);
+ }
+
+ bool MatchAndExplain(LhsContainer lhs,
+ MatchResultListener* listener) const override {
+ LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
+ const size_t actual_size = lhs_stl_container.size();
+ if (actual_size != rhs_.size()) {
+ *listener << "which contains " << actual_size << " values";
+ return false;
+ }
+
+ typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
+ typename RhsStlContainer::const_iterator right = rhs_.begin();
+ for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
+ if (listener->IsInterested()) {
+ StringMatchResultListener inner_listener;
+ // Create InnerMatcherArg as a temporarily object to avoid it outlives
+ // *left and *right. Dereference or the conversion to `const T&` may
+ // return temp objects, e.g for vector<bool>.
+ if (!mono_tuple_matcher_.MatchAndExplain(
+ InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
+ ImplicitCast_<const RhsValue&>(*right)),
+ &inner_listener)) {
+ *listener << "where the value pair (";
+ UniversalPrint(*left, listener->stream());
+ *listener << ", ";
+ UniversalPrint(*right, listener->stream());
+ *listener << ") at index #" << i << " don't match";
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
+ return false;
+ }
+ } else {
+ if (!mono_tuple_matcher_.Matches(
+ InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
+ ImplicitCast_<const RhsValue&>(*right))))
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private:
+ const Matcher<InnerMatcherArg> mono_tuple_matcher_;
+ const RhsStlContainer rhs_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ private:
+ const TupleMatcher tuple_matcher_;
+ const RhsStlContainer rhs_;
+
+ GTEST_DISALLOW_ASSIGN_(PointwiseMatcher);
+};
+
+// Holds the logic common to ContainsMatcherImpl and EachMatcherImpl.
+template <typename Container>
+class QuantifierMatcherImpl : public MatcherInterface<Container> {
+ public:
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
+ typedef StlContainerView<RawContainer> View;
+ typedef typename View::type StlContainer;
+ typedef typename View::const_reference StlContainerReference;
+ typedef typename StlContainer::value_type Element;
+
+ template <typename InnerMatcher>
+ explicit QuantifierMatcherImpl(InnerMatcher inner_matcher)
+ : inner_matcher_(
+ testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
+
+ // Checks whether:
+ // * All elements in the container match, if all_elements_should_match.
+ // * Any element in the container matches, if !all_elements_should_match.
+ bool MatchAndExplainImpl(bool all_elements_should_match,
+ Container container,
+ MatchResultListener* listener) const {
+ StlContainerReference stl_container = View::ConstReference(container);
+ size_t i = 0;
+ for (typename StlContainer::const_iterator it = stl_container.begin();
+ it != stl_container.end(); ++it, ++i) {
+ StringMatchResultListener inner_listener;
+ const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
+
+ if (matches != all_elements_should_match) {
+ *listener << "whose element #" << i
+ << (matches ? " matches" : " doesn't match");
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
+ return !all_elements_should_match;
+ }
+ }
+ return all_elements_should_match;
+ }
+
+ protected:
+ const Matcher<const Element&> inner_matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl);
+};
+
+// Implements Contains(element_matcher) for the given argument type Container.
+// Symmetric to EachMatcherImpl.
+template <typename Container>
+class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> {
+ public:
+ template <typename InnerMatcher>
+ explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
+ : QuantifierMatcherImpl<Container>(inner_matcher) {}
+
+ // Describes what this matcher does.
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "contains at least one element that ";
+ this->inner_matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "doesn't contain any element that ";
+ this->inner_matcher_.DescribeTo(os);
+ }
+
+ bool MatchAndExplain(Container container,
+ MatchResultListener* listener) const override {
+ return this->MatchAndExplainImpl(false, container, listener);
+ }
+
+ private:
+ GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl);
+};
+
+// Implements Each(element_matcher) for the given argument type Container.
+// Symmetric to ContainsMatcherImpl.
+template <typename Container>
+class EachMatcherImpl : public QuantifierMatcherImpl<Container> {
+ public:
+ template <typename InnerMatcher>
+ explicit EachMatcherImpl(InnerMatcher inner_matcher)
+ : QuantifierMatcherImpl<Container>(inner_matcher) {}
+
+ // Describes what this matcher does.
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "only contains elements that ";
+ this->inner_matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "contains some element that ";
+ this->inner_matcher_.DescribeNegationTo(os);
+ }
+
+ bool MatchAndExplain(Container container,
+ MatchResultListener* listener) const override {
+ return this->MatchAndExplainImpl(true, container, listener);
+ }
+
+ private:
+ GTEST_DISALLOW_ASSIGN_(EachMatcherImpl);
+};
+
+// Implements polymorphic Contains(element_matcher).
+template <typename M>
+class ContainsMatcher {
+ public:
+ explicit ContainsMatcher(M m) : inner_matcher_(m) {}
+
+ template <typename Container>
+ operator Matcher<Container>() const {
+ return Matcher<Container>(
+ new ContainsMatcherImpl<const Container&>(inner_matcher_));
+ }
+
+ private:
+ const M inner_matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(ContainsMatcher);
+};
+
+// Implements polymorphic Each(element_matcher).
+template <typename M>
+class EachMatcher {
+ public:
+ explicit EachMatcher(M m) : inner_matcher_(m) {}
+
+ template <typename Container>
+ operator Matcher<Container>() const {
+ return Matcher<Container>(
+ new EachMatcherImpl<const Container&>(inner_matcher_));
+ }
+
+ private:
+ const M inner_matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(EachMatcher);
+};
+
+struct Rank1 {};
+struct Rank0 : Rank1 {};
+
+namespace pair_getters {
+using std::get;
+template <typename T>
+auto First(T& x, Rank1) -> decltype(get<0>(x)) { // NOLINT
+ return get<0>(x);
+}
+template <typename T>
+auto First(T& x, Rank0) -> decltype((x.first)) { // NOLINT
+ return x.first;
+}
+
+template <typename T>
+auto Second(T& x, Rank1) -> decltype(get<1>(x)) { // NOLINT
+ return get<1>(x);
+}
+template <typename T>
+auto Second(T& x, Rank0) -> decltype((x.second)) { // NOLINT
+ return x.second;
+}
+} // namespace pair_getters
+
+// Implements Key(inner_matcher) for the given argument pair type.
+// Key(inner_matcher) matches an std::pair whose 'first' field matches
+// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
+// std::map that contains at least one element whose key is >= 5.
+template <typename PairType>
+class KeyMatcherImpl : public MatcherInterface<PairType> {
+ public:
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
+ typedef typename RawPairType::first_type KeyType;
+
+ template <typename InnerMatcher>
+ explicit KeyMatcherImpl(InnerMatcher inner_matcher)
+ : inner_matcher_(
+ testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
+ }
+
+ // Returns true iff 'key_value.first' (the key) matches the inner matcher.
+ bool MatchAndExplain(PairType key_value,
+ MatchResultListener* listener) const override {
+ StringMatchResultListener inner_listener;
+ const bool match = inner_matcher_.MatchAndExplain(
+ pair_getters::First(key_value, Rank0()), &inner_listener);
+ const std::string explanation = inner_listener.str();
+ if (explanation != "") {
+ *listener << "whose first field is a value " << explanation;
+ }
+ return match;
+ }
+
+ // Describes what this matcher does.
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "has a key that ";
+ inner_matcher_.DescribeTo(os);
+ }
+
+ // Describes what the negation of this matcher does.
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "doesn't have a key that ";
+ inner_matcher_.DescribeTo(os);
+ }
+
+ private:
+ const Matcher<const KeyType&> inner_matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl);
+};
+
+// Implements polymorphic Key(matcher_for_key).
+template <typename M>
+class KeyMatcher {
+ public:
+ explicit KeyMatcher(M m) : matcher_for_key_(m) {}
+
+ template <typename PairType>
+ operator Matcher<PairType>() const {
+ return Matcher<PairType>(
+ new KeyMatcherImpl<const PairType&>(matcher_for_key_));
+ }
+
+ private:
+ const M matcher_for_key_;
+
+ GTEST_DISALLOW_ASSIGN_(KeyMatcher);
+};
+
+// Implements Pair(first_matcher, second_matcher) for the given argument pair
+// type with its two matchers. See Pair() function below.
+template <typename PairType>
+class PairMatcherImpl : public MatcherInterface<PairType> {
+ public:
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
+ typedef typename RawPairType::first_type FirstType;
+ typedef typename RawPairType::second_type SecondType;
+
+ template <typename FirstMatcher, typename SecondMatcher>
+ PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
+ : first_matcher_(
+ testing::SafeMatcherCast<const FirstType&>(first_matcher)),
+ second_matcher_(
+ testing::SafeMatcherCast<const SecondType&>(second_matcher)) {
+ }
+
+ // Describes what this matcher does.
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "has a first field that ";
+ first_matcher_.DescribeTo(os);
+ *os << ", and has a second field that ";
+ second_matcher_.DescribeTo(os);
+ }
+
+ // Describes what the negation of this matcher does.
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "has a first field that ";
+ first_matcher_.DescribeNegationTo(os);
+ *os << ", or has a second field that ";
+ second_matcher_.DescribeNegationTo(os);
+ }
+
+ // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second'
+ // matches second_matcher.
+ bool MatchAndExplain(PairType a_pair,
+ MatchResultListener* listener) const override {
+ if (!listener->IsInterested()) {
+ // If the listener is not interested, we don't need to construct the
+ // explanation.
+ return first_matcher_.Matches(pair_getters::First(a_pair, Rank0())) &&
+ second_matcher_.Matches(pair_getters::Second(a_pair, Rank0()));
+ }
+ StringMatchResultListener first_inner_listener;
+ if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank0()),
+ &first_inner_listener)) {
+ *listener << "whose first field does not match";
+ PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
+ return false;
+ }
+ StringMatchResultListener second_inner_listener;
+ if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank0()),
+ &second_inner_listener)) {
+ *listener << "whose second field does not match";
+ PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
+ return false;
+ }
+ ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
+ listener);
+ return true;
+ }
+
+ private:
+ void ExplainSuccess(const std::string& first_explanation,
+ const std::string& second_explanation,
+ MatchResultListener* listener) const {
+ *listener << "whose both fields match";
+ if (first_explanation != "") {
+ *listener << ", where the first field is a value " << first_explanation;
+ }
+ if (second_explanation != "") {
+ *listener << ", ";
+ if (first_explanation != "") {
+ *listener << "and ";
+ } else {
+ *listener << "where ";
+ }
+ *listener << "the second field is a value " << second_explanation;
+ }
+ }
+
+ const Matcher<const FirstType&> first_matcher_;
+ const Matcher<const SecondType&> second_matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(PairMatcherImpl);
+};
+
+// Implements polymorphic Pair(first_matcher, second_matcher).
+template <typename FirstMatcher, typename SecondMatcher>
+class PairMatcher {
+ public:
+ PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
+ : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
+
+ template <typename PairType>
+ operator Matcher<PairType> () const {
+ return Matcher<PairType>(
+ new PairMatcherImpl<const PairType&>(first_matcher_, second_matcher_));
+ }
+
+ private:
+ const FirstMatcher first_matcher_;
+ const SecondMatcher second_matcher_;
+
+ GTEST_DISALLOW_ASSIGN_(PairMatcher);
+};
+
+// Implements ElementsAre() and ElementsAreArray().
+template <typename Container>
+class ElementsAreMatcherImpl : public MatcherInterface<Container> {
+ public:
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
+ typedef internal::StlContainerView<RawContainer> View;
+ typedef typename View::type StlContainer;
+ typedef typename View::const_reference StlContainerReference;
+ typedef typename StlContainer::value_type Element;
+
+ // Constructs the matcher from a sequence of element values or
+ // element matchers.
+ template <typename InputIter>
+ ElementsAreMatcherImpl(InputIter first, InputIter last) {
+ while (first != last) {
+ matchers_.push_back(MatcherCast<const Element&>(*first++));
+ }
+ }
+
+ // Describes what this matcher does.
+ void DescribeTo(::std::ostream* os) const override {
+ if (count() == 0) {
+ *os << "is empty";
+ } else if (count() == 1) {
+ *os << "has 1 element that ";
+ matchers_[0].DescribeTo(os);
+ } else {
+ *os << "has " << Elements(count()) << " where\n";
+ for (size_t i = 0; i != count(); ++i) {
+ *os << "element #" << i << " ";
+ matchers_[i].DescribeTo(os);
+ if (i + 1 < count()) {
+ *os << ",\n";
+ }
+ }
+ }
+ }
+
+ // Describes what the negation of this matcher does.
+ void DescribeNegationTo(::std::ostream* os) const override {
+ if (count() == 0) {
+ *os << "isn't empty";
+ return;
+ }
+
+ *os << "doesn't have " << Elements(count()) << ", or\n";
+ for (size_t i = 0; i != count(); ++i) {
+ *os << "element #" << i << " ";
+ matchers_[i].DescribeNegationTo(os);
+ if (i + 1 < count()) {
+ *os << ", or\n";
+ }
+ }
+ }
+
+ bool MatchAndExplain(Container container,
+ MatchResultListener* listener) const override {
+ // To work with stream-like "containers", we must only walk
+ // through the elements in one pass.
+
+ const bool listener_interested = listener->IsInterested();
+
+ // explanations[i] is the explanation of the element at index i.
+ ::std::vector<std::string> explanations(count());
+ StlContainerReference stl_container = View::ConstReference(container);
+ typename StlContainer::const_iterator it = stl_container.begin();
+ size_t exam_pos = 0;
+ bool mismatch_found = false; // Have we found a mismatched element yet?
+
+ // Go through the elements and matchers in pairs, until we reach
+ // the end of either the elements or the matchers, or until we find a
+ // mismatch.
+ for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
+ bool match; // Does the current element match the current matcher?
+ if (listener_interested) {
+ StringMatchResultListener s;
+ match = matchers_[exam_pos].MatchAndExplain(*it, &s);
+ explanations[exam_pos] = s.str();
+ } else {
+ match = matchers_[exam_pos].Matches(*it);
+ }
+
+ if (!match) {
+ mismatch_found = true;
+ break;
+ }
+ }
+ // If mismatch_found is true, 'exam_pos' is the index of the mismatch.
+
+ // Find how many elements the actual container has. We avoid
+ // calling size() s.t. this code works for stream-like "containers"
+ // that don't define size().
+ size_t actual_count = exam_pos;
+ for (; it != stl_container.end(); ++it) {
+ ++actual_count;
+ }
+
+ if (actual_count != count()) {
+ // The element count doesn't match. If the container is empty,
+ // there's no need to explain anything as Google Mock already
+ // prints the empty container. Otherwise we just need to show
+ // how many elements there actually are.
+ if (listener_interested && (actual_count != 0)) {
+ *listener << "which has " << Elements(actual_count);
+ }
+ return false;
+ }
+
+ if (mismatch_found) {
+ // The element count matches, but the exam_pos-th element doesn't match.
+ if (listener_interested) {
+ *listener << "whose element #" << exam_pos << " doesn't match";
+ PrintIfNotEmpty(explanations[exam_pos], listener->stream());
+ }
+ return false;
+ }
+
+ // Every element matches its expectation. We need to explain why
+ // (the obvious ones can be skipped).
+ if (listener_interested) {
+ bool reason_printed = false;
+ for (size_t i = 0; i != count(); ++i) {
+ const std::string& s = explanations[i];
+ if (!s.empty()) {
+ if (reason_printed) {
+ *listener << ",\nand ";
+ }
+ *listener << "whose element #" << i << " matches, " << s;
+ reason_printed = true;
+ }
+ }
+ }
+ return true;
+ }
+
+ private:
+ static Message Elements(size_t count) {
+ return Message() << count << (count == 1 ? " element" : " elements");
+ }
+
+ size_t count() const { return matchers_.size(); }
+
+ ::std::vector<Matcher<const Element&> > matchers_;
+
+ GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl);
+};
+
+// Connectivity matrix of (elements X matchers), in element-major order.
+// Initially, there are no edges.
+// Use NextGraph() to iterate over all possible edge configurations.
+// Use Randomize() to generate a random edge configuration.
+class GTEST_API_ MatchMatrix {
+ public:
+ MatchMatrix(size_t num_elements, size_t num_matchers)
+ : num_elements_(num_elements),
+ num_matchers_(num_matchers),
+ matched_(num_elements_* num_matchers_, 0) {
+ }
+
+ size_t LhsSize() const { return num_elements_; }
+ size_t RhsSize() const { return num_matchers_; }
+ bool HasEdge(size_t ilhs, size_t irhs) const {
+ return matched_[SpaceIndex(ilhs, irhs)] == 1;
+ }
+ void SetEdge(size_t ilhs, size_t irhs, bool b) {
+ matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
+ }
+
+ // Treating the connectivity matrix as a (LhsSize()*RhsSize())-bit number,
+ // adds 1 to that number; returns false if incrementing the graph left it
+ // empty.
+ bool NextGraph();
+
+ void Randomize();
+
+ std::string DebugString() const;
+
+ private:
+ size_t SpaceIndex(size_t ilhs, size_t irhs) const {
+ return ilhs * num_matchers_ + irhs;
+ }
+
+ size_t num_elements_;
+ size_t num_matchers_;
+
+ // Each element is a char interpreted as bool. They are stored as a
+ // flattened array in lhs-major order, use 'SpaceIndex()' to translate
+ // a (ilhs, irhs) matrix coordinate into an offset.
+ ::std::vector<char> matched_;
+};
+
+typedef ::std::pair<size_t, size_t> ElementMatcherPair;
+typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
+
+// Returns a maximum bipartite matching for the specified graph 'g'.
+// The matching is represented as a vector of {element, matcher} pairs.
+GTEST_API_ ElementMatcherPairs
+FindMaxBipartiteMatching(const MatchMatrix& g);
+
+struct UnorderedMatcherRequire {
+ enum Flags {
+ Superset = 1 << 0,
+ Subset = 1 << 1,
+ ExactMatch = Superset | Subset,
+ };
+};
+
+// Untyped base class for implementing UnorderedElementsAre. By
+// putting logic that's not specific to the element type here, we
+// reduce binary bloat and increase compilation speed.
+class GTEST_API_ UnorderedElementsAreMatcherImplBase {
+ protected:
+ explicit UnorderedElementsAreMatcherImplBase(
+ UnorderedMatcherRequire::Flags matcher_flags)
+ : match_flags_(matcher_flags) {}
+
+ // A vector of matcher describers, one for each element matcher.
+ // Does not own the describers (and thus can be used only when the
+ // element matchers are alive).
+ typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
+
+ // Describes this UnorderedElementsAre matcher.
+ void DescribeToImpl(::std::ostream* os) const;
+
+ // Describes the negation of this UnorderedElementsAre matcher.
+ void DescribeNegationToImpl(::std::ostream* os) const;
+
+ bool VerifyMatchMatrix(const ::std::vector<std::string>& element_printouts,
+ const MatchMatrix& matrix,
+ MatchResultListener* listener) const;
+
+ bool FindPairing(const MatchMatrix& matrix,
+ MatchResultListener* listener) const;
+
+ MatcherDescriberVec& matcher_describers() {
+ return matcher_describers_;
+ }
+
+ static Message Elements(size_t n) {
+ return Message() << n << " element" << (n == 1 ? "" : "s");
+ }
+
+ UnorderedMatcherRequire::Flags match_flags() const { return match_flags_; }
+
+ private:
+ UnorderedMatcherRequire::Flags match_flags_;
+ MatcherDescriberVec matcher_describers_;
+
+ GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase);
+};
+
+// Implements UnorderedElementsAre, UnorderedElementsAreArray, IsSubsetOf, and
+// IsSupersetOf.
+template <typename Container>
+class UnorderedElementsAreMatcherImpl
+ : public MatcherInterface<Container>,
+ public UnorderedElementsAreMatcherImplBase {
+ public:
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
+ typedef internal::StlContainerView<RawContainer> View;
+ typedef typename View::type StlContainer;
+ typedef typename View::const_reference StlContainerReference;
+ typedef typename StlContainer::const_iterator StlContainerConstIterator;
+ typedef typename StlContainer::value_type Element;
+
+ template <typename InputIter>
+ UnorderedElementsAreMatcherImpl(UnorderedMatcherRequire::Flags matcher_flags,
+ InputIter first, InputIter last)
+ : UnorderedElementsAreMatcherImplBase(matcher_flags) {
+ for (; first != last; ++first) {
+ matchers_.push_back(MatcherCast<const Element&>(*first));
+ matcher_describers().push_back(matchers_.back().GetDescriber());
+ }
+ }
+
+ // Describes what this matcher does.
+ void DescribeTo(::std::ostream* os) const override {
+ return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os);
+ }
+
+ // Describes what the negation of this matcher does.
+ void DescribeNegationTo(::std::ostream* os) const override {
+ return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os);
+ }
+
+ bool MatchAndExplain(Container container,
+ MatchResultListener* listener) const override {
+ StlContainerReference stl_container = View::ConstReference(container);
+ ::std::vector<std::string> element_printouts;
+ MatchMatrix matrix =
+ AnalyzeElements(stl_container.begin(), stl_container.end(),
+ &element_printouts, listener);
+
+ if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
+ return true;
+ }
+
+ if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
+ if (matrix.LhsSize() != matrix.RhsSize()) {
+ // The element count doesn't match. If the container is empty,
+ // there's no need to explain anything as Google Mock already
+ // prints the empty container. Otherwise we just need to show
+ // how many elements there actually are.
+ if (matrix.LhsSize() != 0 && listener->IsInterested()) {
+ *listener << "which has " << Elements(matrix.LhsSize());
+ }
+ return false;
+ }
+ }
+
+ return VerifyMatchMatrix(element_printouts, matrix, listener) &&
+ FindPairing(matrix, listener);
+ }
+
+ private:
+ template <typename ElementIter>
+ MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
+ ::std::vector<std::string>* element_printouts,
+ MatchResultListener* listener) const {
+ element_printouts->clear();
+ ::std::vector<char> did_match;
+ size_t num_elements = 0;
+ for (; elem_first != elem_last; ++num_elements, ++elem_first) {
+ if (listener->IsInterested()) {
+ element_printouts->push_back(PrintToString(*elem_first));
+ }
+ for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
+ did_match.push_back(Matches(matchers_[irhs])(*elem_first));
+ }
+ }
+
+ MatchMatrix matrix(num_elements, matchers_.size());
+ ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
+ for (size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
+ for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
+ matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
+ }
+ }
+ return matrix;
+ }
+
+ ::std::vector<Matcher<const Element&> > matchers_;
+
+ GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl);
+};
+
+// Functor for use in TransformTuple.
+// Performs MatcherCast<Target> on an input argument of any type.
+template <typename Target>
+struct CastAndAppendTransform {
+ template <typename Arg>
+ Matcher<Target> operator()(const Arg& a) const {
+ return MatcherCast<Target>(a);
+ }
+};
+
+// Implements UnorderedElementsAre.
+template <typename MatcherTuple>
+class UnorderedElementsAreMatcher {
+ public:
+ explicit UnorderedElementsAreMatcher(const MatcherTuple& args)
+ : matchers_(args) {}
+
+ template <typename Container>
+ operator Matcher<Container>() const {
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
+ typedef typename internal::StlContainerView<RawContainer>::type View;
+ typedef typename View::value_type Element;
+ typedef ::std::vector<Matcher<const Element&> > MatcherVec;
+ MatcherVec matchers;
+ matchers.reserve(::std::tuple_size<MatcherTuple>::value);
+ TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
+ ::std::back_inserter(matchers));
+ return Matcher<Container>(
+ new UnorderedElementsAreMatcherImpl<const Container&>(
+ UnorderedMatcherRequire::ExactMatch, matchers.begin(),
+ matchers.end()));
+ }
+
+ private:
+ const MatcherTuple matchers_;
+ GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcher);
+};
+
+// Implements ElementsAre.
+template <typename MatcherTuple>
+class ElementsAreMatcher {
+ public:
+ explicit ElementsAreMatcher(const MatcherTuple& args) : matchers_(args) {}
+
+ template <typename Container>
+ operator Matcher<Container>() const {
+ GTEST_COMPILE_ASSERT_(
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value ||
+ ::std::tuple_size<MatcherTuple>::value < 2,
+ use_UnorderedElementsAre_with_hash_tables);
+
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
+ typedef typename internal::StlContainerView<RawContainer>::type View;
+ typedef typename View::value_type Element;
+ typedef ::std::vector<Matcher<const Element&> > MatcherVec;
+ MatcherVec matchers;
+ matchers.reserve(::std::tuple_size<MatcherTuple>::value);
+ TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
+ ::std::back_inserter(matchers));
+ return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>(
+ matchers.begin(), matchers.end()));
+ }
+
+ private:
+ const MatcherTuple matchers_;
+ GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher);
+};
+
+// Implements UnorderedElementsAreArray(), IsSubsetOf(), and IsSupersetOf().
+template <typename T>
+class UnorderedElementsAreArrayMatcher {
+ public:
+ template <typename Iter>
+ UnorderedElementsAreArrayMatcher(UnorderedMatcherRequire::Flags match_flags,
+ Iter first, Iter last)
+ : match_flags_(match_flags), matchers_(first, last) {}
+
+ template <typename Container>
+ operator Matcher<Container>() const {
+ return Matcher<Container>(
+ new UnorderedElementsAreMatcherImpl<const Container&>(
+ match_flags_, matchers_.begin(), matchers_.end()));
+ }
+
+ private:
+ UnorderedMatcherRequire::Flags match_flags_;
+ ::std::vector<T> matchers_;
+
+ GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher);
+};
+
+// Implements ElementsAreArray().
+template <typename T>
+class ElementsAreArrayMatcher {
+ public:
+ template <typename Iter>
+ ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
+
+ template <typename Container>
+ operator Matcher<Container>() const {
+ GTEST_COMPILE_ASSERT_(
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value,
+ use_UnorderedElementsAreArray_with_hash_tables);
+
+ return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>(
+ matchers_.begin(), matchers_.end()));
+ }
+
+ private:
+ const ::std::vector<T> matchers_;
+
+ GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher);
+};
+
+// Given a 2-tuple matcher tm of type Tuple2Matcher and a value second
+// of type Second, BoundSecondMatcher<Tuple2Matcher, Second>(tm,
+// second) is a polymorphic matcher that matches a value x iff tm
+// matches tuple (x, second). Useful for implementing
+// UnorderedPointwise() in terms of UnorderedElementsAreArray().
+//
+// BoundSecondMatcher is copyable and assignable, as we need to put
+// instances of this class in a vector when implementing
+// UnorderedPointwise().
+template <typename Tuple2Matcher, typename Second>
+class BoundSecondMatcher {
+ public:
+ BoundSecondMatcher(const Tuple2Matcher& tm, const Second& second)
+ : tuple2_matcher_(tm), second_value_(second) {}
+
+ template <typename T>
+ operator Matcher<T>() const {
+ return MakeMatcher(new Impl<T>(tuple2_matcher_, second_value_));
+ }
+
+ // We have to define this for UnorderedPointwise() to compile in
+ // C++98 mode, as it puts BoundSecondMatcher instances in a vector,
+ // which requires the elements to be assignable in C++98. The
+ // compiler cannot generate the operator= for us, as Tuple2Matcher
+ // and Second may not be assignable.
+ //
+ // However, this should never be called, so the implementation just
+ // need to assert.
+ void operator=(const BoundSecondMatcher& /*rhs*/) {
+ GTEST_LOG_(FATAL) << "BoundSecondMatcher should never be assigned.";
+ }
+
+ private:
+ template <typename T>
+ class Impl : public MatcherInterface<T> {
+ public:
+ typedef ::std::tuple<T, Second> ArgTuple;
+
+ Impl(const Tuple2Matcher& tm, const Second& second)
+ : mono_tuple2_matcher_(SafeMatcherCast<const ArgTuple&>(tm)),
+ second_value_(second) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "and ";
+ UniversalPrint(second_value_, os);
+ *os << " ";
+ mono_tuple2_matcher_.DescribeTo(os);
+ }
+
+ bool MatchAndExplain(T x, MatchResultListener* listener) const override {
+ return mono_tuple2_matcher_.MatchAndExplain(ArgTuple(x, second_value_),
+ listener);
+ }
+
+ private:
+ const Matcher<const ArgTuple&> mono_tuple2_matcher_;
+ const Second second_value_;
+
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ const Tuple2Matcher tuple2_matcher_;
+ const Second second_value_;
+};
+
+// Given a 2-tuple matcher tm and a value second,
+// MatcherBindSecond(tm, second) returns a matcher that matches a
+// value x iff tm matches tuple (x, second). Useful for implementing
+// UnorderedPointwise() in terms of UnorderedElementsAreArray().
+template <typename Tuple2Matcher, typename Second>
+BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
+ const Tuple2Matcher& tm, const Second& second) {
+ return BoundSecondMatcher<Tuple2Matcher, Second>(tm, second);
+}
+
+// Returns the description for a matcher defined using the MATCHER*()
+// macro where the user-supplied description string is "", if
+// 'negation' is false; otherwise returns the description of the
+// negation of the matcher. 'param_values' contains a list of strings
+// that are the print-out of the matcher's parameters.
+GTEST_API_ std::string FormatMatcherDescription(bool negation,
+ const char* matcher_name,
+ const Strings& param_values);
+
+// Implements a matcher that checks the value of a optional<> type variable.
+template <typename ValueMatcher>
+class OptionalMatcher {
+ public:
+ explicit OptionalMatcher(const ValueMatcher& value_matcher)
+ : value_matcher_(value_matcher) {}
+
+ template <typename Optional>
+ operator Matcher<Optional>() const {
+ return Matcher<Optional>(new Impl<const Optional&>(value_matcher_));
+ }
+
+ template <typename Optional>
+ class Impl : public MatcherInterface<Optional> {
+ public:
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Optional) OptionalView;
+ typedef typename OptionalView::value_type ValueType;
+ explicit Impl(const ValueMatcher& value_matcher)
+ : value_matcher_(MatcherCast<ValueType>(value_matcher)) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "value ";
+ value_matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "value ";
+ value_matcher_.DescribeNegationTo(os);
+ }
+
+ bool MatchAndExplain(Optional optional,
+ MatchResultListener* listener) const override {
+ if (!optional) {
+ *listener << "which is not engaged";
+ return false;
+ }
+ const ValueType& value = *optional;
+ StringMatchResultListener value_listener;
+ const bool match = value_matcher_.MatchAndExplain(value, &value_listener);
+ *listener << "whose value " << PrintToString(value)
+ << (match ? " matches" : " doesn't match");
+ PrintIfNotEmpty(value_listener.str(), listener->stream());
+ return match;
+ }
+
+ private:
+ const Matcher<ValueType> value_matcher_;
+ GTEST_DISALLOW_ASSIGN_(Impl);
+ };
+
+ private:
+ const ValueMatcher value_matcher_;
+ GTEST_DISALLOW_ASSIGN_(OptionalMatcher);
+};
+
+namespace variant_matcher {
+// Overloads to allow VariantMatcher to do proper ADL lookup.
+template <typename T>
+void holds_alternative() {}
+template <typename T>
+void get() {}
+
+// Implements a matcher that checks the value of a variant<> type variable.
+template <typename T>
+class VariantMatcher {
+ public:
+ explicit VariantMatcher(::testing::Matcher<const T&> matcher)
+ : matcher_(std::move(matcher)) {}
+
+ template <typename Variant>
+ bool MatchAndExplain(const Variant& value,
+ ::testing::MatchResultListener* listener) const {
+ using std::get;
+ if (!listener->IsInterested()) {
+ return holds_alternative<T>(value) && matcher_.Matches(get<T>(value));
+ }
+
+ if (!holds_alternative<T>(value)) {
+ *listener << "whose value is not of type '" << GetTypeName() << "'";
+ return false;
+ }
+
+ const T& elem = get<T>(value);
+ StringMatchResultListener elem_listener;
+ const bool match = matcher_.MatchAndExplain(elem, &elem_listener);
+ *listener << "whose value " << PrintToString(elem)
+ << (match ? " matches" : " doesn't match");
+ PrintIfNotEmpty(elem_listener.str(), listener->stream());
+ return match;
+ }
+
+ void DescribeTo(std::ostream* os) const {
+ *os << "is a variant<> with value of type '" << GetTypeName()
+ << "' and the value ";
+ matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(std::ostream* os) const {
+ *os << "is a variant<> with value of type other than '" << GetTypeName()
+ << "' or the value ";
+ matcher_.DescribeNegationTo(os);
+ }
+
+ private:
+ static std::string GetTypeName() {
+#if GTEST_HAS_RTTI
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
+ return internal::GetTypeName<T>());
+#endif
+ return "the element type";
+ }
+
+ const ::testing::Matcher<const T&> matcher_;
+};
+
+} // namespace variant_matcher
+
+namespace any_cast_matcher {
+
+// Overloads to allow AnyCastMatcher to do proper ADL lookup.
+template <typename T>
+void any_cast() {}
+
+// Implements a matcher that any_casts the value.
+template <typename T>
+class AnyCastMatcher {
+ public:
+ explicit AnyCastMatcher(const ::testing::Matcher<const T&>& matcher)
+ : matcher_(matcher) {}
+
+ template <typename AnyType>
+ bool MatchAndExplain(const AnyType& value,
+ ::testing::MatchResultListener* listener) const {
+ if (!listener->IsInterested()) {
+ const T* ptr = any_cast<T>(&value);
+ return ptr != nullptr && matcher_.Matches(*ptr);
+ }
+
+ const T* elem = any_cast<T>(&value);
+ if (elem == nullptr) {
+ *listener << "whose value is not of type '" << GetTypeName() << "'";
+ return false;
+ }
+
+ StringMatchResultListener elem_listener;
+ const bool match = matcher_.MatchAndExplain(*elem, &elem_listener);
+ *listener << "whose value " << PrintToString(*elem)
+ << (match ? " matches" : " doesn't match");
+ PrintIfNotEmpty(elem_listener.str(), listener->stream());
+ return match;
+ }
+
+ void DescribeTo(std::ostream* os) const {
+ *os << "is an 'any' type with value of type '" << GetTypeName()
+ << "' and the value ";
+ matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(std::ostream* os) const {
+ *os << "is an 'any' type with value of type other than '" << GetTypeName()
+ << "' or the value ";
+ matcher_.DescribeNegationTo(os);
+ }
+
+ private:
+ static std::string GetTypeName() {
+#if GTEST_HAS_RTTI
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
+ return internal::GetTypeName<T>());
+#endif
+ return "the element type";
+ }
+
+ const ::testing::Matcher<const T&> matcher_;
+};
+
+} // namespace any_cast_matcher
+
+// Implements the Args() matcher.
+template <class ArgsTuple, size_t... k>
+class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
+ public:
+ using RawArgsTuple = typename std::decay<ArgsTuple>::type;
+ using SelectedArgs =
+ std::tuple<typename std::tuple_element<k, RawArgsTuple>::type...>;
+ using MonomorphicInnerMatcher = Matcher<const SelectedArgs&>;
+
+ template <typename InnerMatcher>
+ explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
+ : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
+
+ bool MatchAndExplain(ArgsTuple args,
+ MatchResultListener* listener) const override {
+ // Workaround spurious C4100 on MSVC<=15.7 when k is empty.
+ (void)args;
+ const SelectedArgs& selected_args =
+ std::forward_as_tuple(std::get<k>(args)...);
+ if (!listener->IsInterested()) return inner_matcher_.Matches(selected_args);
+
+ PrintIndices(listener->stream());
+ *listener << "are " << PrintToString(selected_args);
+
+ StringMatchResultListener inner_listener;
+ const bool match =
+ inner_matcher_.MatchAndExplain(selected_args, &inner_listener);
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
+ return match;
+ }
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "are a tuple ";
+ PrintIndices(os);
+ inner_matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "are a tuple ";
+ PrintIndices(os);
+ inner_matcher_.DescribeNegationTo(os);
+ }
+
+ private:
+ // Prints the indices of the selected fields.
+ static void PrintIndices(::std::ostream* os) {
+ *os << "whose fields (";
+ const char* sep = "";
+ // Workaround spurious C4189 on MSVC<=15.7 when k is empty.
+ (void)sep;
+ const char* dummy[] = {"", (*os << sep << "#" << k, sep = ", ")...};
+ (void)dummy;
+ *os << ") ";
+ }
+
+ MonomorphicInnerMatcher inner_matcher_;
+};
+
+template <class InnerMatcher, size_t... k>
+class ArgsMatcher {
+ public:
+ explicit ArgsMatcher(InnerMatcher inner_matcher)
+ : inner_matcher_(std::move(inner_matcher)) {}
+
+ template <typename ArgsTuple>
+ operator Matcher<ArgsTuple>() const { // NOLINT
+ return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k...>(inner_matcher_));
+ }
+
+ private:
+ InnerMatcher inner_matcher_;
+};
+
+} // namespace internal
+
+// ElementsAreArray(iterator_first, iterator_last)
+// ElementsAreArray(pointer, count)
+// ElementsAreArray(array)
+// ElementsAreArray(container)
+// ElementsAreArray({ e1, e2, ..., en })
+//
+// The ElementsAreArray() functions are like ElementsAre(...), except
+// that they are given a homogeneous sequence rather than taking each
+// element as a function argument. The sequence can be specified as an
+// array, a pointer and count, a vector, an initializer list, or an
+// STL iterator range. In each of these cases, the underlying sequence
+// can be either a sequence of values or a sequence of matchers.
+//
+// All forms of ElementsAreArray() make a copy of the input matcher sequence.
+
+template <typename Iter>
+inline internal::ElementsAreArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>
+ElementsAreArray(Iter first, Iter last) {
+ typedef typename ::std::iterator_traits<Iter>::value_type T;
+ return internal::ElementsAreArrayMatcher<T>(first, last);
+}
+
+template <typename T>
+inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
+ const T* pointer, size_t count) {
+ return ElementsAreArray(pointer, pointer + count);
+}
+
+template <typename T, size_t N>
+inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
+ const T (&array)[N]) {
+ return ElementsAreArray(array, N);
+}
+
+template <typename Container>
+inline internal::ElementsAreArrayMatcher<typename Container::value_type>
+ElementsAreArray(const Container& container) {
+ return ElementsAreArray(container.begin(), container.end());
+}
+
+template <typename T>
+inline internal::ElementsAreArrayMatcher<T>
+ElementsAreArray(::std::initializer_list<T> xs) {
+ return ElementsAreArray(xs.begin(), xs.end());
+}
+
+// UnorderedElementsAreArray(iterator_first, iterator_last)
+// UnorderedElementsAreArray(pointer, count)
+// UnorderedElementsAreArray(array)
+// UnorderedElementsAreArray(container)
+// UnorderedElementsAreArray({ e1, e2, ..., en })
+//
+// UnorderedElementsAreArray() verifies that a bijective mapping onto a
+// collection of matchers exists.
+//
+// The matchers can be specified as an array, a pointer and count, a container,
+// an initializer list, or an STL iterator range. In each of these cases, the
+// underlying matchers can be either values or matchers.
+
+template <typename Iter>
+inline internal::UnorderedElementsAreArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>
+UnorderedElementsAreArray(Iter first, Iter last) {
+ typedef typename ::std::iterator_traits<Iter>::value_type T;
+ return internal::UnorderedElementsAreArrayMatcher<T>(
+ internal::UnorderedMatcherRequire::ExactMatch, first, last);
+}
+
+template <typename T>
+inline internal::UnorderedElementsAreArrayMatcher<T>
+UnorderedElementsAreArray(const T* pointer, size_t count) {
+ return UnorderedElementsAreArray(pointer, pointer + count);
+}
+
+template <typename T, size_t N>
+inline internal::UnorderedElementsAreArrayMatcher<T>
+UnorderedElementsAreArray(const T (&array)[N]) {
+ return UnorderedElementsAreArray(array, N);
+}
+
+template <typename Container>
+inline internal::UnorderedElementsAreArrayMatcher<
+ typename Container::value_type>
+UnorderedElementsAreArray(const Container& container) {
+ return UnorderedElementsAreArray(container.begin(), container.end());
+}
+
+template <typename T>
+inline internal::UnorderedElementsAreArrayMatcher<T>
+UnorderedElementsAreArray(::std::initializer_list<T> xs) {
+ return UnorderedElementsAreArray(xs.begin(), xs.end());
+}
+
+// _ is a matcher that matches anything of any type.
+//
+// This definition is fine as:
+//
+// 1. The C++ standard permits using the name _ in a namespace that
+// is not the global namespace or ::std.
+// 2. The AnythingMatcher class has no data member or constructor,
+// so it's OK to create global variables of this type.
+// 3. c-style has approved of using _ in this case.
+const internal::AnythingMatcher _ = {};
+// Creates a matcher that matches any value of the given type T.
+template <typename T>
+inline Matcher<T> A() {
+ return Matcher<T>(new internal::AnyMatcherImpl<T>());
+}
+
+// Creates a matcher that matches any value of the given type T.
+template <typename T>
+inline Matcher<T> An() { return A<T>(); }
+
+template <typename T, typename M>
+Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl(
+ const M& value,
+ internal::BooleanConstant<false> /* convertible_to_matcher */,
+ internal::BooleanConstant<false> /* convertible_to_T */) {
+ return Eq(value);
+}
+
+// Creates a polymorphic matcher that matches any NULL pointer.
+inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() {
+ return MakePolymorphicMatcher(internal::IsNullMatcher());
+}
+
+// Creates a polymorphic matcher that matches any non-NULL pointer.
+// This is convenient as Not(NULL) doesn't compile (the compiler
+// thinks that that expression is comparing a pointer with an integer).
+inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() {
+ return MakePolymorphicMatcher(internal::NotNullMatcher());
+}
+
+// Creates a polymorphic matcher that matches any argument that
+// references variable x.
+template <typename T>
+inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT
+ return internal::RefMatcher<T&>(x);
+}
+
+// Creates a matcher that matches any double argument approximately
+// equal to rhs, where two NANs are considered unequal.
+inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
+ return internal::FloatingEqMatcher<double>(rhs, false);
+}
+
+// Creates a matcher that matches any double argument approximately
+// equal to rhs, including NaN values when rhs is NaN.
+inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) {
+ return internal::FloatingEqMatcher<double>(rhs, true);
+}
+
+// Creates a matcher that matches any double argument approximately equal to
+// rhs, up to the specified max absolute error bound, where two NANs are
+// considered unequal. The max absolute error bound must be non-negative.
+inline internal::FloatingEqMatcher<double> DoubleNear(
+ double rhs, double max_abs_error) {
+ return internal::FloatingEqMatcher<double>(rhs, false, max_abs_error);
+}
+
+// Creates a matcher that matches any double argument approximately equal to
+// rhs, up to the specified max absolute error bound, including NaN values when
+// rhs is NaN. The max absolute error bound must be non-negative.
+inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear(
+ double rhs, double max_abs_error) {
+ return internal::FloatingEqMatcher<double>(rhs, true, max_abs_error);
+}
+
+// Creates a matcher that matches any float argument approximately
+// equal to rhs, where two NANs are considered unequal.
+inline internal::FloatingEqMatcher<float> FloatEq(float rhs) {
+ return internal::FloatingEqMatcher<float>(rhs, false);
+}
+
+// Creates a matcher that matches any float argument approximately
+// equal to rhs, including NaN values when rhs is NaN.
+inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) {
+ return internal::FloatingEqMatcher<float>(rhs, true);
+}
+
+// Creates a matcher that matches any float argument approximately equal to
+// rhs, up to the specified max absolute error bound, where two NANs are
+// considered unequal. The max absolute error bound must be non-negative.
+inline internal::FloatingEqMatcher<float> FloatNear(
+ float rhs, float max_abs_error) {
+ return internal::FloatingEqMatcher<float>(rhs, false, max_abs_error);
+}
+
+// Creates a matcher that matches any float argument approximately equal to
+// rhs, up to the specified max absolute error bound, including NaN values when
+// rhs is NaN. The max absolute error bound must be non-negative.
+inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear(
+ float rhs, float max_abs_error) {
+ return internal::FloatingEqMatcher<float>(rhs, true, max_abs_error);
+}
+
+// Creates a matcher that matches a pointer (raw or smart) that points
+// to a value that matches inner_matcher.
+template <typename InnerMatcher>
+inline internal::PointeeMatcher<InnerMatcher> Pointee(
+ const InnerMatcher& inner_matcher) {
+ return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
+}
+
+#if GTEST_HAS_RTTI
+// Creates a matcher that matches a pointer or reference that matches
+// inner_matcher when dynamic_cast<To> is applied.
+// The result of dynamic_cast<To> is forwarded to the inner matcher.
+// If To is a pointer and the cast fails, the inner matcher will receive NULL.
+// If To is a reference and the cast fails, this matcher returns false
+// immediately.
+template <typename To>
+inline PolymorphicMatcher<internal::WhenDynamicCastToMatcher<To> >
+WhenDynamicCastTo(const Matcher<To>& inner_matcher) {
+ return MakePolymorphicMatcher(
+ internal::WhenDynamicCastToMatcher<To>(inner_matcher));
+}
+#endif // GTEST_HAS_RTTI
+
+// Creates a matcher that matches an object whose given field matches
+// 'matcher'. For example,
+// Field(&Foo::number, Ge(5))
+// matches a Foo object x iff x.number >= 5.
+template <typename Class, typename FieldType, typename FieldMatcher>
+inline PolymorphicMatcher<
+ internal::FieldMatcher<Class, FieldType> > Field(
+ FieldType Class::*field, const FieldMatcher& matcher) {
+ return MakePolymorphicMatcher(
+ internal::FieldMatcher<Class, FieldType>(
+ field, MatcherCast<const FieldType&>(matcher)));
+ // The call to MatcherCast() is required for supporting inner
+ // matchers of compatible types. For example, it allows
+ // Field(&Foo::bar, m)
+ // to compile where bar is an int32 and m is a matcher for int64.
+}
+
+// Same as Field() but also takes the name of the field to provide better error
+// messages.
+template <typename Class, typename FieldType, typename FieldMatcher>
+inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType> > Field(
+ const std::string& field_name, FieldType Class::*field,
+ const FieldMatcher& matcher) {
+ return MakePolymorphicMatcher(internal::FieldMatcher<Class, FieldType>(
+ field_name, field, MatcherCast<const FieldType&>(matcher)));
+}
+
+// Creates a matcher that matches an object whose given property
+// matches 'matcher'. For example,
+// Property(&Foo::str, StartsWith("hi"))
+// matches a Foo object x iff x.str() starts with "hi".
+template <typename Class, typename PropertyType, typename PropertyMatcher>
+inline PolymorphicMatcher<internal::PropertyMatcher<
+ Class, PropertyType, PropertyType (Class::*)() const> >
+Property(PropertyType (Class::*property)() const,
+ const PropertyMatcher& matcher) {
+ return MakePolymorphicMatcher(
+ internal::PropertyMatcher<Class, PropertyType,
+ PropertyType (Class::*)() const>(
+ property, MatcherCast<const PropertyType&>(matcher)));
+ // The call to MatcherCast() is required for supporting inner
+ // matchers of compatible types. For example, it allows
+ // Property(&Foo::bar, m)
+ // to compile where bar() returns an int32 and m is a matcher for int64.
+}
+
+// Same as Property() above, but also takes the name of the property to provide
+// better error messages.
+template <typename Class, typename PropertyType, typename PropertyMatcher>
+inline PolymorphicMatcher<internal::PropertyMatcher<
+ Class, PropertyType, PropertyType (Class::*)() const> >
+Property(const std::string& property_name,
+ PropertyType (Class::*property)() const,
+ const PropertyMatcher& matcher) {
+ return MakePolymorphicMatcher(
+ internal::PropertyMatcher<Class, PropertyType,
+ PropertyType (Class::*)() const>(
+ property_name, property, MatcherCast<const PropertyType&>(matcher)));
+}
+
+// The same as above but for reference-qualified member functions.
+template <typename Class, typename PropertyType, typename PropertyMatcher>
+inline PolymorphicMatcher<internal::PropertyMatcher<
+ Class, PropertyType, PropertyType (Class::*)() const &> >
+Property(PropertyType (Class::*property)() const &,
+ const PropertyMatcher& matcher) {
+ return MakePolymorphicMatcher(
+ internal::PropertyMatcher<Class, PropertyType,
+ PropertyType (Class::*)() const&>(
+ property, MatcherCast<const PropertyType&>(matcher)));
+}
+
+// Three-argument form for reference-qualified member functions.
+template <typename Class, typename PropertyType, typename PropertyMatcher>
+inline PolymorphicMatcher<internal::PropertyMatcher<
+ Class, PropertyType, PropertyType (Class::*)() const &> >
+Property(const std::string& property_name,
+ PropertyType (Class::*property)() const &,
+ const PropertyMatcher& matcher) {
+ return MakePolymorphicMatcher(
+ internal::PropertyMatcher<Class, PropertyType,
+ PropertyType (Class::*)() const&>(
+ property_name, property, MatcherCast<const PropertyType&>(matcher)));
+}
+
+// Creates a matcher that matches an object iff the result of applying
+// a callable to x matches 'matcher'.
+// For example,
+// ResultOf(f, StartsWith("hi"))
+// matches a Foo object x iff f(x) starts with "hi".
+// `callable` parameter can be a function, function pointer, or a functor. It is
+// required to keep no state affecting the results of the calls on it and make
+// no assumptions about how many calls will be made. Any state it keeps must be
+// protected from the concurrent access.
+template <typename Callable, typename InnerMatcher>
+internal::ResultOfMatcher<Callable, InnerMatcher> ResultOf(
+ Callable callable, InnerMatcher matcher) {
+ return internal::ResultOfMatcher<Callable, InnerMatcher>(
+ std::move(callable), std::move(matcher));
+}
+
+// String matchers.
+
+// Matches a string equal to str.
+inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrEq(
+ const std::string& str) {
+ return MakePolymorphicMatcher(
+ internal::StrEqualityMatcher<std::string>(str, true, true));
+}
+
+// Matches a string not equal to str.
+inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrNe(
+ const std::string& str) {
+ return MakePolymorphicMatcher(
+ internal::StrEqualityMatcher<std::string>(str, false, true));
+}
+
+// Matches a string equal to str, ignoring case.
+inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseEq(
+ const std::string& str) {
+ return MakePolymorphicMatcher(
+ internal::StrEqualityMatcher<std::string>(str, true, false));
+}
+
+// Matches a string not equal to str, ignoring case.
+inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseNe(
+ const std::string& str) {
+ return MakePolymorphicMatcher(
+ internal::StrEqualityMatcher<std::string>(str, false, false));
+}
+
+// Creates a matcher that matches any string, std::string, or C string
+// that contains the given substring.
+inline PolymorphicMatcher<internal::HasSubstrMatcher<std::string> > HasSubstr(
+ const std::string& substring) {
+ return MakePolymorphicMatcher(
+ internal::HasSubstrMatcher<std::string>(substring));
+}
+
+// Matches a string that starts with 'prefix' (case-sensitive).
+inline PolymorphicMatcher<internal::StartsWithMatcher<std::string> > StartsWith(
+ const std::string& prefix) {
+ return MakePolymorphicMatcher(
+ internal::StartsWithMatcher<std::string>(prefix));
+}
+
+// Matches a string that ends with 'suffix' (case-sensitive).
+inline PolymorphicMatcher<internal::EndsWithMatcher<std::string> > EndsWith(
+ const std::string& suffix) {
+ return MakePolymorphicMatcher(internal::EndsWithMatcher<std::string>(suffix));
+}
+
+#if GTEST_HAS_STD_WSTRING
+// Wide string matchers.
+
+// Matches a string equal to str.
+inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrEq(
+ const std::wstring& str) {
+ return MakePolymorphicMatcher(
+ internal::StrEqualityMatcher<std::wstring>(str, true, true));
+}
+
+// Matches a string not equal to str.
+inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrNe(
+ const std::wstring& str) {
+ return MakePolymorphicMatcher(
+ internal::StrEqualityMatcher<std::wstring>(str, false, true));
+}
+
+// Matches a string equal to str, ignoring case.
+inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> >
+StrCaseEq(const std::wstring& str) {
+ return MakePolymorphicMatcher(
+ internal::StrEqualityMatcher<std::wstring>(str, true, false));
+}
+
+// Matches a string not equal to str, ignoring case.
+inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> >
+StrCaseNe(const std::wstring& str) {
+ return MakePolymorphicMatcher(
+ internal::StrEqualityMatcher<std::wstring>(str, false, false));
+}
+
+// Creates a matcher that matches any ::wstring, std::wstring, or C wide string
+// that contains the given substring.
+inline PolymorphicMatcher<internal::HasSubstrMatcher<std::wstring> > HasSubstr(
+ const std::wstring& substring) {
+ return MakePolymorphicMatcher(
+ internal::HasSubstrMatcher<std::wstring>(substring));
+}
+
+// Matches a string that starts with 'prefix' (case-sensitive).
+inline PolymorphicMatcher<internal::StartsWithMatcher<std::wstring> >
+StartsWith(const std::wstring& prefix) {
+ return MakePolymorphicMatcher(
+ internal::StartsWithMatcher<std::wstring>(prefix));
+}
+
+// Matches a string that ends with 'suffix' (case-sensitive).
+inline PolymorphicMatcher<internal::EndsWithMatcher<std::wstring> > EndsWith(
+ const std::wstring& suffix) {
+ return MakePolymorphicMatcher(
+ internal::EndsWithMatcher<std::wstring>(suffix));
+}
+
+#endif // GTEST_HAS_STD_WSTRING
+
+// Creates a polymorphic matcher that matches a 2-tuple where the
+// first field == the second field.
+inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); }
+
+// Creates a polymorphic matcher that matches a 2-tuple where the
+// first field >= the second field.
+inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); }
+
+// Creates a polymorphic matcher that matches a 2-tuple where the
+// first field > the second field.
+inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); }
+
+// Creates a polymorphic matcher that matches a 2-tuple where the
+// first field <= the second field.
+inline internal::Le2Matcher Le() { return internal::Le2Matcher(); }
+
+// Creates a polymorphic matcher that matches a 2-tuple where the
+// first field < the second field.
+inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); }
+
+// Creates a polymorphic matcher that matches a 2-tuple where the
+// first field != the second field.
+inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); }
+
+// Creates a polymorphic matcher that matches a 2-tuple where
+// FloatEq(first field) matches the second field.
+inline internal::FloatingEq2Matcher<float> FloatEq() {
+ return internal::FloatingEq2Matcher<float>();
+}
+
+// Creates a polymorphic matcher that matches a 2-tuple where
+// DoubleEq(first field) matches the second field.
+inline internal::FloatingEq2Matcher<double> DoubleEq() {
+ return internal::FloatingEq2Matcher<double>();
+}
+
+// Creates a polymorphic matcher that matches a 2-tuple where
+// FloatEq(first field) matches the second field with NaN equality.
+inline internal::FloatingEq2Matcher<float> NanSensitiveFloatEq() {
+ return internal::FloatingEq2Matcher<float>(true);
+}
+
+// Creates a polymorphic matcher that matches a 2-tuple where
+// DoubleEq(first field) matches the second field with NaN equality.
+inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleEq() {
+ return internal::FloatingEq2Matcher<double>(true);
+}
+
+// Creates a polymorphic matcher that matches a 2-tuple where
+// FloatNear(first field, max_abs_error) matches the second field.
+inline internal::FloatingEq2Matcher<float> FloatNear(float max_abs_error) {
+ return internal::FloatingEq2Matcher<float>(max_abs_error);
+}
+
+// Creates a polymorphic matcher that matches a 2-tuple where
+// DoubleNear(first field, max_abs_error) matches the second field.
+inline internal::FloatingEq2Matcher<double> DoubleNear(double max_abs_error) {
+ return internal::FloatingEq2Matcher<double>(max_abs_error);
+}
+
+// Creates a polymorphic matcher that matches a 2-tuple where
+// FloatNear(first field, max_abs_error) matches the second field with NaN
+// equality.
+inline internal::FloatingEq2Matcher<float> NanSensitiveFloatNear(
+ float max_abs_error) {
+ return internal::FloatingEq2Matcher<float>(max_abs_error, true);
+}
+
+// Creates a polymorphic matcher that matches a 2-tuple where
+// DoubleNear(first field, max_abs_error) matches the second field with NaN
+// equality.
+inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleNear(
+ double max_abs_error) {
+ return internal::FloatingEq2Matcher<double>(max_abs_error, true);
+}
+
+// Creates a matcher that matches any value of type T that m doesn't
+// match.
+template <typename InnerMatcher>
+inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
+ return internal::NotMatcher<InnerMatcher>(m);
+}
+
+// Returns a matcher that matches anything that satisfies the given
+// predicate. The predicate can be any unary function or functor
+// whose return type can be implicitly converted to bool.
+template <typename Predicate>
+inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
+Truly(Predicate pred) {
+ return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
+}
+
+// Returns a matcher that matches the container size. The container must
+// support both size() and size_type which all STL-like containers provide.
+// Note that the parameter 'size' can be a value of type size_type as well as
+// matcher. For instance:
+// EXPECT_THAT(container, SizeIs(2)); // Checks container has 2 elements.
+// EXPECT_THAT(container, SizeIs(Le(2)); // Checks container has at most 2.
+template <typename SizeMatcher>
+inline internal::SizeIsMatcher<SizeMatcher>
+SizeIs(const SizeMatcher& size_matcher) {
+ return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
+}
+
+// Returns a matcher that matches the distance between the container's begin()
+// iterator and its end() iterator, i.e. the size of the container. This matcher
+// can be used instead of SizeIs with containers such as std::forward_list which
+// do not implement size(). The container must provide const_iterator (with
+// valid iterator_traits), begin() and end().
+template <typename DistanceMatcher>
+inline internal::BeginEndDistanceIsMatcher<DistanceMatcher>
+BeginEndDistanceIs(const DistanceMatcher& distance_matcher) {
+ return internal::BeginEndDistanceIsMatcher<DistanceMatcher>(distance_matcher);
+}
+
+// Returns a matcher that matches an equal container.
+// This matcher behaves like Eq(), but in the event of mismatch lists the
+// values that are included in one container but not the other. (Duplicate
+// values and order differences are not explained.)
+template <typename Container>
+inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT
+ GTEST_REMOVE_CONST_(Container)> >
+ ContainerEq(const Container& rhs) {
+ // This following line is for working around a bug in MSVC 8.0,
+ // which causes Container to be a const type sometimes.
+ typedef GTEST_REMOVE_CONST_(Container) RawContainer;
+ return MakePolymorphicMatcher(
+ internal::ContainerEqMatcher<RawContainer>(rhs));
+}
+
+// Returns a matcher that matches a container that, when sorted using
+// the given comparator, matches container_matcher.
+template <typename Comparator, typename ContainerMatcher>
+inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
+WhenSortedBy(const Comparator& comparator,
+ const ContainerMatcher& container_matcher) {
+ return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
+ comparator, container_matcher);
+}
+
+// Returns a matcher that matches a container that, when sorted using
+// the < operator, matches container_matcher.
+template <typename ContainerMatcher>
+inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
+WhenSorted(const ContainerMatcher& container_matcher) {
+ return
+ internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>(
+ internal::LessComparator(), container_matcher);
+}
+
+// Matches an STL-style container or a native array that contains the
+// same number of elements as in rhs, where its i-th element and rhs's
+// i-th element (as a pair) satisfy the given pair matcher, for all i.
+// TupleMatcher must be able to be safely cast to Matcher<std::tuple<const
+// T1&, const T2&> >, where T1 and T2 are the types of elements in the
+// LHS container and the RHS container respectively.
+template <typename TupleMatcher, typename Container>
+inline internal::PointwiseMatcher<TupleMatcher,
+ GTEST_REMOVE_CONST_(Container)>
+Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) {
+ // This following line is for working around a bug in MSVC 8.0,
+ // which causes Container to be a const type sometimes (e.g. when
+ // rhs is a const int[])..
+ typedef GTEST_REMOVE_CONST_(Container) RawContainer;
+ return internal::PointwiseMatcher<TupleMatcher, RawContainer>(
+ tuple_matcher, rhs);
+}
+
+
+// Supports the Pointwise(m, {a, b, c}) syntax.
+template <typename TupleMatcher, typename T>
+inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> > Pointwise(
+ const TupleMatcher& tuple_matcher, std::initializer_list<T> rhs) {
+ return Pointwise(tuple_matcher, std::vector<T>(rhs));
+}
+
+
+// UnorderedPointwise(pair_matcher, rhs) matches an STL-style
+// container or a native array that contains the same number of
+// elements as in rhs, where in some permutation of the container, its
+// i-th element and rhs's i-th element (as a pair) satisfy the given
+// pair matcher, for all i. Tuple2Matcher must be able to be safely
+// cast to Matcher<std::tuple<const T1&, const T2&> >, where T1 and T2 are
+// the types of elements in the LHS container and the RHS container
+// respectively.
+//
+// This is like Pointwise(pair_matcher, rhs), except that the element
+// order doesn't matter.
+template <typename Tuple2Matcher, typename RhsContainer>
+inline internal::UnorderedElementsAreArrayMatcher<
+ typename internal::BoundSecondMatcher<
+ Tuple2Matcher, typename internal::StlContainerView<GTEST_REMOVE_CONST_(
+ RhsContainer)>::type::value_type> >
+UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
+ const RhsContainer& rhs_container) {
+ // This following line is for working around a bug in MSVC 8.0,
+ // which causes RhsContainer to be a const type sometimes (e.g. when
+ // rhs_container is a const int[]).
+ typedef GTEST_REMOVE_CONST_(RhsContainer) RawRhsContainer;
+
+ // RhsView allows the same code to handle RhsContainer being a
+ // STL-style container and it being a native C-style array.
+ typedef typename internal::StlContainerView<RawRhsContainer> RhsView;
+ typedef typename RhsView::type RhsStlContainer;
+ typedef typename RhsStlContainer::value_type Second;
+ const RhsStlContainer& rhs_stl_container =
+ RhsView::ConstReference(rhs_container);
+
+ // Create a matcher for each element in rhs_container.
+ ::std::vector<internal::BoundSecondMatcher<Tuple2Matcher, Second> > matchers;
+ for (typename RhsStlContainer::const_iterator it = rhs_stl_container.begin();
+ it != rhs_stl_container.end(); ++it) {
+ matchers.push_back(
+ internal::MatcherBindSecond(tuple2_matcher, *it));
+ }
+
+ // Delegate the work to UnorderedElementsAreArray().
+ return UnorderedElementsAreArray(matchers);
+}
+
+
+// Supports the UnorderedPointwise(m, {a, b, c}) syntax.
+template <typename Tuple2Matcher, typename T>
+inline internal::UnorderedElementsAreArrayMatcher<
+ typename internal::BoundSecondMatcher<Tuple2Matcher, T> >
+UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
+ std::initializer_list<T> rhs) {
+ return UnorderedPointwise(tuple2_matcher, std::vector<T>(rhs));
+}
+
+
+// Matches an STL-style container or a native array that contains at
+// least one element matching the given value or matcher.
+//
+// Examples:
+// ::std::set<int> page_ids;
+// page_ids.insert(3);
+// page_ids.insert(1);
+// EXPECT_THAT(page_ids, Contains(1));
+// EXPECT_THAT(page_ids, Contains(Gt(2)));
+// EXPECT_THAT(page_ids, Not(Contains(4)));
+//
+// ::std::map<int, size_t> page_lengths;
+// page_lengths[1] = 100;
+// EXPECT_THAT(page_lengths,
+// Contains(::std::pair<const int, size_t>(1, 100)));
+//
+// const char* user_ids[] = { "joe", "mike", "tom" };
+// EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom"))));
+template <typename M>
+inline internal::ContainsMatcher<M> Contains(M matcher) {
+ return internal::ContainsMatcher<M>(matcher);
+}
+
+// IsSupersetOf(iterator_first, iterator_last)
+// IsSupersetOf(pointer, count)
+// IsSupersetOf(array)
+// IsSupersetOf(container)
+// IsSupersetOf({e1, e2, ..., en})
+//
+// IsSupersetOf() verifies that a surjective partial mapping onto a collection
+// of matchers exists. In other words, a container matches
+// IsSupersetOf({e1, ..., en}) if and only if there is a permutation
+// {y1, ..., yn} of some of the container's elements where y1 matches e1,
+// ..., and yn matches en. Obviously, the size of the container must be >= n
+// in order to have a match. Examples:
+//
+// - {1, 2, 3} matches IsSupersetOf({Ge(3), Ne(0)}), as 3 matches Ge(3) and
+// 1 matches Ne(0).
+// - {1, 2} doesn't match IsSupersetOf({Eq(1), Lt(2)}), even though 1 matches
+// both Eq(1) and Lt(2). The reason is that different matchers must be used
+// for elements in different slots of the container.
+// - {1, 1, 2} matches IsSupersetOf({Eq(1), Lt(2)}), as (the first) 1 matches
+// Eq(1) and (the second) 1 matches Lt(2).
+// - {1, 2, 3} matches IsSupersetOf(Gt(1), Gt(1)), as 2 matches (the first)
+// Gt(1) and 3 matches (the second) Gt(1).
+//
+// The matchers can be specified as an array, a pointer and count, a container,
+// an initializer list, or an STL iterator range. In each of these cases, the
+// underlying matchers can be either values or matchers.
+
+template <typename Iter>
+inline internal::UnorderedElementsAreArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>
+IsSupersetOf(Iter first, Iter last) {
+ typedef typename ::std::iterator_traits<Iter>::value_type T;
+ return internal::UnorderedElementsAreArrayMatcher<T>(
+ internal::UnorderedMatcherRequire::Superset, first, last);
+}
+
+template <typename T>
+inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
+ const T* pointer, size_t count) {
+ return IsSupersetOf(pointer, pointer + count);
+}
+
+template <typename T, size_t N>
+inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
+ const T (&array)[N]) {
+ return IsSupersetOf(array, N);
+}
+
+template <typename Container>
+inline internal::UnorderedElementsAreArrayMatcher<
+ typename Container::value_type>
+IsSupersetOf(const Container& container) {
+ return IsSupersetOf(container.begin(), container.end());
+}
+
+template <typename T>
+inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
+ ::std::initializer_list<T> xs) {
+ return IsSupersetOf(xs.begin(), xs.end());
+}
+
+// IsSubsetOf(iterator_first, iterator_last)
+// IsSubsetOf(pointer, count)
+// IsSubsetOf(array)
+// IsSubsetOf(container)
+// IsSubsetOf({e1, e2, ..., en})
+//
+// IsSubsetOf() verifies that an injective mapping onto a collection of matchers
+// exists. In other words, a container matches IsSubsetOf({e1, ..., en}) if and
+// only if there is a subset of matchers {m1, ..., mk} which would match the
+// container using UnorderedElementsAre. Obviously, the size of the container
+// must be <= n in order to have a match. Examples:
+//
+// - {1} matches IsSubsetOf({Gt(0), Lt(0)}), as 1 matches Gt(0).
+// - {1, -1} matches IsSubsetOf({Lt(0), Gt(0)}), as 1 matches Gt(0) and -1
+// matches Lt(0).
+// - {1, 2} doesn't matches IsSubsetOf({Gt(0), Lt(0)}), even though 1 and 2 both
+// match Gt(0). The reason is that different matchers must be used for
+// elements in different slots of the container.
+//
+// The matchers can be specified as an array, a pointer and count, a container,
+// an initializer list, or an STL iterator range. In each of these cases, the
+// underlying matchers can be either values or matchers.
+
+template <typename Iter>
+inline internal::UnorderedElementsAreArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>
+IsSubsetOf(Iter first, Iter last) {
+ typedef typename ::std::iterator_traits<Iter>::value_type T;
+ return internal::UnorderedElementsAreArrayMatcher<T>(
+ internal::UnorderedMatcherRequire::Subset, first, last);
+}
+
+template <typename T>
+inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
+ const T* pointer, size_t count) {
+ return IsSubsetOf(pointer, pointer + count);
+}
+
+template <typename T, size_t N>
+inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
+ const T (&array)[N]) {
+ return IsSubsetOf(array, N);
+}
+
+template <typename Container>
+inline internal::UnorderedElementsAreArrayMatcher<
+ typename Container::value_type>
+IsSubsetOf(const Container& container) {
+ return IsSubsetOf(container.begin(), container.end());
+}
+
+template <typename T>
+inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
+ ::std::initializer_list<T> xs) {
+ return IsSubsetOf(xs.begin(), xs.end());
+}
+
+// Matches an STL-style container or a native array that contains only
+// elements matching the given value or matcher.
+//
+// Each(m) is semantically equivalent to Not(Contains(Not(m))). Only
+// the messages are different.
+//
+// Examples:
+// ::std::set<int> page_ids;
+// // Each(m) matches an empty container, regardless of what m is.
+// EXPECT_THAT(page_ids, Each(Eq(1)));
+// EXPECT_THAT(page_ids, Each(Eq(77)));
+//
+// page_ids.insert(3);
+// EXPECT_THAT(page_ids, Each(Gt(0)));
+// EXPECT_THAT(page_ids, Not(Each(Gt(4))));
+// page_ids.insert(1);
+// EXPECT_THAT(page_ids, Not(Each(Lt(2))));
+//
+// ::std::map<int, size_t> page_lengths;
+// page_lengths[1] = 100;
+// page_lengths[2] = 200;
+// page_lengths[3] = 300;
+// EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100))));
+// EXPECT_THAT(page_lengths, Each(Key(Le(3))));
+//
+// const char* user_ids[] = { "joe", "mike", "tom" };
+// EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom")))));
+template <typename M>
+inline internal::EachMatcher<M> Each(M matcher) {
+ return internal::EachMatcher<M>(matcher);
+}
+
+// Key(inner_matcher) matches an std::pair whose 'first' field matches
+// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
+// std::map that contains at least one element whose key is >= 5.
+template <typename M>
+inline internal::KeyMatcher<M> Key(M inner_matcher) {
+ return internal::KeyMatcher<M>(inner_matcher);
+}
+
+// Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field
+// matches first_matcher and whose 'second' field matches second_matcher. For
+// example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used
+// to match a std::map<int, string> that contains exactly one element whose key
+// is >= 5 and whose value equals "foo".
+template <typename FirstMatcher, typename SecondMatcher>
+inline internal::PairMatcher<FirstMatcher, SecondMatcher>
+Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) {
+ return internal::PairMatcher<FirstMatcher, SecondMatcher>(
+ first_matcher, second_matcher);
+}
+
+// Returns a predicate that is satisfied by anything that matches the
+// given matcher.
+template <typename M>
+inline internal::MatcherAsPredicate<M> Matches(M matcher) {
+ return internal::MatcherAsPredicate<M>(matcher);
+}
+
+// Returns true iff the value matches the matcher.
+template <typename T, typename M>
+inline bool Value(const T& value, M matcher) {
+ return testing::Matches(matcher)(value);
+}
+
+// Matches the value against the given matcher and explains the match
+// result to listener.
+template <typename T, typename M>
+inline bool ExplainMatchResult(
+ M matcher, const T& value, MatchResultListener* listener) {
+ return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
+}
+
+// Returns a string representation of the given matcher. Useful for description
+// strings of matchers defined using MATCHER_P* macros that accept matchers as
+// their arguments. For example:
+//
+// MATCHER_P(XAndYThat, matcher,
+// "X that " + DescribeMatcher<int>(matcher, negation) +
+// " and Y that " + DescribeMatcher<double>(matcher, negation)) {
+// return ExplainMatchResult(matcher, arg.x(), result_listener) &&
+// ExplainMatchResult(matcher, arg.y(), result_listener);
+// }
+template <typename T, typename M>
+std::string DescribeMatcher(const M& matcher, bool negation = false) {
+ ::std::stringstream ss;
+ Matcher<T> monomorphic_matcher = SafeMatcherCast<T>(matcher);
+ if (negation) {
+ monomorphic_matcher.DescribeNegationTo(&ss);
+ } else {
+ monomorphic_matcher.DescribeTo(&ss);
+ }
+ return ss.str();
+}
+
+template <typename... Args>
+internal::ElementsAreMatcher<
+ std::tuple<typename std::decay<const Args&>::type...>>
+ElementsAre(const Args&... matchers) {
+ return internal::ElementsAreMatcher<
+ std::tuple<typename std::decay<const Args&>::type...>>(
+ std::make_tuple(matchers...));
+}
+
+template <typename... Args>
+internal::UnorderedElementsAreMatcher<
+ std::tuple<typename std::decay<const Args&>::type...>>
+UnorderedElementsAre(const Args&... matchers) {
+ return internal::UnorderedElementsAreMatcher<
+ std::tuple<typename std::decay<const Args&>::type...>>(
+ std::make_tuple(matchers...));
+}
+
+// Define variadic matcher versions.
+template <typename... Args>
+internal::AllOfMatcher<typename std::decay<const Args&>::type...> AllOf(
+ const Args&... matchers) {
+ return internal::AllOfMatcher<typename std::decay<const Args&>::type...>(
+ matchers...);
+}
+
+template <typename... Args>
+internal::AnyOfMatcher<typename std::decay<const Args&>::type...> AnyOf(
+ const Args&... matchers) {
+ return internal::AnyOfMatcher<typename std::decay<const Args&>::type...>(
+ matchers...);
+}
+
+// AnyOfArray(array)
+// AnyOfArray(pointer, count)
+// AnyOfArray(container)
+// AnyOfArray({ e1, e2, ..., en })
+// AnyOfArray(iterator_first, iterator_last)
+//
+// AnyOfArray() verifies whether a given value matches any member of a
+// collection of matchers.
+//
+// AllOfArray(array)
+// AllOfArray(pointer, count)
+// AllOfArray(container)
+// AllOfArray({ e1, e2, ..., en })
+// AllOfArray(iterator_first, iterator_last)
+//
+// AllOfArray() verifies whether a given value matches all members of a
+// collection of matchers.
+//
+// The matchers can be specified as an array, a pointer and count, a container,
+// an initializer list, or an STL iterator range. In each of these cases, the
+// underlying matchers can be either values or matchers.
+
+template <typename Iter>
+inline internal::AnyOfArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>
+AnyOfArray(Iter first, Iter last) {
+ return internal::AnyOfArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>(first, last);
+}
+
+template <typename Iter>
+inline internal::AllOfArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>
+AllOfArray(Iter first, Iter last) {
+ return internal::AllOfArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>(first, last);
+}
+
+template <typename T>
+inline internal::AnyOfArrayMatcher<T> AnyOfArray(const T* ptr, size_t count) {
+ return AnyOfArray(ptr, ptr + count);
+}
+
+template <typename T>
+inline internal::AllOfArrayMatcher<T> AllOfArray(const T* ptr, size_t count) {
+ return AllOfArray(ptr, ptr + count);
+}
+
+template <typename T, size_t N>
+inline internal::AnyOfArrayMatcher<T> AnyOfArray(const T (&array)[N]) {
+ return AnyOfArray(array, N);
+}
+
+template <typename T, size_t N>
+inline internal::AllOfArrayMatcher<T> AllOfArray(const T (&array)[N]) {
+ return AllOfArray(array, N);
+}
+
+template <typename Container>
+inline internal::AnyOfArrayMatcher<typename Container::value_type> AnyOfArray(
+ const Container& container) {
+ return AnyOfArray(container.begin(), container.end());
+}
+
+template <typename Container>
+inline internal::AllOfArrayMatcher<typename Container::value_type> AllOfArray(
+ const Container& container) {
+ return AllOfArray(container.begin(), container.end());
+}
+
+template <typename T>
+inline internal::AnyOfArrayMatcher<T> AnyOfArray(
+ ::std::initializer_list<T> xs) {
+ return AnyOfArray(xs.begin(), xs.end());
+}
+
+template <typename T>
+inline internal::AllOfArrayMatcher<T> AllOfArray(
+ ::std::initializer_list<T> xs) {
+ return AllOfArray(xs.begin(), xs.end());
+}
+
+// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
+// fields of it matches a_matcher. C++ doesn't support default
+// arguments for function templates, so we have to overload it.
+template <size_t... k, typename InnerMatcher>
+internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...> Args(
+ InnerMatcher&& matcher) {
+ return internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...>(
+ std::forward<InnerMatcher>(matcher));
+}
+
+// AllArgs(m) is a synonym of m. This is useful in
+//
+// EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
+//
+// which is easier to read than
+//
+// EXPECT_CALL(foo, Bar(_, _)).With(Eq());
+template <typename InnerMatcher>
+inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
+
+// Returns a matcher that matches the value of an optional<> type variable.
+// The matcher implementation only uses '!arg' and requires that the optional<>
+// type has a 'value_type' member type and that '*arg' is of type 'value_type'
+// and is printable using 'PrintToString'. It is compatible with
+// std::optional/std::experimental::optional.
+// Note that to compare an optional type variable against nullopt you should
+// use Eq(nullopt) and not Optional(Eq(nullopt)). The latter implies that the
+// optional value contains an optional itself.
+template <typename ValueMatcher>
+inline internal::OptionalMatcher<ValueMatcher> Optional(
+ const ValueMatcher& value_matcher) {
+ return internal::OptionalMatcher<ValueMatcher>(value_matcher);
+}
+
+// Returns a matcher that matches the value of a absl::any type variable.
+template <typename T>
+PolymorphicMatcher<internal::any_cast_matcher::AnyCastMatcher<T> > AnyWith(
+ const Matcher<const T&>& matcher) {
+ return MakePolymorphicMatcher(
+ internal::any_cast_matcher::AnyCastMatcher<T>(matcher));
+}
+
+// Returns a matcher that matches the value of a variant<> type variable.
+// The matcher implementation uses ADL to find the holds_alternative and get
+// functions.
+// It is compatible with std::variant.
+template <typename T>
+PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T> > VariantWith(
+ const Matcher<const T&>& matcher) {
+ return MakePolymorphicMatcher(
+ internal::variant_matcher::VariantMatcher<T>(matcher));
+}
+
+// These macros allow using matchers to check values in Google Test
+// tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
+// succeed iff the value matches the matcher. If the assertion fails,
+// the value and the description of the matcher will be printed.
+#define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
+ ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+#define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
+ ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+
+} // namespace testing
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 5046
+
+// Include any custom callback matchers added by the local installation.
+// We must include this header at the end to make sure it can use the
+// declarations from this file.
+#include "gmock/internal/custom/gmock-matchers.h"
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements some actions that depend on gmock-generated-actions.h.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
+
+#include <algorithm>
+#include <type_traits>
+
+#include "gmock/gmock-generated-actions.h"
+
+namespace testing {
+namespace internal {
+
+// An internal replacement for std::copy which mimics its behavior. This is
+// necessary because Visual Studio deprecates ::std::copy, issuing warning 4996.
+// However Visual Studio 2010 and later do not honor #pragmas which disable that
+// warning.
+template<typename InputIterator, typename OutputIterator>
+inline OutputIterator CopyElements(InputIterator first,
+ InputIterator last,
+ OutputIterator output) {
+ for (; first != last; ++first, ++output) {
+ *output = *first;
+ }
+ return output;
+}
+
+} // namespace internal
+
+// Various overloads for Invoke().
+
+// The ACTION*() macros trigger warning C4100 (unreferenced formal
+// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
+// the macro definition, as the warnings are generated when the macro
+// is expanded and macro expansion cannot contain #pragma. Therefore
+// we suppress them here.
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable:4100)
+#endif
+
+// Action ReturnArg<k>() returns the k-th argument of the mock function.
+ACTION_TEMPLATE(ReturnArg,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_0_VALUE_PARAMS()) {
+ return ::std::get<k>(args);
+}
+
+// Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
+// mock function to *pointer.
+ACTION_TEMPLATE(SaveArg,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_1_VALUE_PARAMS(pointer)) {
+ *pointer = ::std::get<k>(args);
+}
+
+// Action SaveArgPointee<k>(pointer) saves the value pointed to
+// by the k-th (0-based) argument of the mock function to *pointer.
+ACTION_TEMPLATE(SaveArgPointee,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_1_VALUE_PARAMS(pointer)) {
+ *pointer = *::std::get<k>(args);
+}
+
+// Action SetArgReferee<k>(value) assigns 'value' to the variable
+// referenced by the k-th (0-based) argument of the mock function.
+ACTION_TEMPLATE(SetArgReferee,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_1_VALUE_PARAMS(value)) {
+ typedef typename ::std::tuple_element<k, args_type>::type argk_type;
+ // Ensures that argument #k is a reference. If you get a compiler
+ // error on the next line, you are using SetArgReferee<k>(value) in
+ // a mock function whose k-th (0-based) argument is not a reference.
+ GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
+ SetArgReferee_must_be_used_with_a_reference_argument);
+ ::std::get<k>(args) = value;
+}
+
+// Action SetArrayArgument<k>(first, last) copies the elements in
+// source range [first, last) to the array pointed to by the k-th
+// (0-based) argument, which can be either a pointer or an
+// iterator. The action does not take ownership of the elements in the
+// source range.
+ACTION_TEMPLATE(SetArrayArgument,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_2_VALUE_PARAMS(first, last)) {
+ // Visual Studio deprecates ::std::copy, so we use our own copy in that case.
+#ifdef _MSC_VER
+ internal::CopyElements(first, last, ::std::get<k>(args));
+#else
+ ::std::copy(first, last, ::std::get<k>(args));
+#endif
+}
+
+// Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
+// function.
+ACTION_TEMPLATE(DeleteArg,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_0_VALUE_PARAMS()) {
+ delete ::std::get<k>(args);
+}
+
+// This action returns the value pointed to by 'pointer'.
+ACTION_P(ReturnPointee, pointer) { return *pointer; }
+
+// Action Throw(exception) can be used in a mock function of any type
+// to throw the given exception. Any copyable value can be thrown.
+#if GTEST_HAS_EXCEPTIONS
+
+// Suppresses the 'unreachable code' warning that VC generates in opt modes.
+# ifdef _MSC_VER
+# pragma warning(push) // Saves the current warning state.
+# pragma warning(disable:4702) // Temporarily disables warning 4702.
+# endif
+ACTION_P(Throw, exception) { throw exception; }
+# ifdef _MSC_VER
+# pragma warning(pop) // Restores the warning state.
+# endif
+
+#endif // GTEST_HAS_EXCEPTIONS
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+} // namespace testing
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
--- /dev/null
+// Copyright 2013, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements some matchers that depend on gmock-generated-matchers.h.
+//
+// Note that tests are implemented in gmock-matchers_test.cc rather than
+// gmock-more-matchers-test.cc.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_
+#define GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_
+
+#include "gmock/gmock-generated-matchers.h"
+
+namespace testing {
+
+// Silence C4100 (unreferenced formal
+// parameter) for MSVC
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable:4100)
+#if (_MSC_VER == 1900)
+// and silence C4800 (C4800: 'int *const ': forcing value
+// to bool 'true' or 'false') for MSVC 14
+# pragma warning(disable:4800)
+ #endif
+#endif
+
+// Defines a matcher that matches an empty container. The container must
+// support both size() and empty(), which all STL-like containers provide.
+MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
+ if (arg.empty()) {
+ return true;
+ }
+ *result_listener << "whose size is " << arg.size();
+ return false;
+}
+
+// Define a matcher that matches a value that evaluates in boolean
+// context to true. Useful for types that define "explicit operator
+// bool" operators and so can't be compared for equality with true
+// and false.
+MATCHER(IsTrue, negation ? "is false" : "is true") {
+ return static_cast<bool>(arg);
+}
+
+// Define a matcher that matches a value that evaluates in boolean
+// context to false. Useful for types that define "explicit operator
+// bool" operators and so can't be compared for equality with true
+// and false.
+MATCHER(IsFalse, negation ? "is true" : "is false") {
+ return !static_cast<bool>(arg);
+}
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+
+} // namespace testing
+
+#endif // GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Implements class templates NiceMock, NaggyMock, and StrictMock.
+//
+// Given a mock class MockFoo that is created using Google Mock,
+// NiceMock<MockFoo> is a subclass of MockFoo that allows
+// uninteresting calls (i.e. calls to mock methods that have no
+// EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
+// that prints a warning when an uninteresting call occurs, and
+// StrictMock<MockFoo> is a subclass of MockFoo that treats all
+// uninteresting calls as errors.
+//
+// Currently a mock is naggy by default, so MockFoo and
+// NaggyMock<MockFoo> behave like the same. However, we will soon
+// switch the default behavior of mocks to be nice, as that in general
+// leads to more maintainable tests. When that happens, MockFoo will
+// stop behaving like NaggyMock<MockFoo> and start behaving like
+// NiceMock<MockFoo>.
+//
+// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
+// their respective base class. Therefore you can write
+// NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
+// has a constructor that accepts (int, const char*), for example.
+//
+// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
+// and StrictMock<MockFoo> only works for mock methods defined using
+// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
+// If a mock method is defined in a base class of MockFoo, the "nice"
+// or "strict" modifier may not affect it, depending on the compiler.
+// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
+// supported.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
+
+#include "gmock/gmock-spec-builders.h"
+#include "gmock/internal/gmock-port.h"
+
+namespace testing {
+
+template <class MockClass>
+class NiceMock : public MockClass {
+ public:
+ NiceMock() : MockClass() {
+ ::testing::Mock::AllowUninterestingCalls(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ // Ideally, we would inherit base class's constructors through a using
+ // declaration, which would preserve their visibility. However, many existing
+ // tests rely on the fact that current implementation reexports protected
+ // constructors as public. These tests would need to be cleaned up first.
+
+ // Single argument constructor is special-cased so that it can be
+ // made explicit.
+ template <typename A>
+ explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
+ ::testing::Mock::AllowUninterestingCalls(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ template <typename A1, typename A2, typename... An>
+ NiceMock(A1&& arg1, A2&& arg2, An&&... args)
+ : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
+ std::forward<An>(args)...) {
+ ::testing::Mock::AllowUninterestingCalls(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ ~NiceMock() { // NOLINT
+ ::testing::Mock::UnregisterCallReaction(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
+};
+
+template <class MockClass>
+class NaggyMock : public MockClass {
+ public:
+ NaggyMock() : MockClass() {
+ ::testing::Mock::WarnUninterestingCalls(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ // Ideally, we would inherit base class's constructors through a using
+ // declaration, which would preserve their visibility. However, many existing
+ // tests rely on the fact that current implementation reexports protected
+ // constructors as public. These tests would need to be cleaned up first.
+
+ // Single argument constructor is special-cased so that it can be
+ // made explicit.
+ template <typename A>
+ explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
+ ::testing::Mock::WarnUninterestingCalls(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ template <typename A1, typename A2, typename... An>
+ NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
+ : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
+ std::forward<An>(args)...) {
+ ::testing::Mock::WarnUninterestingCalls(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ ~NaggyMock() { // NOLINT
+ ::testing::Mock::UnregisterCallReaction(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
+};
+
+template <class MockClass>
+class StrictMock : public MockClass {
+ public:
+ StrictMock() : MockClass() {
+ ::testing::Mock::FailUninterestingCalls(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ // Ideally, we would inherit base class's constructors through a using
+ // declaration, which would preserve their visibility. However, many existing
+ // tests rely on the fact that current implementation reexports protected
+ // constructors as public. These tests would need to be cleaned up first.
+
+ // Single argument constructor is special-cased so that it can be
+ // made explicit.
+ template <typename A>
+ explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
+ ::testing::Mock::FailUninterestingCalls(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ template <typename A1, typename A2, typename... An>
+ StrictMock(A1&& arg1, A2&& arg2, An&&... args)
+ : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
+ std::forward<An>(args)...) {
+ ::testing::Mock::FailUninterestingCalls(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ ~StrictMock() { // NOLINT
+ ::testing::Mock::UnregisterCallReaction(
+ internal::ImplicitCast_<MockClass*>(this));
+ }
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
+};
+
+// The following specializations catch some (relatively more common)
+// user errors of nesting nice and strict mocks. They do NOT catch
+// all possible errors.
+
+// These specializations are declared but not defined, as NiceMock,
+// NaggyMock, and StrictMock cannot be nested.
+
+template <typename MockClass>
+class NiceMock<NiceMock<MockClass> >;
+template <typename MockClass>
+class NiceMock<NaggyMock<MockClass> >;
+template <typename MockClass>
+class NiceMock<StrictMock<MockClass> >;
+
+template <typename MockClass>
+class NaggyMock<NiceMock<MockClass> >;
+template <typename MockClass>
+class NaggyMock<NaggyMock<MockClass> >;
+template <typename MockClass>
+class NaggyMock<StrictMock<MockClass> >;
+
+template <typename MockClass>
+class StrictMock<NiceMock<MockClass> >;
+template <typename MockClass>
+class StrictMock<NaggyMock<MockClass> >;
+template <typename MockClass>
+class StrictMock<StrictMock<MockClass> >;
+
+} // namespace testing
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements the ON_CALL() and EXPECT_CALL() macros.
+//
+// A user can use the ON_CALL() macro to specify the default action of
+// a mock method. The syntax is:
+//
+// ON_CALL(mock_object, Method(argument-matchers))
+// .With(multi-argument-matcher)
+// .WillByDefault(action);
+//
+// where the .With() clause is optional.
+//
+// A user can use the EXPECT_CALL() macro to specify an expectation on
+// a mock method. The syntax is:
+//
+// EXPECT_CALL(mock_object, Method(argument-matchers))
+// .With(multi-argument-matchers)
+// .Times(cardinality)
+// .InSequence(sequences)
+// .After(expectations)
+// .WillOnce(action)
+// .WillRepeatedly(action)
+// .RetiresOnSaturation();
+//
+// where all clauses are optional, and .InSequence()/.After()/
+// .WillOnce() can appear any number of times.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
+
+#include <map>
+#include <memory>
+#include <set>
+#include <sstream>
+#include <string>
+#include <utility>
+#include <vector>
+#include "gmock/gmock-actions.h"
+#include "gmock/gmock-cardinalities.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/internal/gmock-internal-utils.h"
+#include "gmock/internal/gmock-port.h"
+#include "gtest/gtest.h"
+
+#if GTEST_HAS_EXCEPTIONS
+# include <stdexcept> // NOLINT
+#endif
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
+/* class A needs to have dll-interface to be used by clients of class B */)
+
+namespace testing {
+
+// An abstract handle of an expectation.
+class Expectation;
+
+// A set of expectation handles.
+class ExpectationSet;
+
+// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
+// and MUST NOT BE USED IN USER CODE!!!
+namespace internal {
+
+// Implements a mock function.
+template <typename F> class FunctionMocker;
+
+// Base class for expectations.
+class ExpectationBase;
+
+// Implements an expectation.
+template <typename F> class TypedExpectation;
+
+// Helper class for testing the Expectation class template.
+class ExpectationTester;
+
+// Protects the mock object registry (in class Mock), all function
+// mockers, and all expectations.
+//
+// The reason we don't use more fine-grained protection is: when a
+// mock function Foo() is called, it needs to consult its expectations
+// to see which one should be picked. If another thread is allowed to
+// call a mock function (either Foo() or a different one) at the same
+// time, it could affect the "retired" attributes of Foo()'s
+// expectations when InSequence() is used, and thus affect which
+// expectation gets picked. Therefore, we sequence all mock function
+// calls to ensure the integrity of the mock objects' states.
+GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
+
+// Untyped base class for ActionResultHolder<R>.
+class UntypedActionResultHolderBase;
+
+// Abstract base class of FunctionMocker. This is the
+// type-agnostic part of the function mocker interface. Its pure
+// virtual methods are implemented by FunctionMocker.
+class GTEST_API_ UntypedFunctionMockerBase {
+ public:
+ UntypedFunctionMockerBase();
+ virtual ~UntypedFunctionMockerBase();
+
+ // Verifies that all expectations on this mock function have been
+ // satisfied. Reports one or more Google Test non-fatal failures
+ // and returns false if not.
+ bool VerifyAndClearExpectationsLocked()
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
+
+ // Clears the ON_CALL()s set on this mock function.
+ virtual void ClearDefaultActionsLocked()
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0;
+
+ // In all of the following Untyped* functions, it's the caller's
+ // responsibility to guarantee the correctness of the arguments'
+ // types.
+
+ // Performs the default action with the given arguments and returns
+ // the action's result. The call description string will be used in
+ // the error message to describe the call in the case the default
+ // action fails.
+ // L = *
+ virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
+ void* untyped_args, const std::string& call_description) const = 0;
+
+ // Performs the given action with the given arguments and returns
+ // the action's result.
+ // L = *
+ virtual UntypedActionResultHolderBase* UntypedPerformAction(
+ const void* untyped_action, void* untyped_args) const = 0;
+
+ // Writes a message that the call is uninteresting (i.e. neither
+ // explicitly expected nor explicitly unexpected) to the given
+ // ostream.
+ virtual void UntypedDescribeUninterestingCall(
+ const void* untyped_args,
+ ::std::ostream* os) const
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
+
+ // Returns the expectation that matches the given function arguments
+ // (or NULL is there's no match); when a match is found,
+ // untyped_action is set to point to the action that should be
+ // performed (or NULL if the action is "do default"), and
+ // is_excessive is modified to indicate whether the call exceeds the
+ // expected number.
+ virtual const ExpectationBase* UntypedFindMatchingExpectation(
+ const void* untyped_args,
+ const void** untyped_action, bool* is_excessive,
+ ::std::ostream* what, ::std::ostream* why)
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
+
+ // Prints the given function arguments to the ostream.
+ virtual void UntypedPrintArgs(const void* untyped_args,
+ ::std::ostream* os) const = 0;
+
+ // Sets the mock object this mock method belongs to, and registers
+ // this information in the global mock registry. Will be called
+ // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
+ // method.
+ void RegisterOwner(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
+
+ // Sets the mock object this mock method belongs to, and sets the
+ // name of the mock function. Will be called upon each invocation
+ // of this mock function.
+ void SetOwnerAndName(const void* mock_obj, const char* name)
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
+
+ // Returns the mock object this mock method belongs to. Must be
+ // called after RegisterOwner() or SetOwnerAndName() has been
+ // called.
+ const void* MockObject() const
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
+
+ // Returns the name of this mock method. Must be called after
+ // SetOwnerAndName() has been called.
+ const char* Name() const
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
+
+ // Returns the result of invoking this mock function with the given
+ // arguments. This function can be safely called from multiple
+ // threads concurrently. The caller is responsible for deleting the
+ // result.
+ UntypedActionResultHolderBase* UntypedInvokeWith(void* untyped_args)
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
+
+ protected:
+ typedef std::vector<const void*> UntypedOnCallSpecs;
+
+ using UntypedExpectations = std::vector<std::shared_ptr<ExpectationBase>>;
+
+ // Returns an Expectation object that references and co-owns exp,
+ // which must be an expectation on this mock function.
+ Expectation GetHandleOf(ExpectationBase* exp);
+
+ // Address of the mock object this mock method belongs to. Only
+ // valid after this mock method has been called or
+ // ON_CALL/EXPECT_CALL has been invoked on it.
+ const void* mock_obj_; // Protected by g_gmock_mutex.
+
+ // Name of the function being mocked. Only valid after this mock
+ // method has been called.
+ const char* name_; // Protected by g_gmock_mutex.
+
+ // All default action specs for this function mocker.
+ UntypedOnCallSpecs untyped_on_call_specs_;
+
+ // All expectations for this function mocker.
+ //
+ // It's undefined behavior to interleave expectations (EXPECT_CALLs
+ // or ON_CALLs) and mock function calls. Also, the order of
+ // expectations is important. Therefore it's a logic race condition
+ // to read/write untyped_expectations_ concurrently. In order for
+ // tools like tsan to catch concurrent read/write accesses to
+ // untyped_expectations, we deliberately leave accesses to it
+ // unprotected.
+ UntypedExpectations untyped_expectations_;
+}; // class UntypedFunctionMockerBase
+
+// Untyped base class for OnCallSpec<F>.
+class UntypedOnCallSpecBase {
+ public:
+ // The arguments are the location of the ON_CALL() statement.
+ UntypedOnCallSpecBase(const char* a_file, int a_line)
+ : file_(a_file), line_(a_line), last_clause_(kNone) {}
+
+ // Where in the source file was the default action spec defined?
+ const char* file() const { return file_; }
+ int line() const { return line_; }
+
+ protected:
+ // Gives each clause in the ON_CALL() statement a name.
+ enum Clause {
+ // Do not change the order of the enum members! The run-time
+ // syntax checking relies on it.
+ kNone,
+ kWith,
+ kWillByDefault
+ };
+
+ // Asserts that the ON_CALL() statement has a certain property.
+ void AssertSpecProperty(bool property,
+ const std::string& failure_message) const {
+ Assert(property, file_, line_, failure_message);
+ }
+
+ // Expects that the ON_CALL() statement has a certain property.
+ void ExpectSpecProperty(bool property,
+ const std::string& failure_message) const {
+ Expect(property, file_, line_, failure_message);
+ }
+
+ const char* file_;
+ int line_;
+
+ // The last clause in the ON_CALL() statement as seen so far.
+ // Initially kNone and changes as the statement is parsed.
+ Clause last_clause_;
+}; // class UntypedOnCallSpecBase
+
+// This template class implements an ON_CALL spec.
+template <typename F>
+class OnCallSpec : public UntypedOnCallSpecBase {
+ public:
+ typedef typename Function<F>::ArgumentTuple ArgumentTuple;
+ typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
+
+ // Constructs an OnCallSpec object from the information inside
+ // the parenthesis of an ON_CALL() statement.
+ OnCallSpec(const char* a_file, int a_line,
+ const ArgumentMatcherTuple& matchers)
+ : UntypedOnCallSpecBase(a_file, a_line),
+ matchers_(matchers),
+ // By default, extra_matcher_ should match anything. However,
+ // we cannot initialize it with _ as that causes ambiguity between
+ // Matcher's copy and move constructor for some argument types.
+ extra_matcher_(A<const ArgumentTuple&>()) {}
+
+ // Implements the .With() clause.
+ OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) {
+ // Makes sure this is called at most once.
+ ExpectSpecProperty(last_clause_ < kWith,
+ ".With() cannot appear "
+ "more than once in an ON_CALL().");
+ last_clause_ = kWith;
+
+ extra_matcher_ = m;
+ return *this;
+ }
+
+ // Implements the .WillByDefault() clause.
+ OnCallSpec& WillByDefault(const Action<F>& action) {
+ ExpectSpecProperty(last_clause_ < kWillByDefault,
+ ".WillByDefault() must appear "
+ "exactly once in an ON_CALL().");
+ last_clause_ = kWillByDefault;
+
+ ExpectSpecProperty(!action.IsDoDefault(),
+ "DoDefault() cannot be used in ON_CALL().");
+ action_ = action;
+ return *this;
+ }
+
+ // Returns true iff the given arguments match the matchers.
+ bool Matches(const ArgumentTuple& args) const {
+ return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
+ }
+
+ // Returns the action specified by the user.
+ const Action<F>& GetAction() const {
+ AssertSpecProperty(last_clause_ == kWillByDefault,
+ ".WillByDefault() must appear exactly "
+ "once in an ON_CALL().");
+ return action_;
+ }
+
+ private:
+ // The information in statement
+ //
+ // ON_CALL(mock_object, Method(matchers))
+ // .With(multi-argument-matcher)
+ // .WillByDefault(action);
+ //
+ // is recorded in the data members like this:
+ //
+ // source file that contains the statement => file_
+ // line number of the statement => line_
+ // matchers => matchers_
+ // multi-argument-matcher => extra_matcher_
+ // action => action_
+ ArgumentMatcherTuple matchers_;
+ Matcher<const ArgumentTuple&> extra_matcher_;
+ Action<F> action_;
+}; // class OnCallSpec
+
+// Possible reactions on uninteresting calls.
+enum CallReaction {
+ kAllow,
+ kWarn,
+ kFail,
+};
+
+} // namespace internal
+
+// Utilities for manipulating mock objects.
+class GTEST_API_ Mock {
+ public:
+ // The following public methods can be called concurrently.
+
+ // Tells Google Mock to ignore mock_obj when checking for leaked
+ // mock objects.
+ static void AllowLeak(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ // Verifies and clears all expectations on the given mock object.
+ // If the expectations aren't satisfied, generates one or more
+ // Google Test non-fatal failures and returns false.
+ static bool VerifyAndClearExpectations(void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ // Verifies all expectations on the given mock object and clears its
+ // default actions and expectations. Returns true iff the
+ // verification was successful.
+ static bool VerifyAndClear(void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ // Returns whether the mock was created as a naggy mock (default)
+ static bool IsNaggy(void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+ // Returns whether the mock was created as a nice mock
+ static bool IsNice(void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+ // Returns whether the mock was created as a strict mock
+ static bool IsStrict(void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ private:
+ friend class internal::UntypedFunctionMockerBase;
+
+ // Needed for a function mocker to register itself (so that we know
+ // how to clear a mock object).
+ template <typename F>
+ friend class internal::FunctionMocker;
+
+ template <typename M>
+ friend class NiceMock;
+
+ template <typename M>
+ friend class NaggyMock;
+
+ template <typename M>
+ friend class StrictMock;
+
+ // Tells Google Mock to allow uninteresting calls on the given mock
+ // object.
+ static void AllowUninterestingCalls(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ // Tells Google Mock to warn the user about uninteresting calls on
+ // the given mock object.
+ static void WarnUninterestingCalls(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ // Tells Google Mock to fail uninteresting calls on the given mock
+ // object.
+ static void FailUninterestingCalls(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ // Tells Google Mock the given mock object is being destroyed and
+ // its entry in the call-reaction table should be removed.
+ static void UnregisterCallReaction(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ // Returns the reaction Google Mock will have on uninteresting calls
+ // made on the given mock object.
+ static internal::CallReaction GetReactionOnUninterestingCalls(
+ const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ // Verifies that all expectations on the given mock object have been
+ // satisfied. Reports one or more Google Test non-fatal failures
+ // and returns false if not.
+ static bool VerifyAndClearExpectationsLocked(void* mock_obj)
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
+
+ // Clears all ON_CALL()s set on the given mock object.
+ static void ClearDefaultActionsLocked(void* mock_obj)
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
+
+ // Registers a mock object and a mock method it owns.
+ static void Register(
+ const void* mock_obj,
+ internal::UntypedFunctionMockerBase* mocker)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ // Tells Google Mock where in the source code mock_obj is used in an
+ // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
+ // information helps the user identify which object it is.
+ static void RegisterUseByOnCallOrExpectCall(
+ const void* mock_obj, const char* file, int line)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
+
+ // Unregisters a mock method; removes the owning mock object from
+ // the registry when the last mock method associated with it has
+ // been unregistered. This is called only in the destructor of
+ // FunctionMocker.
+ static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
+}; // class Mock
+
+// An abstract handle of an expectation. Useful in the .After()
+// clause of EXPECT_CALL() for setting the (partial) order of
+// expectations. The syntax:
+//
+// Expectation e1 = EXPECT_CALL(...)...;
+// EXPECT_CALL(...).After(e1)...;
+//
+// sets two expectations where the latter can only be matched after
+// the former has been satisfied.
+//
+// Notes:
+// - This class is copyable and has value semantics.
+// - Constness is shallow: a const Expectation object itself cannot
+// be modified, but the mutable methods of the ExpectationBase
+// object it references can be called via expectation_base().
+
+class GTEST_API_ Expectation {
+ public:
+ // Constructs a null object that doesn't reference any expectation.
+ Expectation();
+
+ ~Expectation();
+
+ // This single-argument ctor must not be explicit, in order to support the
+ // Expectation e = EXPECT_CALL(...);
+ // syntax.
+ //
+ // A TypedExpectation object stores its pre-requisites as
+ // Expectation objects, and needs to call the non-const Retire()
+ // method on the ExpectationBase objects they reference. Therefore
+ // Expectation must receive a *non-const* reference to the
+ // ExpectationBase object.
+ Expectation(internal::ExpectationBase& exp); // NOLINT
+
+ // The compiler-generated copy ctor and operator= work exactly as
+ // intended, so we don't need to define our own.
+
+ // Returns true iff rhs references the same expectation as this object does.
+ bool operator==(const Expectation& rhs) const {
+ return expectation_base_ == rhs.expectation_base_;
+ }
+
+ bool operator!=(const Expectation& rhs) const { return !(*this == rhs); }
+
+ private:
+ friend class ExpectationSet;
+ friend class Sequence;
+ friend class ::testing::internal::ExpectationBase;
+ friend class ::testing::internal::UntypedFunctionMockerBase;
+
+ template <typename F>
+ friend class ::testing::internal::FunctionMocker;
+
+ template <typename F>
+ friend class ::testing::internal::TypedExpectation;
+
+ // This comparator is needed for putting Expectation objects into a set.
+ class Less {
+ public:
+ bool operator()(const Expectation& lhs, const Expectation& rhs) const {
+ return lhs.expectation_base_.get() < rhs.expectation_base_.get();
+ }
+ };
+
+ typedef ::std::set<Expectation, Less> Set;
+
+ Expectation(
+ const std::shared_ptr<internal::ExpectationBase>& expectation_base);
+
+ // Returns the expectation this object references.
+ const std::shared_ptr<internal::ExpectationBase>& expectation_base() const {
+ return expectation_base_;
+ }
+
+ // A shared_ptr that co-owns the expectation this handle references.
+ std::shared_ptr<internal::ExpectationBase> expectation_base_;
+};
+
+// A set of expectation handles. Useful in the .After() clause of
+// EXPECT_CALL() for setting the (partial) order of expectations. The
+// syntax:
+//
+// ExpectationSet es;
+// es += EXPECT_CALL(...)...;
+// es += EXPECT_CALL(...)...;
+// EXPECT_CALL(...).After(es)...;
+//
+// sets three expectations where the last one can only be matched
+// after the first two have both been satisfied.
+//
+// This class is copyable and has value semantics.
+class ExpectationSet {
+ public:
+ // A bidirectional iterator that can read a const element in the set.
+ typedef Expectation::Set::const_iterator const_iterator;
+
+ // An object stored in the set. This is an alias of Expectation.
+ typedef Expectation::Set::value_type value_type;
+
+ // Constructs an empty set.
+ ExpectationSet() {}
+
+ // This single-argument ctor must not be explicit, in order to support the
+ // ExpectationSet es = EXPECT_CALL(...);
+ // syntax.
+ ExpectationSet(internal::ExpectationBase& exp) { // NOLINT
+ *this += Expectation(exp);
+ }
+
+ // This single-argument ctor implements implicit conversion from
+ // Expectation and thus must not be explicit. This allows either an
+ // Expectation or an ExpectationSet to be used in .After().
+ ExpectationSet(const Expectation& e) { // NOLINT
+ *this += e;
+ }
+
+ // The compiler-generator ctor and operator= works exactly as
+ // intended, so we don't need to define our own.
+
+ // Returns true iff rhs contains the same set of Expectation objects
+ // as this does.
+ bool operator==(const ExpectationSet& rhs) const {
+ return expectations_ == rhs.expectations_;
+ }
+
+ bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); }
+
+ // Implements the syntax
+ // expectation_set += EXPECT_CALL(...);
+ ExpectationSet& operator+=(const Expectation& e) {
+ expectations_.insert(e);
+ return *this;
+ }
+
+ int size() const { return static_cast<int>(expectations_.size()); }
+
+ const_iterator begin() const { return expectations_.begin(); }
+ const_iterator end() const { return expectations_.end(); }
+
+ private:
+ Expectation::Set expectations_;
+};
+
+
+// Sequence objects are used by a user to specify the relative order
+// in which the expectations should match. They are copyable (we rely
+// on the compiler-defined copy constructor and assignment operator).
+class GTEST_API_ Sequence {
+ public:
+ // Constructs an empty sequence.
+ Sequence() : last_expectation_(new Expectation) {}
+
+ // Adds an expectation to this sequence. The caller must ensure
+ // that no other thread is accessing this Sequence object.
+ void AddExpectation(const Expectation& expectation) const;
+
+ private:
+ // The last expectation in this sequence.
+ std::shared_ptr<Expectation> last_expectation_;
+}; // class Sequence
+
+// An object of this type causes all EXPECT_CALL() statements
+// encountered in its scope to be put in an anonymous sequence. The
+// work is done in the constructor and destructor. You should only
+// create an InSequence object on the stack.
+//
+// The sole purpose for this class is to support easy definition of
+// sequential expectations, e.g.
+//
+// {
+// InSequence dummy; // The name of the object doesn't matter.
+//
+// // The following expectations must match in the order they appear.
+// EXPECT_CALL(a, Bar())...;
+// EXPECT_CALL(a, Baz())...;
+// ...
+// EXPECT_CALL(b, Xyz())...;
+// }
+//
+// You can create InSequence objects in multiple threads, as long as
+// they are used to affect different mock objects. The idea is that
+// each thread can create and set up its own mocks as if it's the only
+// thread. However, for clarity of your tests we recommend you to set
+// up mocks in the main thread unless you have a good reason not to do
+// so.
+class GTEST_API_ InSequence {
+ public:
+ InSequence();
+ ~InSequence();
+ private:
+ bool sequence_created_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT
+} GTEST_ATTRIBUTE_UNUSED_;
+
+namespace internal {
+
+// Points to the implicit sequence introduced by a living InSequence
+// object (if any) in the current thread or NULL.
+GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
+
+// Base class for implementing expectations.
+//
+// There are two reasons for having a type-agnostic base class for
+// Expectation:
+//
+// 1. We need to store collections of expectations of different
+// types (e.g. all pre-requisites of a particular expectation, all
+// expectations in a sequence). Therefore these expectation objects
+// must share a common base class.
+//
+// 2. We can avoid binary code bloat by moving methods not depending
+// on the template argument of Expectation to the base class.
+//
+// This class is internal and mustn't be used by user code directly.
+class GTEST_API_ ExpectationBase {
+ public:
+ // source_text is the EXPECT_CALL(...) source that created this Expectation.
+ ExpectationBase(const char* file, int line, const std::string& source_text);
+
+ virtual ~ExpectationBase();
+
+ // Where in the source file was the expectation spec defined?
+ const char* file() const { return file_; }
+ int line() const { return line_; }
+ const char* source_text() const { return source_text_.c_str(); }
+ // Returns the cardinality specified in the expectation spec.
+ const Cardinality& cardinality() const { return cardinality_; }
+
+ // Describes the source file location of this expectation.
+ void DescribeLocationTo(::std::ostream* os) const {
+ *os << FormatFileLocation(file(), line()) << " ";
+ }
+
+ // Describes how many times a function call matching this
+ // expectation has occurred.
+ void DescribeCallCountTo(::std::ostream* os) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
+
+ // If this mock method has an extra matcher (i.e. .With(matcher)),
+ // describes it to the ostream.
+ virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
+
+ protected:
+ friend class ::testing::Expectation;
+ friend class UntypedFunctionMockerBase;
+
+ enum Clause {
+ // Don't change the order of the enum members!
+ kNone,
+ kWith,
+ kTimes,
+ kInSequence,
+ kAfter,
+ kWillOnce,
+ kWillRepeatedly,
+ kRetiresOnSaturation
+ };
+
+ typedef std::vector<const void*> UntypedActions;
+
+ // Returns an Expectation object that references and co-owns this
+ // expectation.
+ virtual Expectation GetHandle() = 0;
+
+ // Asserts that the EXPECT_CALL() statement has the given property.
+ void AssertSpecProperty(bool property,
+ const std::string& failure_message) const {
+ Assert(property, file_, line_, failure_message);
+ }
+
+ // Expects that the EXPECT_CALL() statement has the given property.
+ void ExpectSpecProperty(bool property,
+ const std::string& failure_message) const {
+ Expect(property, file_, line_, failure_message);
+ }
+
+ // Explicitly specifies the cardinality of this expectation. Used
+ // by the subclasses to implement the .Times() clause.
+ void SpecifyCardinality(const Cardinality& cardinality);
+
+ // Returns true iff the user specified the cardinality explicitly
+ // using a .Times().
+ bool cardinality_specified() const { return cardinality_specified_; }
+
+ // Sets the cardinality of this expectation spec.
+ void set_cardinality(const Cardinality& a_cardinality) {
+ cardinality_ = a_cardinality;
+ }
+
+ // The following group of methods should only be called after the
+ // EXPECT_CALL() statement, and only when g_gmock_mutex is held by
+ // the current thread.
+
+ // Retires all pre-requisites of this expectation.
+ void RetireAllPreRequisites()
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
+
+ // Returns true iff this expectation is retired.
+ bool is_retired() const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ return retired_;
+ }
+
+ // Retires this expectation.
+ void Retire()
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ retired_ = true;
+ }
+
+ // Returns true iff this expectation is satisfied.
+ bool IsSatisfied() const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ return cardinality().IsSatisfiedByCallCount(call_count_);
+ }
+
+ // Returns true iff this expectation is saturated.
+ bool IsSaturated() const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ return cardinality().IsSaturatedByCallCount(call_count_);
+ }
+
+ // Returns true iff this expectation is over-saturated.
+ bool IsOverSaturated() const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ return cardinality().IsOverSaturatedByCallCount(call_count_);
+ }
+
+ // Returns true iff all pre-requisites of this expectation are satisfied.
+ bool AllPrerequisitesAreSatisfied() const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
+
+ // Adds unsatisfied pre-requisites of this expectation to 'result'.
+ void FindUnsatisfiedPrerequisites(ExpectationSet* result) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
+
+ // Returns the number this expectation has been invoked.
+ int call_count() const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ return call_count_;
+ }
+
+ // Increments the number this expectation has been invoked.
+ void IncrementCallCount()
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ call_count_++;
+ }
+
+ // Checks the action count (i.e. the number of WillOnce() and
+ // WillRepeatedly() clauses) against the cardinality if this hasn't
+ // been done before. Prints a warning if there are too many or too
+ // few actions.
+ void CheckActionCountIfNotDone() const
+ GTEST_LOCK_EXCLUDED_(mutex_);
+
+ friend class ::testing::Sequence;
+ friend class ::testing::internal::ExpectationTester;
+
+ template <typename Function>
+ friend class TypedExpectation;
+
+ // Implements the .Times() clause.
+ void UntypedTimes(const Cardinality& a_cardinality);
+
+ // This group of fields are part of the spec and won't change after
+ // an EXPECT_CALL() statement finishes.
+ const char* file_; // The file that contains the expectation.
+ int line_; // The line number of the expectation.
+ const std::string source_text_; // The EXPECT_CALL(...) source text.
+ // True iff the cardinality is specified explicitly.
+ bool cardinality_specified_;
+ Cardinality cardinality_; // The cardinality of the expectation.
+ // The immediate pre-requisites (i.e. expectations that must be
+ // satisfied before this expectation can be matched) of this
+ // expectation. We use std::shared_ptr in the set because we want an
+ // Expectation object to be co-owned by its FunctionMocker and its
+ // successors. This allows multiple mock objects to be deleted at
+ // different times.
+ ExpectationSet immediate_prerequisites_;
+
+ // This group of fields are the current state of the expectation,
+ // and can change as the mock function is called.
+ int call_count_; // How many times this expectation has been invoked.
+ bool retired_; // True iff this expectation has retired.
+ UntypedActions untyped_actions_;
+ bool extra_matcher_specified_;
+ bool repeated_action_specified_; // True if a WillRepeatedly() was specified.
+ bool retires_on_saturation_;
+ Clause last_clause_;
+ mutable bool action_count_checked_; // Under mutex_.
+ mutable Mutex mutex_; // Protects action_count_checked_.
+
+ GTEST_DISALLOW_ASSIGN_(ExpectationBase);
+}; // class ExpectationBase
+
+// Impements an expectation for the given function type.
+template <typename F>
+class TypedExpectation : public ExpectationBase {
+ public:
+ typedef typename Function<F>::ArgumentTuple ArgumentTuple;
+ typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
+ typedef typename Function<F>::Result Result;
+
+ TypedExpectation(FunctionMocker<F>* owner, const char* a_file, int a_line,
+ const std::string& a_source_text,
+ const ArgumentMatcherTuple& m)
+ : ExpectationBase(a_file, a_line, a_source_text),
+ owner_(owner),
+ matchers_(m),
+ // By default, extra_matcher_ should match anything. However,
+ // we cannot initialize it with _ as that causes ambiguity between
+ // Matcher's copy and move constructor for some argument types.
+ extra_matcher_(A<const ArgumentTuple&>()),
+ repeated_action_(DoDefault()) {}
+
+ ~TypedExpectation() override {
+ // Check the validity of the action count if it hasn't been done
+ // yet (for example, if the expectation was never used).
+ CheckActionCountIfNotDone();
+ for (UntypedActions::const_iterator it = untyped_actions_.begin();
+ it != untyped_actions_.end(); ++it) {
+ delete static_cast<const Action<F>*>(*it);
+ }
+ }
+
+ // Implements the .With() clause.
+ TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) {
+ if (last_clause_ == kWith) {
+ ExpectSpecProperty(false,
+ ".With() cannot appear "
+ "more than once in an EXPECT_CALL().");
+ } else {
+ ExpectSpecProperty(last_clause_ < kWith,
+ ".With() must be the first "
+ "clause in an EXPECT_CALL().");
+ }
+ last_clause_ = kWith;
+
+ extra_matcher_ = m;
+ extra_matcher_specified_ = true;
+ return *this;
+ }
+
+ // Implements the .Times() clause.
+ TypedExpectation& Times(const Cardinality& a_cardinality) {
+ ExpectationBase::UntypedTimes(a_cardinality);
+ return *this;
+ }
+
+ // Implements the .Times() clause.
+ TypedExpectation& Times(int n) {
+ return Times(Exactly(n));
+ }
+
+ // Implements the .InSequence() clause.
+ TypedExpectation& InSequence(const Sequence& s) {
+ ExpectSpecProperty(last_clause_ <= kInSequence,
+ ".InSequence() cannot appear after .After(),"
+ " .WillOnce(), .WillRepeatedly(), or "
+ ".RetiresOnSaturation().");
+ last_clause_ = kInSequence;
+
+ s.AddExpectation(GetHandle());
+ return *this;
+ }
+ TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) {
+ return InSequence(s1).InSequence(s2);
+ }
+ TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
+ const Sequence& s3) {
+ return InSequence(s1, s2).InSequence(s3);
+ }
+ TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
+ const Sequence& s3, const Sequence& s4) {
+ return InSequence(s1, s2, s3).InSequence(s4);
+ }
+ TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
+ const Sequence& s3, const Sequence& s4,
+ const Sequence& s5) {
+ return InSequence(s1, s2, s3, s4).InSequence(s5);
+ }
+
+ // Implements that .After() clause.
+ TypedExpectation& After(const ExpectationSet& s) {
+ ExpectSpecProperty(last_clause_ <= kAfter,
+ ".After() cannot appear after .WillOnce(),"
+ " .WillRepeatedly(), or "
+ ".RetiresOnSaturation().");
+ last_clause_ = kAfter;
+
+ for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) {
+ immediate_prerequisites_ += *it;
+ }
+ return *this;
+ }
+ TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) {
+ return After(s1).After(s2);
+ }
+ TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
+ const ExpectationSet& s3) {
+ return After(s1, s2).After(s3);
+ }
+ TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
+ const ExpectationSet& s3, const ExpectationSet& s4) {
+ return After(s1, s2, s3).After(s4);
+ }
+ TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
+ const ExpectationSet& s3, const ExpectationSet& s4,
+ const ExpectationSet& s5) {
+ return After(s1, s2, s3, s4).After(s5);
+ }
+
+ // Implements the .WillOnce() clause.
+ TypedExpectation& WillOnce(const Action<F>& action) {
+ ExpectSpecProperty(last_clause_ <= kWillOnce,
+ ".WillOnce() cannot appear after "
+ ".WillRepeatedly() or .RetiresOnSaturation().");
+ last_clause_ = kWillOnce;
+
+ untyped_actions_.push_back(new Action<F>(action));
+ if (!cardinality_specified()) {
+ set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
+ }
+ return *this;
+ }
+
+ // Implements the .WillRepeatedly() clause.
+ TypedExpectation& WillRepeatedly(const Action<F>& action) {
+ if (last_clause_ == kWillRepeatedly) {
+ ExpectSpecProperty(false,
+ ".WillRepeatedly() cannot appear "
+ "more than once in an EXPECT_CALL().");
+ } else {
+ ExpectSpecProperty(last_clause_ < kWillRepeatedly,
+ ".WillRepeatedly() cannot appear "
+ "after .RetiresOnSaturation().");
+ }
+ last_clause_ = kWillRepeatedly;
+ repeated_action_specified_ = true;
+
+ repeated_action_ = action;
+ if (!cardinality_specified()) {
+ set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size())));
+ }
+
+ // Now that no more action clauses can be specified, we check
+ // whether their count makes sense.
+ CheckActionCountIfNotDone();
+ return *this;
+ }
+
+ // Implements the .RetiresOnSaturation() clause.
+ TypedExpectation& RetiresOnSaturation() {
+ ExpectSpecProperty(last_clause_ < kRetiresOnSaturation,
+ ".RetiresOnSaturation() cannot appear "
+ "more than once.");
+ last_clause_ = kRetiresOnSaturation;
+ retires_on_saturation_ = true;
+
+ // Now that no more action clauses can be specified, we check
+ // whether their count makes sense.
+ CheckActionCountIfNotDone();
+ return *this;
+ }
+
+ // Returns the matchers for the arguments as specified inside the
+ // EXPECT_CALL() macro.
+ const ArgumentMatcherTuple& matchers() const {
+ return matchers_;
+ }
+
+ // Returns the matcher specified by the .With() clause.
+ const Matcher<const ArgumentTuple&>& extra_matcher() const {
+ return extra_matcher_;
+ }
+
+ // Returns the action specified by the .WillRepeatedly() clause.
+ const Action<F>& repeated_action() const { return repeated_action_; }
+
+ // If this mock method has an extra matcher (i.e. .With(matcher)),
+ // describes it to the ostream.
+ void MaybeDescribeExtraMatcherTo(::std::ostream* os) override {
+ if (extra_matcher_specified_) {
+ *os << " Expected args: ";
+ extra_matcher_.DescribeTo(os);
+ *os << "\n";
+ }
+ }
+
+ private:
+ template <typename Function>
+ friend class FunctionMocker;
+
+ // Returns an Expectation object that references and co-owns this
+ // expectation.
+ Expectation GetHandle() override { return owner_->GetHandleOf(this); }
+
+ // The following methods will be called only after the EXPECT_CALL()
+ // statement finishes and when the current thread holds
+ // g_gmock_mutex.
+
+ // Returns true iff this expectation matches the given arguments.
+ bool Matches(const ArgumentTuple& args) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
+ }
+
+ // Returns true iff this expectation should handle the given arguments.
+ bool ShouldHandleArguments(const ArgumentTuple& args) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+
+ // In case the action count wasn't checked when the expectation
+ // was defined (e.g. if this expectation has no WillRepeatedly()
+ // or RetiresOnSaturation() clause), we check it when the
+ // expectation is used for the first time.
+ CheckActionCountIfNotDone();
+ return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args);
+ }
+
+ // Describes the result of matching the arguments against this
+ // expectation to the given ostream.
+ void ExplainMatchResultTo(
+ const ArgumentTuple& args,
+ ::std::ostream* os) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+
+ if (is_retired()) {
+ *os << " Expected: the expectation is active\n"
+ << " Actual: it is retired\n";
+ } else if (!Matches(args)) {
+ if (!TupleMatches(matchers_, args)) {
+ ExplainMatchFailureTupleTo(matchers_, args, os);
+ }
+ StringMatchResultListener listener;
+ if (!extra_matcher_.MatchAndExplain(args, &listener)) {
+ *os << " Expected args: ";
+ extra_matcher_.DescribeTo(os);
+ *os << "\n Actual: don't match";
+
+ internal::PrintIfNotEmpty(listener.str(), os);
+ *os << "\n";
+ }
+ } else if (!AllPrerequisitesAreSatisfied()) {
+ *os << " Expected: all pre-requisites are satisfied\n"
+ << " Actual: the following immediate pre-requisites "
+ << "are not satisfied:\n";
+ ExpectationSet unsatisfied_prereqs;
+ FindUnsatisfiedPrerequisites(&unsatisfied_prereqs);
+ int i = 0;
+ for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin();
+ it != unsatisfied_prereqs.end(); ++it) {
+ it->expectation_base()->DescribeLocationTo(os);
+ *os << "pre-requisite #" << i++ << "\n";
+ }
+ *os << " (end of pre-requisites)\n";
+ } else {
+ // This line is here just for completeness' sake. It will never
+ // be executed as currently the ExplainMatchResultTo() function
+ // is called only when the mock function call does NOT match the
+ // expectation.
+ *os << "The call matches the expectation.\n";
+ }
+ }
+
+ // Returns the action that should be taken for the current invocation.
+ const Action<F>& GetCurrentAction(const FunctionMocker<F>* mocker,
+ const ArgumentTuple& args) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ const int count = call_count();
+ Assert(count >= 1, __FILE__, __LINE__,
+ "call_count() is <= 0 when GetCurrentAction() is "
+ "called - this should never happen.");
+
+ const int action_count = static_cast<int>(untyped_actions_.size());
+ if (action_count > 0 && !repeated_action_specified_ &&
+ count > action_count) {
+ // If there is at least one WillOnce() and no WillRepeatedly(),
+ // we warn the user when the WillOnce() clauses ran out.
+ ::std::stringstream ss;
+ DescribeLocationTo(&ss);
+ ss << "Actions ran out in " << source_text() << "...\n"
+ << "Called " << count << " times, but only "
+ << action_count << " WillOnce()"
+ << (action_count == 1 ? " is" : "s are") << " specified - ";
+ mocker->DescribeDefaultActionTo(args, &ss);
+ Log(kWarning, ss.str(), 1);
+ }
+
+ return count <= action_count
+ ? *static_cast<const Action<F>*>(
+ untyped_actions_[static_cast<size_t>(count - 1)])
+ : repeated_action();
+ }
+
+ // Given the arguments of a mock function call, if the call will
+ // over-saturate this expectation, returns the default action;
+ // otherwise, returns the next action in this expectation. Also
+ // describes *what* happened to 'what', and explains *why* Google
+ // Mock does it to 'why'. This method is not const as it calls
+ // IncrementCallCount(). A return value of NULL means the default
+ // action.
+ const Action<F>* GetActionForArguments(const FunctionMocker<F>* mocker,
+ const ArgumentTuple& args,
+ ::std::ostream* what,
+ ::std::ostream* why)
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ if (IsSaturated()) {
+ // We have an excessive call.
+ IncrementCallCount();
+ *what << "Mock function called more times than expected - ";
+ mocker->DescribeDefaultActionTo(args, what);
+ DescribeCallCountTo(why);
+
+ return nullptr;
+ }
+
+ IncrementCallCount();
+ RetireAllPreRequisites();
+
+ if (retires_on_saturation_ && IsSaturated()) {
+ Retire();
+ }
+
+ // Must be done after IncrementCount()!
+ *what << "Mock function call matches " << source_text() <<"...\n";
+ return &(GetCurrentAction(mocker, args));
+ }
+
+ // All the fields below won't change once the EXPECT_CALL()
+ // statement finishes.
+ FunctionMocker<F>* const owner_;
+ ArgumentMatcherTuple matchers_;
+ Matcher<const ArgumentTuple&> extra_matcher_;
+ Action<F> repeated_action_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation);
+}; // class TypedExpectation
+
+// A MockSpec object is used by ON_CALL() or EXPECT_CALL() for
+// specifying the default behavior of, or expectation on, a mock
+// function.
+
+// Note: class MockSpec really belongs to the ::testing namespace.
+// However if we define it in ::testing, MSVC will complain when
+// classes in ::testing::internal declare it as a friend class
+// template. To workaround this compiler bug, we define MockSpec in
+// ::testing::internal and import it into ::testing.
+
+// Logs a message including file and line number information.
+GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
+ const char* file, int line,
+ const std::string& message);
+
+template <typename F>
+class MockSpec {
+ public:
+ typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
+ typedef typename internal::Function<F>::ArgumentMatcherTuple
+ ArgumentMatcherTuple;
+
+ // Constructs a MockSpec object, given the function mocker object
+ // that the spec is associated with.
+ MockSpec(internal::FunctionMocker<F>* function_mocker,
+ const ArgumentMatcherTuple& matchers)
+ : function_mocker_(function_mocker), matchers_(matchers) {}
+
+ // Adds a new default action spec to the function mocker and returns
+ // the newly created spec.
+ internal::OnCallSpec<F>& InternalDefaultActionSetAt(
+ const char* file, int line, const char* obj, const char* call) {
+ LogWithLocation(internal::kInfo, file, line,
+ std::string("ON_CALL(") + obj + ", " + call + ") invoked");
+ return function_mocker_->AddNewOnCallSpec(file, line, matchers_);
+ }
+
+ // Adds a new expectation spec to the function mocker and returns
+ // the newly created spec.
+ internal::TypedExpectation<F>& InternalExpectedAt(
+ const char* file, int line, const char* obj, const char* call) {
+ const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " +
+ call + ")");
+ LogWithLocation(internal::kInfo, file, line, source_text + " invoked");
+ return function_mocker_->AddNewExpectation(
+ file, line, source_text, matchers_);
+ }
+
+ // This operator overload is used to swallow the superfluous parameter list
+ // introduced by the ON/EXPECT_CALL macros. See the macro comments for more
+ // explanation.
+ MockSpec<F>& operator()(const internal::WithoutMatchers&, void* const) {
+ return *this;
+ }
+
+ private:
+ template <typename Function>
+ friend class internal::FunctionMocker;
+
+ // The function mocker that owns this spec.
+ internal::FunctionMocker<F>* const function_mocker_;
+ // The argument matchers specified in the spec.
+ ArgumentMatcherTuple matchers_;
+
+ GTEST_DISALLOW_ASSIGN_(MockSpec);
+}; // class MockSpec
+
+// Wrapper type for generically holding an ordinary value or lvalue reference.
+// If T is not a reference type, it must be copyable or movable.
+// ReferenceOrValueWrapper<T> is movable, and will also be copyable unless
+// T is a move-only value type (which means that it will always be copyable
+// if the current platform does not support move semantics).
+//
+// The primary template defines handling for values, but function header
+// comments describe the contract for the whole template (including
+// specializations).
+template <typename T>
+class ReferenceOrValueWrapper {
+ public:
+ // Constructs a wrapper from the given value/reference.
+ explicit ReferenceOrValueWrapper(T value)
+ : value_(std::move(value)) {
+ }
+
+ // Unwraps and returns the underlying value/reference, exactly as
+ // originally passed. The behavior of calling this more than once on
+ // the same object is unspecified.
+ T Unwrap() { return std::move(value_); }
+
+ // Provides nondestructive access to the underlying value/reference.
+ // Always returns a const reference (more precisely,
+ // const RemoveReference<T>&). The behavior of calling this after
+ // calling Unwrap on the same object is unspecified.
+ const T& Peek() const {
+ return value_;
+ }
+
+ private:
+ T value_;
+};
+
+// Specialization for lvalue reference types. See primary template
+// for documentation.
+template <typename T>
+class ReferenceOrValueWrapper<T&> {
+ public:
+ // Workaround for debatable pass-by-reference lint warning (c-library-team
+ // policy precludes NOLINT in this context)
+ typedef T& reference;
+ explicit ReferenceOrValueWrapper(reference ref)
+ : value_ptr_(&ref) {}
+ T& Unwrap() { return *value_ptr_; }
+ const T& Peek() const { return *value_ptr_; }
+
+ private:
+ T* value_ptr_;
+};
+
+// MSVC warns about using 'this' in base member initializer list, so
+// we need to temporarily disable the warning. We have to do it for
+// the entire class to suppress the warning, even though it's about
+// the constructor only.
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355)
+
+// C++ treats the void type specially. For example, you cannot define
+// a void-typed variable or pass a void value to a function.
+// ActionResultHolder<T> holds a value of type T, where T must be a
+// copyable type or void (T doesn't need to be default-constructable).
+// It hides the syntactic difference between void and other types, and
+// is used to unify the code for invoking both void-returning and
+// non-void-returning mock functions.
+
+// Untyped base class for ActionResultHolder<T>.
+class UntypedActionResultHolderBase {
+ public:
+ virtual ~UntypedActionResultHolderBase() {}
+
+ // Prints the held value as an action's result to os.
+ virtual void PrintAsActionResult(::std::ostream* os) const = 0;
+};
+
+// This generic definition is used when T is not void.
+template <typename T>
+class ActionResultHolder : public UntypedActionResultHolderBase {
+ public:
+ // Returns the held value. Must not be called more than once.
+ T Unwrap() {
+ return result_.Unwrap();
+ }
+
+ // Prints the held value as an action's result to os.
+ void PrintAsActionResult(::std::ostream* os) const override {
+ *os << "\n Returns: ";
+ // T may be a reference type, so we don't use UniversalPrint().
+ UniversalPrinter<T>::Print(result_.Peek(), os);
+ }
+
+ // Performs the given mock function's default action and returns the
+ // result in a new-ed ActionResultHolder.
+ template <typename F>
+ static ActionResultHolder* PerformDefaultAction(
+ const FunctionMocker<F>* func_mocker,
+ typename Function<F>::ArgumentTuple&& args,
+ const std::string& call_description) {
+ return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction(
+ std::move(args), call_description)));
+ }
+
+ // Performs the given action and returns the result in a new-ed
+ // ActionResultHolder.
+ template <typename F>
+ static ActionResultHolder* PerformAction(
+ const Action<F>& action, typename Function<F>::ArgumentTuple&& args) {
+ return new ActionResultHolder(
+ Wrapper(action.Perform(std::move(args))));
+ }
+
+ private:
+ typedef ReferenceOrValueWrapper<T> Wrapper;
+
+ explicit ActionResultHolder(Wrapper result)
+ : result_(std::move(result)) {
+ }
+
+ Wrapper result_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
+};
+
+// Specialization for T = void.
+template <>
+class ActionResultHolder<void> : public UntypedActionResultHolderBase {
+ public:
+ void Unwrap() { }
+
+ void PrintAsActionResult(::std::ostream* /* os */) const override {}
+
+ // Performs the given mock function's default action and returns ownership
+ // of an empty ActionResultHolder*.
+ template <typename F>
+ static ActionResultHolder* PerformDefaultAction(
+ const FunctionMocker<F>* func_mocker,
+ typename Function<F>::ArgumentTuple&& args,
+ const std::string& call_description) {
+ func_mocker->PerformDefaultAction(std::move(args), call_description);
+ return new ActionResultHolder;
+ }
+
+ // Performs the given action and returns ownership of an empty
+ // ActionResultHolder*.
+ template <typename F>
+ static ActionResultHolder* PerformAction(
+ const Action<F>& action, typename Function<F>::ArgumentTuple&& args) {
+ action.Perform(std::move(args));
+ return new ActionResultHolder;
+ }
+
+ private:
+ ActionResultHolder() {}
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
+};
+
+template <typename F>
+class FunctionMocker;
+
+template <typename R, typename... Args>
+class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase {
+ using F = R(Args...);
+
+ public:
+ using Result = R;
+ using ArgumentTuple = std::tuple<Args...>;
+ using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
+
+ FunctionMocker() {}
+
+ // There is no generally useful and implementable semantics of
+ // copying a mock object, so copying a mock is usually a user error.
+ // Thus we disallow copying function mockers. If the user really
+ // wants to copy a mock object, they should implement their own copy
+ // operation, for example:
+ //
+ // class MockFoo : public Foo {
+ // public:
+ // // Defines a copy constructor explicitly.
+ // MockFoo(const MockFoo& src) {}
+ // ...
+ // };
+ FunctionMocker(const FunctionMocker&) = delete;
+ FunctionMocker& operator=(const FunctionMocker&) = delete;
+
+ // The destructor verifies that all expectations on this mock
+ // function have been satisfied. If not, it will report Google Test
+ // non-fatal failures for the violations.
+ ~FunctionMocker() override GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ MutexLock l(&g_gmock_mutex);
+ VerifyAndClearExpectationsLocked();
+ Mock::UnregisterLocked(this);
+ ClearDefaultActionsLocked();
+ }
+
+ // Returns the ON_CALL spec that matches this mock function with the
+ // given arguments; returns NULL if no matching ON_CALL is found.
+ // L = *
+ const OnCallSpec<F>* FindOnCallSpec(
+ const ArgumentTuple& args) const {
+ for (UntypedOnCallSpecs::const_reverse_iterator it
+ = untyped_on_call_specs_.rbegin();
+ it != untyped_on_call_specs_.rend(); ++it) {
+ const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
+ if (spec->Matches(args))
+ return spec;
+ }
+
+ return nullptr;
+ }
+
+ // Performs the default action of this mock function on the given
+ // arguments and returns the result. Asserts (or throws if
+ // exceptions are enabled) with a helpful call descrption if there
+ // is no valid return value. This method doesn't depend on the
+ // mutable state of this object, and thus can be called concurrently
+ // without locking.
+ // L = *
+ Result PerformDefaultAction(ArgumentTuple&& args,
+ const std::string& call_description) const {
+ const OnCallSpec<F>* const spec =
+ this->FindOnCallSpec(args);
+ if (spec != nullptr) {
+ return spec->GetAction().Perform(std::move(args));
+ }
+ const std::string message =
+ call_description +
+ "\n The mock function has no default action "
+ "set, and its return type has no default value set.";
+#if GTEST_HAS_EXCEPTIONS
+ if (!DefaultValue<Result>::Exists()) {
+ throw std::runtime_error(message);
+ }
+#else
+ Assert(DefaultValue<Result>::Exists(), "", -1, message);
+#endif
+ return DefaultValue<Result>::Get();
+ }
+
+ // Performs the default action with the given arguments and returns
+ // the action's result. The call description string will be used in
+ // the error message to describe the call in the case the default
+ // action fails. The caller is responsible for deleting the result.
+ // L = *
+ UntypedActionResultHolderBase* UntypedPerformDefaultAction(
+ void* untyped_args, // must point to an ArgumentTuple
+ const std::string& call_description) const override {
+ ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
+ return ResultHolder::PerformDefaultAction(this, std::move(*args),
+ call_description);
+ }
+
+ // Performs the given action with the given arguments and returns
+ // the action's result. The caller is responsible for deleting the
+ // result.
+ // L = *
+ UntypedActionResultHolderBase* UntypedPerformAction(
+ const void* untyped_action, void* untyped_args) const override {
+ // Make a copy of the action before performing it, in case the
+ // action deletes the mock object (and thus deletes itself).
+ const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
+ ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
+ return ResultHolder::PerformAction(action, std::move(*args));
+ }
+
+ // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
+ // clears the ON_CALL()s set on this mock function.
+ void ClearDefaultActionsLocked() override
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+
+ // Deleting our default actions may trigger other mock objects to be
+ // deleted, for example if an action contains a reference counted smart
+ // pointer to that mock object, and that is the last reference. So if we
+ // delete our actions within the context of the global mutex we may deadlock
+ // when this method is called again. Instead, make a copy of the set of
+ // actions to delete, clear our set within the mutex, and then delete the
+ // actions outside of the mutex.
+ UntypedOnCallSpecs specs_to_delete;
+ untyped_on_call_specs_.swap(specs_to_delete);
+
+ g_gmock_mutex.Unlock();
+ for (UntypedOnCallSpecs::const_iterator it =
+ specs_to_delete.begin();
+ it != specs_to_delete.end(); ++it) {
+ delete static_cast<const OnCallSpec<F>*>(*it);
+ }
+
+ // Lock the mutex again, since the caller expects it to be locked when we
+ // return.
+ g_gmock_mutex.Lock();
+ }
+
+ // Returns the result of invoking this mock function with the given
+ // arguments. This function can be safely called from multiple
+ // threads concurrently.
+ Result Invoke(Args... args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ ArgumentTuple tuple(std::forward<Args>(args)...);
+ std::unique_ptr<ResultHolder> holder(DownCast_<ResultHolder*>(
+ this->UntypedInvokeWith(static_cast<void*>(&tuple))));
+ return holder->Unwrap();
+ }
+
+ MockSpec<F> With(Matcher<Args>... m) {
+ return MockSpec<F>(this, ::std::make_tuple(std::move(m)...));
+ }
+
+ protected:
+ template <typename Function>
+ friend class MockSpec;
+
+ typedef ActionResultHolder<Result> ResultHolder;
+
+ // Adds and returns a default action spec for this mock function.
+ OnCallSpec<F>& AddNewOnCallSpec(
+ const char* file, int line,
+ const ArgumentMatcherTuple& m)
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
+ OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
+ untyped_on_call_specs_.push_back(on_call_spec);
+ return *on_call_spec;
+ }
+
+ // Adds and returns an expectation spec for this mock function.
+ TypedExpectation<F>& AddNewExpectation(const char* file, int line,
+ const std::string& source_text,
+ const ArgumentMatcherTuple& m)
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
+ TypedExpectation<F>* const expectation =
+ new TypedExpectation<F>(this, file, line, source_text, m);
+ const std::shared_ptr<ExpectationBase> untyped_expectation(expectation);
+ // See the definition of untyped_expectations_ for why access to
+ // it is unprotected here.
+ untyped_expectations_.push_back(untyped_expectation);
+
+ // Adds this expectation into the implicit sequence if there is one.
+ Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
+ if (implicit_sequence != nullptr) {
+ implicit_sequence->AddExpectation(Expectation(untyped_expectation));
+ }
+
+ return *expectation;
+ }
+
+ private:
+ template <typename Func> friend class TypedExpectation;
+
+ // Some utilities needed for implementing UntypedInvokeWith().
+
+ // Describes what default action will be performed for the given
+ // arguments.
+ // L = *
+ void DescribeDefaultActionTo(const ArgumentTuple& args,
+ ::std::ostream* os) const {
+ const OnCallSpec<F>* const spec = FindOnCallSpec(args);
+
+ if (spec == nullptr) {
+ *os << (internal::type_equals<Result, void>::value ?
+ "returning directly.\n" :
+ "returning default value.\n");
+ } else {
+ *os << "taking default action specified at:\n"
+ << FormatFileLocation(spec->file(), spec->line()) << "\n";
+ }
+ }
+
+ // Writes a message that the call is uninteresting (i.e. neither
+ // explicitly expected nor explicitly unexpected) to the given
+ // ostream.
+ void UntypedDescribeUninterestingCall(const void* untyped_args,
+ ::std::ostream* os) const override
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ const ArgumentTuple& args =
+ *static_cast<const ArgumentTuple*>(untyped_args);
+ *os << "Uninteresting mock function call - ";
+ DescribeDefaultActionTo(args, os);
+ *os << " Function call: " << Name();
+ UniversalPrint(args, os);
+ }
+
+ // Returns the expectation that matches the given function arguments
+ // (or NULL is there's no match); when a match is found,
+ // untyped_action is set to point to the action that should be
+ // performed (or NULL if the action is "do default"), and
+ // is_excessive is modified to indicate whether the call exceeds the
+ // expected number.
+ //
+ // Critical section: We must find the matching expectation and the
+ // corresponding action that needs to be taken in an ATOMIC
+ // transaction. Otherwise another thread may call this mock
+ // method in the middle and mess up the state.
+ //
+ // However, performing the action has to be left out of the critical
+ // section. The reason is that we have no control on what the
+ // action does (it can invoke an arbitrary user function or even a
+ // mock function) and excessive locking could cause a dead lock.
+ const ExpectationBase* UntypedFindMatchingExpectation(
+ const void* untyped_args, const void** untyped_action, bool* is_excessive,
+ ::std::ostream* what, ::std::ostream* why) override
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ const ArgumentTuple& args =
+ *static_cast<const ArgumentTuple*>(untyped_args);
+ MutexLock l(&g_gmock_mutex);
+ TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args);
+ if (exp == nullptr) { // A match wasn't found.
+ this->FormatUnexpectedCallMessageLocked(args, what, why);
+ return nullptr;
+ }
+
+ // This line must be done before calling GetActionForArguments(),
+ // which will increment the call count for *exp and thus affect
+ // its saturation status.
+ *is_excessive = exp->IsSaturated();
+ const Action<F>* action = exp->GetActionForArguments(this, args, what, why);
+ if (action != nullptr && action->IsDoDefault())
+ action = nullptr; // Normalize "do default" to NULL.
+ *untyped_action = action;
+ return exp;
+ }
+
+ // Prints the given function arguments to the ostream.
+ void UntypedPrintArgs(const void* untyped_args,
+ ::std::ostream* os) const override {
+ const ArgumentTuple& args =
+ *static_cast<const ArgumentTuple*>(untyped_args);
+ UniversalPrint(args, os);
+ }
+
+ // Returns the expectation that matches the arguments, or NULL if no
+ // expectation matches them.
+ TypedExpectation<F>* FindMatchingExpectationLocked(
+ const ArgumentTuple& args) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ // See the definition of untyped_expectations_ for why access to
+ // it is unprotected here.
+ for (typename UntypedExpectations::const_reverse_iterator it =
+ untyped_expectations_.rbegin();
+ it != untyped_expectations_.rend(); ++it) {
+ TypedExpectation<F>* const exp =
+ static_cast<TypedExpectation<F>*>(it->get());
+ if (exp->ShouldHandleArguments(args)) {
+ return exp;
+ }
+ }
+ return nullptr;
+ }
+
+ // Returns a message that the arguments don't match any expectation.
+ void FormatUnexpectedCallMessageLocked(
+ const ArgumentTuple& args,
+ ::std::ostream* os,
+ ::std::ostream* why) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ *os << "\nUnexpected mock function call - ";
+ DescribeDefaultActionTo(args, os);
+ PrintTriedExpectationsLocked(args, why);
+ }
+
+ // Prints a list of expectations that have been tried against the
+ // current mock function call.
+ void PrintTriedExpectationsLocked(
+ const ArgumentTuple& args,
+ ::std::ostream* why) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ const size_t count = untyped_expectations_.size();
+ *why << "Google Mock tried the following " << count << " "
+ << (count == 1 ? "expectation, but it didn't match" :
+ "expectations, but none matched")
+ << ":\n";
+ for (size_t i = 0; i < count; i++) {
+ TypedExpectation<F>* const expectation =
+ static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get());
+ *why << "\n";
+ expectation->DescribeLocationTo(why);
+ if (count > 1) {
+ *why << "tried expectation #" << i << ": ";
+ }
+ *why << expectation->source_text() << "...\n";
+ expectation->ExplainMatchResultTo(args, why);
+ expectation->DescribeCallCountTo(why);
+ }
+ }
+}; // class FunctionMocker
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4355
+
+// Reports an uninteresting call (whose description is in msg) in the
+// manner specified by 'reaction'.
+void ReportUninterestingCall(CallReaction reaction, const std::string& msg);
+
+} // namespace internal
+
+// A MockFunction<F> class has one mock method whose type is F. It is
+// useful when you just want your test code to emit some messages and
+// have Google Mock verify the right messages are sent (and perhaps at
+// the right times). For example, if you are exercising code:
+//
+// Foo(1);
+// Foo(2);
+// Foo(3);
+//
+// and want to verify that Foo(1) and Foo(3) both invoke
+// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write:
+//
+// TEST(FooTest, InvokesBarCorrectly) {
+// MyMock mock;
+// MockFunction<void(string check_point_name)> check;
+// {
+// InSequence s;
+//
+// EXPECT_CALL(mock, Bar("a"));
+// EXPECT_CALL(check, Call("1"));
+// EXPECT_CALL(check, Call("2"));
+// EXPECT_CALL(mock, Bar("a"));
+// }
+// Foo(1);
+// check.Call("1");
+// Foo(2);
+// check.Call("2");
+// Foo(3);
+// }
+//
+// The expectation spec says that the first Bar("a") must happen
+// before check point "1", the second Bar("a") must happen after check
+// point "2", and nothing should happen between the two check
+// points. The explicit check points make it easy to tell which
+// Bar("a") is called by which call to Foo().
+//
+// MockFunction<F> can also be used to exercise code that accepts
+// std::function<F> callbacks. To do so, use AsStdFunction() method
+// to create std::function proxy forwarding to original object's Call.
+// Example:
+//
+// TEST(FooTest, RunsCallbackWithBarArgument) {
+// MockFunction<int(string)> callback;
+// EXPECT_CALL(callback, Call("bar")).WillOnce(Return(1));
+// Foo(callback.AsStdFunction());
+// }
+template <typename F>
+class MockFunction;
+
+template <typename R, typename... Args>
+class MockFunction<R(Args...)> {
+ public:
+ MockFunction() {}
+ MockFunction(const MockFunction&) = delete;
+ MockFunction& operator=(const MockFunction&) = delete;
+
+ std::function<R(Args...)> AsStdFunction() {
+ return [this](Args... args) -> R {
+ return this->Call(std::forward<Args>(args)...);
+ };
+ }
+
+ // Implementation detail: the expansion of the MOCK_METHOD macro.
+ R Call(Args... args) {
+ mock_.SetOwnerAndName(this, "Call");
+ return mock_.Invoke(std::forward<Args>(args)...);
+ }
+
+ internal::MockSpec<R(Args...)> gmock_Call(Matcher<Args>... m) {
+ mock_.RegisterOwner(this);
+ return mock_.With(std::move(m)...);
+ }
+
+ internal::MockSpec<R(Args...)> gmock_Call(const internal::WithoutMatchers&,
+ R (*)(Args...)) {
+ return this->gmock_Call(::testing::A<Args>()...);
+ }
+
+ private:
+ mutable internal::FunctionMocker<R(Args...)> mock_;
+};
+
+// The style guide prohibits "using" statements in a namespace scope
+// inside a header file. However, the MockSpec class template is
+// meant to be defined in the ::testing namespace. The following line
+// is just a trick for working around a bug in MSVC 8.0, which cannot
+// handle it if we define MockSpec in ::testing.
+using internal::MockSpec;
+
+// Const(x) is a convenient function for obtaining a const reference
+// to x. This is useful for setting expectations on an overloaded
+// const mock method, e.g.
+//
+// class MockFoo : public FooInterface {
+// public:
+// MOCK_METHOD0(Bar, int());
+// MOCK_CONST_METHOD0(Bar, int&());
+// };
+//
+// MockFoo foo;
+// // Expects a call to non-const MockFoo::Bar().
+// EXPECT_CALL(foo, Bar());
+// // Expects a call to const MockFoo::Bar().
+// EXPECT_CALL(Const(foo), Bar());
+template <typename T>
+inline const T& Const(const T& x) { return x; }
+
+// Constructs an Expectation object that references and co-owns exp.
+inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT
+ : expectation_base_(exp.GetHandle().expectation_base()) {}
+
+} // namespace testing
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
+
+// Implementation for ON_CALL and EXPECT_CALL macros. A separate macro is
+// required to avoid compile errors when the name of the method used in call is
+// a result of macro expansion. See CompilesWithMethodNameExpandedFromMacro
+// tests in internal/gmock-spec-builders_test.cc for more details.
+//
+// This macro supports statements both with and without parameter matchers. If
+// the parameter list is omitted, gMock will accept any parameters, which allows
+// tests to be written that don't need to encode the number of method
+// parameter. This technique may only be used for non-overloaded methods.
+//
+// // These are the same:
+// ON_CALL(mock, NoArgsMethod()).WillByDefault(...);
+// ON_CALL(mock, NoArgsMethod).WillByDefault(...);
+//
+// // As are these:
+// ON_CALL(mock, TwoArgsMethod(_, _)).WillByDefault(...);
+// ON_CALL(mock, TwoArgsMethod).WillByDefault(...);
+//
+// // Can also specify args if you want, of course:
+// ON_CALL(mock, TwoArgsMethod(_, 45)).WillByDefault(...);
+//
+// // Overloads work as long as you specify parameters:
+// ON_CALL(mock, OverloadedMethod(_)).WillByDefault(...);
+// ON_CALL(mock, OverloadedMethod(_, _)).WillByDefault(...);
+//
+// // Oops! Which overload did you want?
+// ON_CALL(mock, OverloadedMethod).WillByDefault(...);
+// => ERROR: call to member function 'gmock_OverloadedMethod' is ambiguous
+//
+// How this works: The mock class uses two overloads of the gmock_Method
+// expectation setter method plus an operator() overload on the MockSpec object.
+// In the matcher list form, the macro expands to:
+//
+// // This statement:
+// ON_CALL(mock, TwoArgsMethod(_, 45))...
+//
+// // ...expands to:
+// mock.gmock_TwoArgsMethod(_, 45)(WithoutMatchers(), nullptr)...
+// |-------------v---------------||------------v-------------|
+// invokes first overload swallowed by operator()
+//
+// // ...which is essentially:
+// mock.gmock_TwoArgsMethod(_, 45)...
+//
+// Whereas the form without a matcher list:
+//
+// // This statement:
+// ON_CALL(mock, TwoArgsMethod)...
+//
+// // ...expands to:
+// mock.gmock_TwoArgsMethod(WithoutMatchers(), nullptr)...
+// |-----------------------v--------------------------|
+// invokes second overload
+//
+// // ...which is essentially:
+// mock.gmock_TwoArgsMethod(_, _)...
+//
+// The WithoutMatchers() argument is used to disambiguate overloads and to
+// block the caller from accidentally invoking the second overload directly. The
+// second argument is an internal type derived from the method signature. The
+// failure to disambiguate two overloads of this method in the ON_CALL statement
+// is how we block callers from setting expectations on overloaded methods.
+#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \
+ ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \
+ nullptr) \
+ .Setter(__FILE__, __LINE__, #mock_expr, #call)
+
+#define ON_CALL(obj, call) \
+ GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call)
+
+#define EXPECT_CALL(obj, call) \
+ GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call)
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This is the main header file a user should include.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_H_
+
+// This file implements the following syntax:
+//
+// ON_CALL(mock_object.Method(...))
+// .With(...) ?
+// .WillByDefault(...);
+//
+// where With() is optional and WillByDefault() must appear exactly
+// once.
+//
+// EXPECT_CALL(mock_object.Method(...))
+// .With(...) ?
+// .Times(...) ?
+// .InSequence(...) *
+// .WillOnce(...) *
+// .WillRepeatedly(...) ?
+// .RetiresOnSaturation() ? ;
+//
+// where all clauses are optional and WillOnce() can be repeated.
+
+#include "gmock/gmock-actions.h"
+#include "gmock/gmock-cardinalities.h"
+#include "gmock/gmock-function-mocker.h"
+#include "gmock/gmock-generated-actions.h"
+#include "gmock/gmock-generated-function-mockers.h"
+#include "gmock/gmock-generated-matchers.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock-more-actions.h"
+#include "gmock/gmock-more-matchers.h"
+#include "gmock/gmock-nice-strict.h"
+#include "gmock/internal/gmock-internal-utils.h"
+
+namespace testing {
+
+// Declares Google Mock flags that we want a user to use programmatically.
+GMOCK_DECLARE_bool_(catch_leaked_mocks);
+GMOCK_DECLARE_string_(verbose);
+GMOCK_DECLARE_int32_(default_mock_behavior);
+
+// Initializes Google Mock. This must be called before running the
+// tests. In particular, it parses the command line for the flags
+// that Google Mock recognizes. Whenever a Google Mock flag is seen,
+// it is removed from argv, and *argc is decremented.
+//
+// No value is returned. Instead, the Google Mock flag variables are
+// updated.
+//
+// Since Google Test is needed for Google Mock to work, this function
+// also initializes Google Test and parses its flags, if that hasn't
+// been done.
+GTEST_API_ void InitGoogleMock(int* argc, char** argv);
+
+// This overloaded version can be used in Windows programs compiled in
+// UNICODE mode.
+GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv);
+
+// This overloaded version can be used on Arduino/embedded platforms where
+// there is no argc/argv.
+GTEST_API_ void InitGoogleMock();
+
+} // namespace testing
+
+#endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_
--- /dev/null
+# Customization Points
+
+The custom directory is an injection point for custom user configurations.
+
+## Header `gmock-port.h`
+
+The following macros can be defined:
+
+### Flag related macros:
+
+* `GMOCK_DECLARE_bool_(name)`
+* `GMOCK_DECLARE_int32_(name)`
+* `GMOCK_DECLARE_string_(name)`
+* `GMOCK_DEFINE_bool_(name, default_val, doc)`
+* `GMOCK_DEFINE_int32_(name, default_val, doc)`
+* `GMOCK_DEFINE_string_(name, default_val, doc)`
--- /dev/null
+// This file was GENERATED by command:
+// pump.py gmock-generated-actions.h.pump
+// DO NOT EDIT BY HAND!!!
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
+#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
+
+#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
--- /dev/null
+$$ -*- mode: c++; -*-
+$$ This is a Pump source file. Please use Pump to convert
+$$ it to callback-actions.h.
+$$
+$var max_callback_arity = 5
+$$}} This meta comment fixes auto-indentation in editors.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
+#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
+
+#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
--- /dev/null
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Injection point for custom user configurations. See README for details
+//
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
+#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
+#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
--- /dev/null
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Injection point for custom user configurations. See README for details
+//
+// ** Custom implementation starts here **
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
+#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
+
+#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file defines some utilities useful for implementing Google
+// Mock. They are subject to change without notice, so please DO NOT
+// USE THEM IN USER CODE.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
+#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
+
+#include <stdio.h>
+#include <ostream> // NOLINT
+#include <string>
+#include <type_traits>
+#include "gmock/internal/gmock-port.h"
+#include "gtest/gtest.h"
+
+namespace testing {
+
+template <typename>
+class Matcher;
+
+namespace internal {
+
+// Silence MSVC C4100 (unreferenced formal parameter) and
+// C4805('==': unsafe mix of type 'const int' and type 'const bool')
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable:4100)
+# pragma warning(disable:4805)
+#endif
+
+// Joins a vector of strings as if they are fields of a tuple; returns
+// the joined string.
+GTEST_API_ std::string JoinAsTuple(const Strings& fields);
+
+// Converts an identifier name to a space-separated list of lower-case
+// words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
+// treated as one word. For example, both "FooBar123" and
+// "foo_bar_123" are converted to "foo bar 123".
+GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name);
+
+// PointeeOf<Pointer>::type is the type of a value pointed to by a
+// Pointer, which can be either a smart pointer or a raw pointer. The
+// following default implementation is for the case where Pointer is a
+// smart pointer.
+template <typename Pointer>
+struct PointeeOf {
+ // Smart pointer classes define type element_type as the type of
+ // their pointees.
+ typedef typename Pointer::element_type type;
+};
+// This specialization is for the raw pointer case.
+template <typename T>
+struct PointeeOf<T*> { typedef T type; }; // NOLINT
+
+// GetRawPointer(p) returns the raw pointer underlying p when p is a
+// smart pointer, or returns p itself when p is already a raw pointer.
+// The following default implementation is for the smart pointer case.
+template <typename Pointer>
+inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
+ return p.get();
+}
+// This overloaded version is for the raw pointer case.
+template <typename Element>
+inline Element* GetRawPointer(Element* p) { return p; }
+
+// MSVC treats wchar_t as a native type usually, but treats it as the
+// same as unsigned short when the compiler option /Zc:wchar_t- is
+// specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
+// is a native type.
+#if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)
+// wchar_t is a typedef.
+#else
+# define GMOCK_WCHAR_T_IS_NATIVE_ 1
+#endif
+
+// signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
+// Using them is a bad practice and not portable. So DON'T use them.
+//
+// Still, Google Mock is designed to work even if the user uses signed
+// wchar_t or unsigned wchar_t (obviously, assuming the compiler
+// supports them).
+//
+// To gcc,
+// wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
+#ifdef __GNUC__
+#if !defined(__WCHAR_UNSIGNED__)
+// signed/unsigned wchar_t are valid types.
+# define GMOCK_HAS_SIGNED_WCHAR_T_ 1
+#endif
+#endif
+
+// In what follows, we use the term "kind" to indicate whether a type
+// is bool, an integer type (excluding bool), a floating-point type,
+// or none of them. This categorization is useful for determining
+// when a matcher argument type can be safely converted to another
+// type in the implementation of SafeMatcherCast.
+enum TypeKind {
+ kBool, kInteger, kFloatingPoint, kOther
+};
+
+// KindOf<T>::value is the kind of type T.
+template <typename T> struct KindOf {
+ enum { value = kOther }; // The default kind.
+};
+
+// This macro declares that the kind of 'type' is 'kind'.
+#define GMOCK_DECLARE_KIND_(type, kind) \
+ template <> struct KindOf<type> { enum { value = kind }; }
+
+GMOCK_DECLARE_KIND_(bool, kBool);
+
+// All standard integer types.
+GMOCK_DECLARE_KIND_(char, kInteger);
+GMOCK_DECLARE_KIND_(signed char, kInteger);
+GMOCK_DECLARE_KIND_(unsigned char, kInteger);
+GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT
+GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT
+GMOCK_DECLARE_KIND_(int, kInteger);
+GMOCK_DECLARE_KIND_(unsigned int, kInteger);
+GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
+GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
+
+#if GMOCK_WCHAR_T_IS_NATIVE_
+GMOCK_DECLARE_KIND_(wchar_t, kInteger);
+#endif
+
+// Non-standard integer types.
+GMOCK_DECLARE_KIND_(Int64, kInteger);
+GMOCK_DECLARE_KIND_(UInt64, kInteger);
+
+// All standard floating-point types.
+GMOCK_DECLARE_KIND_(float, kFloatingPoint);
+GMOCK_DECLARE_KIND_(double, kFloatingPoint);
+GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
+
+#undef GMOCK_DECLARE_KIND_
+
+// Evaluates to the kind of 'type'.
+#define GMOCK_KIND_OF_(type) \
+ static_cast< ::testing::internal::TypeKind>( \
+ ::testing::internal::KindOf<type>::value)
+
+// Evaluates to true iff integer type T is signed.
+#define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
+
+// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
+// is true iff arithmetic type From can be losslessly converted to
+// arithmetic type To.
+//
+// It's the user's responsibility to ensure that both From and To are
+// raw (i.e. has no CV modifier, is not a pointer, and is not a
+// reference) built-in arithmetic types, kFromKind is the kind of
+// From, and kToKind is the kind of To; the value is
+// implementation-defined when the above pre-condition is violated.
+template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
+struct LosslessArithmeticConvertibleImpl : public false_type {};
+
+// Converting bool to bool is lossless.
+template <>
+struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
+ : public true_type {}; // NOLINT
+
+// Converting bool to any integer type is lossless.
+template <typename To>
+struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
+ : public true_type {}; // NOLINT
+
+// Converting bool to any floating-point type is lossless.
+template <typename To>
+struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
+ : public true_type {}; // NOLINT
+
+// Converting an integer to bool is lossy.
+template <typename From>
+struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
+ : public false_type {}; // NOLINT
+
+// Converting an integer to another non-bool integer is lossless iff
+// the target type's range encloses the source type's range.
+template <typename From, typename To>
+struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
+ : public bool_constant<
+ // When converting from a smaller size to a larger size, we are
+ // fine as long as we are not converting from signed to unsigned.
+ ((sizeof(From) < sizeof(To)) &&
+ (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
+ // When converting between the same size, the signedness must match.
+ ((sizeof(From) == sizeof(To)) &&
+ (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT
+
+#undef GMOCK_IS_SIGNED_
+
+// Converting an integer to a floating-point type may be lossy, since
+// the format of a floating-point number is implementation-defined.
+template <typename From, typename To>
+struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
+ : public false_type {}; // NOLINT
+
+// Converting a floating-point to bool is lossy.
+template <typename From>
+struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
+ : public false_type {}; // NOLINT
+
+// Converting a floating-point to an integer is lossy.
+template <typename From, typename To>
+struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
+ : public false_type {}; // NOLINT
+
+// Converting a floating-point to another floating-point is lossless
+// iff the target type is at least as big as the source type.
+template <typename From, typename To>
+struct LosslessArithmeticConvertibleImpl<
+ kFloatingPoint, From, kFloatingPoint, To>
+ : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
+
+// LosslessArithmeticConvertible<From, To>::value is true iff arithmetic
+// type From can be losslessly converted to arithmetic type To.
+//
+// It's the user's responsibility to ensure that both From and To are
+// raw (i.e. has no CV modifier, is not a pointer, and is not a
+// reference) built-in arithmetic types; the value is
+// implementation-defined when the above pre-condition is violated.
+template <typename From, typename To>
+struct LosslessArithmeticConvertible
+ : public LosslessArithmeticConvertibleImpl<
+ GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
+
+// This interface knows how to report a Google Mock failure (either
+// non-fatal or fatal).
+class FailureReporterInterface {
+ public:
+ // The type of a failure (either non-fatal or fatal).
+ enum FailureType {
+ kNonfatal, kFatal
+ };
+
+ virtual ~FailureReporterInterface() {}
+
+ // Reports a failure that occurred at the given source file location.
+ virtual void ReportFailure(FailureType type, const char* file, int line,
+ const std::string& message) = 0;
+};
+
+// Returns the failure reporter used by Google Mock.
+GTEST_API_ FailureReporterInterface* GetFailureReporter();
+
+// Asserts that condition is true; aborts the process with the given
+// message if condition is false. We cannot use LOG(FATAL) or CHECK()
+// as Google Mock might be used to mock the log sink itself. We
+// inline this function to prevent it from showing up in the stack
+// trace.
+inline void Assert(bool condition, const char* file, int line,
+ const std::string& msg) {
+ if (!condition) {
+ GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
+ file, line, msg);
+ }
+}
+inline void Assert(bool condition, const char* file, int line) {
+ Assert(condition, file, line, "Assertion failed.");
+}
+
+// Verifies that condition is true; generates a non-fatal failure if
+// condition is false.
+inline void Expect(bool condition, const char* file, int line,
+ const std::string& msg) {
+ if (!condition) {
+ GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
+ file, line, msg);
+ }
+}
+inline void Expect(bool condition, const char* file, int line) {
+ Expect(condition, file, line, "Expectation failed.");
+}
+
+// Severity level of a log.
+enum LogSeverity {
+ kInfo = 0,
+ kWarning = 1
+};
+
+// Valid values for the --gmock_verbose flag.
+
+// All logs (informational and warnings) are printed.
+const char kInfoVerbosity[] = "info";
+// Only warnings are printed.
+const char kWarningVerbosity[] = "warning";
+// No logs are printed.
+const char kErrorVerbosity[] = "error";
+
+// Returns true iff a log with the given severity is visible according
+// to the --gmock_verbose flag.
+GTEST_API_ bool LogIsVisible(LogSeverity severity);
+
+// Prints the given message to stdout iff 'severity' >= the level
+// specified by the --gmock_verbose flag. If stack_frames_to_skip >=
+// 0, also prints the stack trace excluding the top
+// stack_frames_to_skip frames. In opt mode, any positive
+// stack_frames_to_skip is treated as 0, since we don't know which
+// function calls will be inlined by the compiler and need to be
+// conservative.
+GTEST_API_ void Log(LogSeverity severity, const std::string& message,
+ int stack_frames_to_skip);
+
+// A marker class that is used to resolve parameterless expectations to the
+// correct overload. This must not be instantiable, to prevent client code from
+// accidentally resolving to the overload; for example:
+//
+// ON_CALL(mock, Method({}, nullptr))...
+//
+class WithoutMatchers {
+ private:
+ WithoutMatchers() {}
+ friend GTEST_API_ WithoutMatchers GetWithoutMatchers();
+};
+
+// Internal use only: access the singleton instance of WithoutMatchers.
+GTEST_API_ WithoutMatchers GetWithoutMatchers();
+
+// Type traits.
+
+// is_reference<T>::value is non-zero iff T is a reference type.
+template <typename T> struct is_reference : public false_type {};
+template <typename T> struct is_reference<T&> : public true_type {};
+
+// type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type.
+template <typename T1, typename T2> struct type_equals : public false_type {};
+template <typename T> struct type_equals<T, T> : public true_type {};
+
+// remove_reference<T>::type removes the reference from type T, if any.
+template <typename T> struct remove_reference { typedef T type; }; // NOLINT
+template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT
+
+// DecayArray<T>::type turns an array type U[N] to const U* and preserves
+// other types. Useful for saving a copy of a function argument.
+template <typename T> struct DecayArray { typedef T type; }; // NOLINT
+template <typename T, size_t N> struct DecayArray<T[N]> {
+ typedef const T* type;
+};
+// Sometimes people use arrays whose size is not available at the use site
+// (e.g. extern const char kNamePrefix[]). This specialization covers that
+// case.
+template <typename T> struct DecayArray<T[]> {
+ typedef const T* type;
+};
+
+// Disable MSVC warnings for infinite recursion, since in this case the
+// the recursion is unreachable.
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable:4717)
+#endif
+
+// Invalid<T>() is usable as an expression of type T, but will terminate
+// the program with an assertion failure if actually run. This is useful
+// when a value of type T is needed for compilation, but the statement
+// will not really be executed (or we don't care if the statement
+// crashes).
+template <typename T>
+inline T Invalid() {
+ Assert(false, "", -1, "Internal error: attempt to return invalid value");
+ // This statement is unreachable, and would never terminate even if it
+ // could be reached. It is provided only to placate compiler warnings
+ // about missing return statements.
+ return Invalid<T>();
+}
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+// Given a raw type (i.e. having no top-level reference or const
+// modifier) RawContainer that's either an STL-style container or a
+// native array, class StlContainerView<RawContainer> has the
+// following members:
+//
+// - type is a type that provides an STL-style container view to
+// (i.e. implements the STL container concept for) RawContainer;
+// - const_reference is a type that provides a reference to a const
+// RawContainer;
+// - ConstReference(raw_container) returns a const reference to an STL-style
+// container view to raw_container, which is a RawContainer.
+// - Copy(raw_container) returns an STL-style container view of a
+// copy of raw_container, which is a RawContainer.
+//
+// This generic version is used when RawContainer itself is already an
+// STL-style container.
+template <class RawContainer>
+class StlContainerView {
+ public:
+ typedef RawContainer type;
+ typedef const type& const_reference;
+
+ static const_reference ConstReference(const RawContainer& container) {
+ // Ensures that RawContainer is not a const type.
+ testing::StaticAssertTypeEq<RawContainer,
+ GTEST_REMOVE_CONST_(RawContainer)>();
+ return container;
+ }
+ static type Copy(const RawContainer& container) { return container; }
+};
+
+// This specialization is used when RawContainer is a native array type.
+template <typename Element, size_t N>
+class StlContainerView<Element[N]> {
+ public:
+ typedef GTEST_REMOVE_CONST_(Element) RawElement;
+ typedef internal::NativeArray<RawElement> type;
+ // NativeArray<T> can represent a native array either by value or by
+ // reference (selected by a constructor argument), so 'const type'
+ // can be used to reference a const native array. We cannot
+ // 'typedef const type& const_reference' here, as that would mean
+ // ConstReference() has to return a reference to a local variable.
+ typedef const type const_reference;
+
+ static const_reference ConstReference(const Element (&array)[N]) {
+ // Ensures that Element is not a const type.
+ testing::StaticAssertTypeEq<Element, RawElement>();
+ return type(array, N, RelationToSourceReference());
+ }
+ static type Copy(const Element (&array)[N]) {
+ return type(array, N, RelationToSourceCopy());
+ }
+};
+
+// This specialization is used when RawContainer is a native array
+// represented as a (pointer, size) tuple.
+template <typename ElementPointer, typename Size>
+class StlContainerView< ::std::tuple<ElementPointer, Size> > {
+ public:
+ typedef GTEST_REMOVE_CONST_(
+ typename internal::PointeeOf<ElementPointer>::type) RawElement;
+ typedef internal::NativeArray<RawElement> type;
+ typedef const type const_reference;
+
+ static const_reference ConstReference(
+ const ::std::tuple<ElementPointer, Size>& array) {
+ return type(std::get<0>(array), std::get<1>(array),
+ RelationToSourceReference());
+ }
+ static type Copy(const ::std::tuple<ElementPointer, Size>& array) {
+ return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy());
+ }
+};
+
+// The following specialization prevents the user from instantiating
+// StlContainer with a reference type.
+template <typename T> class StlContainerView<T&>;
+
+// A type transform to remove constness from the first part of a pair.
+// Pairs like that are used as the value_type of associative containers,
+// and this transform produces a similar but assignable pair.
+template <typename T>
+struct RemoveConstFromKey {
+ typedef T type;
+};
+
+// Partially specialized to remove constness from std::pair<const K, V>.
+template <typename K, typename V>
+struct RemoveConstFromKey<std::pair<const K, V> > {
+ typedef std::pair<K, V> type;
+};
+
+// Mapping from booleans to types. Similar to boost::bool_<kValue> and
+// std::integral_constant<bool, kValue>.
+template <bool kValue>
+struct BooleanConstant {};
+
+// Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to
+// reduce code size.
+GTEST_API_ void IllegalDoDefault(const char* file, int line);
+
+// Helper types for Apply() below.
+template <size_t... Is> struct int_pack { typedef int_pack type; };
+
+template <class Pack, size_t I> struct append;
+template <size_t... Is, size_t I>
+struct append<int_pack<Is...>, I> : int_pack<Is..., I> {};
+
+template <size_t C>
+struct make_int_pack : append<typename make_int_pack<C - 1>::type, C - 1> {};
+template <> struct make_int_pack<0> : int_pack<> {};
+
+template <typename F, typename Tuple, size_t... Idx>
+auto ApplyImpl(F&& f, Tuple&& args, int_pack<Idx...>) -> decltype(
+ std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...)) {
+ return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...);
+}
+
+// Apply the function to a tuple of arguments.
+template <typename F, typename Tuple>
+auto Apply(F&& f, Tuple&& args)
+ -> decltype(ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
+ make_int_pack<std::tuple_size<Tuple>::value>())) {
+ return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
+ make_int_pack<std::tuple_size<Tuple>::value>());
+}
+
+// Template struct Function<F>, where F must be a function type, contains
+// the following typedefs:
+//
+// Result: the function's return type.
+// Arg<N>: the type of the N-th argument, where N starts with 0.
+// ArgumentTuple: the tuple type consisting of all parameters of F.
+// ArgumentMatcherTuple: the tuple type consisting of Matchers for all
+// parameters of F.
+// MakeResultVoid: the function type obtained by substituting void
+// for the return type of F.
+// MakeResultIgnoredValue:
+// the function type obtained by substituting Something
+// for the return type of F.
+template <typename T>
+struct Function;
+
+template <typename R, typename... Args>
+struct Function<R(Args...)> {
+ using Result = R;
+ static constexpr size_t ArgumentCount = sizeof...(Args);
+ template <size_t I>
+ using Arg = ElemFromList<I, typename MakeIndexSequence<sizeof...(Args)>::type,
+ Args...>;
+ using ArgumentTuple = std::tuple<Args...>;
+ using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
+ using MakeResultVoid = void(Args...);
+ using MakeResultIgnoredValue = IgnoredValue(Args...);
+};
+
+template <typename R, typename... Args>
+constexpr size_t Function<R(Args...)>::ArgumentCount;
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+} // namespace internal
+} // namespace testing
+
+#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// Low-level types and utilities for porting Google Mock to various
+// platforms. All macros ending with _ and symbols defined in an
+// internal namespace are subject to change without notice. Code
+// outside Google Mock MUST NOT USE THEM DIRECTLY. Macros that don't
+// end with _ are part of Google Mock's public API and can be used by
+// code outside Google Mock.
+
+// GOOGLETEST_CM0002 DO NOT DELETE
+
+#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
+#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
+
+#include <assert.h>
+#include <stdlib.h>
+#include <iostream>
+
+// Most of the utilities needed for porting Google Mock are also
+// required for Google Test and are defined in gtest-port.h.
+//
+// Note to maintainers: to reduce code duplication, prefer adding
+// portability utilities to Google Test's gtest-port.h instead of
+// here, as Google Mock depends on Google Test. Only add a utility
+// here if it's truly specific to Google Mock.
+
+#include "gtest/internal/gtest-port.h"
+#include "gmock/internal/custom/gmock-port.h"
+
+// For MS Visual C++, check the compiler version. At least VS 2015 is
+// required to compile Google Mock.
+#if defined(_MSC_VER) && _MSC_VER < 1900
+# error "At least Visual C++ 2015 (14.0) is required to compile Google Mock."
+#endif
+
+// Macro for referencing flags. This is public as we want the user to
+// use this syntax to reference Google Mock flags.
+#define GMOCK_FLAG(name) FLAGS_gmock_##name
+
+#if !defined(GMOCK_DECLARE_bool_)
+
+// Macros for declaring flags.
+# define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name)
+# define GMOCK_DECLARE_int32_(name) \
+ extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name)
+# define GMOCK_DECLARE_string_(name) \
+ extern GTEST_API_ ::std::string GMOCK_FLAG(name)
+
+// Macros for defining flags.
+# define GMOCK_DEFINE_bool_(name, default_val, doc) \
+ GTEST_API_ bool GMOCK_FLAG(name) = (default_val)
+# define GMOCK_DEFINE_int32_(name, default_val, doc) \
+ GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val)
+# define GMOCK_DEFINE_string_(name, default_val, doc) \
+ GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val)
+
+#endif // !defined(GMOCK_DECLARE_bool_)
+
+#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
--- /dev/null
+#ifndef THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_
+#define THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_
+
+#undef GMOCK_PP_INTERNAL_USE_MSVC
+#if defined(__clang__)
+#define GMOCK_PP_INTERNAL_USE_MSVC 0
+#elif defined(_MSC_VER)
+// TODO(iserna): Also verify tradional versus comformant preprocessor.
+static_assert(
+ _MSC_VER >= 1900,
+ "MSVC version not supported. There is support for MSVC 14.0 and above.");
+#define GMOCK_PP_INTERNAL_USE_MSVC 1
+#else
+#define GMOCK_PP_INTERNAL_USE_MSVC 0
+#endif
+
+// Expands and concatenates the arguments. Constructed macros reevaluate.
+#define GMOCK_PP_CAT(_1, _2) GMOCK_PP_INTERNAL_CAT(_1, _2)
+
+// Expands and stringifies the only argument.
+#define GMOCK_PP_STRINGIZE(...) GMOCK_PP_INTERNAL_STRINGIZE(__VA_ARGS__)
+
+// Returns empty. Given a variadic number of arguments.
+#define GMOCK_PP_EMPTY(...)
+
+// Returns a comma. Given a variadic number of arguments.
+#define GMOCK_PP_COMMA(...) ,
+
+// Returns the only argument.
+#define GMOCK_PP_IDENTITY(_1) _1
+
+// MSVC preprocessor collapses __VA_ARGS__ in a single argument, we use a
+// CAT-like directive to force correct evaluation. Each macro has its own.
+#if GMOCK_PP_INTERNAL_USE_MSVC
+
+// Evaluates to the number of arguments after expansion.
+//
+// #define PAIR x, y
+//
+// GMOCK_PP_NARG() => 1
+// GMOCK_PP_NARG(x) => 1
+// GMOCK_PP_NARG(x, y) => 2
+// GMOCK_PP_NARG(PAIR) => 2
+//
+// Requires: the number of arguments after expansion is at most 15.
+#define GMOCK_PP_NARG(...) \
+ GMOCK_PP_INTERNAL_NARG_CAT( \
+ GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, \
+ 8, 7, 6, 5, 4, 3, 2, 1), )
+
+// Returns 1 if the expansion of arguments has an unprotected comma. Otherwise
+// returns 0. Requires no more than 15 unprotected commas.
+#define GMOCK_PP_HAS_COMMA(...) \
+ GMOCK_PP_INTERNAL_HAS_COMMA_CAT( \
+ GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
+ 1, 1, 1, 1, 1, 0), )
+// Returns the first argument.
+#define GMOCK_PP_HEAD(...) \
+ GMOCK_PP_INTERNAL_HEAD_CAT(GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__), )
+
+// Returns the tail. A variadic list of all arguments minus the first. Requires
+// at least one argument.
+#define GMOCK_PP_TAIL(...) \
+ GMOCK_PP_INTERNAL_TAIL_CAT(GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__), )
+
+// Calls CAT(_Macro, NARG(__VA_ARGS__))(__VA_ARGS__)
+#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \
+ GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT( \
+ GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__), )
+
+#else // GMOCK_PP_INTERNAL_USE_MSVC
+
+#define GMOCK_PP_NARG(...) \
+ GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, \
+ 7, 6, 5, 4, 3, 2, 1)
+#define GMOCK_PP_HAS_COMMA(...) \
+ GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
+ 1, 1, 1, 1, 0)
+#define GMOCK_PP_HEAD(...) GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__)
+#define GMOCK_PP_TAIL(...) GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__)
+#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \
+ GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__)
+
+#endif // GMOCK_PP_INTERNAL_USE_MSVC
+
+// If the arguments after expansion have no tokens, evaluates to `1`. Otherwise
+// evaluates to `0`.
+//
+// Requires: * the number of arguments after expansion is at most 15.
+// * If the argument is a macro, it must be able to be called with one
+// argument.
+//
+// Implementation details:
+//
+// There is one case when it generates a compile error: if the argument is macro
+// that cannot be called with one argument.
+//
+// #define M(a, b) // it doesn't matter what it expands to
+//
+// // Expected: expands to `0`.
+// // Actual: compile error.
+// GMOCK_PP_IS_EMPTY(M)
+//
+// There are 4 cases tested:
+//
+// * __VA_ARGS__ possible expansion has no unparen'd commas. Expected 0.
+// * __VA_ARGS__ possible expansion is not enclosed in parenthesis. Expected 0.
+// * __VA_ARGS__ possible expansion is not a macro that ()-evaluates to a comma.
+// Expected 0
+// * __VA_ARGS__ is empty, or has unparen'd commas, or is enclosed in
+// parenthesis, or is a macro that ()-evaluates to comma. Expected 1.
+//
+// We trigger detection on '0001', i.e. on empty.
+#define GMOCK_PP_IS_EMPTY(...) \
+ GMOCK_PP_INTERNAL_IS_EMPTY(GMOCK_PP_HAS_COMMA(__VA_ARGS__), \
+ GMOCK_PP_HAS_COMMA(GMOCK_PP_COMMA __VA_ARGS__), \
+ GMOCK_PP_HAS_COMMA(__VA_ARGS__()), \
+ GMOCK_PP_HAS_COMMA(GMOCK_PP_COMMA __VA_ARGS__()))
+
+// Evaluates to _Then if _Cond is 1 and _Else if _Cond is 0.
+#define GMOCK_PP_IF(_Cond, _Then, _Else) \
+ GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IF_, _Cond)(_Then, _Else)
+
+// Evaluates to the number of arguments after expansion. Identifies 'empty' as
+// 0.
+//
+// #define PAIR x, y
+//
+// GMOCK_PP_NARG0() => 0
+// GMOCK_PP_NARG0(x) => 1
+// GMOCK_PP_NARG0(x, y) => 2
+// GMOCK_PP_NARG0(PAIR) => 2
+//
+// Requires: * the number of arguments after expansion is at most 15.
+// * If the argument is a macro, it must be able to be called with one
+// argument.
+#define GMOCK_PP_NARG0(...) \
+ GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(__VA_ARGS__), 0, GMOCK_PP_NARG(__VA_ARGS__))
+
+// Expands to 1 if the first argument starts with something in parentheses,
+// otherwise to 0.
+#define GMOCK_PP_IS_BEGIN_PARENS(...) \
+ GMOCK_PP_INTERNAL_ALTERNATE_HEAD( \
+ GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_, \
+ GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C __VA_ARGS__))
+
+// Expands to 1 is there is only one argument and it is enclosed in parentheses.
+#define GMOCK_PP_IS_ENCLOSED_PARENS(...) \
+ GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(__VA_ARGS__), \
+ GMOCK_PP_IS_EMPTY(GMOCK_PP_EMPTY __VA_ARGS__), 0)
+
+// Remove the parens, requires GMOCK_PP_IS_ENCLOSED_PARENS(args) => 1.
+#define GMOCK_PP_REMOVE_PARENS(...) GMOCK_PP_INTERNAL_REMOVE_PARENS __VA_ARGS__
+
+// Expands to _Macro(0, _Data, e1) _Macro(1, _Data, e2) ... _Macro(K -1, _Data,
+// eK) as many of GMOCK_INTERNAL_NARG0 _Tuple.
+// Requires: * |_Macro| can be called with 3 arguments.
+// * |_Tuple| expansion has no more than 15 elements.
+#define GMOCK_PP_FOR_EACH(_Macro, _Data, _Tuple) \
+ GMOCK_PP_CAT(GMOCK_PP_INTERNAL_FOR_EACH_IMPL_, GMOCK_PP_NARG0 _Tuple) \
+ (0, _Macro, _Data, _Tuple)
+
+// Expands to _Macro(0, _Data, ) _Macro(1, _Data, ) ... _Macro(K - 1, _Data, )
+// Empty if _K = 0.
+// Requires: * |_Macro| can be called with 3 arguments.
+// * |_K| literal between 0 and 15
+#define GMOCK_PP_REPEAT(_Macro, _Data, _N) \
+ GMOCK_PP_CAT(GMOCK_PP_INTERNAL_FOR_EACH_IMPL_, _N) \
+ (0, _Macro, _Data, GMOCK_PP_INTENRAL_EMPTY_TUPLE)
+
+// Increments the argument, requires the argument to be between 0 and 15.
+#define GMOCK_PP_INC(_i) GMOCK_PP_CAT(GMOCK_PP_INTERNAL_INC_, _i)
+
+// Returns comma if _i != 0. Requires _i to be between 0 and 15.
+#define GMOCK_PP_COMMA_IF(_i) GMOCK_PP_CAT(GMOCK_PP_INTERNAL_COMMA_IF_, _i)
+
+// Internal details follow. Do not use any of these symbols outside of this
+// file or we will break your code.
+#define GMOCK_PP_INTENRAL_EMPTY_TUPLE (, , , , , , , , , , , , , , , )
+#define GMOCK_PP_INTERNAL_CAT(_1, _2) _1##_2
+#define GMOCK_PP_INTERNAL_STRINGIZE(...) #__VA_ARGS__
+#define GMOCK_PP_INTERNAL_INTERNAL_16TH(_1, _2, _3, _4, _5, _6, _7, _8, _9, \
+ _10, _11, _12, _13, _14, _15, _16, \
+ ...) \
+ _16
+#define GMOCK_PP_INTERNAL_CAT_5(_1, _2, _3, _4, _5) _1##_2##_3##_4##_5
+#define GMOCK_PP_INTERNAL_IS_EMPTY(_1, _2, _3, _4) \
+ GMOCK_PP_HAS_COMMA(GMOCK_PP_INTERNAL_CAT_5(GMOCK_PP_INTERNAL_IS_EMPTY_CASE_, \
+ _1, _2, _3, _4))
+#define GMOCK_PP_INTERNAL_IS_EMPTY_CASE_0001 ,
+#define GMOCK_PP_INTERNAL_IF_1(_Then, _Else) _Then
+#define GMOCK_PP_INTERNAL_IF_0(_Then, _Else) _Else
+#define GMOCK_PP_INTERNAL_HEAD(_1, ...) _1
+#define GMOCK_PP_INTERNAL_TAIL(_1, ...) __VA_ARGS__
+
+#if GMOCK_PP_INTERNAL_USE_MSVC
+#define GMOCK_PP_INTERNAL_NARG_CAT(_1, _2) GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2)
+#define GMOCK_PP_INTERNAL_HEAD_CAT(_1, _2) GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2)
+#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT(_1, _2) \
+ GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2)
+#define GMOCK_PP_INTERNAL_TAIL_CAT(_1, _2) GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2)
+#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT(_1, _2) \
+ GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2)
+#define GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2) _1##_2
+#define GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2) _1##_2
+#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2) _1##_2
+#define GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2) _1##_2
+#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2) _1##_2
+#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) \
+ GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(GMOCK_PP_HEAD(__VA_ARGS__), )
+#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(_1, _2) \
+ GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2)
+#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2) _1##_2
+#else // GMOCK_PP_INTERNAL_USE_MSVC
+#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) GMOCK_PP_HEAD(__VA_ARGS__)
+#endif // GMOCK_PP_INTERNAL_USE_MSVC
+
+#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C(...) 1 _
+#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_1 1,
+#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C \
+ 0,
+#define GMOCK_PP_INTERNAL_REMOVE_PARENS(...) __VA_ARGS__
+#define GMOCK_PP_INTERNAL_INC_0 1
+#define GMOCK_PP_INTERNAL_INC_1 2
+#define GMOCK_PP_INTERNAL_INC_2 3
+#define GMOCK_PP_INTERNAL_INC_3 4
+#define GMOCK_PP_INTERNAL_INC_4 5
+#define GMOCK_PP_INTERNAL_INC_5 6
+#define GMOCK_PP_INTERNAL_INC_6 7
+#define GMOCK_PP_INTERNAL_INC_7 8
+#define GMOCK_PP_INTERNAL_INC_8 9
+#define GMOCK_PP_INTERNAL_INC_9 10
+#define GMOCK_PP_INTERNAL_INC_10 11
+#define GMOCK_PP_INTERNAL_INC_11 12
+#define GMOCK_PP_INTERNAL_INC_12 13
+#define GMOCK_PP_INTERNAL_INC_13 14
+#define GMOCK_PP_INTERNAL_INC_14 15
+#define GMOCK_PP_INTERNAL_INC_15 16
+#define GMOCK_PP_INTERNAL_COMMA_IF_0
+#define GMOCK_PP_INTERNAL_COMMA_IF_1 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_2 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_3 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_4 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_5 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_6 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_7 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_8 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_9 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_10 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_11 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_12 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_13 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_14 ,
+#define GMOCK_PP_INTERNAL_COMMA_IF_15 ,
+#define GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, _element) \
+ _Macro(_i, _Data, _element)
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_0(_i, _Macro, _Data, _Tuple)
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple)
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_2(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_3(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_2(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_4(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_3(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_5(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_4(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_6(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_5(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_7(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_6(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_8(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_7(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_9(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_8(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_10(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_9(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_11(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_10(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_12(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_11(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_13(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_12(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_14(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_13(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_15(_i, _Macro, _Data, _Tuple) \
+ GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
+ GMOCK_PP_INTERNAL_FOR_EACH_IMPL_14(GMOCK_PP_INC(_i), _Macro, _Data, \
+ (GMOCK_PP_TAIL _Tuple))
+
+#endif // THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PP_H_
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// Google C++ Mocking Framework (Google Mock)
+//
+// This file #includes all Google Mock implementation .cc files. The
+// purpose is to allow a user to build Google Mock by compiling this
+// file alone.
+
+// This line ensures that gmock.h can be compiled on its own, even
+// when it's fused.
+#include "gmock/gmock.h"
+
+// The following lines pull in the real gmock *.cc files.
+#include "src/gmock-cardinalities.cc"
+#include "src/gmock-internal-utils.cc"
+#include "src/gmock-matchers.cc"
+#include "src/gmock-spec-builders.cc"
+#include "src/gmock.cc"
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements cardinalities.
+
+#include "gmock/gmock-cardinalities.h"
+
+#include <limits.h>
+#include <ostream> // NOLINT
+#include <sstream>
+#include <string>
+#include "gmock/internal/gmock-internal-utils.h"
+#include "gtest/gtest.h"
+
+namespace testing {
+
+namespace {
+
+// Implements the Between(m, n) cardinality.
+class BetweenCardinalityImpl : public CardinalityInterface {
+ public:
+ BetweenCardinalityImpl(int min, int max)
+ : min_(min >= 0 ? min : 0),
+ max_(max >= min_ ? max : min_) {
+ std::stringstream ss;
+ if (min < 0) {
+ ss << "The invocation lower bound must be >= 0, "
+ << "but is actually " << min << ".";
+ internal::Expect(false, __FILE__, __LINE__, ss.str());
+ } else if (max < 0) {
+ ss << "The invocation upper bound must be >= 0, "
+ << "but is actually " << max << ".";
+ internal::Expect(false, __FILE__, __LINE__, ss.str());
+ } else if (min > max) {
+ ss << "The invocation upper bound (" << max
+ << ") must be >= the invocation lower bound (" << min
+ << ").";
+ internal::Expect(false, __FILE__, __LINE__, ss.str());
+ }
+ }
+
+ // Conservative estimate on the lower/upper bound of the number of
+ // calls allowed.
+ int ConservativeLowerBound() const override { return min_; }
+ int ConservativeUpperBound() const override { return max_; }
+
+ bool IsSatisfiedByCallCount(int call_count) const override {
+ return min_ <= call_count && call_count <= max_;
+ }
+
+ bool IsSaturatedByCallCount(int call_count) const override {
+ return call_count >= max_;
+ }
+
+ void DescribeTo(::std::ostream* os) const override;
+
+ private:
+ const int min_;
+ const int max_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(BetweenCardinalityImpl);
+};
+
+// Formats "n times" in a human-friendly way.
+inline std::string FormatTimes(int n) {
+ if (n == 1) {
+ return "once";
+ } else if (n == 2) {
+ return "twice";
+ } else {
+ std::stringstream ss;
+ ss << n << " times";
+ return ss.str();
+ }
+}
+
+// Describes the Between(m, n) cardinality in human-friendly text.
+void BetweenCardinalityImpl::DescribeTo(::std::ostream* os) const {
+ if (min_ == 0) {
+ if (max_ == 0) {
+ *os << "never called";
+ } else if (max_ == INT_MAX) {
+ *os << "called any number of times";
+ } else {
+ *os << "called at most " << FormatTimes(max_);
+ }
+ } else if (min_ == max_) {
+ *os << "called " << FormatTimes(min_);
+ } else if (max_ == INT_MAX) {
+ *os << "called at least " << FormatTimes(min_);
+ } else {
+ // 0 < min_ < max_ < INT_MAX
+ *os << "called between " << min_ << " and " << max_ << " times";
+ }
+}
+
+} // Unnamed namespace
+
+// Describes the given call count to an ostream.
+void Cardinality::DescribeActualCallCountTo(int actual_call_count,
+ ::std::ostream* os) {
+ if (actual_call_count > 0) {
+ *os << "called " << FormatTimes(actual_call_count);
+ } else {
+ *os << "never called";
+ }
+}
+
+// Creates a cardinality that allows at least n calls.
+GTEST_API_ Cardinality AtLeast(int n) { return Between(n, INT_MAX); }
+
+// Creates a cardinality that allows at most n calls.
+GTEST_API_ Cardinality AtMost(int n) { return Between(0, n); }
+
+// Creates a cardinality that allows any number of calls.
+GTEST_API_ Cardinality AnyNumber() { return AtLeast(0); }
+
+// Creates a cardinality that allows between min and max calls.
+GTEST_API_ Cardinality Between(int min, int max) {
+ return Cardinality(new BetweenCardinalityImpl(min, max));
+}
+
+// Creates a cardinality that allows exactly n calls.
+GTEST_API_ Cardinality Exactly(int n) { return Between(n, n); }
+
+} // namespace testing
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file defines some utilities useful for implementing Google
+// Mock. They are subject to change without notice, so please DO NOT
+// USE THEM IN USER CODE.
+
+#include "gmock/internal/gmock-internal-utils.h"
+
+#include <ctype.h>
+#include <ostream> // NOLINT
+#include <string>
+#include "gmock/gmock.h"
+#include "gmock/internal/gmock-port.h"
+#include "gtest/gtest.h"
+
+namespace testing {
+namespace internal {
+
+// Joins a vector of strings as if they are fields of a tuple; returns
+// the joined string.
+GTEST_API_ std::string JoinAsTuple(const Strings& fields) {
+ switch (fields.size()) {
+ case 0:
+ return "";
+ case 1:
+ return fields[0];
+ default:
+ std::string result = "(" + fields[0];
+ for (size_t i = 1; i < fields.size(); i++) {
+ result += ", ";
+ result += fields[i];
+ }
+ result += ")";
+ return result;
+ }
+}
+
+// Converts an identifier name to a space-separated list of lower-case
+// words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
+// treated as one word. For example, both "FooBar123" and
+// "foo_bar_123" are converted to "foo bar 123".
+GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name) {
+ std::string result;
+ char prev_char = '\0';
+ for (const char* p = id_name; *p != '\0'; prev_char = *(p++)) {
+ // We don't care about the current locale as the input is
+ // guaranteed to be a valid C++ identifier name.
+ const bool starts_new_word = IsUpper(*p) ||
+ (!IsAlpha(prev_char) && IsLower(*p)) ||
+ (!IsDigit(prev_char) && IsDigit(*p));
+
+ if (IsAlNum(*p)) {
+ if (starts_new_word && result != "")
+ result += ' ';
+ result += ToLower(*p);
+ }
+ }
+ return result;
+}
+
+// This class reports Google Mock failures as Google Test failures. A
+// user can define another class in a similar fashion if they intend to
+// use Google Mock with a testing framework other than Google Test.
+class GoogleTestFailureReporter : public FailureReporterInterface {
+ public:
+ void ReportFailure(FailureType type, const char* file, int line,
+ const std::string& message) override {
+ AssertHelper(type == kFatal ?
+ TestPartResult::kFatalFailure :
+ TestPartResult::kNonFatalFailure,
+ file,
+ line,
+ message.c_str()) = Message();
+ if (type == kFatal) {
+ posix::Abort();
+ }
+ }
+};
+
+// Returns the global failure reporter. Will create a
+// GoogleTestFailureReporter and return it the first time called.
+GTEST_API_ FailureReporterInterface* GetFailureReporter() {
+ // Points to the global failure reporter used by Google Mock. gcc
+ // guarantees that the following use of failure_reporter is
+ // thread-safe. We may need to add additional synchronization to
+ // protect failure_reporter if we port Google Mock to other
+ // compilers.
+ static FailureReporterInterface* const failure_reporter =
+ new GoogleTestFailureReporter();
+ return failure_reporter;
+}
+
+// Protects global resources (stdout in particular) used by Log().
+static GTEST_DEFINE_STATIC_MUTEX_(g_log_mutex);
+
+// Returns true iff a log with the given severity is visible according
+// to the --gmock_verbose flag.
+GTEST_API_ bool LogIsVisible(LogSeverity severity) {
+ if (GMOCK_FLAG(verbose) == kInfoVerbosity) {
+ // Always show the log if --gmock_verbose=info.
+ return true;
+ } else if (GMOCK_FLAG(verbose) == kErrorVerbosity) {
+ // Always hide it if --gmock_verbose=error.
+ return false;
+ } else {
+ // If --gmock_verbose is neither "info" nor "error", we treat it
+ // as "warning" (its default value).
+ return severity == kWarning;
+ }
+}
+
+// Prints the given message to stdout iff 'severity' >= the level
+// specified by the --gmock_verbose flag. If stack_frames_to_skip >=
+// 0, also prints the stack trace excluding the top
+// stack_frames_to_skip frames. In opt mode, any positive
+// stack_frames_to_skip is treated as 0, since we don't know which
+// function calls will be inlined by the compiler and need to be
+// conservative.
+GTEST_API_ void Log(LogSeverity severity, const std::string& message,
+ int stack_frames_to_skip) {
+ if (!LogIsVisible(severity))
+ return;
+
+ // Ensures that logs from different threads don't interleave.
+ MutexLock l(&g_log_mutex);
+
+ if (severity == kWarning) {
+ // Prints a GMOCK WARNING marker to make the warnings easily searchable.
+ std::cout << "\nGMOCK WARNING:";
+ }
+ // Pre-pends a new-line to message if it doesn't start with one.
+ if (message.empty() || message[0] != '\n') {
+ std::cout << "\n";
+ }
+ std::cout << message;
+ if (stack_frames_to_skip >= 0) {
+#ifdef NDEBUG
+ // In opt mode, we have to be conservative and skip no stack frame.
+ const int actual_to_skip = 0;
+#else
+ // In dbg mode, we can do what the caller tell us to do (plus one
+ // for skipping this function's stack frame).
+ const int actual_to_skip = stack_frames_to_skip + 1;
+#endif // NDEBUG
+
+ // Appends a new-line to message if it doesn't end with one.
+ if (!message.empty() && *message.rbegin() != '\n') {
+ std::cout << "\n";
+ }
+ std::cout << "Stack trace:\n"
+ << ::testing::internal::GetCurrentOsStackTraceExceptTop(
+ ::testing::UnitTest::GetInstance(), actual_to_skip);
+ }
+ std::cout << ::std::flush;
+}
+
+GTEST_API_ WithoutMatchers GetWithoutMatchers() { return WithoutMatchers(); }
+
+GTEST_API_ void IllegalDoDefault(const char* file, int line) {
+ internal::Assert(
+ false, file, line,
+ "You are using DoDefault() inside a composite action like "
+ "DoAll() or WithArgs(). This is not supported for technical "
+ "reasons. Please instead spell out the default action, or "
+ "assign the default action to an Action variable and use "
+ "the variable in various places.");
+}
+
+} // namespace internal
+} // namespace testing
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements Matcher<const string&>, Matcher<string>, and
+// utilities for defining matchers.
+
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock-generated-matchers.h"
+
+#include <string.h>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+namespace testing {
+namespace internal {
+
+// Returns the description for a matcher defined using the MATCHER*()
+// macro where the user-supplied description string is "", if
+// 'negation' is false; otherwise returns the description of the
+// negation of the matcher. 'param_values' contains a list of strings
+// that are the print-out of the matcher's parameters.
+GTEST_API_ std::string FormatMatcherDescription(bool negation,
+ const char* matcher_name,
+ const Strings& param_values) {
+ std::string result = ConvertIdentifierNameToWords(matcher_name);
+ if (param_values.size() >= 1) result += " " + JoinAsTuple(param_values);
+ return negation ? "not (" + result + ")" : result;
+}
+
+// FindMaxBipartiteMatching and its helper class.
+//
+// Uses the well-known Ford-Fulkerson max flow method to find a maximum
+// bipartite matching. Flow is considered to be from left to right.
+// There is an implicit source node that is connected to all of the left
+// nodes, and an implicit sink node that is connected to all of the
+// right nodes. All edges have unit capacity.
+//
+// Neither the flow graph nor the residual flow graph are represented
+// explicitly. Instead, they are implied by the information in 'graph' and
+// a vector<int> called 'left_' whose elements are initialized to the
+// value kUnused. This represents the initial state of the algorithm,
+// where the flow graph is empty, and the residual flow graph has the
+// following edges:
+// - An edge from source to each left_ node
+// - An edge from each right_ node to sink
+// - An edge from each left_ node to each right_ node, if the
+// corresponding edge exists in 'graph'.
+//
+// When the TryAugment() method adds a flow, it sets left_[l] = r for some
+// nodes l and r. This induces the following changes:
+// - The edges (source, l), (l, r), and (r, sink) are added to the
+// flow graph.
+// - The same three edges are removed from the residual flow graph.
+// - The reverse edges (l, source), (r, l), and (sink, r) are added
+// to the residual flow graph, which is a directional graph
+// representing unused flow capacity.
+//
+// When the method augments a flow (moving left_[l] from some r1 to some
+// other r2), this can be thought of as "undoing" the above steps with
+// respect to r1 and "redoing" them with respect to r2.
+//
+// It bears repeating that the flow graph and residual flow graph are
+// never represented explicitly, but can be derived by looking at the
+// information in 'graph' and in left_.
+//
+// As an optimization, there is a second vector<int> called right_ which
+// does not provide any new information. Instead, it enables more
+// efficient queries about edges entering or leaving the right-side nodes
+// of the flow or residual flow graphs. The following invariants are
+// maintained:
+//
+// left[l] == kUnused or right[left[l]] == l
+// right[r] == kUnused or left[right[r]] == r
+//
+// . [ source ] .
+// . ||| .
+// . ||| .
+// . ||\--> left[0]=1 ---\ right[0]=-1 ----\ .
+// . || | | .
+// . |\---> left[1]=-1 \--> right[1]=0 ---\| .
+// . | || .
+// . \----> left[2]=2 ------> right[2]=2 --\|| .
+// . ||| .
+// . elements matchers vvv .
+// . [ sink ] .
+//
+// See Also:
+// [1] Cormen, et al (2001). "Section 26.2: The Ford-Fulkerson method".
+// "Introduction to Algorithms (Second ed.)", pp. 651-664.
+// [2] "Ford-Fulkerson algorithm", Wikipedia,
+// 'http://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm'
+class MaxBipartiteMatchState {
+ public:
+ explicit MaxBipartiteMatchState(const MatchMatrix& graph)
+ : graph_(&graph),
+ left_(graph_->LhsSize(), kUnused),
+ right_(graph_->RhsSize(), kUnused) {}
+
+ // Returns the edges of a maximal match, each in the form {left, right}.
+ ElementMatcherPairs Compute() {
+ // 'seen' is used for path finding { 0: unseen, 1: seen }.
+ ::std::vector<char> seen;
+ // Searches the residual flow graph for a path from each left node to
+ // the sink in the residual flow graph, and if one is found, add flow
+ // to the graph. It's okay to search through the left nodes once. The
+ // edge from the implicit source node to each previously-visited left
+ // node will have flow if that left node has any path to the sink
+ // whatsoever. Subsequent augmentations can only add flow to the
+ // network, and cannot take away that previous flow unit from the source.
+ // Since the source-to-left edge can only carry one flow unit (or,
+ // each element can be matched to only one matcher), there is no need
+ // to visit the left nodes more than once looking for augmented paths.
+ // The flow is known to be possible or impossible by looking at the
+ // node once.
+ for (size_t ilhs = 0; ilhs < graph_->LhsSize(); ++ilhs) {
+ // Reset the path-marking vector and try to find a path from
+ // source to sink starting at the left_[ilhs] node.
+ GTEST_CHECK_(left_[ilhs] == kUnused)
+ << "ilhs: " << ilhs << ", left_[ilhs]: " << left_[ilhs];
+ // 'seen' initialized to 'graph_->RhsSize()' copies of 0.
+ seen.assign(graph_->RhsSize(), 0);
+ TryAugment(ilhs, &seen);
+ }
+ ElementMatcherPairs result;
+ for (size_t ilhs = 0; ilhs < left_.size(); ++ilhs) {
+ size_t irhs = left_[ilhs];
+ if (irhs == kUnused) continue;
+ result.push_back(ElementMatcherPair(ilhs, irhs));
+ }
+ return result;
+ }
+
+ private:
+ static const size_t kUnused = static_cast<size_t>(-1);
+
+ // Perform a depth-first search from left node ilhs to the sink. If a
+ // path is found, flow is added to the network by linking the left and
+ // right vector elements corresponding each segment of the path.
+ // Returns true if a path to sink was found, which means that a unit of
+ // flow was added to the network. The 'seen' vector elements correspond
+ // to right nodes and are marked to eliminate cycles from the search.
+ //
+ // Left nodes will only be explored at most once because they
+ // are accessible from at most one right node in the residual flow
+ // graph.
+ //
+ // Note that left_[ilhs] is the only element of left_ that TryAugment will
+ // potentially transition from kUnused to another value. Any other
+ // left_ element holding kUnused before TryAugment will be holding it
+ // when TryAugment returns.
+ //
+ bool TryAugment(size_t ilhs, ::std::vector<char>* seen) {
+ for (size_t irhs = 0; irhs < graph_->RhsSize(); ++irhs) {
+ if ((*seen)[irhs]) continue;
+ if (!graph_->HasEdge(ilhs, irhs)) continue;
+ // There's an available edge from ilhs to irhs.
+ (*seen)[irhs] = 1;
+ // Next a search is performed to determine whether
+ // this edge is a dead end or leads to the sink.
+ //
+ // right_[irhs] == kUnused means that there is residual flow from
+ // right node irhs to the sink, so we can use that to finish this
+ // flow path and return success.
+ //
+ // Otherwise there is residual flow to some ilhs. We push flow
+ // along that path and call ourselves recursively to see if this
+ // ultimately leads to sink.
+ if (right_[irhs] == kUnused || TryAugment(right_[irhs], seen)) {
+ // Add flow from left_[ilhs] to right_[irhs].
+ left_[ilhs] = irhs;
+ right_[irhs] = ilhs;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ const MatchMatrix* graph_; // not owned
+ // Each element of the left_ vector represents a left hand side node
+ // (i.e. an element) and each element of right_ is a right hand side
+ // node (i.e. a matcher). The values in the left_ vector indicate
+ // outflow from that node to a node on the right_ side. The values
+ // in the right_ indicate inflow, and specify which left_ node is
+ // feeding that right_ node, if any. For example, left_[3] == 1 means
+ // there's a flow from element #3 to matcher #1. Such a flow would also
+ // be redundantly represented in the right_ vector as right_[1] == 3.
+ // Elements of left_ and right_ are either kUnused or mutually
+ // referent. Mutually referent means that left_[right_[i]] = i and
+ // right_[left_[i]] = i.
+ ::std::vector<size_t> left_;
+ ::std::vector<size_t> right_;
+
+ GTEST_DISALLOW_ASSIGN_(MaxBipartiteMatchState);
+};
+
+const size_t MaxBipartiteMatchState::kUnused;
+
+GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix& g) {
+ return MaxBipartiteMatchState(g).Compute();
+}
+
+static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
+ ::std::ostream* stream) {
+ typedef ElementMatcherPairs::const_iterator Iter;
+ ::std::ostream& os = *stream;
+ os << "{";
+ const char* sep = "";
+ for (Iter it = pairs.begin(); it != pairs.end(); ++it) {
+ os << sep << "\n ("
+ << "element #" << it->first << ", "
+ << "matcher #" << it->second << ")";
+ sep = ",";
+ }
+ os << "\n}";
+}
+
+bool MatchMatrix::NextGraph() {
+ for (size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) {
+ for (size_t irhs = 0; irhs < RhsSize(); ++irhs) {
+ char& b = matched_[SpaceIndex(ilhs, irhs)];
+ if (!b) {
+ b = 1;
+ return true;
+ }
+ b = 0;
+ }
+ }
+ return false;
+}
+
+void MatchMatrix::Randomize() {
+ for (size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) {
+ for (size_t irhs = 0; irhs < RhsSize(); ++irhs) {
+ char& b = matched_[SpaceIndex(ilhs, irhs)];
+ b = static_cast<char>(rand() & 1); // NOLINT
+ }
+ }
+}
+
+std::string MatchMatrix::DebugString() const {
+ ::std::stringstream ss;
+ const char* sep = "";
+ for (size_t i = 0; i < LhsSize(); ++i) {
+ ss << sep;
+ for (size_t j = 0; j < RhsSize(); ++j) {
+ ss << HasEdge(i, j);
+ }
+ sep = ";";
+ }
+ return ss.str();
+}
+
+void UnorderedElementsAreMatcherImplBase::DescribeToImpl(
+ ::std::ostream* os) const {
+ switch (match_flags()) {
+ case UnorderedMatcherRequire::ExactMatch:
+ if (matcher_describers_.empty()) {
+ *os << "is empty";
+ return;
+ }
+ if (matcher_describers_.size() == 1) {
+ *os << "has " << Elements(1) << " and that element ";
+ matcher_describers_[0]->DescribeTo(os);
+ return;
+ }
+ *os << "has " << Elements(matcher_describers_.size())
+ << " and there exists some permutation of elements such that:\n";
+ break;
+ case UnorderedMatcherRequire::Superset:
+ *os << "a surjection from elements to requirements exists such that:\n";
+ break;
+ case UnorderedMatcherRequire::Subset:
+ *os << "an injection from elements to requirements exists such that:\n";
+ break;
+ }
+
+ const char* sep = "";
+ for (size_t i = 0; i != matcher_describers_.size(); ++i) {
+ *os << sep;
+ if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
+ *os << " - element #" << i << " ";
+ } else {
+ *os << " - an element ";
+ }
+ matcher_describers_[i]->DescribeTo(os);
+ if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
+ sep = ", and\n";
+ } else {
+ sep = "\n";
+ }
+ }
+}
+
+void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
+ ::std::ostream* os) const {
+ switch (match_flags()) {
+ case UnorderedMatcherRequire::ExactMatch:
+ if (matcher_describers_.empty()) {
+ *os << "isn't empty";
+ return;
+ }
+ if (matcher_describers_.size() == 1) {
+ *os << "doesn't have " << Elements(1) << ", or has " << Elements(1)
+ << " that ";
+ matcher_describers_[0]->DescribeNegationTo(os);
+ return;
+ }
+ *os << "doesn't have " << Elements(matcher_describers_.size())
+ << ", or there exists no permutation of elements such that:\n";
+ break;
+ case UnorderedMatcherRequire::Superset:
+ *os << "no surjection from elements to requirements exists such that:\n";
+ break;
+ case UnorderedMatcherRequire::Subset:
+ *os << "no injection from elements to requirements exists such that:\n";
+ break;
+ }
+ const char* sep = "";
+ for (size_t i = 0; i != matcher_describers_.size(); ++i) {
+ *os << sep;
+ if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
+ *os << " - element #" << i << " ";
+ } else {
+ *os << " - an element ";
+ }
+ matcher_describers_[i]->DescribeTo(os);
+ if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
+ sep = ", and\n";
+ } else {
+ sep = "\n";
+ }
+ }
+}
+
+// Checks that all matchers match at least one element, and that all
+// elements match at least one matcher. This enables faster matching
+// and better error reporting.
+// Returns false, writing an explanation to 'listener', if and only
+// if the success criteria are not met.
+bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
+ const ::std::vector<std::string>& element_printouts,
+ const MatchMatrix& matrix, MatchResultListener* listener) const {
+ bool result = true;
+ ::std::vector<char> element_matched(matrix.LhsSize(), 0);
+ ::std::vector<char> matcher_matched(matrix.RhsSize(), 0);
+
+ for (size_t ilhs = 0; ilhs < matrix.LhsSize(); ilhs++) {
+ for (size_t irhs = 0; irhs < matrix.RhsSize(); irhs++) {
+ char matched = matrix.HasEdge(ilhs, irhs);
+ element_matched[ilhs] |= matched;
+ matcher_matched[irhs] |= matched;
+ }
+ }
+
+ if (match_flags() & UnorderedMatcherRequire::Superset) {
+ const char* sep =
+ "where the following matchers don't match any elements:\n";
+ for (size_t mi = 0; mi < matcher_matched.size(); ++mi) {
+ if (matcher_matched[mi]) continue;
+ result = false;
+ if (listener->IsInterested()) {
+ *listener << sep << "matcher #" << mi << ": ";
+ matcher_describers_[mi]->DescribeTo(listener->stream());
+ sep = ",\n";
+ }
+ }
+ }
+
+ if (match_flags() & UnorderedMatcherRequire::Subset) {
+ const char* sep =
+ "where the following elements don't match any matchers:\n";
+ const char* outer_sep = "";
+ if (!result) {
+ outer_sep = "\nand ";
+ }
+ for (size_t ei = 0; ei < element_matched.size(); ++ei) {
+ if (element_matched[ei]) continue;
+ result = false;
+ if (listener->IsInterested()) {
+ *listener << outer_sep << sep << "element #" << ei << ": "
+ << element_printouts[ei];
+ sep = ",\n";
+ outer_sep = "";
+ }
+ }
+ }
+ return result;
+}
+
+bool UnorderedElementsAreMatcherImplBase::FindPairing(
+ const MatchMatrix& matrix, MatchResultListener* listener) const {
+ ElementMatcherPairs matches = FindMaxBipartiteMatching(matrix);
+
+ size_t max_flow = matches.size();
+ if ((match_flags() & UnorderedMatcherRequire::Superset) &&
+ max_flow < matrix.RhsSize()) {
+ if (listener->IsInterested()) {
+ *listener << "where no permutation of the elements can satisfy all "
+ "matchers, and the closest match is "
+ << max_flow << " of " << matrix.RhsSize()
+ << " matchers with the pairings:\n";
+ LogElementMatcherPairVec(matches, listener->stream());
+ }
+ return false;
+ }
+ if ((match_flags() & UnorderedMatcherRequire::Subset) &&
+ max_flow < matrix.LhsSize()) {
+ if (listener->IsInterested()) {
+ *listener
+ << "where not all elements can be matched, and the closest match is "
+ << max_flow << " of " << matrix.RhsSize()
+ << " matchers with the pairings:\n";
+ LogElementMatcherPairVec(matches, listener->stream());
+ }
+ return false;
+ }
+
+ if (matches.size() > 1) {
+ if (listener->IsInterested()) {
+ const char* sep = "where:\n";
+ for (size_t mi = 0; mi < matches.size(); ++mi) {
+ *listener << sep << " - element #" << matches[mi].first
+ << " is matched by matcher #" << matches[mi].second;
+ sep = ",\n";
+ }
+ }
+ }
+ return true;
+}
+
+} // namespace internal
+} // namespace testing
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Mock - a framework for writing C++ mock classes.
+//
+// This file implements the spec builder syntax (ON_CALL and
+// EXPECT_CALL).
+
+#include "gmock/gmock-spec-builders.h"
+
+#include <stdlib.h>
+#include <iostream> // NOLINT
+#include <map>
+#include <memory>
+#include <set>
+#include <string>
+#include <vector>
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC
+# include <unistd.h> // NOLINT
+#endif
+
+// Silence C4800 (C4800: 'int *const ': forcing value
+// to bool 'true' or 'false') for MSVC 15
+#ifdef _MSC_VER
+#if _MSC_VER == 1900
+# pragma warning(push)
+# pragma warning(disable:4800)
+#endif
+#endif
+
+namespace testing {
+namespace internal {
+
+// Protects the mock object registry (in class Mock), all function
+// mockers, and all expectations.
+GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_gmock_mutex);
+
+// Logs a message including file and line number information.
+GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
+ const char* file, int line,
+ const std::string& message) {
+ ::std::ostringstream s;
+ s << file << ":" << line << ": " << message << ::std::endl;
+ Log(severity, s.str(), 0);
+}
+
+// Constructs an ExpectationBase object.
+ExpectationBase::ExpectationBase(const char* a_file, int a_line,
+ const std::string& a_source_text)
+ : file_(a_file),
+ line_(a_line),
+ source_text_(a_source_text),
+ cardinality_specified_(false),
+ cardinality_(Exactly(1)),
+ call_count_(0),
+ retired_(false),
+ extra_matcher_specified_(false),
+ repeated_action_specified_(false),
+ retires_on_saturation_(false),
+ last_clause_(kNone),
+ action_count_checked_(false) {}
+
+// Destructs an ExpectationBase object.
+ExpectationBase::~ExpectationBase() {}
+
+// Explicitly specifies the cardinality of this expectation. Used by
+// the subclasses to implement the .Times() clause.
+void ExpectationBase::SpecifyCardinality(const Cardinality& a_cardinality) {
+ cardinality_specified_ = true;
+ cardinality_ = a_cardinality;
+}
+
+// Retires all pre-requisites of this expectation.
+void ExpectationBase::RetireAllPreRequisites()
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ if (is_retired()) {
+ // We can take this short-cut as we never retire an expectation
+ // until we have retired all its pre-requisites.
+ return;
+ }
+
+ ::std::vector<ExpectationBase*> expectations(1, this);
+ while (!expectations.empty()) {
+ ExpectationBase* exp = expectations.back();
+ expectations.pop_back();
+
+ for (ExpectationSet::const_iterator it =
+ exp->immediate_prerequisites_.begin();
+ it != exp->immediate_prerequisites_.end(); ++it) {
+ ExpectationBase* next = it->expectation_base().get();
+ if (!next->is_retired()) {
+ next->Retire();
+ expectations.push_back(next);
+ }
+ }
+ }
+}
+
+// Returns true iff all pre-requisites of this expectation have been
+// satisfied.
+bool ExpectationBase::AllPrerequisitesAreSatisfied() const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ ::std::vector<const ExpectationBase*> expectations(1, this);
+ while (!expectations.empty()) {
+ const ExpectationBase* exp = expectations.back();
+ expectations.pop_back();
+
+ for (ExpectationSet::const_iterator it =
+ exp->immediate_prerequisites_.begin();
+ it != exp->immediate_prerequisites_.end(); ++it) {
+ const ExpectationBase* next = it->expectation_base().get();
+ if (!next->IsSatisfied()) return false;
+ expectations.push_back(next);
+ }
+ }
+ return true;
+}
+
+// Adds unsatisfied pre-requisites of this expectation to 'result'.
+void ExpectationBase::FindUnsatisfiedPrerequisites(ExpectationSet* result) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ ::std::vector<const ExpectationBase*> expectations(1, this);
+ while (!expectations.empty()) {
+ const ExpectationBase* exp = expectations.back();
+ expectations.pop_back();
+
+ for (ExpectationSet::const_iterator it =
+ exp->immediate_prerequisites_.begin();
+ it != exp->immediate_prerequisites_.end(); ++it) {
+ const ExpectationBase* next = it->expectation_base().get();
+
+ if (next->IsSatisfied()) {
+ // If *it is satisfied and has a call count of 0, some of its
+ // pre-requisites may not be satisfied yet.
+ if (next->call_count_ == 0) {
+ expectations.push_back(next);
+ }
+ } else {
+ // Now that we know next is unsatisfied, we are not so interested
+ // in whether its pre-requisites are satisfied. Therefore we
+ // don't iterate into it here.
+ *result += *it;
+ }
+ }
+ }
+}
+
+// Describes how many times a function call matching this
+// expectation has occurred.
+void ExpectationBase::DescribeCallCountTo(::std::ostream* os) const
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+
+ // Describes how many times the function is expected to be called.
+ *os << " Expected: to be ";
+ cardinality().DescribeTo(os);
+ *os << "\n Actual: ";
+ Cardinality::DescribeActualCallCountTo(call_count(), os);
+
+ // Describes the state of the expectation (e.g. is it satisfied?
+ // is it active?).
+ *os << " - " << (IsOverSaturated() ? "over-saturated" :
+ IsSaturated() ? "saturated" :
+ IsSatisfied() ? "satisfied" : "unsatisfied")
+ << " and "
+ << (is_retired() ? "retired" : "active");
+}
+
+// Checks the action count (i.e. the number of WillOnce() and
+// WillRepeatedly() clauses) against the cardinality if this hasn't
+// been done before. Prints a warning if there are too many or too
+// few actions.
+void ExpectationBase::CheckActionCountIfNotDone() const
+ GTEST_LOCK_EXCLUDED_(mutex_) {
+ bool should_check = false;
+ {
+ MutexLock l(&mutex_);
+ if (!action_count_checked_) {
+ action_count_checked_ = true;
+ should_check = true;
+ }
+ }
+
+ if (should_check) {
+ if (!cardinality_specified_) {
+ // The cardinality was inferred - no need to check the action
+ // count against it.
+ return;
+ }
+
+ // The cardinality was explicitly specified.
+ const int action_count = static_cast<int>(untyped_actions_.size());
+ const int upper_bound = cardinality().ConservativeUpperBound();
+ const int lower_bound = cardinality().ConservativeLowerBound();
+ bool too_many; // True if there are too many actions, or false
+ // if there are too few.
+ if (action_count > upper_bound ||
+ (action_count == upper_bound && repeated_action_specified_)) {
+ too_many = true;
+ } else if (0 < action_count && action_count < lower_bound &&
+ !repeated_action_specified_) {
+ too_many = false;
+ } else {
+ return;
+ }
+
+ ::std::stringstream ss;
+ DescribeLocationTo(&ss);
+ ss << "Too " << (too_many ? "many" : "few")
+ << " actions specified in " << source_text() << "...\n"
+ << "Expected to be ";
+ cardinality().DescribeTo(&ss);
+ ss << ", but has " << (too_many ? "" : "only ")
+ << action_count << " WillOnce()"
+ << (action_count == 1 ? "" : "s");
+ if (repeated_action_specified_) {
+ ss << " and a WillRepeatedly()";
+ }
+ ss << ".";
+ Log(kWarning, ss.str(), -1); // -1 means "don't print stack trace".
+ }
+}
+
+// Implements the .Times() clause.
+void ExpectationBase::UntypedTimes(const Cardinality& a_cardinality) {
+ if (last_clause_ == kTimes) {
+ ExpectSpecProperty(false,
+ ".Times() cannot appear "
+ "more than once in an EXPECT_CALL().");
+ } else {
+ ExpectSpecProperty(last_clause_ < kTimes,
+ ".Times() cannot appear after "
+ ".InSequence(), .WillOnce(), .WillRepeatedly(), "
+ "or .RetiresOnSaturation().");
+ }
+ last_clause_ = kTimes;
+
+ SpecifyCardinality(a_cardinality);
+}
+
+// Points to the implicit sequence introduced by a living InSequence
+// object (if any) in the current thread or NULL.
+GTEST_API_ ThreadLocal<Sequence*> g_gmock_implicit_sequence;
+
+// Reports an uninteresting call (whose description is in msg) in the
+// manner specified by 'reaction'.
+void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
+ // Include a stack trace only if --gmock_verbose=info is specified.
+ const int stack_frames_to_skip =
+ GMOCK_FLAG(verbose) == kInfoVerbosity ? 3 : -1;
+ switch (reaction) {
+ case kAllow:
+ Log(kInfo, msg, stack_frames_to_skip);
+ break;
+ case kWarn:
+ Log(kWarning,
+ msg +
+ "\nNOTE: You can safely ignore the above warning unless this "
+ "call should not happen. Do not suppress it by blindly adding "
+ "an EXPECT_CALL() if you don't mean to enforce the call. "
+ "See "
+ "https://github.com/google/googletest/blob/master/googlemock/"
+ "docs/CookBook.md#"
+ "knowing-when-to-expect for details.\n",
+ stack_frames_to_skip);
+ break;
+ default: // FAIL
+ Expect(false, nullptr, -1, msg);
+ }
+}
+
+UntypedFunctionMockerBase::UntypedFunctionMockerBase()
+ : mock_obj_(nullptr), name_("") {}
+
+UntypedFunctionMockerBase::~UntypedFunctionMockerBase() {}
+
+// Sets the mock object this mock method belongs to, and registers
+// this information in the global mock registry. Will be called
+// whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
+// method.
+void UntypedFunctionMockerBase::RegisterOwner(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ {
+ MutexLock l(&g_gmock_mutex);
+ mock_obj_ = mock_obj;
+ }
+ Mock::Register(mock_obj, this);
+}
+
+// Sets the mock object this mock method belongs to, and sets the name
+// of the mock function. Will be called upon each invocation of this
+// mock function.
+void UntypedFunctionMockerBase::SetOwnerAndName(const void* mock_obj,
+ const char* name)
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ // We protect name_ under g_gmock_mutex in case this mock function
+ // is called from two threads concurrently.
+ MutexLock l(&g_gmock_mutex);
+ mock_obj_ = mock_obj;
+ name_ = name;
+}
+
+// Returns the name of the function being mocked. Must be called
+// after RegisterOwner() or SetOwnerAndName() has been called.
+const void* UntypedFunctionMockerBase::MockObject() const
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ const void* mock_obj;
+ {
+ // We protect mock_obj_ under g_gmock_mutex in case this mock
+ // function is called from two threads concurrently.
+ MutexLock l(&g_gmock_mutex);
+ Assert(mock_obj_ != nullptr, __FILE__, __LINE__,
+ "MockObject() must not be called before RegisterOwner() or "
+ "SetOwnerAndName() has been called.");
+ mock_obj = mock_obj_;
+ }
+ return mock_obj;
+}
+
+// Returns the name of this mock method. Must be called after
+// SetOwnerAndName() has been called.
+const char* UntypedFunctionMockerBase::Name() const
+ GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ const char* name;
+ {
+ // We protect name_ under g_gmock_mutex in case this mock
+ // function is called from two threads concurrently.
+ MutexLock l(&g_gmock_mutex);
+ Assert(name_ != nullptr, __FILE__, __LINE__,
+ "Name() must not be called before SetOwnerAndName() has "
+ "been called.");
+ name = name_;
+ }
+ return name;
+}
+
+// Calculates the result of invoking this mock function with the given
+// arguments, prints it, and returns it. The caller is responsible
+// for deleting the result.
+UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith(
+ void* const untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
+ // See the definition of untyped_expectations_ for why access to it
+ // is unprotected here.
+ if (untyped_expectations_.size() == 0) {
+ // No expectation is set on this mock method - we have an
+ // uninteresting call.
+
+ // We must get Google Mock's reaction on uninteresting calls
+ // made on this mock object BEFORE performing the action,
+ // because the action may DELETE the mock object and make the
+ // following expression meaningless.
+ const CallReaction reaction =
+ Mock::GetReactionOnUninterestingCalls(MockObject());
+
+ // True iff we need to print this call's arguments and return
+ // value. This definition must be kept in sync with
+ // the behavior of ReportUninterestingCall().
+ const bool need_to_report_uninteresting_call =
+ // If the user allows this uninteresting call, we print it
+ // only when they want informational messages.
+ reaction == kAllow ? LogIsVisible(kInfo) :
+ // If the user wants this to be a warning, we print
+ // it only when they want to see warnings.
+ reaction == kWarn
+ ? LogIsVisible(kWarning)
+ :
+ // Otherwise, the user wants this to be an error, and we
+ // should always print detailed information in the error.
+ true;
+
+ if (!need_to_report_uninteresting_call) {
+ // Perform the action without printing the call information.
+ return this->UntypedPerformDefaultAction(
+ untyped_args, "Function call: " + std::string(Name()));
+ }
+
+ // Warns about the uninteresting call.
+ ::std::stringstream ss;
+ this->UntypedDescribeUninterestingCall(untyped_args, &ss);
+
+ // Calculates the function result.
+ UntypedActionResultHolderBase* const result =
+ this->UntypedPerformDefaultAction(untyped_args, ss.str());
+
+ // Prints the function result.
+ if (result != nullptr) result->PrintAsActionResult(&ss);
+
+ ReportUninterestingCall(reaction, ss.str());
+ return result;
+ }
+
+ bool is_excessive = false;
+ ::std::stringstream ss;
+ ::std::stringstream why;
+ ::std::stringstream loc;
+ const void* untyped_action = nullptr;
+
+ // The UntypedFindMatchingExpectation() function acquires and
+ // releases g_gmock_mutex.
+ const ExpectationBase* const untyped_expectation =
+ this->UntypedFindMatchingExpectation(
+ untyped_args, &untyped_action, &is_excessive,
+ &ss, &why);
+ const bool found = untyped_expectation != nullptr;
+
+ // True iff we need to print the call's arguments and return value.
+ // This definition must be kept in sync with the uses of Expect()
+ // and Log() in this function.
+ const bool need_to_report_call =
+ !found || is_excessive || LogIsVisible(kInfo);
+ if (!need_to_report_call) {
+ // Perform the action without printing the call information.
+ return untyped_action == nullptr
+ ? this->UntypedPerformDefaultAction(untyped_args, "")
+ : this->UntypedPerformAction(untyped_action, untyped_args);
+ }
+
+ ss << " Function call: " << Name();
+ this->UntypedPrintArgs(untyped_args, &ss);
+
+ // In case the action deletes a piece of the expectation, we
+ // generate the message beforehand.
+ if (found && !is_excessive) {
+ untyped_expectation->DescribeLocationTo(&loc);
+ }
+
+ UntypedActionResultHolderBase* const result =
+ untyped_action == nullptr
+ ? this->UntypedPerformDefaultAction(untyped_args, ss.str())
+ : this->UntypedPerformAction(untyped_action, untyped_args);
+ if (result != nullptr) result->PrintAsActionResult(&ss);
+ ss << "\n" << why.str();
+
+ if (!found) {
+ // No expectation matches this call - reports a failure.
+ Expect(false, nullptr, -1, ss.str());
+ } else if (is_excessive) {
+ // We had an upper-bound violation and the failure message is in ss.
+ Expect(false, untyped_expectation->file(),
+ untyped_expectation->line(), ss.str());
+ } else {
+ // We had an expected call and the matching expectation is
+ // described in ss.
+ Log(kInfo, loc.str() + ss.str(), 2);
+ }
+
+ return result;
+}
+
+// Returns an Expectation object that references and co-owns exp,
+// which must be an expectation on this mock function.
+Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) {
+ // See the definition of untyped_expectations_ for why access to it
+ // is unprotected here.
+ for (UntypedExpectations::const_iterator it =
+ untyped_expectations_.begin();
+ it != untyped_expectations_.end(); ++it) {
+ if (it->get() == exp) {
+ return Expectation(*it);
+ }
+ }
+
+ Assert(false, __FILE__, __LINE__, "Cannot find expectation.");
+ return Expectation();
+ // The above statement is just to make the code compile, and will
+ // never be executed.
+}
+
+// Verifies that all expectations on this mock function have been
+// satisfied. Reports one or more Google Test non-fatal failures
+// and returns false if not.
+bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
+ g_gmock_mutex.AssertHeld();
+ bool expectations_met = true;
+ for (UntypedExpectations::const_iterator it =
+ untyped_expectations_.begin();
+ it != untyped_expectations_.end(); ++it) {
+ ExpectationBase* const untyped_expectation = it->get();
+ if (untyped_expectation->IsOverSaturated()) {
+ // There was an upper-bound violation. Since the error was
+ // already reported when it occurred, there is no need to do
+ // anything here.
+ expectations_met = false;
+ } else if (!untyped_expectation->IsSatisfied()) {
+ expectations_met = false;
+ ::std::stringstream ss;
+ ss << "Actual function call count doesn't match "
+ << untyped_expectation->source_text() << "...\n";
+ // No need to show the source file location of the expectation
+ // in the description, as the Expect() call that follows already
+ // takes care of it.
+ untyped_expectation->MaybeDescribeExtraMatcherTo(&ss);
+ untyped_expectation->DescribeCallCountTo(&ss);
+ Expect(false, untyped_expectation->file(),
+ untyped_expectation->line(), ss.str());
+ }
+ }
+
+ // Deleting our expectations may trigger other mock objects to be deleted, for
+ // example if an action contains a reference counted smart pointer to that
+ // mock object, and that is the last reference. So if we delete our
+ // expectations within the context of the global mutex we may deadlock when
+ // this method is called again. Instead, make a copy of the set of
+ // expectations to delete, clear our set within the mutex, and then clear the
+ // copied set outside of it.
+ UntypedExpectations expectations_to_delete;
+ untyped_expectations_.swap(expectations_to_delete);
+
+ g_gmock_mutex.Unlock();
+ expectations_to_delete.clear();
+ g_gmock_mutex.Lock();
+
+ return expectations_met;
+}
+
+CallReaction intToCallReaction(int mock_behavior) {
+ if (mock_behavior >= kAllow && mock_behavior <= kFail) {
+ return static_cast<internal::CallReaction>(mock_behavior);
+ }
+ return kWarn;
+}
+
+} // namespace internal
+
+// Class Mock.
+
+namespace {
+
+typedef std::set<internal::UntypedFunctionMockerBase*> FunctionMockers;
+
+// The current state of a mock object. Such information is needed for
+// detecting leaked mock objects and explicitly verifying a mock's
+// expectations.
+struct MockObjectState {
+ MockObjectState()
+ : first_used_file(nullptr), first_used_line(-1), leakable(false) {}
+
+ // Where in the source file an ON_CALL or EXPECT_CALL is first
+ // invoked on this mock object.
+ const char* first_used_file;
+ int first_used_line;
+ ::std::string first_used_test_suite;
+ ::std::string first_used_test;
+ bool leakable; // true iff it's OK to leak the object.
+ FunctionMockers function_mockers; // All registered methods of the object.
+};
+
+// A global registry holding the state of all mock objects that are
+// alive. A mock object is added to this registry the first time
+// Mock::AllowLeak(), ON_CALL(), or EXPECT_CALL() is called on it. It
+// is removed from the registry in the mock object's destructor.
+class MockObjectRegistry {
+ public:
+ // Maps a mock object (identified by its address) to its state.
+ typedef std::map<const void*, MockObjectState> StateMap;
+
+ // This destructor will be called when a program exits, after all
+ // tests in it have been run. By then, there should be no mock
+ // object alive. Therefore we report any living object as test
+ // failure, unless the user explicitly asked us to ignore it.
+ ~MockObjectRegistry() {
+ if (!GMOCK_FLAG(catch_leaked_mocks))
+ return;
+
+ int leaked_count = 0;
+ for (StateMap::const_iterator it = states_.begin(); it != states_.end();
+ ++it) {
+ if (it->second.leakable) // The user said it's fine to leak this object.
+ continue;
+
+ // FIXME: Print the type of the leaked object.
+ // This can help the user identify the leaked object.
+ std::cout << "\n";
+ const MockObjectState& state = it->second;
+ std::cout << internal::FormatFileLocation(state.first_used_file,
+ state.first_used_line);
+ std::cout << " ERROR: this mock object";
+ if (state.first_used_test != "") {
+ std::cout << " (used in test " << state.first_used_test_suite << "."
+ << state.first_used_test << ")";
+ }
+ std::cout << " should be deleted but never is. Its address is @"
+ << it->first << ".";
+ leaked_count++;
+ }
+ if (leaked_count > 0) {
+ std::cout << "\nERROR: " << leaked_count << " leaked mock "
+ << (leaked_count == 1 ? "object" : "objects")
+ << " found at program exit. Expectations on a mock object is "
+ "verified when the object is destructed. Leaking a mock "
+ "means that its expectations aren't verified, which is "
+ "usually a test bug. If you really intend to leak a mock, "
+ "you can suppress this error using "
+ "testing::Mock::AllowLeak(mock_object), or you may use a "
+ "fake or stub instead of a mock.\n";
+ std::cout.flush();
+ ::std::cerr.flush();
+ // RUN_ALL_TESTS() has already returned when this destructor is
+ // called. Therefore we cannot use the normal Google Test
+ // failure reporting mechanism.
+ _exit(1); // We cannot call exit() as it is not reentrant and
+ // may already have been called.
+ }
+ }
+
+ StateMap& states() { return states_; }
+
+ private:
+ StateMap states_;
+};
+
+// Protected by g_gmock_mutex.
+MockObjectRegistry g_mock_object_registry;
+
+// Maps a mock object to the reaction Google Mock should have when an
+// uninteresting method is called. Protected by g_gmock_mutex.
+std::map<const void*, internal::CallReaction> g_uninteresting_call_reaction;
+
+// Sets the reaction Google Mock should have when an uninteresting
+// method of the given mock object is called.
+void SetReactionOnUninterestingCalls(const void* mock_obj,
+ internal::CallReaction reaction)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ internal::MutexLock l(&internal::g_gmock_mutex);
+ g_uninteresting_call_reaction[mock_obj] = reaction;
+}
+
+} // namespace
+
+// Tells Google Mock to allow uninteresting calls on the given mock
+// object.
+void Mock::AllowUninterestingCalls(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ SetReactionOnUninterestingCalls(mock_obj, internal::kAllow);
+}
+
+// Tells Google Mock to warn the user about uninteresting calls on the
+// given mock object.
+void Mock::WarnUninterestingCalls(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ SetReactionOnUninterestingCalls(mock_obj, internal::kWarn);
+}
+
+// Tells Google Mock to fail uninteresting calls on the given mock
+// object.
+void Mock::FailUninterestingCalls(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ SetReactionOnUninterestingCalls(mock_obj, internal::kFail);
+}
+
+// Tells Google Mock the given mock object is being destroyed and its
+// entry in the call-reaction table should be removed.
+void Mock::UnregisterCallReaction(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ internal::MutexLock l(&internal::g_gmock_mutex);
+ g_uninteresting_call_reaction.erase(mock_obj);
+}
+
+// Returns the reaction Google Mock will have on uninteresting calls
+// made on the given mock object.
+internal::CallReaction Mock::GetReactionOnUninterestingCalls(
+ const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ internal::MutexLock l(&internal::g_gmock_mutex);
+ return (g_uninteresting_call_reaction.count(mock_obj) == 0) ?
+ internal::intToCallReaction(GMOCK_FLAG(default_mock_behavior)) :
+ g_uninteresting_call_reaction[mock_obj];
+}
+
+// Tells Google Mock to ignore mock_obj when checking for leaked mock
+// objects.
+void Mock::AllowLeak(const void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ internal::MutexLock l(&internal::g_gmock_mutex);
+ g_mock_object_registry.states()[mock_obj].leakable = true;
+}
+
+// Verifies and clears all expectations on the given mock object. If
+// the expectations aren't satisfied, generates one or more Google
+// Test non-fatal failures and returns false.
+bool Mock::VerifyAndClearExpectations(void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ internal::MutexLock l(&internal::g_gmock_mutex);
+ return VerifyAndClearExpectationsLocked(mock_obj);
+}
+
+// Verifies all expectations on the given mock object and clears its
+// default actions and expectations. Returns true iff the
+// verification was successful.
+bool Mock::VerifyAndClear(void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ internal::MutexLock l(&internal::g_gmock_mutex);
+ ClearDefaultActionsLocked(mock_obj);
+ return VerifyAndClearExpectationsLocked(mock_obj);
+}
+
+// Verifies and clears all expectations on the given mock object. If
+// the expectations aren't satisfied, generates one or more Google
+// Test non-fatal failures and returns false.
+bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj)
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex) {
+ internal::g_gmock_mutex.AssertHeld();
+ if (g_mock_object_registry.states().count(mock_obj) == 0) {
+ // No EXPECT_CALL() was set on the given mock object.
+ return true;
+ }
+
+ // Verifies and clears the expectations on each mock method in the
+ // given mock object.
+ bool expectations_met = true;
+ FunctionMockers& mockers =
+ g_mock_object_registry.states()[mock_obj].function_mockers;
+ for (FunctionMockers::const_iterator it = mockers.begin();
+ it != mockers.end(); ++it) {
+ if (!(*it)->VerifyAndClearExpectationsLocked()) {
+ expectations_met = false;
+ }
+ }
+
+ // We don't clear the content of mockers, as they may still be
+ // needed by ClearDefaultActionsLocked().
+ return expectations_met;
+}
+
+bool Mock::IsNaggy(void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kWarn;
+}
+bool Mock::IsNice(void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kAllow;
+}
+bool Mock::IsStrict(void* mock_obj)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kFail;
+}
+
+// Registers a mock object and a mock method it owns.
+void Mock::Register(const void* mock_obj,
+ internal::UntypedFunctionMockerBase* mocker)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ internal::MutexLock l(&internal::g_gmock_mutex);
+ g_mock_object_registry.states()[mock_obj].function_mockers.insert(mocker);
+}
+
+// Tells Google Mock where in the source code mock_obj is used in an
+// ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
+// information helps the user identify which object it is.
+void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj,
+ const char* file, int line)
+ GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
+ internal::MutexLock l(&internal::g_gmock_mutex);
+ MockObjectState& state = g_mock_object_registry.states()[mock_obj];
+ if (state.first_used_file == nullptr) {
+ state.first_used_file = file;
+ state.first_used_line = line;
+ const TestInfo* const test_info =
+ UnitTest::GetInstance()->current_test_info();
+ if (test_info != nullptr) {
+ state.first_used_test_suite = test_info->test_suite_name();
+ state.first_used_test = test_info->name();
+ }
+ }
+}
+
+// Unregisters a mock method; removes the owning mock object from the
+// registry when the last mock method associated with it has been
+// unregistered. This is called only in the destructor of
+// FunctionMockerBase.
+void Mock::UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex) {
+ internal::g_gmock_mutex.AssertHeld();
+ for (MockObjectRegistry::StateMap::iterator it =
+ g_mock_object_registry.states().begin();
+ it != g_mock_object_registry.states().end(); ++it) {
+ FunctionMockers& mockers = it->second.function_mockers;
+ if (mockers.erase(mocker) > 0) {
+ // mocker was in mockers and has been just removed.
+ if (mockers.empty()) {
+ g_mock_object_registry.states().erase(it);
+ }
+ return;
+ }
+ }
+}
+
+// Clears all ON_CALL()s set on the given mock object.
+void Mock::ClearDefaultActionsLocked(void* mock_obj)
+ GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex) {
+ internal::g_gmock_mutex.AssertHeld();
+
+ if (g_mock_object_registry.states().count(mock_obj) == 0) {
+ // No ON_CALL() was set on the given mock object.
+ return;
+ }
+
+ // Clears the default actions for each mock method in the given mock
+ // object.
+ FunctionMockers& mockers =
+ g_mock_object_registry.states()[mock_obj].function_mockers;
+ for (FunctionMockers::const_iterator it = mockers.begin();
+ it != mockers.end(); ++it) {
+ (*it)->ClearDefaultActionsLocked();
+ }
+
+ // We don't clear the content of mockers, as they may still be
+ // needed by VerifyAndClearExpectationsLocked().
+}
+
+Expectation::Expectation() {}
+
+Expectation::Expectation(
+ const std::shared_ptr<internal::ExpectationBase>& an_expectation_base)
+ : expectation_base_(an_expectation_base) {}
+
+Expectation::~Expectation() {}
+
+// Adds an expectation to a sequence.
+void Sequence::AddExpectation(const Expectation& expectation) const {
+ if (*last_expectation_ != expectation) {
+ if (last_expectation_->expectation_base() != nullptr) {
+ expectation.expectation_base()->immediate_prerequisites_
+ += *last_expectation_;
+ }
+ *last_expectation_ = expectation;
+ }
+}
+
+// Creates the implicit sequence if there isn't one.
+InSequence::InSequence() {
+ if (internal::g_gmock_implicit_sequence.get() == nullptr) {
+ internal::g_gmock_implicit_sequence.set(new Sequence);
+ sequence_created_ = true;
+ } else {
+ sequence_created_ = false;
+ }
+}
+
+// Deletes the implicit sequence if it was created by the constructor
+// of this object.
+InSequence::~InSequence() {
+ if (sequence_created_) {
+ delete internal::g_gmock_implicit_sequence.get();
+ internal::g_gmock_implicit_sequence.set(nullptr);
+ }
+}
+
+} // namespace testing
+
+#ifdef _MSC_VER
+#if _MSC_VER == 1900
+# pragma warning(pop)
+#endif
+#endif
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+#include "gmock/gmock.h"
+#include "gmock/internal/gmock-port.h"
+
+namespace testing {
+
+GMOCK_DEFINE_bool_(catch_leaked_mocks, true,
+ "true iff Google Mock should report leaked mock objects "
+ "as failures.");
+
+GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity,
+ "Controls how verbose Google Mock's output is."
+ " Valid values:\n"
+ " info - prints all messages.\n"
+ " warning - prints warnings and errors.\n"
+ " error - prints errors only.");
+
+GMOCK_DEFINE_int32_(default_mock_behavior, 1,
+ "Controls the default behavior of mocks."
+ " Valid values:\n"
+ " 0 - by default, mocks act as NiceMocks.\n"
+ " 1 - by default, mocks act as NaggyMocks.\n"
+ " 2 - by default, mocks act as StrictMocks.");
+
+namespace internal {
+
+// Parses a string as a command line flag. The string should have the
+// format "--gmock_flag=value". When def_optional is true, the
+// "=value" part can be omitted.
+//
+// Returns the value of the flag, or NULL if the parsing failed.
+static const char* ParseGoogleMockFlagValue(const char* str,
+ const char* flag,
+ bool def_optional) {
+ // str and flag must not be NULL.
+ if (str == nullptr || flag == nullptr) return nullptr;
+
+ // The flag must start with "--gmock_".
+ const std::string flag_str = std::string("--gmock_") + flag;
+ const size_t flag_len = flag_str.length();
+ if (strncmp(str, flag_str.c_str(), flag_len) != 0) return nullptr;
+
+ // Skips the flag name.
+ const char* flag_end = str + flag_len;
+
+ // When def_optional is true, it's OK to not have a "=value" part.
+ if (def_optional && (flag_end[0] == '\0')) {
+ return flag_end;
+ }
+
+ // If def_optional is true and there are more characters after the
+ // flag name, or if def_optional is false, there must be a '=' after
+ // the flag name.
+ if (flag_end[0] != '=') return nullptr;
+
+ // Returns the string after "=".
+ return flag_end + 1;
+}
+
+// Parses a string for a Google Mock bool flag, in the form of
+// "--gmock_flag=value".
+//
+// On success, stores the value of the flag in *value, and returns
+// true. On failure, returns false without changing *value.
+static bool ParseGoogleMockBoolFlag(const char* str, const char* flag,
+ bool* value) {
+ // Gets the value of the flag as a string.
+ const char* const value_str = ParseGoogleMockFlagValue(str, flag, true);
+
+ // Aborts if the parsing failed.
+ if (value_str == nullptr) return false;
+
+ // Converts the string value to a bool.
+ *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F');
+ return true;
+}
+
+// Parses a string for a Google Mock string flag, in the form of
+// "--gmock_flag=value".
+//
+// On success, stores the value of the flag in *value, and returns
+// true. On failure, returns false without changing *value.
+template <typename String>
+static bool ParseGoogleMockStringFlag(const char* str, const char* flag,
+ String* value) {
+ // Gets the value of the flag as a string.
+ const char* const value_str = ParseGoogleMockFlagValue(str, flag, false);
+
+ // Aborts if the parsing failed.
+ if (value_str == nullptr) return false;
+
+ // Sets *value to the value of the flag.
+ *value = value_str;
+ return true;
+}
+
+static bool ParseGoogleMockIntFlag(const char* str, const char* flag,
+ int* value) {
+ // Gets the value of the flag as a string.
+ const char* const value_str = ParseGoogleMockFlagValue(str, flag, true);
+
+ // Aborts if the parsing failed.
+ if (value_str == nullptr) return false;
+
+ // Sets *value to the value of the flag.
+ return ParseInt32(Message() << "The value of flag --" << flag,
+ value_str, value);
+}
+
+// The internal implementation of InitGoogleMock().
+//
+// The type parameter CharType can be instantiated to either char or
+// wchar_t.
+template <typename CharType>
+void InitGoogleMockImpl(int* argc, CharType** argv) {
+ // Makes sure Google Test is initialized. InitGoogleTest() is
+ // idempotent, so it's fine if the user has already called it.
+ InitGoogleTest(argc, argv);
+ if (*argc <= 0) return;
+
+ for (int i = 1; i != *argc; i++) {
+ const std::string arg_string = StreamableToString(argv[i]);
+ const char* const arg = arg_string.c_str();
+
+ // Do we see a Google Mock flag?
+ if (ParseGoogleMockBoolFlag(arg, "catch_leaked_mocks",
+ &GMOCK_FLAG(catch_leaked_mocks)) ||
+ ParseGoogleMockStringFlag(arg, "verbose", &GMOCK_FLAG(verbose)) ||
+ ParseGoogleMockIntFlag(arg, "default_mock_behavior",
+ &GMOCK_FLAG(default_mock_behavior))) {
+ // Yes. Shift the remainder of the argv list left by one. Note
+ // that argv has (*argc + 1) elements, the last one always being
+ // NULL. The following loop moves the trailing NULL element as
+ // well.
+ for (int j = i; j != *argc; j++) {
+ argv[j] = argv[j + 1];
+ }
+
+ // Decrements the argument count.
+ (*argc)--;
+
+ // We also need to decrement the iterator as we just removed
+ // an element.
+ i--;
+ }
+ }
+}
+
+} // namespace internal
+
+// Initializes Google Mock. This must be called before running the
+// tests. In particular, it parses a command line for the flags that
+// Google Mock recognizes. Whenever a Google Mock flag is seen, it is
+// removed from argv, and *argc is decremented.
+//
+// No value is returned. Instead, the Google Mock flag variables are
+// updated.
+//
+// Since Google Test is needed for Google Mock to work, this function
+// also initializes Google Test and parses its flags, if that hasn't
+// been done.
+GTEST_API_ void InitGoogleMock(int* argc, char** argv) {
+ internal::InitGoogleMockImpl(argc, argv);
+}
+
+// This overloaded version can be used in Windows programs compiled in
+// UNICODE mode.
+GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv) {
+ internal::InitGoogleMockImpl(argc, argv);
+}
+
+// This overloaded version can be used on Arduino/embedded platforms where
+// there is no argc/argv.
+GTEST_API_ void InitGoogleMock() {
+ // Since Arduino doesn't have a command line, fake out the argc/argv arguments
+ int argc = 1;
+ const auto arg0 = "dummy";
+ char* argv0 = const_cast<char*>(arg0);
+ char** argv = &argv0;
+
+ internal::InitGoogleMockImpl(&argc, argv);
+}
+
+} // namespace testing
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+#include <iostream>
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#ifdef ARDUINO
+void setup() {
+ // Since Google Mock depends on Google Test, InitGoogleMock() is
+ // also responsible for initializing Google Test. Therefore there's
+ // no need for calling testing::InitGoogleTest() separately.
+ testing::InitGoogleMock();
+}
+void loop() { RUN_ALL_TESTS(); }
+#else
+
+// MS C++ compiler/linker has a bug on Windows (not on Windows CE), which
+// causes a link error when _tmain is defined in a static library and UNICODE
+// is enabled. For this reason instead of _tmain, main function is used on
+// Windows. See the following link to track the current status of this bug:
+// https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library
+// // NOLINT
+#if GTEST_OS_WINDOWS_MOBILE
+# include <tchar.h> // NOLINT
+
+GTEST_API_ int _tmain(int argc, TCHAR** argv) {
+#else
+GTEST_API_ int main(int argc, char** argv) {
+#endif // GTEST_OS_WINDOWS_MOBILE
+ std::cout << "Running main() from gmock_main.cc\n";
+ // Since Google Mock depends on Google Test, InitGoogleMock() is
+ // also responsible for initializing Google Test. Therefore there's
+ // no need for calling testing::InitGoogleTest() separately.
+ testing::InitGoogleMock(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+#endif
--- /dev/null
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// The Google C++ Testing and Mocking Framework (Google Test)
+//
+// This header file defines the public API for death tests. It is
+// #included by gtest.h so a user doesn't need to include this
+// directly.
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
+#define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
+
+#include "gtest/internal/gtest-death-test-internal.h"
+
+namespace testing {
+
+// This flag controls the style of death tests. Valid values are "threadsafe",
+// meaning that the death test child process will re-execute the test binary
+// from the start, running only a single death test, or "fast",
+// meaning that the child process will execute the test logic immediately
+// after forking.
+GTEST_DECLARE_string_(death_test_style);
+
+#if GTEST_HAS_DEATH_TEST
+
+namespace internal {
+
+// Returns a Boolean value indicating whether the caller is currently
+// executing in the context of the death test child process. Tools such as
+// Valgrind heap checkers may need this to modify their behavior in death
+// tests. IMPORTANT: This is an internal utility. Using it may break the
+// implementation of death tests. User code MUST NOT use it.
+GTEST_API_ bool InDeathTestChild();
+
+} // namespace internal
+
+// The following macros are useful for writing death tests.
+
+// Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is
+// executed:
+//
+// 1. It generates a warning if there is more than one active
+// thread. This is because it's safe to fork() or clone() only
+// when there is a single thread.
+//
+// 2. The parent process clone()s a sub-process and runs the death
+// test in it; the sub-process exits with code 0 at the end of the
+// death test, if it hasn't exited already.
+//
+// 3. The parent process waits for the sub-process to terminate.
+//
+// 4. The parent process checks the exit code and error message of
+// the sub-process.
+//
+// Examples:
+//
+// ASSERT_DEATH(server.SendMessage(56, "Hello"), "Invalid port number");
+// for (int i = 0; i < 5; i++) {
+// EXPECT_DEATH(server.ProcessRequest(i),
+// "Invalid request .* in ProcessRequest()")
+// << "Failed to die on request " << i;
+// }
+//
+// ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting");
+//
+// bool KilledBySIGHUP(int exit_code) {
+// return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP;
+// }
+//
+// ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!");
+//
+// On the regular expressions used in death tests:
+//
+// GOOGLETEST_CM0005 DO NOT DELETE
+// On POSIX-compliant systems (*nix), we use the <regex.h> library,
+// which uses the POSIX extended regex syntax.
+//
+// On other platforms (e.g. Windows or Mac), we only support a simple regex
+// syntax implemented as part of Google Test. This limited
+// implementation should be enough most of the time when writing
+// death tests; though it lacks many features you can find in PCRE
+// or POSIX extended regex syntax. For example, we don't support
+// union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and
+// repetition count ("x{5,7}"), among others.
+//
+// Below is the syntax that we do support. We chose it to be a
+// subset of both PCRE and POSIX extended regex, so it's easy to
+// learn wherever you come from. In the following: 'A' denotes a
+// literal character, period (.), or a single \\ escape sequence;
+// 'x' and 'y' denote regular expressions; 'm' and 'n' are for
+// natural numbers.
+//
+// c matches any literal character c
+// \\d matches any decimal digit
+// \\D matches any character that's not a decimal digit
+// \\f matches \f
+// \\n matches \n
+// \\r matches \r
+// \\s matches any ASCII whitespace, including \n
+// \\S matches any character that's not a whitespace
+// \\t matches \t
+// \\v matches \v
+// \\w matches any letter, _, or decimal digit
+// \\W matches any character that \\w doesn't match
+// \\c matches any literal character c, which must be a punctuation
+// . matches any single character except \n
+// A? matches 0 or 1 occurrences of A
+// A* matches 0 or many occurrences of A
+// A+ matches 1 or many occurrences of A
+// ^ matches the beginning of a string (not that of each line)
+// $ matches the end of a string (not that of each line)
+// xy matches x followed by y
+//
+// If you accidentally use PCRE or POSIX extended regex features
+// not implemented by us, you will get a run-time failure. In that
+// case, please try to rewrite your regular expression within the
+// above syntax.
+//
+// This implementation is *not* meant to be as highly tuned or robust
+// as a compiled regex library, but should perform well enough for a
+// death test, which already incurs significant overhead by launching
+// a child process.
+//
+// Known caveats:
+//
+// A "threadsafe" style death test obtains the path to the test
+// program from argv[0] and re-executes it in the sub-process. For
+// simplicity, the current implementation doesn't search the PATH
+// when launching the sub-process. This means that the user must
+// invoke the test program via a path that contains at least one
+// path separator (e.g. path/to/foo_test and
+// /absolute/path/to/bar_test are fine, but foo_test is not). This
+// is rarely a problem as people usually don't put the test binary
+// directory in PATH.
+//
+
+// Asserts that a given statement causes the program to exit, with an
+// integer exit status that satisfies predicate, and emitting error output
+// that matches regex.
+# define ASSERT_EXIT(statement, predicate, regex) \
+ GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
+
+// Like ASSERT_EXIT, but continues on to successive tests in the
+// test suite, if any:
+# define EXPECT_EXIT(statement, predicate, regex) \
+ GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
+
+// Asserts that a given statement causes the program to exit, either by
+// explicitly exiting with a nonzero exit code or being killed by a
+// signal, and emitting error output that matches regex.
+# define ASSERT_DEATH(statement, regex) \
+ ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
+
+// Like ASSERT_DEATH, but continues on to successive tests in the
+// test suite, if any:
+# define EXPECT_DEATH(statement, regex) \
+ EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
+
+// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
+
+// Tests that an exit code describes a normal exit with a given exit code.
+class GTEST_API_ ExitedWithCode {
+ public:
+ explicit ExitedWithCode(int exit_code);
+ bool operator()(int exit_status) const;
+ private:
+ // No implementation - assignment is unsupported.
+ void operator=(const ExitedWithCode& other);
+
+ const int exit_code_;
+};
+
+# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
+// Tests that an exit code describes an exit due to termination by a
+// given signal.
+// GOOGLETEST_CM0006 DO NOT DELETE
+class GTEST_API_ KilledBySignal {
+ public:
+ explicit KilledBySignal(int signum);
+ bool operator()(int exit_status) const;
+ private:
+ const int signum_;
+};
+# endif // !GTEST_OS_WINDOWS
+
+// EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode.
+// The death testing framework causes this to have interesting semantics,
+// since the sideeffects of the call are only visible in opt mode, and not
+// in debug mode.
+//
+// In practice, this can be used to test functions that utilize the
+// LOG(DFATAL) macro using the following style:
+//
+// int DieInDebugOr12(int* sideeffect) {
+// if (sideeffect) {
+// *sideeffect = 12;
+// }
+// LOG(DFATAL) << "death";
+// return 12;
+// }
+//
+// TEST(TestSuite, TestDieOr12WorksInDgbAndOpt) {
+// int sideeffect = 0;
+// // Only asserts in dbg.
+// EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death");
+//
+// #ifdef NDEBUG
+// // opt-mode has sideeffect visible.
+// EXPECT_EQ(12, sideeffect);
+// #else
+// // dbg-mode no visible sideeffect.
+// EXPECT_EQ(0, sideeffect);
+// #endif
+// }
+//
+// This will assert that DieInDebugReturn12InOpt() crashes in debug
+// mode, usually due to a DCHECK or LOG(DFATAL), but returns the
+// appropriate fallback value (12 in this case) in opt mode. If you
+// need to test that a function has appropriate side-effects in opt
+// mode, include assertions against the side-effects. A general
+// pattern for this is:
+//
+// EXPECT_DEBUG_DEATH({
+// // Side-effects here will have an effect after this statement in
+// // opt mode, but none in debug mode.
+// EXPECT_EQ(12, DieInDebugOr12(&sideeffect));
+// }, "death");
+//
+# ifdef NDEBUG
+
+# define EXPECT_DEBUG_DEATH(statement, regex) \
+ GTEST_EXECUTE_STATEMENT_(statement, regex)
+
+# define ASSERT_DEBUG_DEATH(statement, regex) \
+ GTEST_EXECUTE_STATEMENT_(statement, regex)
+
+# else
+
+# define EXPECT_DEBUG_DEATH(statement, regex) \
+ EXPECT_DEATH(statement, regex)
+
+# define ASSERT_DEBUG_DEATH(statement, regex) \
+ ASSERT_DEATH(statement, regex)
+
+# endif // NDEBUG for EXPECT_DEBUG_DEATH
+#endif // GTEST_HAS_DEATH_TEST
+
+// This macro is used for implementing macros such as
+// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where
+// death tests are not supported. Those macros must compile on such systems
+// iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on
+// systems that support death tests. This allows one to write such a macro
+// on a system that does not support death tests and be sure that it will
+// compile on a death-test supporting system. It is exposed publicly so that
+// systems that have death-tests with stricter requirements than
+// GTEST_HAS_DEATH_TEST can write their own equivalent of
+// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED.
+//
+// Parameters:
+// statement - A statement that a macro such as EXPECT_DEATH would test
+// for program termination. This macro has to make sure this
+// statement is compiled but not executed, to ensure that
+// EXPECT_DEATH_IF_SUPPORTED compiles with a certain
+// parameter iff EXPECT_DEATH compiles with it.
+// regex - A regex that a macro such as EXPECT_DEATH would use to test
+// the output of statement. This parameter has to be
+// compiled but not evaluated by this macro, to ensure that
+// this macro only accepts expressions that a macro such as
+// EXPECT_DEATH would accept.
+// terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED
+// and a return statement for ASSERT_DEATH_IF_SUPPORTED.
+// This ensures that ASSERT_DEATH_IF_SUPPORTED will not
+// compile inside functions where ASSERT_DEATH doesn't
+// compile.
+//
+// The branch that has an always false condition is used to ensure that
+// statement and regex are compiled (and thus syntactically correct) but
+// never executed. The unreachable code macro protects the terminator
+// statement from generating an 'unreachable code' warning in case
+// statement unconditionally returns or throws. The Message constructor at
+// the end allows the syntax of streaming additional messages into the
+// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
+# define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::AlwaysTrue()) { \
+ GTEST_LOG_(WARNING) \
+ << "Death tests are not supported on this platform.\n" \
+ << "Statement '" #statement "' cannot be verified."; \
+ } else if (::testing::internal::AlwaysFalse()) { \
+ ::testing::internal::RE::PartialMatch(".*", (regex)); \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ terminator; \
+ } else \
+ ::testing::Message()
+
+// EXPECT_DEATH_IF_SUPPORTED(statement, regex) and
+// ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if
+// death tests are supported; otherwise they just issue a warning. This is
+// useful when you are combining death test assertions with normal test
+// assertions in one test.
+#if GTEST_HAS_DEATH_TEST
+# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
+ EXPECT_DEATH(statement, regex)
+# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
+ ASSERT_DEATH(statement, regex)
+#else
+# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
+ GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, )
+# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
+ GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return)
+#endif
+
+} // namespace testing
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The Google C++ Testing and Mocking Framework (Google Test)
+//
+// This file implements just enough of the matcher interface to allow
+// EXPECT_DEATH and friends to accept a matcher argument.
+
+// IWYU pragma: private, include "testing/base/public/gunit.h"
+// IWYU pragma: friend third_party/googletest/googlemock/.*
+// IWYU pragma: friend third_party/googletest/googletest/.*
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
+#define GTEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
+
+#include <memory>
+#include <ostream>
+#include <string>
+
+#include "gtest/gtest-printers.h"
+#include "gtest/internal/gtest-internal.h"
+#include "gtest/internal/gtest-port.h"
+
+// MSVC warning C5046 is new as of VS2017 version 15.8.
+#if defined(_MSC_VER) && _MSC_VER >= 1915
+#define GTEST_MAYBE_5046_ 5046
+#else
+#define GTEST_MAYBE_5046_
+#endif
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(
+ 4251 GTEST_MAYBE_5046_ /* class A needs to have dll-interface to be used by
+ clients of class B */
+ /* Symbol involving type with internal linkage not defined */)
+
+namespace testing {
+
+// To implement a matcher Foo for type T, define:
+// 1. a class FooMatcherImpl that implements the
+// MatcherInterface<T> interface, and
+// 2. a factory function that creates a Matcher<T> object from a
+// FooMatcherImpl*.
+//
+// The two-level delegation design makes it possible to allow a user
+// to write "v" instead of "Eq(v)" where a Matcher is expected, which
+// is impossible if we pass matchers by pointers. It also eases
+// ownership management as Matcher objects can now be copied like
+// plain values.
+
+// MatchResultListener is an abstract class. Its << operator can be
+// used by a matcher to explain why a value matches or doesn't match.
+//
+class MatchResultListener {
+ public:
+ // Creates a listener object with the given underlying ostream. The
+ // listener does not own the ostream, and does not dereference it
+ // in the constructor or destructor.
+ explicit MatchResultListener(::std::ostream* os) : stream_(os) {}
+ virtual ~MatchResultListener() = 0; // Makes this class abstract.
+
+ // Streams x to the underlying ostream; does nothing if the ostream
+ // is NULL.
+ template <typename T>
+ MatchResultListener& operator<<(const T& x) {
+ if (stream_ != nullptr) *stream_ << x;
+ return *this;
+ }
+
+ // Returns the underlying ostream.
+ ::std::ostream* stream() { return stream_; }
+
+ // Returns true iff the listener is interested in an explanation of
+ // the match result. A matcher's MatchAndExplain() method can use
+ // this information to avoid generating the explanation when no one
+ // intends to hear it.
+ bool IsInterested() const { return stream_ != nullptr; }
+
+ private:
+ ::std::ostream* const stream_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener);
+};
+
+inline MatchResultListener::~MatchResultListener() {
+}
+
+// An instance of a subclass of this knows how to describe itself as a
+// matcher.
+class MatcherDescriberInterface {
+ public:
+ virtual ~MatcherDescriberInterface() {}
+
+ // Describes this matcher to an ostream. The function should print
+ // a verb phrase that describes the property a value matching this
+ // matcher should have. The subject of the verb phrase is the value
+ // being matched. For example, the DescribeTo() method of the Gt(7)
+ // matcher prints "is greater than 7".
+ virtual void DescribeTo(::std::ostream* os) const = 0;
+
+ // Describes the negation of this matcher to an ostream. For
+ // example, if the description of this matcher is "is greater than
+ // 7", the negated description could be "is not greater than 7".
+ // You are not required to override this when implementing
+ // MatcherInterface, but it is highly advised so that your matcher
+ // can produce good error messages.
+ virtual void DescribeNegationTo(::std::ostream* os) const {
+ *os << "not (";
+ DescribeTo(os);
+ *os << ")";
+ }
+};
+
+// The implementation of a matcher.
+template <typename T>
+class MatcherInterface : public MatcherDescriberInterface {
+ public:
+ // Returns true iff the matcher matches x; also explains the match
+ // result to 'listener' if necessary (see the next paragraph), in
+ // the form of a non-restrictive relative clause ("which ...",
+ // "whose ...", etc) that describes x. For example, the
+ // MatchAndExplain() method of the Pointee(...) matcher should
+ // generate an explanation like "which points to ...".
+ //
+ // Implementations of MatchAndExplain() should add an explanation of
+ // the match result *if and only if* they can provide additional
+ // information that's not already present (or not obvious) in the
+ // print-out of x and the matcher's description. Whether the match
+ // succeeds is not a factor in deciding whether an explanation is
+ // needed, as sometimes the caller needs to print a failure message
+ // when the match succeeds (e.g. when the matcher is used inside
+ // Not()).
+ //
+ // For example, a "has at least 10 elements" matcher should explain
+ // what the actual element count is, regardless of the match result,
+ // as it is useful information to the reader; on the other hand, an
+ // "is empty" matcher probably only needs to explain what the actual
+ // size is when the match fails, as it's redundant to say that the
+ // size is 0 when the value is already known to be empty.
+ //
+ // You should override this method when defining a new matcher.
+ //
+ // It's the responsibility of the caller (Google Test) to guarantee
+ // that 'listener' is not NULL. This helps to simplify a matcher's
+ // implementation when it doesn't care about the performance, as it
+ // can talk to 'listener' without checking its validity first.
+ // However, in order to implement dummy listeners efficiently,
+ // listener->stream() may be NULL.
+ virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0;
+
+ // Inherits these methods from MatcherDescriberInterface:
+ // virtual void DescribeTo(::std::ostream* os) const = 0;
+ // virtual void DescribeNegationTo(::std::ostream* os) const;
+};
+
+namespace internal {
+
+// Converts a MatcherInterface<T> to a MatcherInterface<const T&>.
+template <typename T>
+class MatcherInterfaceAdapter : public MatcherInterface<const T&> {
+ public:
+ explicit MatcherInterfaceAdapter(const MatcherInterface<T>* impl)
+ : impl_(impl) {}
+ ~MatcherInterfaceAdapter() override { delete impl_; }
+
+ void DescribeTo(::std::ostream* os) const override { impl_->DescribeTo(os); }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ impl_->DescribeNegationTo(os);
+ }
+
+ bool MatchAndExplain(const T& x,
+ MatchResultListener* listener) const override {
+ return impl_->MatchAndExplain(x, listener);
+ }
+
+ private:
+ const MatcherInterface<T>* const impl_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MatcherInterfaceAdapter);
+};
+
+struct AnyEq {
+ template <typename A, typename B>
+ bool operator()(const A& a, const B& b) const { return a == b; }
+};
+struct AnyNe {
+ template <typename A, typename B>
+ bool operator()(const A& a, const B& b) const { return a != b; }
+};
+struct AnyLt {
+ template <typename A, typename B>
+ bool operator()(const A& a, const B& b) const { return a < b; }
+};
+struct AnyGt {
+ template <typename A, typename B>
+ bool operator()(const A& a, const B& b) const { return a > b; }
+};
+struct AnyLe {
+ template <typename A, typename B>
+ bool operator()(const A& a, const B& b) const { return a <= b; }
+};
+struct AnyGe {
+ template <typename A, typename B>
+ bool operator()(const A& a, const B& b) const { return a >= b; }
+};
+
+// A match result listener that ignores the explanation.
+class DummyMatchResultListener : public MatchResultListener {
+ public:
+ DummyMatchResultListener() : MatchResultListener(nullptr) {}
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener);
+};
+
+// A match result listener that forwards the explanation to a given
+// ostream. The difference between this and MatchResultListener is
+// that the former is concrete.
+class StreamMatchResultListener : public MatchResultListener {
+ public:
+ explicit StreamMatchResultListener(::std::ostream* os)
+ : MatchResultListener(os) {}
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener);
+};
+
+// An internal class for implementing Matcher<T>, which will derive
+// from it. We put functionalities common to all Matcher<T>
+// specializations here to avoid code duplication.
+template <typename T>
+class MatcherBase {
+ public:
+ // Returns true iff the matcher matches x; also explains the match
+ // result to 'listener'.
+ bool MatchAndExplain(const T& x, MatchResultListener* listener) const {
+ return impl_->MatchAndExplain(x, listener);
+ }
+
+ // Returns true iff this matcher matches x.
+ bool Matches(const T& x) const {
+ DummyMatchResultListener dummy;
+ return MatchAndExplain(x, &dummy);
+ }
+
+ // Describes this matcher to an ostream.
+ void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
+
+ // Describes the negation of this matcher to an ostream.
+ void DescribeNegationTo(::std::ostream* os) const {
+ impl_->DescribeNegationTo(os);
+ }
+
+ // Explains why x matches, or doesn't match, the matcher.
+ void ExplainMatchResultTo(const T& x, ::std::ostream* os) const {
+ StreamMatchResultListener listener(os);
+ MatchAndExplain(x, &listener);
+ }
+
+ // Returns the describer for this matcher object; retains ownership
+ // of the describer, which is only guaranteed to be alive when
+ // this matcher object is alive.
+ const MatcherDescriberInterface* GetDescriber() const {
+ return impl_.get();
+ }
+
+ protected:
+ MatcherBase() {}
+
+ // Constructs a matcher from its implementation.
+ explicit MatcherBase(const MatcherInterface<const T&>* impl) : impl_(impl) {}
+
+ template <typename U>
+ explicit MatcherBase(
+ const MatcherInterface<U>* impl,
+ typename internal::EnableIf<
+ !internal::IsSame<U, const U&>::value>::type* = nullptr)
+ : impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {}
+
+ MatcherBase(const MatcherBase&) = default;
+ MatcherBase& operator=(const MatcherBase&) = default;
+ MatcherBase(MatcherBase&&) = default;
+ MatcherBase& operator=(MatcherBase&&) = default;
+
+ virtual ~MatcherBase() {}
+
+ private:
+ std::shared_ptr<const MatcherInterface<const T&>> impl_;
+};
+
+} // namespace internal
+
+// A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
+// object that can check whether a value of type T matches. The
+// implementation of Matcher<T> is just a std::shared_ptr to const
+// MatcherInterface<T>. Don't inherit from Matcher!
+template <typename T>
+class Matcher : public internal::MatcherBase<T> {
+ public:
+ // Constructs a null matcher. Needed for storing Matcher objects in STL
+ // containers. A default-constructed matcher is not yet initialized. You
+ // cannot use it until a valid value has been assigned to it.
+ explicit Matcher() {} // NOLINT
+
+ // Constructs a matcher from its implementation.
+ explicit Matcher(const MatcherInterface<const T&>* impl)
+ : internal::MatcherBase<T>(impl) {}
+
+ template <typename U>
+ explicit Matcher(const MatcherInterface<U>* impl,
+ typename internal::EnableIf<
+ !internal::IsSame<U, const U&>::value>::type* = nullptr)
+ : internal::MatcherBase<T>(impl) {}
+
+ // Implicit constructor here allows people to write
+ // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes
+ Matcher(T value); // NOLINT
+};
+
+// The following two specializations allow the user to write str
+// instead of Eq(str) and "foo" instead of Eq("foo") when a std::string
+// matcher is expected.
+template <>
+class GTEST_API_ Matcher<const std::string&>
+ : public internal::MatcherBase<const std::string&> {
+ public:
+ Matcher() {}
+
+ explicit Matcher(const MatcherInterface<const std::string&>* impl)
+ : internal::MatcherBase<const std::string&>(impl) {}
+
+ // Allows the user to write str instead of Eq(str) sometimes, where
+ // str is a std::string object.
+ Matcher(const std::string& s); // NOLINT
+
+ // Allows the user to write "foo" instead of Eq("foo") sometimes.
+ Matcher(const char* s); // NOLINT
+};
+
+template <>
+class GTEST_API_ Matcher<std::string>
+ : public internal::MatcherBase<std::string> {
+ public:
+ Matcher() {}
+
+ explicit Matcher(const MatcherInterface<const std::string&>* impl)
+ : internal::MatcherBase<std::string>(impl) {}
+ explicit Matcher(const MatcherInterface<std::string>* impl)
+ : internal::MatcherBase<std::string>(impl) {}
+
+ // Allows the user to write str instead of Eq(str) sometimes, where
+ // str is a string object.
+ Matcher(const std::string& s); // NOLINT
+
+ // Allows the user to write "foo" instead of Eq("foo") sometimes.
+ Matcher(const char* s); // NOLINT
+};
+
+#if GTEST_HAS_ABSL
+// The following two specializations allow the user to write str
+// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view
+// matcher is expected.
+template <>
+class GTEST_API_ Matcher<const absl::string_view&>
+ : public internal::MatcherBase<const absl::string_view&> {
+ public:
+ Matcher() {}
+
+ explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
+ : internal::MatcherBase<const absl::string_view&>(impl) {}
+
+ // Allows the user to write str instead of Eq(str) sometimes, where
+ // str is a std::string object.
+ Matcher(const std::string& s); // NOLINT
+
+ // Allows the user to write "foo" instead of Eq("foo") sometimes.
+ Matcher(const char* s); // NOLINT
+
+ // Allows the user to pass absl::string_views directly.
+ Matcher(absl::string_view s); // NOLINT
+};
+
+template <>
+class GTEST_API_ Matcher<absl::string_view>
+ : public internal::MatcherBase<absl::string_view> {
+ public:
+ Matcher() {}
+
+ explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
+ : internal::MatcherBase<absl::string_view>(impl) {}
+ explicit Matcher(const MatcherInterface<absl::string_view>* impl)
+ : internal::MatcherBase<absl::string_view>(impl) {}
+
+ // Allows the user to write str instead of Eq(str) sometimes, where
+ // str is a std::string object.
+ Matcher(const std::string& s); // NOLINT
+
+ // Allows the user to write "foo" instead of Eq("foo") sometimes.
+ Matcher(const char* s); // NOLINT
+
+ // Allows the user to pass absl::string_views directly.
+ Matcher(absl::string_view s); // NOLINT
+};
+#endif // GTEST_HAS_ABSL
+
+// Prints a matcher in a human-readable format.
+template <typename T>
+std::ostream& operator<<(std::ostream& os, const Matcher<T>& matcher) {
+ matcher.DescribeTo(&os);
+ return os;
+}
+
+// The PolymorphicMatcher class template makes it easy to implement a
+// polymorphic matcher (i.e. a matcher that can match values of more
+// than one type, e.g. Eq(n) and NotNull()).
+//
+// To define a polymorphic matcher, a user should provide an Impl
+// class that has a DescribeTo() method and a DescribeNegationTo()
+// method, and define a member function (or member function template)
+//
+// bool MatchAndExplain(const Value& value,
+// MatchResultListener* listener) const;
+//
+// See the definition of NotNull() for a complete example.
+template <class Impl>
+class PolymorphicMatcher {
+ public:
+ explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {}
+
+ // Returns a mutable reference to the underlying matcher
+ // implementation object.
+ Impl& mutable_impl() { return impl_; }
+
+ // Returns an immutable reference to the underlying matcher
+ // implementation object.
+ const Impl& impl() const { return impl_; }
+
+ template <typename T>
+ operator Matcher<T>() const {
+ return Matcher<T>(new MonomorphicImpl<const T&>(impl_));
+ }
+
+ private:
+ template <typename T>
+ class MonomorphicImpl : public MatcherInterface<T> {
+ public:
+ explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
+
+ virtual void DescribeTo(::std::ostream* os) const { impl_.DescribeTo(os); }
+
+ virtual void DescribeNegationTo(::std::ostream* os) const {
+ impl_.DescribeNegationTo(os);
+ }
+
+ virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
+ return impl_.MatchAndExplain(x, listener);
+ }
+
+ private:
+ const Impl impl_;
+ };
+
+ Impl impl_;
+};
+
+// Creates a matcher from its implementation.
+// DEPRECATED: Especially in the generic code, prefer:
+// Matcher<T>(new MyMatcherImpl<const T&>(...));
+//
+// MakeMatcher may create a Matcher that accepts its argument by value, which
+// leads to unnecessary copies & lack of support for non-copyable types.
+template <typename T>
+inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) {
+ return Matcher<T>(impl);
+}
+
+// Creates a polymorphic matcher from its implementation. This is
+// easier to use than the PolymorphicMatcher<Impl> constructor as it
+// doesn't require you to explicitly write the template argument, e.g.
+//
+// MakePolymorphicMatcher(foo);
+// vs
+// PolymorphicMatcher<TypeOfFoo>(foo);
+template <class Impl>
+inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) {
+ return PolymorphicMatcher<Impl>(impl);
+}
+
+namespace internal {
+// Implements a matcher that compares a given value with a
+// pre-supplied value using one of the ==, <=, <, etc, operators. The
+// two values being compared don't have to have the same type.
+//
+// The matcher defined here is polymorphic (for example, Eq(5) can be
+// used to match an int, a short, a double, etc). Therefore we use
+// a template type conversion operator in the implementation.
+//
+// The following template definition assumes that the Rhs parameter is
+// a "bare" type (i.e. neither 'const T' nor 'T&').
+template <typename D, typename Rhs, typename Op>
+class ComparisonBase {
+ public:
+ explicit ComparisonBase(const Rhs& rhs) : rhs_(rhs) {}
+ template <typename Lhs>
+ operator Matcher<Lhs>() const {
+ return Matcher<Lhs>(new Impl<const Lhs&>(rhs_));
+ }
+
+ private:
+ template <typename T>
+ static const T& Unwrap(const T& v) { return v; }
+ template <typename T>
+ static const T& Unwrap(std::reference_wrapper<T> v) { return v; }
+
+ template <typename Lhs, typename = Rhs>
+ class Impl : public MatcherInterface<Lhs> {
+ public:
+ explicit Impl(const Rhs& rhs) : rhs_(rhs) {}
+ bool MatchAndExplain(Lhs lhs,
+ MatchResultListener* /* listener */) const override {
+ return Op()(lhs, Unwrap(rhs_));
+ }
+ void DescribeTo(::std::ostream* os) const override {
+ *os << D::Desc() << " ";
+ UniversalPrint(Unwrap(rhs_), os);
+ }
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << D::NegatedDesc() << " ";
+ UniversalPrint(Unwrap(rhs_), os);
+ }
+
+ private:
+ Rhs rhs_;
+ };
+ Rhs rhs_;
+};
+
+template <typename Rhs>
+class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> {
+ public:
+ explicit EqMatcher(const Rhs& rhs)
+ : ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) { }
+ static const char* Desc() { return "is equal to"; }
+ static const char* NegatedDesc() { return "isn't equal to"; }
+};
+template <typename Rhs>
+class NeMatcher : public ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe> {
+ public:
+ explicit NeMatcher(const Rhs& rhs)
+ : ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe>(rhs) { }
+ static const char* Desc() { return "isn't equal to"; }
+ static const char* NegatedDesc() { return "is equal to"; }
+};
+template <typename Rhs>
+class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt> {
+ public:
+ explicit LtMatcher(const Rhs& rhs)
+ : ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt>(rhs) { }
+ static const char* Desc() { return "is <"; }
+ static const char* NegatedDesc() { return "isn't <"; }
+};
+template <typename Rhs>
+class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt> {
+ public:
+ explicit GtMatcher(const Rhs& rhs)
+ : ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt>(rhs) { }
+ static const char* Desc() { return "is >"; }
+ static const char* NegatedDesc() { return "isn't >"; }
+};
+template <typename Rhs>
+class LeMatcher : public ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe> {
+ public:
+ explicit LeMatcher(const Rhs& rhs)
+ : ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe>(rhs) { }
+ static const char* Desc() { return "is <="; }
+ static const char* NegatedDesc() { return "isn't <="; }
+};
+template <typename Rhs>
+class GeMatcher : public ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe> {
+ public:
+ explicit GeMatcher(const Rhs& rhs)
+ : ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe>(rhs) { }
+ static const char* Desc() { return "is >="; }
+ static const char* NegatedDesc() { return "isn't >="; }
+};
+
+// Implements polymorphic matchers MatchesRegex(regex) and
+// ContainsRegex(regex), which can be used as a Matcher<T> as long as
+// T can be converted to a string.
+class MatchesRegexMatcher {
+ public:
+ MatchesRegexMatcher(const RE* regex, bool full_match)
+ : regex_(regex), full_match_(full_match) {}
+
+#if GTEST_HAS_ABSL
+ bool MatchAndExplain(const absl::string_view& s,
+ MatchResultListener* listener) const {
+ return MatchAndExplain(std::string(s), listener);
+ }
+#endif // GTEST_HAS_ABSL
+
+ // Accepts pointer types, particularly:
+ // const char*
+ // char*
+ // const wchar_t*
+ // wchar_t*
+ template <typename CharType>
+ bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
+ return s != nullptr && MatchAndExplain(std::string(s), listener);
+ }
+
+ // Matches anything that can convert to std::string.
+ //
+ // This is a template, not just a plain function with const std::string&,
+ // because absl::string_view has some interfering non-explicit constructors.
+ template <class MatcheeStringType>
+ bool MatchAndExplain(const MatcheeStringType& s,
+ MatchResultListener* /* listener */) const {
+ const std::string& s2(s);
+ return full_match_ ? RE::FullMatch(s2, *regex_)
+ : RE::PartialMatch(s2, *regex_);
+ }
+
+ void DescribeTo(::std::ostream* os) const {
+ *os << (full_match_ ? "matches" : "contains") << " regular expression ";
+ UniversalPrinter<std::string>::Print(regex_->pattern(), os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "doesn't " << (full_match_ ? "match" : "contain")
+ << " regular expression ";
+ UniversalPrinter<std::string>::Print(regex_->pattern(), os);
+ }
+
+ private:
+ const std::shared_ptr<const RE> regex_;
+ const bool full_match_;
+};
+} // namespace internal
+
+// Matches a string that fully matches regular expression 'regex'.
+// The matcher takes ownership of 'regex'.
+inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
+ const internal::RE* regex) {
+ return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true));
+}
+inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
+ const std::string& regex) {
+ return MatchesRegex(new internal::RE(regex));
+}
+
+// Matches a string that contains regular expression 'regex'.
+// The matcher takes ownership of 'regex'.
+inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
+ const internal::RE* regex) {
+ return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false));
+}
+inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
+ const std::string& regex) {
+ return ContainsRegex(new internal::RE(regex));
+}
+
+// Creates a polymorphic matcher that matches anything equal to x.
+// Note: if the parameter of Eq() were declared as const T&, Eq("foo")
+// wouldn't compile.
+template <typename T>
+inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
+
+// Constructs a Matcher<T> from a 'value' of type T. The constructed
+// matcher matches any value that's equal to 'value'.
+template <typename T>
+Matcher<T>::Matcher(T value) { *this = Eq(value); }
+
+// Creates a monomorphic matcher that matches anything with type Lhs
+// and equal to rhs. A user may need to use this instead of Eq(...)
+// in order to resolve an overloading ambiguity.
+//
+// TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x))
+// or Matcher<T>(x), but more readable than the latter.
+//
+// We could define similar monomorphic matchers for other comparison
+// operations (e.g. TypedLt, TypedGe, and etc), but decided not to do
+// it yet as those are used much less than Eq() in practice. A user
+// can always write Matcher<T>(Lt(5)) to be explicit about the type,
+// for example.
+template <typename Lhs, typename Rhs>
+inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); }
+
+// Creates a polymorphic matcher that matches anything >= x.
+template <typename Rhs>
+inline internal::GeMatcher<Rhs> Ge(Rhs x) {
+ return internal::GeMatcher<Rhs>(x);
+}
+
+// Creates a polymorphic matcher that matches anything > x.
+template <typename Rhs>
+inline internal::GtMatcher<Rhs> Gt(Rhs x) {
+ return internal::GtMatcher<Rhs>(x);
+}
+
+// Creates a polymorphic matcher that matches anything <= x.
+template <typename Rhs>
+inline internal::LeMatcher<Rhs> Le(Rhs x) {
+ return internal::LeMatcher<Rhs>(x);
+}
+
+// Creates a polymorphic matcher that matches anything < x.
+template <typename Rhs>
+inline internal::LtMatcher<Rhs> Lt(Rhs x) {
+ return internal::LtMatcher<Rhs>(x);
+}
+
+// Creates a polymorphic matcher that matches anything != x.
+template <typename Rhs>
+inline internal::NeMatcher<Rhs> Ne(Rhs x) {
+ return internal::NeMatcher<Rhs>(x);
+}
+} // namespace testing
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 5046
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
--- /dev/null
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// The Google C++ Testing and Mocking Framework (Google Test)
+//
+// This header file defines the Message class.
+//
+// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
+// leave some internal implementation details in this header file.
+// They are clearly marked by comments like this:
+//
+// // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+//
+// Such code is NOT meant to be used by a user directly, and is subject
+// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
+// program!
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
+#define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
+
+#include <limits>
+#include <memory>
+
+#include "gtest/internal/gtest-port.h"
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
+/* class A needs to have dll-interface to be used by clients of class B */)
+
+// Ensures that there is at least one operator<< in the global namespace.
+// See Message& operator<<(...) below for why.
+void operator<<(const testing::internal::Secret&, int);
+
+namespace testing {
+
+// The Message class works like an ostream repeater.
+//
+// Typical usage:
+//
+// 1. You stream a bunch of values to a Message object.
+// It will remember the text in a stringstream.
+// 2. Then you stream the Message object to an ostream.
+// This causes the text in the Message to be streamed
+// to the ostream.
+//
+// For example;
+//
+// testing::Message foo;
+// foo << 1 << " != " << 2;
+// std::cout << foo;
+//
+// will print "1 != 2".
+//
+// Message is not intended to be inherited from. In particular, its
+// destructor is not virtual.
+//
+// Note that stringstream behaves differently in gcc and in MSVC. You
+// can stream a NULL char pointer to it in the former, but not in the
+// latter (it causes an access violation if you do). The Message
+// class hides this difference by treating a NULL char pointer as
+// "(null)".
+class GTEST_API_ Message {
+ private:
+ // The type of basic IO manipulators (endl, ends, and flush) for
+ // narrow streams.
+ typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&);
+
+ public:
+ // Constructs an empty Message.
+ Message();
+
+ // Copy constructor.
+ Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT
+ *ss_ << msg.GetString();
+ }
+
+ // Constructs a Message from a C-string.
+ explicit Message(const char* str) : ss_(new ::std::stringstream) {
+ *ss_ << str;
+ }
+
+ // Streams a non-pointer value to this object.
+ template <typename T>
+ inline Message& operator <<(const T& val) {
+ // Some libraries overload << for STL containers. These
+ // overloads are defined in the global namespace instead of ::std.
+ //
+ // C++'s symbol lookup rule (i.e. Koenig lookup) says that these
+ // overloads are visible in either the std namespace or the global
+ // namespace, but not other namespaces, including the testing
+ // namespace which Google Test's Message class is in.
+ //
+ // To allow STL containers (and other types that has a << operator
+ // defined in the global namespace) to be used in Google Test
+ // assertions, testing::Message must access the custom << operator
+ // from the global namespace. With this using declaration,
+ // overloads of << defined in the global namespace and those
+ // visible via Koenig lookup are both exposed in this function.
+ using ::operator <<;
+ *ss_ << val;
+ return *this;
+ }
+
+ // Streams a pointer value to this object.
+ //
+ // This function is an overload of the previous one. When you
+ // stream a pointer to a Message, this definition will be used as it
+ // is more specialized. (The C++ Standard, section
+ // [temp.func.order].) If you stream a non-pointer, then the
+ // previous definition will be used.
+ //
+ // The reason for this overload is that streaming a NULL pointer to
+ // ostream is undefined behavior. Depending on the compiler, you
+ // may get "0", "(nil)", "(null)", or an access violation. To
+ // ensure consistent result across compilers, we always treat NULL
+ // as "(null)".
+ template <typename T>
+ inline Message& operator <<(T* const& pointer) { // NOLINT
+ if (pointer == nullptr) {
+ *ss_ << "(null)";
+ } else {
+ *ss_ << pointer;
+ }
+ return *this;
+ }
+
+ // Since the basic IO manipulators are overloaded for both narrow
+ // and wide streams, we have to provide this specialized definition
+ // of operator <<, even though its body is the same as the
+ // templatized version above. Without this definition, streaming
+ // endl or other basic IO manipulators to Message will confuse the
+ // compiler.
+ Message& operator <<(BasicNarrowIoManip val) {
+ *ss_ << val;
+ return *this;
+ }
+
+ // Instead of 1/0, we want to see true/false for bool values.
+ Message& operator <<(bool b) {
+ return *this << (b ? "true" : "false");
+ }
+
+ // These two overloads allow streaming a wide C string to a Message
+ // using the UTF-8 encoding.
+ Message& operator <<(const wchar_t* wide_c_str);
+ Message& operator <<(wchar_t* wide_c_str);
+
+#if GTEST_HAS_STD_WSTRING
+ // Converts the given wide string to a narrow string using the UTF-8
+ // encoding, and streams the result to this Message object.
+ Message& operator <<(const ::std::wstring& wstr);
+#endif // GTEST_HAS_STD_WSTRING
+
+ // Gets the text streamed to this object so far as an std::string.
+ // Each '\0' character in the buffer is replaced with "\\0".
+ //
+ // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+ std::string GetString() const;
+
+ private:
+ // We'll hold the text streamed to this object here.
+ const std::unique_ptr< ::std::stringstream> ss_;
+
+ // We declare (but don't implement) this to prevent the compiler
+ // from implementing the assignment operator.
+ void operator=(const Message&);
+};
+
+// Streams a Message to an ostream.
+inline std::ostream& operator <<(std::ostream& os, const Message& sb) {
+ return os << sb.GetString();
+}
+
+namespace internal {
+
+// Converts a streamable value to an std::string. A NULL pointer is
+// converted to "(null)". When the input value is a ::string,
+// ::std::string, ::wstring, or ::std::wstring object, each NUL
+// character in it is replaced with "\\0".
+template <typename T>
+std::string StreamableToString(const T& streamable) {
+ return (Message() << streamable).GetString();
+}
+
+} // namespace internal
+} // namespace testing
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Macros and functions for implementing parameterized tests
+// in Google C++ Testing and Mocking Framework (Google Test)
+//
+// This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
+//
+// GOOGLETEST_CM0001 DO NOT DELETE
+#ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
+#define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
+
+
+// Value-parameterized tests allow you to test your code with different
+// parameters without writing multiple copies of the same test.
+//
+// Here is how you use value-parameterized tests:
+
+#if 0
+
+// To write value-parameterized tests, first you should define a fixture
+// class. It is usually derived from testing::TestWithParam<T> (see below for
+// another inheritance scheme that's sometimes useful in more complicated
+// class hierarchies), where the type of your parameter values.
+// TestWithParam<T> is itself derived from testing::Test. T can be any
+// copyable type. If it's a raw pointer, you are responsible for managing the
+// lifespan of the pointed values.
+
+class FooTest : public ::testing::TestWithParam<const char*> {
+ // You can implement all the usual class fixture members here.
+};
+
+// Then, use the TEST_P macro to define as many parameterized tests
+// for this fixture as you want. The _P suffix is for "parameterized"
+// or "pattern", whichever you prefer to think.
+
+TEST_P(FooTest, DoesBlah) {
+ // Inside a test, access the test parameter with the GetParam() method
+ // of the TestWithParam<T> class:
+ EXPECT_TRUE(foo.Blah(GetParam()));
+ ...
+}
+
+TEST_P(FooTest, HasBlahBlah) {
+ ...
+}
+
+// Finally, you can use INSTANTIATE_TEST_SUITE_P to instantiate the test
+// case with any set of parameters you want. Google Test defines a number
+// of functions for generating test parameters. They return what we call
+// (surprise!) parameter generators. Here is a summary of them, which
+// are all in the testing namespace:
+//
+//
+// Range(begin, end [, step]) - Yields values {begin, begin+step,
+// begin+step+step, ...}. The values do not
+// include end. step defaults to 1.
+// Values(v1, v2, ..., vN) - Yields values {v1, v2, ..., vN}.
+// ValuesIn(container) - Yields values from a C-style array, an STL
+// ValuesIn(begin,end) container, or an iterator range [begin, end).
+// Bool() - Yields sequence {false, true}.
+// Combine(g1, g2, ..., gN) - Yields all combinations (the Cartesian product
+// for the math savvy) of the values generated
+// by the N generators.
+//
+// For more details, see comments at the definitions of these functions below
+// in this file.
+//
+// The following statement will instantiate tests from the FooTest test suite
+// each with parameter values "meeny", "miny", and "moe".
+
+INSTANTIATE_TEST_SUITE_P(InstantiationName,
+ FooTest,
+ Values("meeny", "miny", "moe"));
+
+// To distinguish different instances of the pattern, (yes, you
+// can instantiate it more than once) the first argument to the
+// INSTANTIATE_TEST_SUITE_P macro is a prefix that will be added to the
+// actual test suite name. Remember to pick unique prefixes for different
+// instantiations. The tests from the instantiation above will have
+// these names:
+//
+// * InstantiationName/FooTest.DoesBlah/0 for "meeny"
+// * InstantiationName/FooTest.DoesBlah/1 for "miny"
+// * InstantiationName/FooTest.DoesBlah/2 for "moe"
+// * InstantiationName/FooTest.HasBlahBlah/0 for "meeny"
+// * InstantiationName/FooTest.HasBlahBlah/1 for "miny"
+// * InstantiationName/FooTest.HasBlahBlah/2 for "moe"
+//
+// You can use these names in --gtest_filter.
+//
+// This statement will instantiate all tests from FooTest again, each
+// with parameter values "cat" and "dog":
+
+const char* pets[] = {"cat", "dog"};
+INSTANTIATE_TEST_SUITE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
+
+// The tests from the instantiation above will have these names:
+//
+// * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat"
+// * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog"
+// * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
+// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
+//
+// Please note that INSTANTIATE_TEST_SUITE_P will instantiate all tests
+// in the given test suite, whether their definitions come before or
+// AFTER the INSTANTIATE_TEST_SUITE_P statement.
+//
+// Please also note that generator expressions (including parameters to the
+// generators) are evaluated in InitGoogleTest(), after main() has started.
+// This allows the user on one hand, to adjust generator parameters in order
+// to dynamically determine a set of tests to run and on the other hand,
+// give the user a chance to inspect the generated tests with Google Test
+// reflection API before RUN_ALL_TESTS() is executed.
+//
+// You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
+// for more examples.
+//
+// In the future, we plan to publish the API for defining new parameter
+// generators. But for now this interface remains part of the internal
+// implementation and is subject to change.
+//
+//
+// A parameterized test fixture must be derived from testing::Test and from
+// testing::WithParamInterface<T>, where T is the type of the parameter
+// values. Inheriting from TestWithParam<T> satisfies that requirement because
+// TestWithParam<T> inherits from both Test and WithParamInterface. In more
+// complicated hierarchies, however, it is occasionally useful to inherit
+// separately from Test and WithParamInterface. For example:
+
+class BaseTest : public ::testing::Test {
+ // You can inherit all the usual members for a non-parameterized test
+ // fixture here.
+};
+
+class DerivedTest : public BaseTest, public ::testing::WithParamInterface<int> {
+ // The usual test fixture members go here too.
+};
+
+TEST_F(BaseTest, HasFoo) {
+ // This is an ordinary non-parameterized test.
+}
+
+TEST_P(DerivedTest, DoesBlah) {
+ // GetParam works just the same here as if you inherit from TestWithParam.
+ EXPECT_TRUE(foo.Blah(GetParam()));
+}
+
+#endif // 0
+
+#include <utility>
+
+#include "gtest/internal/gtest-internal.h"
+#include "gtest/internal/gtest-param-util.h"
+#include "gtest/internal/gtest-port.h"
+
+namespace testing {
+
+// Functions producing parameter generators.
+//
+// Google Test uses these generators to produce parameters for value-
+// parameterized tests. When a parameterized test suite is instantiated
+// with a particular generator, Google Test creates and runs tests
+// for each element in the sequence produced by the generator.
+//
+// In the following sample, tests from test suite FooTest are instantiated
+// each three times with parameter values 3, 5, and 8:
+//
+// class FooTest : public TestWithParam<int> { ... };
+//
+// TEST_P(FooTest, TestThis) {
+// }
+// TEST_P(FooTest, TestThat) {
+// }
+// INSTANTIATE_TEST_SUITE_P(TestSequence, FooTest, Values(3, 5, 8));
+//
+
+// Range() returns generators providing sequences of values in a range.
+//
+// Synopsis:
+// Range(start, end)
+// - returns a generator producing a sequence of values {start, start+1,
+// start+2, ..., }.
+// Range(start, end, step)
+// - returns a generator producing a sequence of values {start, start+step,
+// start+step+step, ..., }.
+// Notes:
+// * The generated sequences never include end. For example, Range(1, 5)
+// returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2)
+// returns a generator producing {1, 3, 5, 7}.
+// * start and end must have the same type. That type may be any integral or
+// floating-point type or a user defined type satisfying these conditions:
+// * It must be assignable (have operator=() defined).
+// * It must have operator+() (operator+(int-compatible type) for
+// two-operand version).
+// * It must have operator<() defined.
+// Elements in the resulting sequences will also have that type.
+// * Condition start < end must be satisfied in order for resulting sequences
+// to contain any elements.
+//
+template <typename T, typename IncrementT>
+internal::ParamGenerator<T> Range(T start, T end, IncrementT step) {
+ return internal::ParamGenerator<T>(
+ new internal::RangeGenerator<T, IncrementT>(start, end, step));
+}
+
+template <typename T>
+internal::ParamGenerator<T> Range(T start, T end) {
+ return Range(start, end, 1);
+}
+
+// ValuesIn() function allows generation of tests with parameters coming from
+// a container.
+//
+// Synopsis:
+// ValuesIn(const T (&array)[N])
+// - returns a generator producing sequences with elements from
+// a C-style array.
+// ValuesIn(const Container& container)
+// - returns a generator producing sequences with elements from
+// an STL-style container.
+// ValuesIn(Iterator begin, Iterator end)
+// - returns a generator producing sequences with elements from
+// a range [begin, end) defined by a pair of STL-style iterators. These
+// iterators can also be plain C pointers.
+//
+// Please note that ValuesIn copies the values from the containers
+// passed in and keeps them to generate tests in RUN_ALL_TESTS().
+//
+// Examples:
+//
+// This instantiates tests from test suite StringTest
+// each with C-string values of "foo", "bar", and "baz":
+//
+// const char* strings[] = {"foo", "bar", "baz"};
+// INSTANTIATE_TEST_SUITE_P(StringSequence, StringTest, ValuesIn(strings));
+//
+// This instantiates tests from test suite StlStringTest
+// each with STL strings with values "a" and "b":
+//
+// ::std::vector< ::std::string> GetParameterStrings() {
+// ::std::vector< ::std::string> v;
+// v.push_back("a");
+// v.push_back("b");
+// return v;
+// }
+//
+// INSTANTIATE_TEST_SUITE_P(CharSequence,
+// StlStringTest,
+// ValuesIn(GetParameterStrings()));
+//
+//
+// This will also instantiate tests from CharTest
+// each with parameter values 'a' and 'b':
+//
+// ::std::list<char> GetParameterChars() {
+// ::std::list<char> list;
+// list.push_back('a');
+// list.push_back('b');
+// return list;
+// }
+// ::std::list<char> l = GetParameterChars();
+// INSTANTIATE_TEST_SUITE_P(CharSequence2,
+// CharTest,
+// ValuesIn(l.begin(), l.end()));
+//
+template <typename ForwardIterator>
+internal::ParamGenerator<
+ typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
+ValuesIn(ForwardIterator begin, ForwardIterator end) {
+ typedef typename ::testing::internal::IteratorTraits<ForwardIterator>
+ ::value_type ParamType;
+ return internal::ParamGenerator<ParamType>(
+ new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));
+}
+
+template <typename T, size_t N>
+internal::ParamGenerator<T> ValuesIn(const T (&array)[N]) {
+ return ValuesIn(array, array + N);
+}
+
+template <class Container>
+internal::ParamGenerator<typename Container::value_type> ValuesIn(
+ const Container& container) {
+ return ValuesIn(container.begin(), container.end());
+}
+
+// Values() allows generating tests from explicitly specified list of
+// parameters.
+//
+// Synopsis:
+// Values(T v1, T v2, ..., T vN)
+// - returns a generator producing sequences with elements v1, v2, ..., vN.
+//
+// For example, this instantiates tests from test suite BarTest each
+// with values "one", "two", and "three":
+//
+// INSTANTIATE_TEST_SUITE_P(NumSequence,
+// BarTest,
+// Values("one", "two", "three"));
+//
+// This instantiates tests from test suite BazTest each with values 1, 2, 3.5.
+// The exact type of values will depend on the type of parameter in BazTest.
+//
+// INSTANTIATE_TEST_SUITE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
+//
+//
+template <typename... T>
+internal::ValueArray<T...> Values(T... v) {
+ return internal::ValueArray<T...>(std::move(v)...);
+}
+
+// Bool() allows generating tests with parameters in a set of (false, true).
+//
+// Synopsis:
+// Bool()
+// - returns a generator producing sequences with elements {false, true}.
+//
+// It is useful when testing code that depends on Boolean flags. Combinations
+// of multiple flags can be tested when several Bool()'s are combined using
+// Combine() function.
+//
+// In the following example all tests in the test suite FlagDependentTest
+// will be instantiated twice with parameters false and true.
+//
+// class FlagDependentTest : public testing::TestWithParam<bool> {
+// virtual void SetUp() {
+// external_flag = GetParam();
+// }
+// }
+// INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool());
+//
+inline internal::ParamGenerator<bool> Bool() {
+ return Values(false, true);
+}
+
+// Combine() allows the user to combine two or more sequences to produce
+// values of a Cartesian product of those sequences' elements.
+//
+// Synopsis:
+// Combine(gen1, gen2, ..., genN)
+// - returns a generator producing sequences with elements coming from
+// the Cartesian product of elements from the sequences generated by
+// gen1, gen2, ..., genN. The sequence elements will have a type of
+// std::tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
+// of elements from sequences produces by gen1, gen2, ..., genN.
+//
+// Combine can have up to 10 arguments.
+//
+// Example:
+//
+// This will instantiate tests in test suite AnimalTest each one with
+// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
+// tuple("dog", BLACK), and tuple("dog", WHITE):
+//
+// enum Color { BLACK, GRAY, WHITE };
+// class AnimalTest
+// : public testing::TestWithParam<std::tuple<const char*, Color> > {...};
+//
+// TEST_P(AnimalTest, AnimalLooksNice) {...}
+//
+// INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest,
+// Combine(Values("cat", "dog"),
+// Values(BLACK, WHITE)));
+//
+// This will instantiate tests in FlagDependentTest with all variations of two
+// Boolean flags:
+//
+// class FlagDependentTest
+// : public testing::TestWithParam<std::tuple<bool, bool> > {
+// virtual void SetUp() {
+// // Assigns external_flag_1 and external_flag_2 values from the tuple.
+// std::tie(external_flag_1, external_flag_2) = GetParam();
+// }
+// };
+//
+// TEST_P(FlagDependentTest, TestFeature1) {
+// // Test your code using external_flag_1 and external_flag_2 here.
+// }
+// INSTANTIATE_TEST_SUITE_P(TwoBoolSequence, FlagDependentTest,
+// Combine(Bool(), Bool()));
+//
+template <typename... Generator>
+internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) {
+ return internal::CartesianProductHolder<Generator...>(g...);
+}
+
+#define TEST_P(test_suite_name, test_name) \
+ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
+ : public test_suite_name { \
+ public: \
+ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
+ virtual void TestBody(); \
+ \
+ private: \
+ static int AddToRegistry() { \
+ ::testing::UnitTest::GetInstance() \
+ ->parameterized_test_registry() \
+ .GetTestSuitePatternHolder<test_suite_name>( \
+ #test_suite_name, \
+ ::testing::internal::CodeLocation(__FILE__, __LINE__)) \
+ ->AddTestPattern( \
+ GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \
+ new ::testing::internal::TestMetaFactory<GTEST_TEST_CLASS_NAME_( \
+ test_suite_name, test_name)>()); \
+ return 0; \
+ } \
+ static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \
+ test_name)); \
+ }; \
+ int GTEST_TEST_CLASS_NAME_(test_suite_name, \
+ test_name)::gtest_registering_dummy_ = \
+ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::AddToRegistry(); \
+ void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
+
+// The last argument to INSTANTIATE_TEST_SUITE_P allows the user to specify
+// generator and an optional function or functor that generates custom test name
+// suffixes based on the test parameters. Such a function or functor should
+// accept one argument of type testing::TestParamInfo<class ParamType>, and
+// return std::string.
+//
+// testing::PrintToStringParamName is a builtin test suffix generator that
+// returns the value of testing::PrintToString(GetParam()).
+//
+// Note: test names must be non-empty, unique, and may only contain ASCII
+// alphanumeric characters or underscore. Because PrintToString adds quotes
+// to std::string and C strings, it won't work for these types.
+
+#define GTEST_EXPAND_(arg) arg
+#define GTEST_GET_FIRST_(first, ...) first
+#define GTEST_GET_SECOND_(first, second, ...) second
+
+#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...) \
+ static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
+ gtest_##prefix##test_suite_name##_EvalGenerator_() { \
+ return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_)); \
+ } \
+ static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
+ const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \
+ if (::testing::internal::AlwaysFalse()) { \
+ ::testing::internal::TestNotEmpty(GTEST_EXPAND_(GTEST_GET_SECOND_( \
+ __VA_ARGS__, \
+ ::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
+ DUMMY_PARAM_))); \
+ auto t = std::make_tuple(__VA_ARGS__); \
+ static_assert(std::tuple_size<decltype(t)>::value <= 2, \
+ "Too Many Args!"); \
+ } \
+ return ((GTEST_EXPAND_(GTEST_GET_SECOND_( \
+ __VA_ARGS__, \
+ ::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
+ DUMMY_PARAM_))))(info); \
+ } \
+ static int gtest_##prefix##test_suite_name##_dummy_ \
+ GTEST_ATTRIBUTE_UNUSED_ = \
+ ::testing::UnitTest::GetInstance() \
+ ->parameterized_test_registry() \
+ .GetTestSuitePatternHolder<test_suite_name>( \
+ #test_suite_name, \
+ ::testing::internal::CodeLocation(__FILE__, __LINE__)) \
+ ->AddTestSuiteInstantiation( \
+ #prefix, >est_##prefix##test_suite_name##_EvalGenerator_, \
+ >est_##prefix##test_suite_name##_EvalGenerateName_, \
+ __FILE__, __LINE__)
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+#define INSTANTIATE_TEST_CASE_P \
+ static_assert(::testing::internal::InstantiateTestCase_P_IsDeprecated(), \
+ ""); \
+ INSTANTIATE_TEST_SUITE_P
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+} // namespace testing
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Test - The Google C++ Testing and Mocking Framework
+//
+// This file implements a universal value printer that can print a
+// value of any type T:
+//
+// void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
+//
+// A user can teach this function how to print a class type T by
+// defining either operator<<() or PrintTo() in the namespace that
+// defines T. More specifically, the FIRST defined function in the
+// following list will be used (assuming T is defined in namespace
+// foo):
+//
+// 1. foo::PrintTo(const T&, ostream*)
+// 2. operator<<(ostream&, const T&) defined in either foo or the
+// global namespace.
+//
+// However if T is an STL-style container then it is printed element-wise
+// unless foo::PrintTo(const T&, ostream*) is defined. Note that
+// operator<<() is ignored for container types.
+//
+// If none of the above is defined, it will print the debug string of
+// the value if it is a protocol buffer, or print the raw bytes in the
+// value otherwise.
+//
+// To aid debugging: when T is a reference type, the address of the
+// value is also printed; when T is a (const) char pointer, both the
+// pointer value and the NUL-terminated string it points to are
+// printed.
+//
+// We also provide some convenient wrappers:
+//
+// // Prints a value to a string. For a (const or not) char
+// // pointer, the NUL-terminated string (but not the pointer) is
+// // printed.
+// std::string ::testing::PrintToString(const T& value);
+//
+// // Prints a value tersely: for a reference type, the referenced
+// // value (but not the address) is printed; for a (const or not) char
+// // pointer, the NUL-terminated string (but not the pointer) is
+// // printed.
+// void ::testing::internal::UniversalTersePrint(const T& value, ostream*);
+//
+// // Prints value using the type inferred by the compiler. The difference
+// // from UniversalTersePrint() is that this function prints both the
+// // pointer and the NUL-terminated string for a (const or not) char pointer.
+// void ::testing::internal::UniversalPrint(const T& value, ostream*);
+//
+// // Prints the fields of a tuple tersely to a string vector, one
+// // element for each field. Tuple support must be enabled in
+// // gtest-port.h.
+// std::vector<string> UniversalTersePrintTupleFieldsToStrings(
+// const Tuple& value);
+//
+// Known limitation:
+//
+// The print primitives print the elements of an STL-style container
+// using the compiler-inferred type of *iter where iter is a
+// const_iterator of the container. When const_iterator is an input
+// iterator but not a forward iterator, this inferred type may not
+// match value_type, and the print output may be incorrect. In
+// practice, this is rarely a problem as for most containers
+// const_iterator is a forward iterator. We'll fix this if there's an
+// actual need for it. Note that this fix cannot rely on value_type
+// being defined as many user-defined container types don't have
+// value_type.
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
+#define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
+
+#include <functional>
+#include <ostream> // NOLINT
+#include <sstream>
+#include <string>
+#include <tuple>
+#include <type_traits>
+#include <utility>
+#include <vector>
+#include "gtest/internal/gtest-internal.h"
+#include "gtest/internal/gtest-port.h"
+
+#if GTEST_HAS_ABSL
+#include "absl/strings/string_view.h"
+#include "absl/types/optional.h"
+#include "absl/types/variant.h"
+#endif // GTEST_HAS_ABSL
+
+namespace testing {
+
+// Definitions in the 'internal' and 'internal2' name spaces are
+// subject to change without notice. DO NOT USE THEM IN USER CODE!
+namespace internal2 {
+
+// Prints the given number of bytes in the given object to the given
+// ostream.
+GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes,
+ size_t count,
+ ::std::ostream* os);
+
+// For selecting which printer to use when a given type has neither <<
+// nor PrintTo().
+enum TypeKind {
+ kProtobuf, // a protobuf type
+ kConvertibleToInteger, // a type implicitly convertible to BiggestInt
+ // (e.g. a named or unnamed enum type)
+#if GTEST_HAS_ABSL
+ kConvertibleToStringView, // a type implicitly convertible to
+ // absl::string_view
+#endif
+ kOtherType // anything else
+};
+
+// TypeWithoutFormatter<T, kTypeKind>::PrintValue(value, os) is called
+// by the universal printer to print a value of type T when neither
+// operator<< nor PrintTo() is defined for T, where kTypeKind is the
+// "kind" of T as defined by enum TypeKind.
+template <typename T, TypeKind kTypeKind>
+class TypeWithoutFormatter {
+ public:
+ // This default version is called when kTypeKind is kOtherType.
+ static void PrintValue(const T& value, ::std::ostream* os) {
+ PrintBytesInObjectTo(static_cast<const unsigned char*>(
+ reinterpret_cast<const void*>(&value)),
+ sizeof(value), os);
+ }
+};
+
+// We print a protobuf using its ShortDebugString() when the string
+// doesn't exceed this many characters; otherwise we print it using
+// DebugString() for better readability.
+const size_t kProtobufOneLinerMaxLength = 50;
+
+template <typename T>
+class TypeWithoutFormatter<T, kProtobuf> {
+ public:
+ static void PrintValue(const T& value, ::std::ostream* os) {
+ std::string pretty_str = value.ShortDebugString();
+ if (pretty_str.length() > kProtobufOneLinerMaxLength) {
+ pretty_str = "\n" + value.DebugString();
+ }
+ *os << ("<" + pretty_str + ">");
+ }
+};
+
+template <typename T>
+class TypeWithoutFormatter<T, kConvertibleToInteger> {
+ public:
+ // Since T has no << operator or PrintTo() but can be implicitly
+ // converted to BiggestInt, we print it as a BiggestInt.
+ //
+ // Most likely T is an enum type (either named or unnamed), in which
+ // case printing it as an integer is the desired behavior. In case
+ // T is not an enum, printing it as an integer is the best we can do
+ // given that it has no user-defined printer.
+ static void PrintValue(const T& value, ::std::ostream* os) {
+ const internal::BiggestInt kBigInt = value;
+ *os << kBigInt;
+ }
+};
+
+#if GTEST_HAS_ABSL
+template <typename T>
+class TypeWithoutFormatter<T, kConvertibleToStringView> {
+ public:
+ // Since T has neither operator<< nor PrintTo() but can be implicitly
+ // converted to absl::string_view, we print it as a absl::string_view.
+ //
+ // Note: the implementation is further below, as it depends on
+ // internal::PrintTo symbol which is defined later in the file.
+ static void PrintValue(const T& value, ::std::ostream* os);
+};
+#endif
+
+// Prints the given value to the given ostream. If the value is a
+// protocol message, its debug string is printed; if it's an enum or
+// of a type implicitly convertible to BiggestInt, it's printed as an
+// integer; otherwise the bytes in the value are printed. This is
+// what UniversalPrinter<T>::Print() does when it knows nothing about
+// type T and T has neither << operator nor PrintTo().
+//
+// A user can override this behavior for a class type Foo by defining
+// a << operator in the namespace where Foo is defined.
+//
+// We put this operator in namespace 'internal2' instead of 'internal'
+// to simplify the implementation, as much code in 'internal' needs to
+// use << in STL, which would conflict with our own << were it defined
+// in 'internal'.
+//
+// Note that this operator<< takes a generic std::basic_ostream<Char,
+// CharTraits> type instead of the more restricted std::ostream. If
+// we define it to take an std::ostream instead, we'll get an
+// "ambiguous overloads" compiler error when trying to print a type
+// Foo that supports streaming to std::basic_ostream<Char,
+// CharTraits>, as the compiler cannot tell whether
+// operator<<(std::ostream&, const T&) or
+// operator<<(std::basic_stream<Char, CharTraits>, const Foo&) is more
+// specific.
+template <typename Char, typename CharTraits, typename T>
+::std::basic_ostream<Char, CharTraits>& operator<<(
+ ::std::basic_ostream<Char, CharTraits>& os, const T& x) {
+ TypeWithoutFormatter<T, (internal::IsAProtocolMessage<T>::value
+ ? kProtobuf
+ : std::is_convertible<
+ const T&, internal::BiggestInt>::value
+ ? kConvertibleToInteger
+ :
+#if GTEST_HAS_ABSL
+ std::is_convertible<
+ const T&, absl::string_view>::value
+ ? kConvertibleToStringView
+ :
+#endif
+ kOtherType)>::PrintValue(x, &os);
+ return os;
+}
+
+} // namespace internal2
+} // namespace testing
+
+// This namespace MUST NOT BE NESTED IN ::testing, or the name look-up
+// magic needed for implementing UniversalPrinter won't work.
+namespace testing_internal {
+
+// Used to print a value that is not an STL-style container when the
+// user doesn't define PrintTo() for it.
+template <typename T>
+void DefaultPrintNonContainerTo(const T& value, ::std::ostream* os) {
+ // With the following statement, during unqualified name lookup,
+ // testing::internal2::operator<< appears as if it was declared in
+ // the nearest enclosing namespace that contains both
+ // ::testing_internal and ::testing::internal2, i.e. the global
+ // namespace. For more details, refer to the C++ Standard section
+ // 7.3.4-1 [namespace.udir]. This allows us to fall back onto
+ // testing::internal2::operator<< in case T doesn't come with a <<
+ // operator.
+ //
+ // We cannot write 'using ::testing::internal2::operator<<;', which
+ // gcc 3.3 fails to compile due to a compiler bug.
+ using namespace ::testing::internal2; // NOLINT
+
+ // Assuming T is defined in namespace foo, in the next statement,
+ // the compiler will consider all of:
+ //
+ // 1. foo::operator<< (thanks to Koenig look-up),
+ // 2. ::operator<< (as the current namespace is enclosed in ::),
+ // 3. testing::internal2::operator<< (thanks to the using statement above).
+ //
+ // The operator<< whose type matches T best will be picked.
+ //
+ // We deliberately allow #2 to be a candidate, as sometimes it's
+ // impossible to define #1 (e.g. when foo is ::std, defining
+ // anything in it is undefined behavior unless you are a compiler
+ // vendor.).
+ *os << value;
+}
+
+} // namespace testing_internal
+
+namespace testing {
+namespace internal {
+
+// FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
+// value of type ToPrint that is an operand of a comparison assertion
+// (e.g. ASSERT_EQ). OtherOperand is the type of the other operand in
+// the comparison, and is used to help determine the best way to
+// format the value. In particular, when the value is a C string
+// (char pointer) and the other operand is an STL string object, we
+// want to format the C string as a string, since we know it is
+// compared by value with the string object. If the value is a char
+// pointer but the other operand is not an STL string object, we don't
+// know whether the pointer is supposed to point to a NUL-terminated
+// string, and thus want to print it as a pointer to be safe.
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+
+// The default case.
+template <typename ToPrint, typename OtherOperand>
+class FormatForComparison {
+ public:
+ static ::std::string Format(const ToPrint& value) {
+ return ::testing::PrintToString(value);
+ }
+};
+
+// Array.
+template <typename ToPrint, size_t N, typename OtherOperand>
+class FormatForComparison<ToPrint[N], OtherOperand> {
+ public:
+ static ::std::string Format(const ToPrint* value) {
+ return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
+ }
+};
+
+// By default, print C string as pointers to be safe, as we don't know
+// whether they actually point to a NUL-terminated string.
+
+#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
+ template <typename OtherOperand> \
+ class FormatForComparison<CharType*, OtherOperand> { \
+ public: \
+ static ::std::string Format(CharType* value) { \
+ return ::testing::PrintToString(static_cast<const void*>(value)); \
+ } \
+ }
+
+GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char);
+GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char);
+GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t);
+GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t);
+
+#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
+
+// If a C string is compared with an STL string object, we know it's meant
+// to point to a NUL-terminated string, and thus can print it as a string.
+
+#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
+ template <> \
+ class FormatForComparison<CharType*, OtherStringType> { \
+ public: \
+ static ::std::string Format(CharType* value) { \
+ return ::testing::PrintToString(value); \
+ } \
+ }
+
+GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
+GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string);
+
+#if GTEST_HAS_STD_WSTRING
+GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring);
+GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
+#endif
+
+#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
+
+// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
+// operand to be used in a failure message. The type (but not value)
+// of the other operand may affect the format. This allows us to
+// print a char* as a raw pointer when it is compared against another
+// char* or void*, and print it as a C string when it is compared
+// against an std::string object, for example.
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+template <typename T1, typename T2>
+std::string FormatForComparisonFailureMessage(
+ const T1& value, const T2& /* other_operand */) {
+ return FormatForComparison<T1, T2>::Format(value);
+}
+
+// UniversalPrinter<T>::Print(value, ostream_ptr) prints the given
+// value to the given ostream. The caller must ensure that
+// 'ostream_ptr' is not NULL, or the behavior is undefined.
+//
+// We define UniversalPrinter as a class template (as opposed to a
+// function template), as we need to partially specialize it for
+// reference types, which cannot be done with function templates.
+template <typename T>
+class UniversalPrinter;
+
+template <typename T>
+void UniversalPrint(const T& value, ::std::ostream* os);
+
+enum DefaultPrinterType {
+ kPrintContainer,
+ kPrintPointer,
+ kPrintFunctionPointer,
+ kPrintOther,
+};
+template <DefaultPrinterType type> struct WrapPrinterType {};
+
+// Used to print an STL-style container when the user doesn't define
+// a PrintTo() for it.
+template <typename C>
+void DefaultPrintTo(WrapPrinterType<kPrintContainer> /* dummy */,
+ const C& container, ::std::ostream* os) {
+ const size_t kMaxCount = 32; // The maximum number of elements to print.
+ *os << '{';
+ size_t count = 0;
+ for (typename C::const_iterator it = container.begin();
+ it != container.end(); ++it, ++count) {
+ if (count > 0) {
+ *os << ',';
+ if (count == kMaxCount) { // Enough has been printed.
+ *os << " ...";
+ break;
+ }
+ }
+ *os << ' ';
+ // We cannot call PrintTo(*it, os) here as PrintTo() doesn't
+ // handle *it being a native array.
+ internal::UniversalPrint(*it, os);
+ }
+
+ if (count > 0) {
+ *os << ' ';
+ }
+ *os << '}';
+}
+
+// Used to print a pointer that is neither a char pointer nor a member
+// pointer, when the user doesn't define PrintTo() for it. (A member
+// variable pointer or member function pointer doesn't really point to
+// a location in the address space. Their representation is
+// implementation-defined. Therefore they will be printed as raw
+// bytes.)
+template <typename T>
+void DefaultPrintTo(WrapPrinterType<kPrintPointer> /* dummy */,
+ T* p, ::std::ostream* os) {
+ if (p == nullptr) {
+ *os << "NULL";
+ } else {
+ // T is not a function type. We just call << to print p,
+ // relying on ADL to pick up user-defined << for their pointer
+ // types, if any.
+ *os << p;
+ }
+}
+template <typename T>
+void DefaultPrintTo(WrapPrinterType<kPrintFunctionPointer> /* dummy */,
+ T* p, ::std::ostream* os) {
+ if (p == nullptr) {
+ *os << "NULL";
+ } else {
+ // T is a function type, so '*os << p' doesn't do what we want
+ // (it just prints p as bool). We want to print p as a const
+ // void*.
+ *os << reinterpret_cast<const void*>(p);
+ }
+}
+
+// Used to print a non-container, non-pointer value when the user
+// doesn't define PrintTo() for it.
+template <typename T>
+void DefaultPrintTo(WrapPrinterType<kPrintOther> /* dummy */,
+ const T& value, ::std::ostream* os) {
+ ::testing_internal::DefaultPrintNonContainerTo(value, os);
+}
+
+// Prints the given value using the << operator if it has one;
+// otherwise prints the bytes in it. This is what
+// UniversalPrinter<T>::Print() does when PrintTo() is not specialized
+// or overloaded for type T.
+//
+// A user can override this behavior for a class type Foo by defining
+// an overload of PrintTo() in the namespace where Foo is defined. We
+// give the user this option as sometimes defining a << operator for
+// Foo is not desirable (e.g. the coding style may prevent doing it,
+// or there is already a << operator but it doesn't do what the user
+// wants).
+template <typename T>
+void PrintTo(const T& value, ::std::ostream* os) {
+ // DefaultPrintTo() is overloaded. The type of its first argument
+ // determines which version will be picked.
+ //
+ // Note that we check for container types here, prior to we check
+ // for protocol message types in our operator<<. The rationale is:
+ //
+ // For protocol messages, we want to give people a chance to
+ // override Google Mock's format by defining a PrintTo() or
+ // operator<<. For STL containers, other formats can be
+ // incompatible with Google Mock's format for the container
+ // elements; therefore we check for container types here to ensure
+ // that our format is used.
+ //
+ // Note that MSVC and clang-cl do allow an implicit conversion from
+ // pointer-to-function to pointer-to-object, but clang-cl warns on it.
+ // So don't use ImplicitlyConvertible if it can be helped since it will
+ // cause this warning, and use a separate overload of DefaultPrintTo for
+ // function pointers so that the `*os << p` in the object pointer overload
+ // doesn't cause that warning either.
+ DefaultPrintTo(
+ WrapPrinterType <
+ (sizeof(IsContainerTest<T>(0)) == sizeof(IsContainer)) &&
+ !IsRecursiveContainer<T>::value
+ ? kPrintContainer
+ : !std::is_pointer<T>::value
+ ? kPrintOther
+ : std::is_function<typename std::remove_pointer<T>::type>::value
+ ? kPrintFunctionPointer
+ : kPrintPointer > (),
+ value, os);
+}
+
+// The following list of PrintTo() overloads tells
+// UniversalPrinter<T>::Print() how to print standard types (built-in
+// types, strings, plain arrays, and pointers).
+
+// Overloads for various char types.
+GTEST_API_ void PrintTo(unsigned char c, ::std::ostream* os);
+GTEST_API_ void PrintTo(signed char c, ::std::ostream* os);
+inline void PrintTo(char c, ::std::ostream* os) {
+ // When printing a plain char, we always treat it as unsigned. This
+ // way, the output won't be affected by whether the compiler thinks
+ // char is signed or not.
+ PrintTo(static_cast<unsigned char>(c), os);
+}
+
+// Overloads for other simple built-in types.
+inline void PrintTo(bool x, ::std::ostream* os) {
+ *os << (x ? "true" : "false");
+}
+
+// Overload for wchar_t type.
+// Prints a wchar_t as a symbol if it is printable or as its internal
+// code otherwise and also as its decimal code (except for L'\0').
+// The L'\0' char is printed as "L'\\0'". The decimal code is printed
+// as signed integer when wchar_t is implemented by the compiler
+// as a signed type and is printed as an unsigned integer when wchar_t
+// is implemented as an unsigned type.
+GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os);
+
+// Overloads for C strings.
+GTEST_API_ void PrintTo(const char* s, ::std::ostream* os);
+inline void PrintTo(char* s, ::std::ostream* os) {
+ PrintTo(ImplicitCast_<const char*>(s), os);
+}
+
+// signed/unsigned char is often used for representing binary data, so
+// we print pointers to it as void* to be safe.
+inline void PrintTo(const signed char* s, ::std::ostream* os) {
+ PrintTo(ImplicitCast_<const void*>(s), os);
+}
+inline void PrintTo(signed char* s, ::std::ostream* os) {
+ PrintTo(ImplicitCast_<const void*>(s), os);
+}
+inline void PrintTo(const unsigned char* s, ::std::ostream* os) {
+ PrintTo(ImplicitCast_<const void*>(s), os);
+}
+inline void PrintTo(unsigned char* s, ::std::ostream* os) {
+ PrintTo(ImplicitCast_<const void*>(s), os);
+}
+
+// MSVC can be configured to define wchar_t as a typedef of unsigned
+// short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native
+// type. When wchar_t is a typedef, defining an overload for const
+// wchar_t* would cause unsigned short* be printed as a wide string,
+// possibly causing invalid memory accesses.
+#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
+// Overloads for wide C strings
+GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os);
+inline void PrintTo(wchar_t* s, ::std::ostream* os) {
+ PrintTo(ImplicitCast_<const wchar_t*>(s), os);
+}
+#endif
+
+// Overload for C arrays. Multi-dimensional arrays are printed
+// properly.
+
+// Prints the given number of elements in an array, without printing
+// the curly braces.
+template <typename T>
+void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) {
+ UniversalPrint(a[0], os);
+ for (size_t i = 1; i != count; i++) {
+ *os << ", ";
+ UniversalPrint(a[i], os);
+ }
+}
+
+// Overloads for ::std::string.
+GTEST_API_ void PrintStringTo(const ::std::string&s, ::std::ostream* os);
+inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
+ PrintStringTo(s, os);
+}
+
+// Overloads for ::std::wstring.
+#if GTEST_HAS_STD_WSTRING
+GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);
+inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
+ PrintWideStringTo(s, os);
+}
+#endif // GTEST_HAS_STD_WSTRING
+
+#if GTEST_HAS_ABSL
+// Overload for absl::string_view.
+inline void PrintTo(absl::string_view sp, ::std::ostream* os) {
+ PrintTo(::std::string(sp), os);
+}
+#endif // GTEST_HAS_ABSL
+
+inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; }
+
+template <typename T>
+void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
+ UniversalPrinter<T&>::Print(ref.get(), os);
+}
+
+// Helper function for printing a tuple. T must be instantiated with
+// a tuple type.
+template <typename T>
+void PrintTupleTo(const T&, std::integral_constant<size_t, 0>,
+ ::std::ostream*) {}
+
+template <typename T, size_t I>
+void PrintTupleTo(const T& t, std::integral_constant<size_t, I>,
+ ::std::ostream* os) {
+ PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os);
+ GTEST_INTENTIONAL_CONST_COND_PUSH_()
+ if (I > 1) {
+ GTEST_INTENTIONAL_CONST_COND_POP_()
+ *os << ", ";
+ }
+ UniversalPrinter<typename std::tuple_element<I - 1, T>::type>::Print(
+ std::get<I - 1>(t), os);
+}
+
+template <typename... Types>
+void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
+ *os << "(";
+ PrintTupleTo(t, std::integral_constant<size_t, sizeof...(Types)>(), os);
+ *os << ")";
+}
+
+// Overload for std::pair.
+template <typename T1, typename T2>
+void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
+ *os << '(';
+ // We cannot use UniversalPrint(value.first, os) here, as T1 may be
+ // a reference type. The same for printing value.second.
+ UniversalPrinter<T1>::Print(value.first, os);
+ *os << ", ";
+ UniversalPrinter<T2>::Print(value.second, os);
+ *os << ')';
+}
+
+// Implements printing a non-reference type T by letting the compiler
+// pick the right overload of PrintTo() for T.
+template <typename T>
+class UniversalPrinter {
+ public:
+ // MSVC warns about adding const to a function type, so we want to
+ // disable the warning.
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
+
+ // Note: we deliberately don't call this PrintTo(), as that name
+ // conflicts with ::testing::internal::PrintTo in the body of the
+ // function.
+ static void Print(const T& value, ::std::ostream* os) {
+ // By default, ::testing::internal::PrintTo() is used for printing
+ // the value.
+ //
+ // Thanks to Koenig look-up, if T is a class and has its own
+ // PrintTo() function defined in its namespace, that function will
+ // be visible here. Since it is more specific than the generic ones
+ // in ::testing::internal, it will be picked by the compiler in the
+ // following statement - exactly what we want.
+ PrintTo(value, os);
+ }
+
+ GTEST_DISABLE_MSC_WARNINGS_POP_()
+};
+
+#if GTEST_HAS_ABSL
+
+// Printer for absl::optional
+
+template <typename T>
+class UniversalPrinter<::absl::optional<T>> {
+ public:
+ static void Print(const ::absl::optional<T>& value, ::std::ostream* os) {
+ *os << '(';
+ if (!value) {
+ *os << "nullopt";
+ } else {
+ UniversalPrint(*value, os);
+ }
+ *os << ')';
+ }
+};
+
+// Printer for absl::variant
+
+template <typename... T>
+class UniversalPrinter<::absl::variant<T...>> {
+ public:
+ static void Print(const ::absl::variant<T...>& value, ::std::ostream* os) {
+ *os << '(';
+ absl::visit(Visitor{os}, value);
+ *os << ')';
+ }
+
+ private:
+ struct Visitor {
+ template <typename U>
+ void operator()(const U& u) const {
+ *os << "'" << GetTypeName<U>() << "' with value ";
+ UniversalPrint(u, os);
+ }
+ ::std::ostream* os;
+ };
+};
+
+#endif // GTEST_HAS_ABSL
+
+// UniversalPrintArray(begin, len, os) prints an array of 'len'
+// elements, starting at address 'begin'.
+template <typename T>
+void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
+ if (len == 0) {
+ *os << "{}";
+ } else {
+ *os << "{ ";
+ const size_t kThreshold = 18;
+ const size_t kChunkSize = 8;
+ // If the array has more than kThreshold elements, we'll have to
+ // omit some details by printing only the first and the last
+ // kChunkSize elements.
+ if (len <= kThreshold) {
+ PrintRawArrayTo(begin, len, os);
+ } else {
+ PrintRawArrayTo(begin, kChunkSize, os);
+ *os << ", ..., ";
+ PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os);
+ }
+ *os << " }";
+ }
+}
+// This overload prints a (const) char array compactly.
+GTEST_API_ void UniversalPrintArray(
+ const char* begin, size_t len, ::std::ostream* os);
+
+// This overload prints a (const) wchar_t array compactly.
+GTEST_API_ void UniversalPrintArray(
+ const wchar_t* begin, size_t len, ::std::ostream* os);
+
+// Implements printing an array type T[N].
+template <typename T, size_t N>
+class UniversalPrinter<T[N]> {
+ public:
+ // Prints the given array, omitting some elements when there are too
+ // many.
+ static void Print(const T (&a)[N], ::std::ostream* os) {
+ UniversalPrintArray(a, N, os);
+ }
+};
+
+// Implements printing a reference type T&.
+template <typename T>
+class UniversalPrinter<T&> {
+ public:
+ // MSVC warns about adding const to a function type, so we want to
+ // disable the warning.
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
+
+ static void Print(const T& value, ::std::ostream* os) {
+ // Prints the address of the value. We use reinterpret_cast here
+ // as static_cast doesn't compile when T is a function type.
+ *os << "@" << reinterpret_cast<const void*>(&value) << " ";
+
+ // Then prints the value itself.
+ UniversalPrint(value, os);
+ }
+
+ GTEST_DISABLE_MSC_WARNINGS_POP_()
+};
+
+// Prints a value tersely: for a reference type, the referenced value
+// (but not the address) is printed; for a (const) char pointer, the
+// NUL-terminated string (but not the pointer) is printed.
+
+template <typename T>
+class UniversalTersePrinter {
+ public:
+ static void Print(const T& value, ::std::ostream* os) {
+ UniversalPrint(value, os);
+ }
+};
+template <typename T>
+class UniversalTersePrinter<T&> {
+ public:
+ static void Print(const T& value, ::std::ostream* os) {
+ UniversalPrint(value, os);
+ }
+};
+template <typename T, size_t N>
+class UniversalTersePrinter<T[N]> {
+ public:
+ static void Print(const T (&value)[N], ::std::ostream* os) {
+ UniversalPrinter<T[N]>::Print(value, os);
+ }
+};
+template <>
+class UniversalTersePrinter<const char*> {
+ public:
+ static void Print(const char* str, ::std::ostream* os) {
+ if (str == nullptr) {
+ *os << "NULL";
+ } else {
+ UniversalPrint(std::string(str), os);
+ }
+ }
+};
+template <>
+class UniversalTersePrinter<char*> {
+ public:
+ static void Print(char* str, ::std::ostream* os) {
+ UniversalTersePrinter<const char*>::Print(str, os);
+ }
+};
+
+#if GTEST_HAS_STD_WSTRING
+template <>
+class UniversalTersePrinter<const wchar_t*> {
+ public:
+ static void Print(const wchar_t* str, ::std::ostream* os) {
+ if (str == nullptr) {
+ *os << "NULL";
+ } else {
+ UniversalPrint(::std::wstring(str), os);
+ }
+ }
+};
+#endif
+
+template <>
+class UniversalTersePrinter<wchar_t*> {
+ public:
+ static void Print(wchar_t* str, ::std::ostream* os) {
+ UniversalTersePrinter<const wchar_t*>::Print(str, os);
+ }
+};
+
+template <typename T>
+void UniversalTersePrint(const T& value, ::std::ostream* os) {
+ UniversalTersePrinter<T>::Print(value, os);
+}
+
+// Prints a value using the type inferred by the compiler. The
+// difference between this and UniversalTersePrint() is that for a
+// (const) char pointer, this prints both the pointer and the
+// NUL-terminated string.
+template <typename T>
+void UniversalPrint(const T& value, ::std::ostream* os) {
+ // A workarond for the bug in VC++ 7.1 that prevents us from instantiating
+ // UniversalPrinter with T directly.
+ typedef T T1;
+ UniversalPrinter<T1>::Print(value, os);
+}
+
+typedef ::std::vector< ::std::string> Strings;
+
+ // Tersely prints the first N fields of a tuple to a string vector,
+ // one element for each field.
+template <typename Tuple>
+void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>,
+ Strings*) {}
+template <typename Tuple, size_t I>
+void TersePrintPrefixToStrings(const Tuple& t,
+ std::integral_constant<size_t, I>,
+ Strings* strings) {
+ TersePrintPrefixToStrings(t, std::integral_constant<size_t, I - 1>(),
+ strings);
+ ::std::stringstream ss;
+ UniversalTersePrint(std::get<I - 1>(t), &ss);
+ strings->push_back(ss.str());
+}
+
+// Prints the fields of a tuple tersely to a string vector, one
+// element for each field. See the comment before
+// UniversalTersePrint() for how we define "tersely".
+template <typename Tuple>
+Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
+ Strings result;
+ TersePrintPrefixToStrings(
+ value, std::integral_constant<size_t, std::tuple_size<Tuple>::value>(),
+ &result);
+ return result;
+}
+
+} // namespace internal
+
+#if GTEST_HAS_ABSL
+namespace internal2 {
+template <typename T>
+void TypeWithoutFormatter<T, kConvertibleToStringView>::PrintValue(
+ const T& value, ::std::ostream* os) {
+ internal::PrintTo(absl::string_view(value), os);
+}
+} // namespace internal2
+#endif
+
+template <typename T>
+::std::string PrintToString(const T& value) {
+ ::std::stringstream ss;
+ internal::UniversalTersePrinter<T>::Print(value, &ss);
+ return ss.str();
+}
+
+} // namespace testing
+
+// Include any custom printer added by the local installation.
+// We must include this header at the end to make sure it can use the
+// declarations from this file.
+#include "gtest/internal/custom/gtest-printers.h"
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// Utilities for testing Google Test itself and code that uses Google Test
+// (e.g. frameworks built on top of Google Test).
+
+// GOOGLETEST_CM0004 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
+#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
+
+#include "gtest/gtest.h"
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
+/* class A needs to have dll-interface to be used by clients of class B */)
+
+namespace testing {
+
+// This helper class can be used to mock out Google Test failure reporting
+// so that we can test Google Test or code that builds on Google Test.
+//
+// An object of this class appends a TestPartResult object to the
+// TestPartResultArray object given in the constructor whenever a Google Test
+// failure is reported. It can either intercept only failures that are
+// generated in the same thread that created this object or it can intercept
+// all generated failures. The scope of this mock object can be controlled with
+// the second argument to the two arguments constructor.
+class GTEST_API_ ScopedFakeTestPartResultReporter
+ : public TestPartResultReporterInterface {
+ public:
+ // The two possible mocking modes of this object.
+ enum InterceptMode {
+ INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures.
+ INTERCEPT_ALL_THREADS // Intercepts all failures.
+ };
+
+ // The c'tor sets this object as the test part result reporter used
+ // by Google Test. The 'result' parameter specifies where to report the
+ // results. This reporter will only catch failures generated in the current
+ // thread. DEPRECATED
+ explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result);
+
+ // Same as above, but you can choose the interception scope of this object.
+ ScopedFakeTestPartResultReporter(InterceptMode intercept_mode,
+ TestPartResultArray* result);
+
+ // The d'tor restores the previous test part result reporter.
+ ~ScopedFakeTestPartResultReporter() override;
+
+ // Appends the TestPartResult object to the TestPartResultArray
+ // received in the constructor.
+ //
+ // This method is from the TestPartResultReporterInterface
+ // interface.
+ void ReportTestPartResult(const TestPartResult& result) override;
+
+ private:
+ void Init();
+
+ const InterceptMode intercept_mode_;
+ TestPartResultReporterInterface* old_reporter_;
+ TestPartResultArray* const result_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter);
+};
+
+namespace internal {
+
+// A helper class for implementing EXPECT_FATAL_FAILURE() and
+// EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given
+// TestPartResultArray contains exactly one failure that has the given
+// type and contains the given substring. If that's not the case, a
+// non-fatal failure will be generated.
+class GTEST_API_ SingleFailureChecker {
+ public:
+ // The constructor remembers the arguments.
+ SingleFailureChecker(const TestPartResultArray* results,
+ TestPartResult::Type type, const std::string& substr);
+ ~SingleFailureChecker();
+ private:
+ const TestPartResultArray* const results_;
+ const TestPartResult::Type type_;
+ const std::string substr_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
+};
+
+} // namespace internal
+
+} // namespace testing
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
+
+// A set of macros for testing Google Test assertions or code that's expected
+// to generate Google Test fatal failures. It verifies that the given
+// statement will cause exactly one fatal Google Test failure with 'substr'
+// being part of the failure message.
+//
+// There are two different versions of this macro. EXPECT_FATAL_FAILURE only
+// affects and considers failures generated in the current thread and
+// EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
+//
+// The verification of the assertion is done correctly even when the statement
+// throws an exception or aborts the current function.
+//
+// Known restrictions:
+// - 'statement' cannot reference local non-static variables or
+// non-static members of the current object.
+// - 'statement' cannot return a value.
+// - You cannot stream a failure message to this macro.
+//
+// Note that even though the implementations of the following two
+// macros are much alike, we cannot refactor them to use a common
+// helper macro, due to some peculiarity in how the preprocessor
+// works. The AcceptsMacroThatExpandsToUnprotectedComma test in
+// gtest_unittest.cc will fail to compile if we do that.
+#define EXPECT_FATAL_FAILURE(statement, substr) \
+ do { \
+ class GTestExpectFatalFailureHelper {\
+ public:\
+ static void Execute() { statement; }\
+ };\
+ ::testing::TestPartResultArray gtest_failures;\
+ ::testing::internal::SingleFailureChecker gtest_checker(\
+ >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
+ {\
+ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
+ ::testing::ScopedFakeTestPartResultReporter:: \
+ INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\
+ GTestExpectFatalFailureHelper::Execute();\
+ }\
+ } while (::testing::internal::AlwaysFalse())
+
+#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
+ do { \
+ class GTestExpectFatalFailureHelper {\
+ public:\
+ static void Execute() { statement; }\
+ };\
+ ::testing::TestPartResultArray gtest_failures;\
+ ::testing::internal::SingleFailureChecker gtest_checker(\
+ >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
+ {\
+ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
+ ::testing::ScopedFakeTestPartResultReporter:: \
+ INTERCEPT_ALL_THREADS, >est_failures);\
+ GTestExpectFatalFailureHelper::Execute();\
+ }\
+ } while (::testing::internal::AlwaysFalse())
+
+// A macro for testing Google Test assertions or code that's expected to
+// generate Google Test non-fatal failures. It asserts that the given
+// statement will cause exactly one non-fatal Google Test failure with 'substr'
+// being part of the failure message.
+//
+// There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only
+// affects and considers failures generated in the current thread and
+// EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
+//
+// 'statement' is allowed to reference local variables and members of
+// the current object.
+//
+// The verification of the assertion is done correctly even when the statement
+// throws an exception or aborts the current function.
+//
+// Known restrictions:
+// - You cannot stream a failure message to this macro.
+//
+// Note that even though the implementations of the following two
+// macros are much alike, we cannot refactor them to use a common
+// helper macro, due to some peculiarity in how the preprocessor
+// works. If we do that, the code won't compile when the user gives
+// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that
+// expands to code containing an unprotected comma. The
+// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc
+// catches that.
+//
+// For the same reason, we have to write
+// if (::testing::internal::AlwaysTrue()) { statement; }
+// instead of
+// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
+// to avoid an MSVC warning on unreachable code.
+#define EXPECT_NONFATAL_FAILURE(statement, substr) \
+ do {\
+ ::testing::TestPartResultArray gtest_failures;\
+ ::testing::internal::SingleFailureChecker gtest_checker(\
+ >est_failures, ::testing::TestPartResult::kNonFatalFailure, \
+ (substr));\
+ {\
+ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
+ ::testing::ScopedFakeTestPartResultReporter:: \
+ INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\
+ if (::testing::internal::AlwaysTrue()) { statement; }\
+ }\
+ } while (::testing::internal::AlwaysFalse())
+
+#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
+ do {\
+ ::testing::TestPartResultArray gtest_failures;\
+ ::testing::internal::SingleFailureChecker gtest_checker(\
+ >est_failures, ::testing::TestPartResult::kNonFatalFailure, \
+ (substr));\
+ {\
+ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
+ ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \
+ >est_failures);\
+ if (::testing::internal::AlwaysTrue()) { statement; }\
+ }\
+ } while (::testing::internal::AlwaysFalse())
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
+#define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
+
+#include <iosfwd>
+#include <vector>
+#include "gtest/internal/gtest-internal.h"
+#include "gtest/internal/gtest-string.h"
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
+/* class A needs to have dll-interface to be used by clients of class B */)
+
+namespace testing {
+
+// A copyable object representing the result of a test part (i.e. an
+// assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
+//
+// Don't inherit from TestPartResult as its destructor is not virtual.
+class GTEST_API_ TestPartResult {
+ public:
+ // The possible outcomes of a test part (i.e. an assertion or an
+ // explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
+ enum Type {
+ kSuccess, // Succeeded.
+ kNonFatalFailure, // Failed but the test can continue.
+ kFatalFailure, // Failed and the test should be terminated.
+ kSkip // Skipped.
+ };
+
+ // C'tor. TestPartResult does NOT have a default constructor.
+ // Always use this constructor (with parameters) to create a
+ // TestPartResult object.
+ TestPartResult(Type a_type, const char* a_file_name, int a_line_number,
+ const char* a_message)
+ : type_(a_type),
+ file_name_(a_file_name == nullptr ? "" : a_file_name),
+ line_number_(a_line_number),
+ summary_(ExtractSummary(a_message)),
+ message_(a_message) {}
+
+ // Gets the outcome of the test part.
+ Type type() const { return type_; }
+
+ // Gets the name of the source file where the test part took place, or
+ // NULL if it's unknown.
+ const char* file_name() const {
+ return file_name_.empty() ? nullptr : file_name_.c_str();
+ }
+
+ // Gets the line in the source file where the test part took place,
+ // or -1 if it's unknown.
+ int line_number() const { return line_number_; }
+
+ // Gets the summary of the failure message.
+ const char* summary() const { return summary_.c_str(); }
+
+ // Gets the message associated with the test part.
+ const char* message() const { return message_.c_str(); }
+
+ // Returns true iff the test part was skipped.
+ bool skipped() const { return type_ == kSkip; }
+
+ // Returns true iff the test part passed.
+ bool passed() const { return type_ == kSuccess; }
+
+ // Returns true iff the test part non-fatally failed.
+ bool nonfatally_failed() const { return type_ == kNonFatalFailure; }
+
+ // Returns true iff the test part fatally failed.
+ bool fatally_failed() const { return type_ == kFatalFailure; }
+
+ // Returns true iff the test part failed.
+ bool failed() const { return fatally_failed() || nonfatally_failed(); }
+
+ private:
+ Type type_;
+
+ // Gets the summary of the failure message by omitting the stack
+ // trace in it.
+ static std::string ExtractSummary(const char* message);
+
+ // The name of the source file where the test part took place, or
+ // "" if the source file is unknown.
+ std::string file_name_;
+ // The line in the source file where the test part took place, or -1
+ // if the line number is unknown.
+ int line_number_;
+ std::string summary_; // The test failure summary.
+ std::string message_; // The test failure message.
+};
+
+// Prints a TestPartResult object.
+std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
+
+// An array of TestPartResult objects.
+//
+// Don't inherit from TestPartResultArray as its destructor is not
+// virtual.
+class GTEST_API_ TestPartResultArray {
+ public:
+ TestPartResultArray() {}
+
+ // Appends the given TestPartResult to the array.
+ void Append(const TestPartResult& result);
+
+ // Returns the TestPartResult at the given index (0-based).
+ const TestPartResult& GetTestPartResult(int index) const;
+
+ // Returns the number of TestPartResult objects in the array.
+ int size() const;
+
+ private:
+ std::vector<TestPartResult> array_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray);
+};
+
+// This interface knows how to report a test part result.
+class GTEST_API_ TestPartResultReporterInterface {
+ public:
+ virtual ~TestPartResultReporterInterface() {}
+
+ virtual void ReportTestPartResult(const TestPartResult& result) = 0;
+};
+
+namespace internal {
+
+// This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a
+// statement generates new fatal failures. To do so it registers itself as the
+// current test part result reporter. Besides checking if fatal failures were
+// reported, it only delegates the reporting to the former result reporter.
+// The original result reporter is restored in the destructor.
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+class GTEST_API_ HasNewFatalFailureHelper
+ : public TestPartResultReporterInterface {
+ public:
+ HasNewFatalFailureHelper();
+ ~HasNewFatalFailureHelper() override;
+ void ReportTestPartResult(const TestPartResult& result) override;
+ bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
+ private:
+ bool has_new_fatal_failure_;
+ TestPartResultReporterInterface* original_reporter_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper);
+};
+
+} // namespace internal
+
+} // namespace testing
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
--- /dev/null
+// Copyright 2008 Google Inc.
+// All Rights Reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
+#define GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
+
+// This header implements typed tests and type-parameterized tests.
+
+// Typed (aka type-driven) tests repeat the same test for types in a
+// list. You must know which types you want to test with when writing
+// typed tests. Here's how you do it:
+
+#if 0
+
+// First, define a fixture class template. It should be parameterized
+// by a type. Remember to derive it from testing::Test.
+template <typename T>
+class FooTest : public testing::Test {
+ public:
+ ...
+ typedef std::list<T> List;
+ static T shared_;
+ T value_;
+};
+
+// Next, associate a list of types with the test suite, which will be
+// repeated for each type in the list. The typedef is necessary for
+// the macro to parse correctly.
+typedef testing::Types<char, int, unsigned int> MyTypes;
+TYPED_TEST_SUITE(FooTest, MyTypes);
+
+// If the type list contains only one type, you can write that type
+// directly without Types<...>:
+// TYPED_TEST_SUITE(FooTest, int);
+
+// Then, use TYPED_TEST() instead of TEST_F() to define as many typed
+// tests for this test suite as you want.
+TYPED_TEST(FooTest, DoesBlah) {
+ // Inside a test, refer to TypeParam to get the type parameter.
+ // Since we are inside a derived class template, C++ requires use to
+ // visit the members of FooTest via 'this'.
+ TypeParam n = this->value_;
+
+ // To visit static members of the fixture, add the TestFixture::
+ // prefix.
+ n += TestFixture::shared_;
+
+ // To refer to typedefs in the fixture, add the "typename
+ // TestFixture::" prefix.
+ typename TestFixture::List values;
+ values.push_back(n);
+ ...
+}
+
+TYPED_TEST(FooTest, HasPropertyA) { ... }
+
+// TYPED_TEST_SUITE takes an optional third argument which allows to specify a
+// class that generates custom test name suffixes based on the type. This should
+// be a class which has a static template function GetName(int index) returning
+// a string for each type. The provided integer index equals the index of the
+// type in the provided type list. In many cases the index can be ignored.
+//
+// For example:
+// class MyTypeNames {
+// public:
+// template <typename T>
+// static std::string GetName(int) {
+// if (std::is_same<T, char>()) return "char";
+// if (std::is_same<T, int>()) return "int";
+// if (std::is_same<T, unsigned int>()) return "unsignedInt";
+// }
+// };
+// TYPED_TEST_SUITE(FooTest, MyTypes, MyTypeNames);
+
+#endif // 0
+
+// Type-parameterized tests are abstract test patterns parameterized
+// by a type. Compared with typed tests, type-parameterized tests
+// allow you to define the test pattern without knowing what the type
+// parameters are. The defined pattern can be instantiated with
+// different types any number of times, in any number of translation
+// units.
+//
+// If you are designing an interface or concept, you can define a
+// suite of type-parameterized tests to verify properties that any
+// valid implementation of the interface/concept should have. Then,
+// each implementation can easily instantiate the test suite to verify
+// that it conforms to the requirements, without having to write
+// similar tests repeatedly. Here's an example:
+
+#if 0
+
+// First, define a fixture class template. It should be parameterized
+// by a type. Remember to derive it from testing::Test.
+template <typename T>
+class FooTest : public testing::Test {
+ ...
+};
+
+// Next, declare that you will define a type-parameterized test suite
+// (the _P suffix is for "parameterized" or "pattern", whichever you
+// prefer):
+TYPED_TEST_SUITE_P(FooTest);
+
+// Then, use TYPED_TEST_P() to define as many type-parameterized tests
+// for this type-parameterized test suite as you want.
+TYPED_TEST_P(FooTest, DoesBlah) {
+ // Inside a test, refer to TypeParam to get the type parameter.
+ TypeParam n = 0;
+ ...
+}
+
+TYPED_TEST_P(FooTest, HasPropertyA) { ... }
+
+// Now the tricky part: you need to register all test patterns before
+// you can instantiate them. The first argument of the macro is the
+// test suite name; the rest are the names of the tests in this test
+// case.
+REGISTER_TYPED_TEST_SUITE_P(FooTest,
+ DoesBlah, HasPropertyA);
+
+// Finally, you are free to instantiate the pattern with the types you
+// want. If you put the above code in a header file, you can #include
+// it in multiple C++ source files and instantiate it multiple times.
+//
+// To distinguish different instances of the pattern, the first
+// argument to the INSTANTIATE_* macro is a prefix that will be added
+// to the actual test suite name. Remember to pick unique prefixes for
+// different instances.
+typedef testing::Types<char, int, unsigned int> MyTypes;
+INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
+
+// If the type list contains only one type, you can write that type
+// directly without Types<...>:
+// INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, int);
+//
+// Similar to the optional argument of TYPED_TEST_SUITE above,
+// INSTANTIATE_TEST_SUITE_P takes an optional fourth argument which allows to
+// generate custom names.
+// INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes, MyTypeNames);
+
+#endif // 0
+
+#include "gtest/internal/gtest-port.h"
+#include "gtest/internal/gtest-type-util.h"
+
+// Implements typed tests.
+
+#if GTEST_HAS_TYPED_TEST
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// Expands to the name of the typedef for the type parameters of the
+// given test suite.
+#define GTEST_TYPE_PARAMS_(TestSuiteName) gtest_type_params_##TestSuiteName##_
+
+// Expands to the name of the typedef for the NameGenerator, responsible for
+// creating the suffixes of the name.
+#define GTEST_NAME_GENERATOR_(TestSuiteName) \
+ gtest_type_params_##TestSuiteName##_NameGenerator
+
+// The 'Types' template argument below must have spaces around it
+// since some compilers may choke on '>>' when passing a template
+// instance (e.g. Types<int>)
+#define TYPED_TEST_SUITE(CaseName, Types, ...) \
+ typedef ::testing::internal::TypeList<Types>::type GTEST_TYPE_PARAMS_( \
+ CaseName); \
+ typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
+ GTEST_NAME_GENERATOR_(CaseName)
+
+# define TYPED_TEST(CaseName, TestName) \
+ template <typename gtest_TypeParam_> \
+ class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
+ : public CaseName<gtest_TypeParam_> { \
+ private: \
+ typedef CaseName<gtest_TypeParam_> TestFixture; \
+ typedef gtest_TypeParam_ TypeParam; \
+ virtual void TestBody(); \
+ }; \
+ static bool gtest_##CaseName##_##TestName##_registered_ \
+ GTEST_ATTRIBUTE_UNUSED_ = \
+ ::testing::internal::TypeParameterizedTest< \
+ CaseName, \
+ ::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_(CaseName, \
+ TestName)>, \
+ GTEST_TYPE_PARAMS_( \
+ CaseName)>::Register("", \
+ ::testing::internal::CodeLocation( \
+ __FILE__, __LINE__), \
+ #CaseName, #TestName, 0, \
+ ::testing::internal::GenerateNames< \
+ GTEST_NAME_GENERATOR_(CaseName), \
+ GTEST_TYPE_PARAMS_(CaseName)>()); \
+ template <typename gtest_TypeParam_> \
+ void GTEST_TEST_CLASS_NAME_(CaseName, \
+ TestName)<gtest_TypeParam_>::TestBody()
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+#define TYPED_TEST_CASE \
+ static_assert(::testing::internal::TypedTestCaseIsDeprecated(), ""); \
+ TYPED_TEST_SUITE
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+#endif // GTEST_HAS_TYPED_TEST
+
+// Implements type-parameterized tests.
+
+#if GTEST_HAS_TYPED_TEST_P
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// Expands to the namespace name that the type-parameterized tests for
+// the given type-parameterized test suite are defined in. The exact
+// name of the namespace is subject to change without notice.
+#define GTEST_SUITE_NAMESPACE_(TestSuiteName) gtest_suite_##TestSuiteName##_
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// Expands to the name of the variable used to remember the names of
+// the defined tests in the given test suite.
+#define GTEST_TYPED_TEST_SUITE_P_STATE_(TestSuiteName) \
+ gtest_typed_test_suite_p_state_##TestSuiteName##_
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
+//
+// Expands to the name of the variable used to remember the names of
+// the registered tests in the given test suite.
+#define GTEST_REGISTERED_TEST_NAMES_(TestSuiteName) \
+ gtest_registered_test_names_##TestSuiteName##_
+
+// The variables defined in the type-parameterized test macros are
+// static as typically these macros are used in a .h file that can be
+// #included in multiple translation units linked together.
+#define TYPED_TEST_SUITE_P(SuiteName) \
+ static ::testing::internal::TypedTestSuitePState \
+ GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName)
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+#define TYPED_TEST_CASE_P \
+ static_assert(::testing::internal::TypedTestCase_P_IsDeprecated(), ""); \
+ TYPED_TEST_SUITE_P
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+#define TYPED_TEST_P(SuiteName, TestName) \
+ namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
+ template <typename gtest_TypeParam_> \
+ class TestName : public SuiteName<gtest_TypeParam_> { \
+ private: \
+ typedef SuiteName<gtest_TypeParam_> TestFixture; \
+ typedef gtest_TypeParam_ TypeParam; \
+ virtual void TestBody(); \
+ }; \
+ static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \
+ GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \
+ __FILE__, __LINE__, #SuiteName, #TestName); \
+ } \
+ template <typename gtest_TypeParam_> \
+ void GTEST_SUITE_NAMESPACE_( \
+ SuiteName)::TestName<gtest_TypeParam_>::TestBody()
+
+#define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \
+ namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
+ typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
+ } \
+ static const char* const GTEST_REGISTERED_TEST_NAMES_( \
+ SuiteName) GTEST_ATTRIBUTE_UNUSED_ = \
+ GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \
+ __FILE__, __LINE__, #__VA_ARGS__)
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+#define REGISTER_TYPED_TEST_CASE_P \
+ static_assert(::testing::internal::RegisterTypedTestCase_P_IsDeprecated(), \
+ ""); \
+ REGISTER_TYPED_TEST_SUITE_P
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+// The 'Types' template argument below must have spaces around it
+// since some compilers may choke on '>>' when passing a template
+// instance (e.g. Types<int>)
+#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \
+ static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \
+ ::testing::internal::TypeParameterizedTestSuite< \
+ SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \
+ ::testing::internal::TypeList<Types>::type>:: \
+ Register(#Prefix, \
+ ::testing::internal::CodeLocation(__FILE__, __LINE__), \
+ >EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), #SuiteName, \
+ GTEST_REGISTERED_TEST_NAMES_(SuiteName), \
+ ::testing::internal::GenerateNames< \
+ ::testing::internal::NameGeneratorSelector< \
+ __VA_ARGS__>::type, \
+ ::testing::internal::TypeList<Types>::type>())
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+#define INSTANTIATE_TYPED_TEST_CASE_P \
+ static_assert( \
+ ::testing::internal::InstantiateTypedTestCase_P_IsDeprecated(), ""); \
+ INSTANTIATE_TYPED_TEST_SUITE_P
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+#endif // GTEST_HAS_TYPED_TEST_P
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
--- /dev/null
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// The Google C++ Testing and Mocking Framework (Google Test)
+//
+// This header file defines the public API for Google Test. It should be
+// included by any test program that uses Google Test.
+//
+// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
+// leave some internal implementation details in this header file.
+// They are clearly marked by comments like this:
+//
+// // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+//
+// Such code is NOT meant to be used by a user directly, and is subject
+// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
+// program!
+//
+// Acknowledgment: Google Test borrowed the idea of automatic test
+// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
+// easyUnit framework.
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
+#define GTEST_INCLUDE_GTEST_GTEST_H_
+
+#include <cstddef>
+#include <limits>
+#include <memory>
+#include <ostream>
+#include <type_traits>
+#include <vector>
+
+#include "gtest/internal/gtest-internal.h"
+#include "gtest/internal/gtest-string.h"
+#include "gtest/gtest-death-test.h"
+#include "gtest/gtest-matchers.h"
+#include "gtest/gtest-message.h"
+#include "gtest/gtest-param-test.h"
+#include "gtest/gtest-printers.h"
+#include "gtest/gtest_prod.h"
+#include "gtest/gtest-test-part.h"
+#include "gtest/gtest-typed-test.h"
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
+/* class A needs to have dll-interface to be used by clients of class B */)
+
+namespace testing {
+
+// Silence C4100 (unreferenced formal parameter) and 4805
+// unsafe mix of type 'const int' and type 'const bool'
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable:4805)
+# pragma warning(disable:4100)
+#endif
+
+
+// Declares the flags.
+
+// This flag temporary enables the disabled tests.
+GTEST_DECLARE_bool_(also_run_disabled_tests);
+
+// This flag brings the debugger on an assertion failure.
+GTEST_DECLARE_bool_(break_on_failure);
+
+// This flag controls whether Google Test catches all test-thrown exceptions
+// and logs them as failures.
+GTEST_DECLARE_bool_(catch_exceptions);
+
+// This flag enables using colors in terminal output. Available values are
+// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
+// to let Google Test decide.
+GTEST_DECLARE_string_(color);
+
+// This flag sets up the filter to select by name using a glob pattern
+// the tests to run. If the filter is not given all tests are executed.
+GTEST_DECLARE_string_(filter);
+
+// This flag controls whether Google Test installs a signal handler that dumps
+// debugging information when fatal signals are raised.
+GTEST_DECLARE_bool_(install_failure_signal_handler);
+
+// This flag causes the Google Test to list tests. None of the tests listed
+// are actually run if the flag is provided.
+GTEST_DECLARE_bool_(list_tests);
+
+// This flag controls whether Google Test emits a detailed XML report to a file
+// in addition to its normal textual output.
+GTEST_DECLARE_string_(output);
+
+// This flags control whether Google Test prints the elapsed time for each
+// test.
+GTEST_DECLARE_bool_(print_time);
+
+// This flags control whether Google Test prints UTF8 characters as text.
+GTEST_DECLARE_bool_(print_utf8);
+
+// This flag specifies the random number seed.
+GTEST_DECLARE_int32_(random_seed);
+
+// This flag sets how many times the tests are repeated. The default value
+// is 1. If the value is -1 the tests are repeating forever.
+GTEST_DECLARE_int32_(repeat);
+
+// This flag controls whether Google Test includes Google Test internal
+// stack frames in failure stack traces.
+GTEST_DECLARE_bool_(show_internal_stack_frames);
+
+// When this flag is specified, tests' order is randomized on every iteration.
+GTEST_DECLARE_bool_(shuffle);
+
+// This flag specifies the maximum number of stack frames to be
+// printed in a failure message.
+GTEST_DECLARE_int32_(stack_trace_depth);
+
+// When this flag is specified, a failed assertion will throw an
+// exception if exceptions are enabled, or exit the program with a
+// non-zero code otherwise. For use with an external test framework.
+GTEST_DECLARE_bool_(throw_on_failure);
+
+// When this flag is set with a "host:port" string, on supported
+// platforms test results are streamed to the specified port on
+// the specified host machine.
+GTEST_DECLARE_string_(stream_result_to);
+
+#if GTEST_USE_OWN_FLAGFILE_FLAG_
+GTEST_DECLARE_string_(flagfile);
+#endif // GTEST_USE_OWN_FLAGFILE_FLAG_
+
+// The upper limit for valid stack trace depths.
+const int kMaxStackTraceDepth = 100;
+
+namespace internal {
+
+class AssertHelper;
+class DefaultGlobalTestPartResultReporter;
+class ExecDeathTest;
+class NoExecDeathTest;
+class FinalSuccessChecker;
+class GTestFlagSaver;
+class StreamingListenerTest;
+class TestResultAccessor;
+class TestEventListenersAccessor;
+class TestEventRepeater;
+class UnitTestRecordPropertyTestHelper;
+class WindowsDeathTest;
+class FuchsiaDeathTest;
+class UnitTestImpl* GetUnitTestImpl();
+void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
+ const std::string& message);
+
+} // namespace internal
+
+// The friend relationship of some of these classes is cyclic.
+// If we don't forward declare them the compiler might confuse the classes
+// in friendship clauses with same named classes on the scope.
+class Test;
+class TestSuite;
+
+// Old API is still available but deprecated
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+using TestCase = TestSuite;
+#endif
+class TestInfo;
+class UnitTest;
+
+// A class for indicating whether an assertion was successful. When
+// the assertion wasn't successful, the AssertionResult object
+// remembers a non-empty message that describes how it failed.
+//
+// To create an instance of this class, use one of the factory functions
+// (AssertionSuccess() and AssertionFailure()).
+//
+// This class is useful for two purposes:
+// 1. Defining predicate functions to be used with Boolean test assertions
+// EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
+// 2. Defining predicate-format functions to be
+// used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
+//
+// For example, if you define IsEven predicate:
+//
+// testing::AssertionResult IsEven(int n) {
+// if ((n % 2) == 0)
+// return testing::AssertionSuccess();
+// else
+// return testing::AssertionFailure() << n << " is odd";
+// }
+//
+// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
+// will print the message
+//
+// Value of: IsEven(Fib(5))
+// Actual: false (5 is odd)
+// Expected: true
+//
+// instead of a more opaque
+//
+// Value of: IsEven(Fib(5))
+// Actual: false
+// Expected: true
+//
+// in case IsEven is a simple Boolean predicate.
+//
+// If you expect your predicate to be reused and want to support informative
+// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
+// about half as often as positive ones in our tests), supply messages for
+// both success and failure cases:
+//
+// testing::AssertionResult IsEven(int n) {
+// if ((n % 2) == 0)
+// return testing::AssertionSuccess() << n << " is even";
+// else
+// return testing::AssertionFailure() << n << " is odd";
+// }
+//
+// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
+//
+// Value of: IsEven(Fib(6))
+// Actual: true (8 is even)
+// Expected: false
+//
+// NB: Predicates that support negative Boolean assertions have reduced
+// performance in positive ones so be careful not to use them in tests
+// that have lots (tens of thousands) of positive Boolean assertions.
+//
+// To use this class with EXPECT_PRED_FORMAT assertions such as:
+//
+// // Verifies that Foo() returns an even number.
+// EXPECT_PRED_FORMAT1(IsEven, Foo());
+//
+// you need to define:
+//
+// testing::AssertionResult IsEven(const char* expr, int n) {
+// if ((n % 2) == 0)
+// return testing::AssertionSuccess();
+// else
+// return testing::AssertionFailure()
+// << "Expected: " << expr << " is even\n Actual: it's " << n;
+// }
+//
+// If Foo() returns 5, you will see the following message:
+//
+// Expected: Foo() is even
+// Actual: it's 5
+//
+class GTEST_API_ AssertionResult {
+ public:
+ // Copy constructor.
+ // Used in EXPECT_TRUE/FALSE(assertion_result).
+ AssertionResult(const AssertionResult& other);
+
+#if defined(_MSC_VER) && _MSC_VER < 1910
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */)
+#endif
+
+ // Used in the EXPECT_TRUE/FALSE(bool_expression).
+ //
+ // T must be contextually convertible to bool.
+ //
+ // The second parameter prevents this overload from being considered if
+ // the argument is implicitly convertible to AssertionResult. In that case
+ // we want AssertionResult's copy constructor to be used.
+ template <typename T>
+ explicit AssertionResult(
+ const T& success,
+ typename internal::EnableIf<
+ !std::is_convertible<T, AssertionResult>::value>::type*
+ /*enabler*/
+ = nullptr)
+ : success_(success) {}
+
+#if defined(_MSC_VER) && _MSC_VER < 1910
+ GTEST_DISABLE_MSC_WARNINGS_POP_()
+#endif
+
+ // Assignment operator.
+ AssertionResult& operator=(AssertionResult other) {
+ swap(other);
+ return *this;
+ }
+
+ // Returns true iff the assertion succeeded.
+ operator bool() const { return success_; } // NOLINT
+
+ // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
+ AssertionResult operator!() const;
+
+ // Returns the text streamed into this AssertionResult. Test assertions
+ // use it when they fail (i.e., the predicate's outcome doesn't match the
+ // assertion's expectation). When nothing has been streamed into the
+ // object, returns an empty string.
+ const char* message() const {
+ return message_.get() != nullptr ? message_->c_str() : "";
+ }
+ // Deprecated; please use message() instead.
+ const char* failure_message() const { return message(); }
+
+ // Streams a custom failure message into this object.
+ template <typename T> AssertionResult& operator<<(const T& value) {
+ AppendMessage(Message() << value);
+ return *this;
+ }
+
+ // Allows streaming basic output manipulators such as endl or flush into
+ // this object.
+ AssertionResult& operator<<(
+ ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
+ AppendMessage(Message() << basic_manipulator);
+ return *this;
+ }
+
+ private:
+ // Appends the contents of message to message_.
+ void AppendMessage(const Message& a_message) {
+ if (message_.get() == nullptr) message_.reset(new ::std::string);
+ message_->append(a_message.GetString().c_str());
+ }
+
+ // Swap the contents of this AssertionResult with other.
+ void swap(AssertionResult& other);
+
+ // Stores result of the assertion predicate.
+ bool success_;
+ // Stores the message describing the condition in case the expectation
+ // construct is not satisfied with the predicate's outcome.
+ // Referenced via a pointer to avoid taking too much stack frame space
+ // with test assertions.
+ std::unique_ptr< ::std::string> message_;
+};
+
+// Makes a successful assertion result.
+GTEST_API_ AssertionResult AssertionSuccess();
+
+// Makes a failed assertion result.
+GTEST_API_ AssertionResult AssertionFailure();
+
+// Makes a failed assertion result with the given failure message.
+// Deprecated; use AssertionFailure() << msg.
+GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
+
+} // namespace testing
+
+// Includes the auto-generated header that implements a family of generic
+// predicate assertion macros. This include comes late because it relies on
+// APIs declared above.
+#include "gtest/gtest_pred_impl.h"
+
+namespace testing {
+
+// The abstract class that all tests inherit from.
+//
+// In Google Test, a unit test program contains one or many TestSuites, and
+// each TestSuite contains one or many Tests.
+//
+// When you define a test using the TEST macro, you don't need to
+// explicitly derive from Test - the TEST macro automatically does
+// this for you.
+//
+// The only time you derive from Test is when defining a test fixture
+// to be used in a TEST_F. For example:
+//
+// class FooTest : public testing::Test {
+// protected:
+// void SetUp() override { ... }
+// void TearDown() override { ... }
+// ...
+// };
+//
+// TEST_F(FooTest, Bar) { ... }
+// TEST_F(FooTest, Baz) { ... }
+//
+// Test is not copyable.
+class GTEST_API_ Test {
+ public:
+ friend class TestInfo;
+
+ // The d'tor is virtual as we intend to inherit from Test.
+ virtual ~Test();
+
+ // Sets up the stuff shared by all tests in this test case.
+ //
+ // Google Test will call Foo::SetUpTestSuite() before running the first
+ // test in test case Foo. Hence a sub-class can define its own
+ // SetUpTestSuite() method to shadow the one defined in the super
+ // class.
+ static void SetUpTestSuite() {}
+
+ // Tears down the stuff shared by all tests in this test case.
+ //
+ // Google Test will call Foo::TearDownTestSuite() after running the last
+ // test in test case Foo. Hence a sub-class can define its own
+ // TearDownTestSuite() method to shadow the one defined in the super
+ // class.
+ static void TearDownTestSuite() {}
+
+ // Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ static void TearDownTestCase() {}
+ static void SetUpTestCase() {}
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+ // Returns true iff the current test has a fatal failure.
+ static bool HasFatalFailure();
+
+ // Returns true iff the current test has a non-fatal failure.
+ static bool HasNonfatalFailure();
+
+ // Returns true iff the current test was skipped.
+ static bool IsSkipped();
+
+ // Returns true iff the current test has a (either fatal or
+ // non-fatal) failure.
+ static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
+
+ // Logs a property for the current test, test suite, or for the entire
+ // invocation of the test program when used outside of the context of a
+ // test suite. Only the last value for a given key is remembered. These
+ // are public static so they can be called from utility functions that are
+ // not members of the test fixture. Calls to RecordProperty made during
+ // lifespan of the test (from the moment its constructor starts to the
+ // moment its destructor finishes) will be output in XML as attributes of
+ // the <testcase> element. Properties recorded from fixture's
+ // SetUpTestSuite or TearDownTestSuite are logged as attributes of the
+ // corresponding <testsuite> element. Calls to RecordProperty made in the
+ // global context (before or after invocation of RUN_ALL_TESTS and from
+ // SetUp/TearDown method of Environment objects registered with Google
+ // Test) will be output as attributes of the <testsuites> element.
+ static void RecordProperty(const std::string& key, const std::string& value);
+ static void RecordProperty(const std::string& key, int value);
+
+ protected:
+ // Creates a Test object.
+ Test();
+
+ // Sets up the test fixture.
+ virtual void SetUp();
+
+ // Tears down the test fixture.
+ virtual void TearDown();
+
+ private:
+ // Returns true iff the current test has the same fixture class as
+ // the first test in the current test suite.
+ static bool HasSameFixtureClass();
+
+ // Runs the test after the test fixture has been set up.
+ //
+ // A sub-class must implement this to define the test logic.
+ //
+ // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
+ // Instead, use the TEST or TEST_F macro.
+ virtual void TestBody() = 0;
+
+ // Sets up, executes, and tears down the test.
+ void Run();
+
+ // Deletes self. We deliberately pick an unusual name for this
+ // internal method to avoid clashing with names used in user TESTs.
+ void DeleteSelf_() { delete this; }
+
+ const std::unique_ptr<GTEST_FLAG_SAVER_> gtest_flag_saver_;
+
+ // Often a user misspells SetUp() as Setup() and spends a long time
+ // wondering why it is never called by Google Test. The declaration of
+ // the following method is solely for catching such an error at
+ // compile time:
+ //
+ // - The return type is deliberately chosen to be not void, so it
+ // will be a conflict if void Setup() is declared in the user's
+ // test fixture.
+ //
+ // - This method is private, so it will be another compiler error
+ // if the method is called from the user's test fixture.
+ //
+ // DO NOT OVERRIDE THIS FUNCTION.
+ //
+ // If you see an error about overriding the following function or
+ // about it being private, you have mis-spelled SetUp() as Setup().
+ struct Setup_should_be_spelled_SetUp {};
+ virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; }
+
+ // We disallow copying Tests.
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
+};
+
+typedef internal::TimeInMillis TimeInMillis;
+
+// A copyable object representing a user specified test property which can be
+// output as a key/value string pair.
+//
+// Don't inherit from TestProperty as its destructor is not virtual.
+class TestProperty {
+ public:
+ // C'tor. TestProperty does NOT have a default constructor.
+ // Always use this constructor (with parameters) to create a
+ // TestProperty object.
+ TestProperty(const std::string& a_key, const std::string& a_value) :
+ key_(a_key), value_(a_value) {
+ }
+
+ // Gets the user supplied key.
+ const char* key() const {
+ return key_.c_str();
+ }
+
+ // Gets the user supplied value.
+ const char* value() const {
+ return value_.c_str();
+ }
+
+ // Sets a new value, overriding the one supplied in the constructor.
+ void SetValue(const std::string& new_value) {
+ value_ = new_value;
+ }
+
+ private:
+ // The key supplied by the user.
+ std::string key_;
+ // The value supplied by the user.
+ std::string value_;
+};
+
+// The result of a single Test. This includes a list of
+// TestPartResults, a list of TestProperties, a count of how many
+// death tests there are in the Test, and how much time it took to run
+// the Test.
+//
+// TestResult is not copyable.
+class GTEST_API_ TestResult {
+ public:
+ // Creates an empty TestResult.
+ TestResult();
+
+ // D'tor. Do not inherit from TestResult.
+ ~TestResult();
+
+ // Gets the number of all test parts. This is the sum of the number
+ // of successful test parts and the number of failed test parts.
+ int total_part_count() const;
+
+ // Returns the number of the test properties.
+ int test_property_count() const;
+
+ // Returns true iff the test passed (i.e. no test part failed).
+ bool Passed() const { return !Skipped() && !Failed(); }
+
+ // Returns true iff the test was skipped.
+ bool Skipped() const;
+
+ // Returns true iff the test failed.
+ bool Failed() const;
+
+ // Returns true iff the test fatally failed.
+ bool HasFatalFailure() const;
+
+ // Returns true iff the test has a non-fatal failure.
+ bool HasNonfatalFailure() const;
+
+ // Returns the elapsed time, in milliseconds.
+ TimeInMillis elapsed_time() const { return elapsed_time_; }
+
+ // Returns the i-th test part result among all the results. i can range from 0
+ // to total_part_count() - 1. If i is not in that range, aborts the program.
+ const TestPartResult& GetTestPartResult(int i) const;
+
+ // Returns the i-th test property. i can range from 0 to
+ // test_property_count() - 1. If i is not in that range, aborts the
+ // program.
+ const TestProperty& GetTestProperty(int i) const;
+
+ private:
+ friend class TestInfo;
+ friend class TestSuite;
+ friend class UnitTest;
+ friend class internal::DefaultGlobalTestPartResultReporter;
+ friend class internal::ExecDeathTest;
+ friend class internal::TestResultAccessor;
+ friend class internal::UnitTestImpl;
+ friend class internal::WindowsDeathTest;
+ friend class internal::FuchsiaDeathTest;
+
+ // Gets the vector of TestPartResults.
+ const std::vector<TestPartResult>& test_part_results() const {
+ return test_part_results_;
+ }
+
+ // Gets the vector of TestProperties.
+ const std::vector<TestProperty>& test_properties() const {
+ return test_properties_;
+ }
+
+ // Sets the elapsed time.
+ void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
+
+ // Adds a test property to the list. The property is validated and may add
+ // a non-fatal failure if invalid (e.g., if it conflicts with reserved
+ // key names). If a property is already recorded for the same key, the
+ // value will be updated, rather than storing multiple values for the same
+ // key. xml_element specifies the element for which the property is being
+ // recorded and is used for validation.
+ void RecordProperty(const std::string& xml_element,
+ const TestProperty& test_property);
+
+ // Adds a failure if the key is a reserved attribute of Google Test
+ // testsuite tags. Returns true if the property is valid.
+ // FIXME: Validate attribute names are legal and human readable.
+ static bool ValidateTestProperty(const std::string& xml_element,
+ const TestProperty& test_property);
+
+ // Adds a test part result to the list.
+ void AddTestPartResult(const TestPartResult& test_part_result);
+
+ // Returns the death test count.
+ int death_test_count() const { return death_test_count_; }
+
+ // Increments the death test count, returning the new count.
+ int increment_death_test_count() { return ++death_test_count_; }
+
+ // Clears the test part results.
+ void ClearTestPartResults();
+
+ // Clears the object.
+ void Clear();
+
+ // Protects mutable state of the property vector and of owned
+ // properties, whose values may be updated.
+ internal::Mutex test_properites_mutex_;
+
+ // The vector of TestPartResults
+ std::vector<TestPartResult> test_part_results_;
+ // The vector of TestProperties
+ std::vector<TestProperty> test_properties_;
+ // Running count of death tests.
+ int death_test_count_;
+ // The elapsed time, in milliseconds.
+ TimeInMillis elapsed_time_;
+
+ // We disallow copying TestResult.
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
+}; // class TestResult
+
+// A TestInfo object stores the following information about a test:
+//
+// Test suite name
+// Test name
+// Whether the test should be run
+// A function pointer that creates the test object when invoked
+// Test result
+//
+// The constructor of TestInfo registers itself with the UnitTest
+// singleton such that the RUN_ALL_TESTS() macro knows which tests to
+// run.
+class GTEST_API_ TestInfo {
+ public:
+ // Destructs a TestInfo object. This function is not virtual, so
+ // don't inherit from TestInfo.
+ ~TestInfo();
+
+ // Returns the test suite name.
+ const char* test_suite_name() const { return test_suite_name_.c_str(); }
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ const char* test_case_name() const { return test_suite_name(); }
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+ // Returns the test name.
+ const char* name() const { return name_.c_str(); }
+
+ // Returns the name of the parameter type, or NULL if this is not a typed
+ // or a type-parameterized test.
+ const char* type_param() const {
+ if (type_param_.get() != nullptr) return type_param_->c_str();
+ return nullptr;
+ }
+
+ // Returns the text representation of the value parameter, or NULL if this
+ // is not a value-parameterized test.
+ const char* value_param() const {
+ if (value_param_.get() != nullptr) return value_param_->c_str();
+ return nullptr;
+ }
+
+ // Returns the file name where this test is defined.
+ const char* file() const { return location_.file.c_str(); }
+
+ // Returns the line where this test is defined.
+ int line() const { return location_.line; }
+
+ // Return true if this test should not be run because it's in another shard.
+ bool is_in_another_shard() const { return is_in_another_shard_; }
+
+ // Returns true if this test should run, that is if the test is not
+ // disabled (or it is disabled but the also_run_disabled_tests flag has
+ // been specified) and its full name matches the user-specified filter.
+ //
+ // Google Test allows the user to filter the tests by their full names.
+ // The full name of a test Bar in test suite Foo is defined as
+ // "Foo.Bar". Only the tests that match the filter will run.
+ //
+ // A filter is a colon-separated list of glob (not regex) patterns,
+ // optionally followed by a '-' and a colon-separated list of
+ // negative patterns (tests to exclude). A test is run if it
+ // matches one of the positive patterns and does not match any of
+ // the negative patterns.
+ //
+ // For example, *A*:Foo.* is a filter that matches any string that
+ // contains the character 'A' or starts with "Foo.".
+ bool should_run() const { return should_run_; }
+
+ // Returns true iff this test will appear in the XML report.
+ bool is_reportable() const {
+ // The XML report includes tests matching the filter, excluding those
+ // run in other shards.
+ return matches_filter_ && !is_in_another_shard_;
+ }
+
+ // Returns the result of the test.
+ const TestResult* result() const { return &result_; }
+
+ private:
+#if GTEST_HAS_DEATH_TEST
+ friend class internal::DefaultDeathTestFactory;
+#endif // GTEST_HAS_DEATH_TEST
+ friend class Test;
+ friend class TestSuite;
+ friend class internal::UnitTestImpl;
+ friend class internal::StreamingListenerTest;
+ friend TestInfo* internal::MakeAndRegisterTestInfo(
+ const char* test_suite_name, const char* name, const char* type_param,
+ const char* value_param, internal::CodeLocation code_location,
+ internal::TypeId fixture_class_id, internal::SetUpTestSuiteFunc set_up_tc,
+ internal::TearDownTestSuiteFunc tear_down_tc,
+ internal::TestFactoryBase* factory);
+
+ // Constructs a TestInfo object. The newly constructed instance assumes
+ // ownership of the factory object.
+ TestInfo(const std::string& test_suite_name, const std::string& name,
+ const char* a_type_param, // NULL if not a type-parameterized test
+ const char* a_value_param, // NULL if not a value-parameterized test
+ internal::CodeLocation a_code_location,
+ internal::TypeId fixture_class_id,
+ internal::TestFactoryBase* factory);
+
+ // Increments the number of death tests encountered in this test so
+ // far.
+ int increment_death_test_count() {
+ return result_.increment_death_test_count();
+ }
+
+ // Creates the test object, runs it, records its result, and then
+ // deletes it.
+ void Run();
+
+ static void ClearTestResult(TestInfo* test_info) {
+ test_info->result_.Clear();
+ }
+
+ // These fields are immutable properties of the test.
+ const std::string test_suite_name_; // test suite name
+ const std::string name_; // Test name
+ // Name of the parameter type, or NULL if this is not a typed or a
+ // type-parameterized test.
+ const std::unique_ptr<const ::std::string> type_param_;
+ // Text representation of the value parameter, or NULL if this is not a
+ // value-parameterized test.
+ const std::unique_ptr<const ::std::string> value_param_;
+ internal::CodeLocation location_;
+ const internal::TypeId fixture_class_id_; // ID of the test fixture class
+ bool should_run_; // True iff this test should run
+ bool is_disabled_; // True iff this test is disabled
+ bool matches_filter_; // True if this test matches the
+ // user-specified filter.
+ bool is_in_another_shard_; // Will be run in another shard.
+ internal::TestFactoryBase* const factory_; // The factory that creates
+ // the test object
+
+ // This field is mutable and needs to be reset before running the
+ // test for the second time.
+ TestResult result_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
+};
+
+// A test suite, which consists of a vector of TestInfos.
+//
+// TestSuite is not copyable.
+class GTEST_API_ TestSuite {
+ public:
+ // Creates a TestSuite with the given name.
+ //
+ // TestSuite does NOT have a default constructor. Always use this
+ // constructor to create a TestSuite object.
+ //
+ // Arguments:
+ //
+ // name: name of the test suite
+ // a_type_param: the name of the test's type parameter, or NULL if
+ // this is not a type-parameterized test.
+ // set_up_tc: pointer to the function that sets up the test suite
+ // tear_down_tc: pointer to the function that tears down the test suite
+ TestSuite(const char* name, const char* a_type_param,
+ internal::SetUpTestSuiteFunc set_up_tc,
+ internal::TearDownTestSuiteFunc tear_down_tc);
+
+ // Destructor of TestSuite.
+ virtual ~TestSuite();
+
+ // Gets the name of the TestSuite.
+ const char* name() const { return name_.c_str(); }
+
+ // Returns the name of the parameter type, or NULL if this is not a
+ // type-parameterized test suite.
+ const char* type_param() const {
+ if (type_param_.get() != nullptr) return type_param_->c_str();
+ return nullptr;
+ }
+
+ // Returns true if any test in this test suite should run.
+ bool should_run() const { return should_run_; }
+
+ // Gets the number of successful tests in this test suite.
+ int successful_test_count() const;
+
+ // Gets the number of skipped tests in this test suite.
+ int skipped_test_count() const;
+
+ // Gets the number of failed tests in this test suite.
+ int failed_test_count() const;
+
+ // Gets the number of disabled tests that will be reported in the XML report.
+ int reportable_disabled_test_count() const;
+
+ // Gets the number of disabled tests in this test suite.
+ int disabled_test_count() const;
+
+ // Gets the number of tests to be printed in the XML report.
+ int reportable_test_count() const;
+
+ // Get the number of tests in this test suite that should run.
+ int test_to_run_count() const;
+
+ // Gets the number of all tests in this test suite.
+ int total_test_count() const;
+
+ // Returns true iff the test suite passed.
+ bool Passed() const { return !Failed(); }
+
+ // Returns true iff the test suite failed.
+ bool Failed() const { return failed_test_count() > 0; }
+
+ // Returns the elapsed time, in milliseconds.
+ TimeInMillis elapsed_time() const { return elapsed_time_; }
+
+ // Returns the i-th test among all the tests. i can range from 0 to
+ // total_test_count() - 1. If i is not in that range, returns NULL.
+ const TestInfo* GetTestInfo(int i) const;
+
+ // Returns the TestResult that holds test properties recorded during
+ // execution of SetUpTestSuite and TearDownTestSuite.
+ const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
+
+ private:
+ friend class Test;
+ friend class internal::UnitTestImpl;
+
+ // Gets the (mutable) vector of TestInfos in this TestSuite.
+ std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
+
+ // Gets the (immutable) vector of TestInfos in this TestSuite.
+ const std::vector<TestInfo*>& test_info_list() const {
+ return test_info_list_;
+ }
+
+ // Returns the i-th test among all the tests. i can range from 0 to
+ // total_test_count() - 1. If i is not in that range, returns NULL.
+ TestInfo* GetMutableTestInfo(int i);
+
+ // Sets the should_run member.
+ void set_should_run(bool should) { should_run_ = should; }
+
+ // Adds a TestInfo to this test suite. Will delete the TestInfo upon
+ // destruction of the TestSuite object.
+ void AddTestInfo(TestInfo * test_info);
+
+ // Clears the results of all tests in this test suite.
+ void ClearResult();
+
+ // Clears the results of all tests in the given test suite.
+ static void ClearTestSuiteResult(TestSuite* test_suite) {
+ test_suite->ClearResult();
+ }
+
+ // Runs every test in this TestSuite.
+ void Run();
+
+ // Runs SetUpTestSuite() for this TestSuite. This wrapper is needed
+ // for catching exceptions thrown from SetUpTestSuite().
+ void RunSetUpTestSuite() {
+ if (set_up_tc_ != nullptr) {
+ (*set_up_tc_)();
+ }
+ }
+
+ // Runs TearDownTestSuite() for this TestSuite. This wrapper is
+ // needed for catching exceptions thrown from TearDownTestSuite().
+ void RunTearDownTestSuite() {
+ if (tear_down_tc_ != nullptr) {
+ (*tear_down_tc_)();
+ }
+ }
+
+ // Returns true iff test passed.
+ static bool TestPassed(const TestInfo* test_info) {
+ return test_info->should_run() && test_info->result()->Passed();
+ }
+
+ // Returns true iff test skipped.
+ static bool TestSkipped(const TestInfo* test_info) {
+ return test_info->should_run() && test_info->result()->Skipped();
+ }
+
+ // Returns true iff test failed.
+ static bool TestFailed(const TestInfo* test_info) {
+ return test_info->should_run() && test_info->result()->Failed();
+ }
+
+ // Returns true iff the test is disabled and will be reported in the XML
+ // report.
+ static bool TestReportableDisabled(const TestInfo* test_info) {
+ return test_info->is_reportable() && test_info->is_disabled_;
+ }
+
+ // Returns true iff test is disabled.
+ static bool TestDisabled(const TestInfo* test_info) {
+ return test_info->is_disabled_;
+ }
+
+ // Returns true iff this test will appear in the XML report.
+ static bool TestReportable(const TestInfo* test_info) {
+ return test_info->is_reportable();
+ }
+
+ // Returns true if the given test should run.
+ static bool ShouldRunTest(const TestInfo* test_info) {
+ return test_info->should_run();
+ }
+
+ // Shuffles the tests in this test suite.
+ void ShuffleTests(internal::Random* random);
+
+ // Restores the test order to before the first shuffle.
+ void UnshuffleTests();
+
+ // Name of the test suite.
+ std::string name_;
+ // Name of the parameter type, or NULL if this is not a typed or a
+ // type-parameterized test.
+ const std::unique_ptr<const ::std::string> type_param_;
+ // The vector of TestInfos in their original order. It owns the
+ // elements in the vector.
+ std::vector<TestInfo*> test_info_list_;
+ // Provides a level of indirection for the test list to allow easy
+ // shuffling and restoring the test order. The i-th element in this
+ // vector is the index of the i-th test in the shuffled test list.
+ std::vector<int> test_indices_;
+ // Pointer to the function that sets up the test suite.
+ internal::SetUpTestSuiteFunc set_up_tc_;
+ // Pointer to the function that tears down the test suite.
+ internal::TearDownTestSuiteFunc tear_down_tc_;
+ // True iff any test in this test suite should run.
+ bool should_run_;
+ // Elapsed time, in milliseconds.
+ TimeInMillis elapsed_time_;
+ // Holds test properties recorded during execution of SetUpTestSuite and
+ // TearDownTestSuite.
+ TestResult ad_hoc_test_result_;
+
+ // We disallow copying TestSuites.
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(TestSuite);
+};
+
+// An Environment object is capable of setting up and tearing down an
+// environment. You should subclass this to define your own
+// environment(s).
+//
+// An Environment object does the set-up and tear-down in virtual
+// methods SetUp() and TearDown() instead of the constructor and the
+// destructor, as:
+//
+// 1. You cannot safely throw from a destructor. This is a problem
+// as in some cases Google Test is used where exceptions are enabled, and
+// we may want to implement ASSERT_* using exceptions where they are
+// available.
+// 2. You cannot use ASSERT_* directly in a constructor or
+// destructor.
+class Environment {
+ public:
+ // The d'tor is virtual as we need to subclass Environment.
+ virtual ~Environment() {}
+
+ // Override this to define how to set up the environment.
+ virtual void SetUp() {}
+
+ // Override this to define how to tear down the environment.
+ virtual void TearDown() {}
+ private:
+ // If you see an error about overriding the following function or
+ // about it being private, you have mis-spelled SetUp() as Setup().
+ struct Setup_should_be_spelled_SetUp {};
+ virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; }
+};
+
+#if GTEST_HAS_EXCEPTIONS
+
+// Exception which can be thrown from TestEventListener::OnTestPartResult.
+class GTEST_API_ AssertionException
+ : public internal::GoogleTestFailureException {
+ public:
+ explicit AssertionException(const TestPartResult& result)
+ : GoogleTestFailureException(result) {}
+};
+
+#endif // GTEST_HAS_EXCEPTIONS
+
+// The interface for tracing execution of tests. The methods are organized in
+// the order the corresponding events are fired.
+class TestEventListener {
+ public:
+ virtual ~TestEventListener() {}
+
+ // Fired before any test activity starts.
+ virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
+
+ // Fired before each iteration of tests starts. There may be more than
+ // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
+ // index, starting from 0.
+ virtual void OnTestIterationStart(const UnitTest& unit_test,
+ int iteration) = 0;
+
+ // Fired before environment set-up for each iteration of tests starts.
+ virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
+
+ // Fired after environment set-up for each iteration of tests ends.
+ virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
+
+ // Fired before the test suite starts.
+ virtual void OnTestSuiteStart(const TestSuite& /*test_suite*/) {}
+
+ // Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+ // Fired before the test starts.
+ virtual void OnTestStart(const TestInfo& test_info) = 0;
+
+ // Fired after a failed assertion or a SUCCEED() invocation.
+ // If you want to throw an exception from this function to skip to the next
+ // TEST, it must be AssertionException defined above, or inherited from it.
+ virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
+
+ // Fired after the test ends.
+ virtual void OnTestEnd(const TestInfo& test_info) = 0;
+
+ // Fired after the test suite ends.
+ virtual void OnTestSuiteEnd(const TestSuite& /*test_suite*/) {}
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+ // Fired before environment tear-down for each iteration of tests starts.
+ virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
+
+ // Fired after environment tear-down for each iteration of tests ends.
+ virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
+
+ // Fired after each iteration of tests finishes.
+ virtual void OnTestIterationEnd(const UnitTest& unit_test,
+ int iteration) = 0;
+
+ // Fired after all test activities have ended.
+ virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
+};
+
+// The convenience class for users who need to override just one or two
+// methods and are not concerned that a possible change to a signature of
+// the methods they override will not be caught during the build. For
+// comments about each method please see the definition of TestEventListener
+// above.
+class EmptyTestEventListener : public TestEventListener {
+ public:
+ void OnTestProgramStart(const UnitTest& /*unit_test*/) override {}
+ void OnTestIterationStart(const UnitTest& /*unit_test*/,
+ int /*iteration*/) override {}
+ void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {}
+ void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {}
+ void OnTestSuiteStart(const TestSuite& /*test_suite*/) override {}
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ void OnTestCaseStart(const TestCase& /*test_case*/) override {}
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+ void OnTestStart(const TestInfo& /*test_info*/) override {}
+ void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {}
+ void OnTestEnd(const TestInfo& /*test_info*/) override {}
+ void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {}
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ void OnTestCaseEnd(const TestCase& /*test_case*/) override {}
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+ void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {}
+ void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {}
+ void OnTestIterationEnd(const UnitTest& /*unit_test*/,
+ int /*iteration*/) override {}
+ void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {}
+};
+
+// TestEventListeners lets users add listeners to track events in Google Test.
+class GTEST_API_ TestEventListeners {
+ public:
+ TestEventListeners();
+ ~TestEventListeners();
+
+ // Appends an event listener to the end of the list. Google Test assumes
+ // the ownership of the listener (i.e. it will delete the listener when
+ // the test program finishes).
+ void Append(TestEventListener* listener);
+
+ // Removes the given event listener from the list and returns it. It then
+ // becomes the caller's responsibility to delete the listener. Returns
+ // NULL if the listener is not found in the list.
+ TestEventListener* Release(TestEventListener* listener);
+
+ // Returns the standard listener responsible for the default console
+ // output. Can be removed from the listeners list to shut down default
+ // console output. Note that removing this object from the listener list
+ // with Release transfers its ownership to the caller and makes this
+ // function return NULL the next time.
+ TestEventListener* default_result_printer() const {
+ return default_result_printer_;
+ }
+
+ // Returns the standard listener responsible for the default XML output
+ // controlled by the --gtest_output=xml flag. Can be removed from the
+ // listeners list by users who want to shut down the default XML output
+ // controlled by this flag and substitute it with custom one. Note that
+ // removing this object from the listener list with Release transfers its
+ // ownership to the caller and makes this function return NULL the next
+ // time.
+ TestEventListener* default_xml_generator() const {
+ return default_xml_generator_;
+ }
+
+ private:
+ friend class TestSuite;
+ friend class TestInfo;
+ friend class internal::DefaultGlobalTestPartResultReporter;
+ friend class internal::NoExecDeathTest;
+ friend class internal::TestEventListenersAccessor;
+ friend class internal::UnitTestImpl;
+
+ // Returns repeater that broadcasts the TestEventListener events to all
+ // subscribers.
+ TestEventListener* repeater();
+
+ // Sets the default_result_printer attribute to the provided listener.
+ // The listener is also added to the listener list and previous
+ // default_result_printer is removed from it and deleted. The listener can
+ // also be NULL in which case it will not be added to the list. Does
+ // nothing if the previous and the current listener objects are the same.
+ void SetDefaultResultPrinter(TestEventListener* listener);
+
+ // Sets the default_xml_generator attribute to the provided listener. The
+ // listener is also added to the listener list and previous
+ // default_xml_generator is removed from it and deleted. The listener can
+ // also be NULL in which case it will not be added to the list. Does
+ // nothing if the previous and the current listener objects are the same.
+ void SetDefaultXmlGenerator(TestEventListener* listener);
+
+ // Controls whether events will be forwarded by the repeater to the
+ // listeners in the list.
+ bool EventForwardingEnabled() const;
+ void SuppressEventForwarding();
+
+ // The actual list of listeners.
+ internal::TestEventRepeater* repeater_;
+ // Listener responsible for the standard result output.
+ TestEventListener* default_result_printer_;
+ // Listener responsible for the creation of the XML output file.
+ TestEventListener* default_xml_generator_;
+
+ // We disallow copying TestEventListeners.
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
+};
+
+// A UnitTest consists of a vector of TestSuites.
+//
+// This is a singleton class. The only instance of UnitTest is
+// created when UnitTest::GetInstance() is first called. This
+// instance is never deleted.
+//
+// UnitTest is not copyable.
+//
+// This class is thread-safe as long as the methods are called
+// according to their specification.
+class GTEST_API_ UnitTest {
+ public:
+ // Gets the singleton UnitTest object. The first time this method
+ // is called, a UnitTest object is constructed and returned.
+ // Consecutive calls will return the same object.
+ static UnitTest* GetInstance();
+
+ // Runs all tests in this UnitTest object and prints the result.
+ // Returns 0 if successful, or 1 otherwise.
+ //
+ // This method can only be called from the main thread.
+ //
+ // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+ int Run() GTEST_MUST_USE_RESULT_;
+
+ // Returns the working directory when the first TEST() or TEST_F()
+ // was executed. The UnitTest object owns the string.
+ const char* original_working_dir() const;
+
+ // Returns the TestSuite object for the test that's currently running,
+ // or NULL if no test is running.
+ const TestSuite* current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_);
+
+// Legacy API is still available but deprecated
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ const TestCase* current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_);
+#endif
+
+ // Returns the TestInfo object for the test that's currently running,
+ // or NULL if no test is running.
+ const TestInfo* current_test_info() const
+ GTEST_LOCK_EXCLUDED_(mutex_);
+
+ // Returns the random seed used at the start of the current test run.
+ int random_seed() const;
+
+ // Returns the ParameterizedTestSuiteRegistry object used to keep track of
+ // value-parameterized tests and instantiate and register them.
+ //
+ // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+ internal::ParameterizedTestSuiteRegistry& parameterized_test_registry()
+ GTEST_LOCK_EXCLUDED_(mutex_);
+
+ // Gets the number of successful test suites.
+ int successful_test_suite_count() const;
+
+ // Gets the number of failed test suites.
+ int failed_test_suite_count() const;
+
+ // Gets the number of all test suites.
+ int total_test_suite_count() const;
+
+ // Gets the number of all test suites that contain at least one test
+ // that should run.
+ int test_suite_to_run_count() const;
+
+ // Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ int successful_test_case_count() const;
+ int failed_test_case_count() const;
+ int total_test_case_count() const;
+ int test_case_to_run_count() const;
+#endif // EMOVE_LEGACY_TEST_CASEAPI
+
+ // Gets the number of successful tests.
+ int successful_test_count() const;
+
+ // Gets the number of skipped tests.
+ int skipped_test_count() const;
+
+ // Gets the number of failed tests.
+ int failed_test_count() const;
+
+ // Gets the number of disabled tests that will be reported in the XML report.
+ int reportable_disabled_test_count() const;
+
+ // Gets the number of disabled tests.
+ int disabled_test_count() const;
+
+ // Gets the number of tests to be printed in the XML report.
+ int reportable_test_count() const;
+
+ // Gets the number of all tests.
+ int total_test_count() const;
+
+ // Gets the number of tests that should run.
+ int test_to_run_count() const;
+
+ // Gets the time of the test program start, in ms from the start of the
+ // UNIX epoch.
+ TimeInMillis start_timestamp() const;
+
+ // Gets the elapsed time, in milliseconds.
+ TimeInMillis elapsed_time() const;
+
+ // Returns true iff the unit test passed (i.e. all test suites passed).
+ bool Passed() const;
+
+ // Returns true iff the unit test failed (i.e. some test suite failed
+ // or something outside of all tests failed).
+ bool Failed() const;
+
+ // Gets the i-th test suite among all the test suites. i can range from 0 to
+ // total_test_suite_count() - 1. If i is not in that range, returns NULL.
+ const TestSuite* GetTestSuite(int i) const;
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ const TestCase* GetTestCase(int i) const;
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+ // Returns the TestResult containing information on test failures and
+ // properties logged outside of individual test suites.
+ const TestResult& ad_hoc_test_result() const;
+
+ // Returns the list of event listeners that can be used to track events
+ // inside Google Test.
+ TestEventListeners& listeners();
+
+ private:
+ // Registers and returns a global test environment. When a test
+ // program is run, all global test environments will be set-up in
+ // the order they were registered. After all tests in the program
+ // have finished, all global test environments will be torn-down in
+ // the *reverse* order they were registered.
+ //
+ // The UnitTest object takes ownership of the given environment.
+ //
+ // This method can only be called from the main thread.
+ Environment* AddEnvironment(Environment* env);
+
+ // Adds a TestPartResult to the current TestResult object. All
+ // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
+ // eventually call this to report their results. The user code
+ // should use the assertion macros instead of calling this directly.
+ void AddTestPartResult(TestPartResult::Type result_type,
+ const char* file_name,
+ int line_number,
+ const std::string& message,
+ const std::string& os_stack_trace)
+ GTEST_LOCK_EXCLUDED_(mutex_);
+
+ // Adds a TestProperty to the current TestResult object when invoked from
+ // inside a test, to current TestSuite's ad_hoc_test_result_ when invoked
+ // from SetUpTestSuite or TearDownTestSuite, or to the global property set
+ // when invoked elsewhere. If the result already contains a property with
+ // the same key, the value will be updated.
+ void RecordProperty(const std::string& key, const std::string& value);
+
+ // Gets the i-th test suite among all the test suites. i can range from 0 to
+ // total_test_suite_count() - 1. If i is not in that range, returns NULL.
+ TestSuite* GetMutableTestSuite(int i);
+
+ // Accessors for the implementation object.
+ internal::UnitTestImpl* impl() { return impl_; }
+ const internal::UnitTestImpl* impl() const { return impl_; }
+
+ // These classes and functions are friends as they need to access private
+ // members of UnitTest.
+ friend class ScopedTrace;
+ friend class Test;
+ friend class internal::AssertHelper;
+ friend class internal::StreamingListenerTest;
+ friend class internal::UnitTestRecordPropertyTestHelper;
+ friend Environment* AddGlobalTestEnvironment(Environment* env);
+ friend internal::UnitTestImpl* internal::GetUnitTestImpl();
+ friend void internal::ReportFailureInUnknownLocation(
+ TestPartResult::Type result_type,
+ const std::string& message);
+
+ // Creates an empty UnitTest.
+ UnitTest();
+
+ // D'tor
+ virtual ~UnitTest();
+
+ // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
+ // Google Test trace stack.
+ void PushGTestTrace(const internal::TraceInfo& trace)
+ GTEST_LOCK_EXCLUDED_(mutex_);
+
+ // Pops a trace from the per-thread Google Test trace stack.
+ void PopGTestTrace()
+ GTEST_LOCK_EXCLUDED_(mutex_);
+
+ // Protects mutable state in *impl_. This is mutable as some const
+ // methods need to lock it too.
+ mutable internal::Mutex mutex_;
+
+ // Opaque implementation object. This field is never changed once
+ // the object is constructed. We don't mark it as const here, as
+ // doing so will cause a warning in the constructor of UnitTest.
+ // Mutable state in *impl_ is protected by mutex_.
+ internal::UnitTestImpl* impl_;
+
+ // We disallow copying UnitTest.
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);
+};
+
+// A convenient wrapper for adding an environment for the test
+// program.
+//
+// You should call this before RUN_ALL_TESTS() is called, probably in
+// main(). If you use gtest_main, you need to call this before main()
+// starts for it to take effect. For example, you can define a global
+// variable like this:
+//
+// testing::Environment* const foo_env =
+// testing::AddGlobalTestEnvironment(new FooEnvironment);
+//
+// However, we strongly recommend you to write your own main() and
+// call AddGlobalTestEnvironment() there, as relying on initialization
+// of global variables makes the code harder to read and may cause
+// problems when you register multiple environments from different
+// translation units and the environments have dependencies among them
+// (remember that the compiler doesn't guarantee the order in which
+// global variables from different translation units are initialized).
+inline Environment* AddGlobalTestEnvironment(Environment* env) {
+ return UnitTest::GetInstance()->AddEnvironment(env);
+}
+
+// Initializes Google Test. This must be called before calling
+// RUN_ALL_TESTS(). In particular, it parses a command line for the
+// flags that Google Test recognizes. Whenever a Google Test flag is
+// seen, it is removed from argv, and *argc is decremented.
+//
+// No value is returned. Instead, the Google Test flag variables are
+// updated.
+//
+// Calling the function for the second time has no user-visible effect.
+GTEST_API_ void InitGoogleTest(int* argc, char** argv);
+
+// This overloaded version can be used in Windows programs compiled in
+// UNICODE mode.
+GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
+
+// This overloaded version can be used on Arduino/embedded platforms where
+// there is no argc/argv.
+GTEST_API_ void InitGoogleTest();
+
+namespace internal {
+
+// Separate the error generating code from the code path to reduce the stack
+// frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers
+// when calling EXPECT_* in a tight loop.
+template <typename T1, typename T2>
+AssertionResult CmpHelperEQFailure(const char* lhs_expression,
+ const char* rhs_expression,
+ const T1& lhs, const T2& rhs) {
+ return EqFailure(lhs_expression,
+ rhs_expression,
+ FormatForComparisonFailureMessage(lhs, rhs),
+ FormatForComparisonFailureMessage(rhs, lhs),
+ false);
+}
+
+// This block of code defines operator==/!=
+// to block lexical scope lookup.
+// It prevents using invalid operator==/!= defined at namespace scope.
+struct faketype {};
+inline bool operator==(faketype, faketype) { return true; }
+inline bool operator!=(faketype, faketype) { return false; }
+
+// The helper function for {ASSERT|EXPECT}_EQ.
+template <typename T1, typename T2>
+AssertionResult CmpHelperEQ(const char* lhs_expression,
+ const char* rhs_expression,
+ const T1& lhs,
+ const T2& rhs) {
+ if (lhs == rhs) {
+ return AssertionSuccess();
+ }
+
+ return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
+}
+
+// With this overloaded version, we allow anonymous enums to be used
+// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
+// can be implicitly cast to BiggestInt.
+GTEST_API_ AssertionResult CmpHelperEQ(const char* lhs_expression,
+ const char* rhs_expression,
+ BiggestInt lhs,
+ BiggestInt rhs);
+
+class EqHelper {
+ public:
+ // This templatized version is for the general case.
+ template <
+ typename T1, typename T2,
+ // Disable this overload for cases where one argument is a pointer
+ // and the other is the null pointer constant.
+ typename std::enable_if<!std::is_integral<T1>::value ||
+ !std::is_pointer<T2>::value>::type* = nullptr>
+ static AssertionResult Compare(const char* lhs_expression,
+ const char* rhs_expression, const T1& lhs,
+ const T2& rhs) {
+ return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
+ }
+
+ // With this overloaded version, we allow anonymous enums to be used
+ // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
+ // enums can be implicitly cast to BiggestInt.
+ //
+ // Even though its body looks the same as the above version, we
+ // cannot merge the two, as it will make anonymous enums unhappy.
+ static AssertionResult Compare(const char* lhs_expression,
+ const char* rhs_expression,
+ BiggestInt lhs,
+ BiggestInt rhs) {
+ return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
+ }
+
+ template <typename T>
+ static AssertionResult Compare(
+ const char* lhs_expression, const char* rhs_expression,
+ // Handle cases where '0' is used as a null pointer literal.
+ std::nullptr_t /* lhs */, T* rhs) {
+ // We already know that 'lhs' is a null pointer.
+ return CmpHelperEQ(lhs_expression, rhs_expression, static_cast<T*>(nullptr),
+ rhs);
+ }
+};
+
+// Separate the error generating code from the code path to reduce the stack
+// frame size of CmpHelperOP. This helps reduce the overhead of some sanitizers
+// when calling EXPECT_OP in a tight loop.
+template <typename T1, typename T2>
+AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2,
+ const T1& val1, const T2& val2,
+ const char* op) {
+ return AssertionFailure()
+ << "Expected: (" << expr1 << ") " << op << " (" << expr2
+ << "), actual: " << FormatForComparisonFailureMessage(val1, val2)
+ << " vs " << FormatForComparisonFailureMessage(val2, val1);
+}
+
+// A macro for implementing the helper functions needed to implement
+// ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste
+// of similar code.
+//
+// For each templatized helper function, we also define an overloaded
+// version for BiggestInt in order to reduce code bloat and allow
+// anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
+// with gcc 4.
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+
+#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
+template <typename T1, typename T2>\
+AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
+ const T1& val1, const T2& val2) {\
+ if (val1 op val2) {\
+ return AssertionSuccess();\
+ } else {\
+ return CmpHelperOpFailure(expr1, expr2, val1, val2, #op);\
+ }\
+}\
+GTEST_API_ AssertionResult CmpHelper##op_name(\
+ const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+
+// Implements the helper function for {ASSERT|EXPECT}_NE
+GTEST_IMPL_CMP_HELPER_(NE, !=);
+// Implements the helper function for {ASSERT|EXPECT}_LE
+GTEST_IMPL_CMP_HELPER_(LE, <=);
+// Implements the helper function for {ASSERT|EXPECT}_LT
+GTEST_IMPL_CMP_HELPER_(LT, <);
+// Implements the helper function for {ASSERT|EXPECT}_GE
+GTEST_IMPL_CMP_HELPER_(GE, >=);
+// Implements the helper function for {ASSERT|EXPECT}_GT
+GTEST_IMPL_CMP_HELPER_(GT, >);
+
+#undef GTEST_IMPL_CMP_HELPER_
+
+// The helper function for {ASSERT|EXPECT}_STREQ.
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
+ const char* s2_expression,
+ const char* s1,
+ const char* s2);
+
+// The helper function for {ASSERT|EXPECT}_STRCASEEQ.
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression,
+ const char* s2_expression,
+ const char* s1,
+ const char* s2);
+
+// The helper function for {ASSERT|EXPECT}_STRNE.
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
+ const char* s2_expression,
+ const char* s1,
+ const char* s2);
+
+// The helper function for {ASSERT|EXPECT}_STRCASENE.
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
+ const char* s2_expression,
+ const char* s1,
+ const char* s2);
+
+
+// Helper function for *_STREQ on wide strings.
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
+ const char* s2_expression,
+ const wchar_t* s1,
+ const wchar_t* s2);
+
+// Helper function for *_STRNE on wide strings.
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
+ const char* s2_expression,
+ const wchar_t* s1,
+ const wchar_t* s2);
+
+} // namespace internal
+
+// IsSubstring() and IsNotSubstring() are intended to be used as the
+// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
+// themselves. They check whether needle is a substring of haystack
+// (NULL is considered a substring of itself only), and return an
+// appropriate error message when they fail.
+//
+// The {needle,haystack}_expr arguments are the stringified
+// expressions that generated the two real arguments.
+GTEST_API_ AssertionResult IsSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const char* needle, const char* haystack);
+GTEST_API_ AssertionResult IsSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const wchar_t* needle, const wchar_t* haystack);
+GTEST_API_ AssertionResult IsNotSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const char* needle, const char* haystack);
+GTEST_API_ AssertionResult IsNotSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const wchar_t* needle, const wchar_t* haystack);
+GTEST_API_ AssertionResult IsSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const ::std::string& needle, const ::std::string& haystack);
+GTEST_API_ AssertionResult IsNotSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const ::std::string& needle, const ::std::string& haystack);
+
+#if GTEST_HAS_STD_WSTRING
+GTEST_API_ AssertionResult IsSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const ::std::wstring& needle, const ::std::wstring& haystack);
+GTEST_API_ AssertionResult IsNotSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const ::std::wstring& needle, const ::std::wstring& haystack);
+#endif // GTEST_HAS_STD_WSTRING
+
+namespace internal {
+
+// Helper template function for comparing floating-points.
+//
+// Template parameter:
+//
+// RawType: the raw floating-point type (either float or double)
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+template <typename RawType>
+AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression,
+ const char* rhs_expression,
+ RawType lhs_value,
+ RawType rhs_value) {
+ const FloatingPoint<RawType> lhs(lhs_value), rhs(rhs_value);
+
+ if (lhs.AlmostEquals(rhs)) {
+ return AssertionSuccess();
+ }
+
+ ::std::stringstream lhs_ss;
+ lhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
+ << lhs_value;
+
+ ::std::stringstream rhs_ss;
+ rhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
+ << rhs_value;
+
+ return EqFailure(lhs_expression,
+ rhs_expression,
+ StringStreamToString(&lhs_ss),
+ StringStreamToString(&rhs_ss),
+ false);
+}
+
+// Helper function for implementing ASSERT_NEAR.
+//
+// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
+GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
+ const char* expr2,
+ const char* abs_error_expr,
+ double val1,
+ double val2,
+ double abs_error);
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+// A class that enables one to stream messages to assertion macros
+class GTEST_API_ AssertHelper {
+ public:
+ // Constructor.
+ AssertHelper(TestPartResult::Type type,
+ const char* file,
+ int line,
+ const char* message);
+ ~AssertHelper();
+
+ // Message assignment is a semantic trick to enable assertion
+ // streaming; see the GTEST_MESSAGE_ macro below.
+ void operator=(const Message& message) const;
+
+ private:
+ // We put our data in a struct so that the size of the AssertHelper class can
+ // be as small as possible. This is important because gcc is incapable of
+ // re-using stack space even for temporary variables, so every EXPECT_EQ
+ // reserves stack space for another AssertHelper.
+ struct AssertHelperData {
+ AssertHelperData(TestPartResult::Type t,
+ const char* srcfile,
+ int line_num,
+ const char* msg)
+ : type(t), file(srcfile), line(line_num), message(msg) { }
+
+ TestPartResult::Type const type;
+ const char* const file;
+ int const line;
+ std::string const message;
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
+ };
+
+ AssertHelperData* const data_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
+};
+
+enum GTestColor { COLOR_DEFAULT, COLOR_RED, COLOR_GREEN, COLOR_YELLOW };
+
+GTEST_API_ GTEST_ATTRIBUTE_PRINTF_(2, 3) void ColoredPrintf(GTestColor color,
+ const char* fmt,
+ ...);
+
+} // namespace internal
+
+// The pure interface class that all value-parameterized tests inherit from.
+// A value-parameterized class must inherit from both ::testing::Test and
+// ::testing::WithParamInterface. In most cases that just means inheriting
+// from ::testing::TestWithParam, but more complicated test hierarchies
+// may need to inherit from Test and WithParamInterface at different levels.
+//
+// This interface has support for accessing the test parameter value via
+// the GetParam() method.
+//
+// Use it with one of the parameter generator defining functions, like Range(),
+// Values(), ValuesIn(), Bool(), and Combine().
+//
+// class FooTest : public ::testing::TestWithParam<int> {
+// protected:
+// FooTest() {
+// // Can use GetParam() here.
+// }
+// ~FooTest() override {
+// // Can use GetParam() here.
+// }
+// void SetUp() override {
+// // Can use GetParam() here.
+// }
+// void TearDown override {
+// // Can use GetParam() here.
+// }
+// };
+// TEST_P(FooTest, DoesBar) {
+// // Can use GetParam() method here.
+// Foo foo;
+// ASSERT_TRUE(foo.DoesBar(GetParam()));
+// }
+// INSTANTIATE_TEST_SUITE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
+
+template <typename T>
+class WithParamInterface {
+ public:
+ typedef T ParamType;
+ virtual ~WithParamInterface() {}
+
+ // The current parameter value. Is also available in the test fixture's
+ // constructor.
+ static const ParamType& GetParam() {
+ GTEST_CHECK_(parameter_ != nullptr)
+ << "GetParam() can only be called inside a value-parameterized test "
+ << "-- did you intend to write TEST_P instead of TEST_F?";
+ return *parameter_;
+ }
+
+ private:
+ // Sets parameter value. The caller is responsible for making sure the value
+ // remains alive and unchanged throughout the current test.
+ static void SetParam(const ParamType* parameter) {
+ parameter_ = parameter;
+ }
+
+ // Static value used for accessing parameter during a test lifetime.
+ static const ParamType* parameter_;
+
+ // TestClass must be a subclass of WithParamInterface<T> and Test.
+ template <class TestClass> friend class internal::ParameterizedTestFactory;
+};
+
+template <typename T>
+const T* WithParamInterface<T>::parameter_ = nullptr;
+
+// Most value-parameterized classes can ignore the existence of
+// WithParamInterface, and can just inherit from ::testing::TestWithParam.
+
+template <typename T>
+class TestWithParam : public Test, public WithParamInterface<T> {
+};
+
+// Macros for indicating success/failure in test code.
+
+// Skips test in runtime.
+// Skipping test aborts current function.
+// Skipped tests are neither successful nor failed.
+#define GTEST_SKIP() GTEST_SKIP_("Skipped")
+
+// ADD_FAILURE unconditionally adds a failure to the current test.
+// SUCCEED generates a success - it doesn't automatically make the
+// current test successful, as a test is only successful when it has
+// no failure.
+//
+// EXPECT_* verifies that a certain condition is satisfied. If not,
+// it behaves like ADD_FAILURE. In particular:
+//
+// EXPECT_TRUE verifies that a Boolean condition is true.
+// EXPECT_FALSE verifies that a Boolean condition is false.
+//
+// FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
+// that they will also abort the current function on failure. People
+// usually want the fail-fast behavior of FAIL and ASSERT_*, but those
+// writing data-driven tests often find themselves using ADD_FAILURE
+// and EXPECT_* more.
+
+// Generates a nonfatal failure with a generic message.
+#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
+
+// Generates a nonfatal failure at the given source file location with
+// a generic message.
+#define ADD_FAILURE_AT(file, line) \
+ GTEST_MESSAGE_AT_(file, line, "Failed", \
+ ::testing::TestPartResult::kNonFatalFailure)
+
+// Generates a fatal failure with a generic message.
+#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
+
+// Like GTEST_FAIL(), but at the given source file location.
+#define GTEST_FAIL_AT(file, line) \
+ GTEST_MESSAGE_AT_(file, line, "Failed", \
+ ::testing::TestPartResult::kFatalFailure)
+
+// Define this macro to 1 to omit the definition of FAIL(), which is a
+// generic name and clashes with some other libraries.
+#if !GTEST_DONT_DEFINE_FAIL
+# define FAIL() GTEST_FAIL()
+#endif
+
+// Generates a success with a generic message.
+#define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
+
+// Define this macro to 1 to omit the definition of SUCCEED(), which
+// is a generic name and clashes with some other libraries.
+#if !GTEST_DONT_DEFINE_SUCCEED
+# define SUCCEED() GTEST_SUCCEED()
+#endif
+
+// Macros for testing exceptions.
+//
+// * {ASSERT|EXPECT}_THROW(statement, expected_exception):
+// Tests that the statement throws the expected exception.
+// * {ASSERT|EXPECT}_NO_THROW(statement):
+// Tests that the statement doesn't throw any exception.
+// * {ASSERT|EXPECT}_ANY_THROW(statement):
+// Tests that the statement throws an exception.
+
+#define EXPECT_THROW(statement, expected_exception) \
+ GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
+#define EXPECT_NO_THROW(statement) \
+ GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
+#define EXPECT_ANY_THROW(statement) \
+ GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_THROW(statement, expected_exception) \
+ GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
+#define ASSERT_NO_THROW(statement) \
+ GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
+#define ASSERT_ANY_THROW(statement) \
+ GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
+
+// Boolean assertions. Condition can be either a Boolean expression or an
+// AssertionResult. For more information on how to use AssertionResult with
+// these macros see comments on that class.
+#define EXPECT_TRUE(condition) \
+ GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
+ GTEST_NONFATAL_FAILURE_)
+#define EXPECT_FALSE(condition) \
+ GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
+ GTEST_NONFATAL_FAILURE_)
+#define ASSERT_TRUE(condition) \
+ GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
+ GTEST_FATAL_FAILURE_)
+#define ASSERT_FALSE(condition) \
+ GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
+ GTEST_FATAL_FAILURE_)
+
+// Macros for testing equalities and inequalities.
+//
+// * {ASSERT|EXPECT}_EQ(v1, v2): Tests that v1 == v2
+// * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
+// * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
+// * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
+// * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
+// * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
+//
+// When they are not, Google Test prints both the tested expressions and
+// their actual values. The values must be compatible built-in types,
+// or you will get a compiler error. By "compatible" we mean that the
+// values can be compared by the respective operator.
+//
+// Note:
+//
+// 1. It is possible to make a user-defined type work with
+// {ASSERT|EXPECT}_??(), but that requires overloading the
+// comparison operators and is thus discouraged by the Google C++
+// Usage Guide. Therefore, you are advised to use the
+// {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
+// equal.
+//
+// 2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
+// pointers (in particular, C strings). Therefore, if you use it
+// with two C strings, you are testing how their locations in memory
+// are related, not how their content is related. To compare two C
+// strings by content, use {ASSERT|EXPECT}_STR*().
+//
+// 3. {ASSERT|EXPECT}_EQ(v1, v2) is preferred to
+// {ASSERT|EXPECT}_TRUE(v1 == v2), as the former tells you
+// what the actual value is when it fails, and similarly for the
+// other comparisons.
+//
+// 4. Do not depend on the order in which {ASSERT|EXPECT}_??()
+// evaluate their arguments, which is undefined.
+//
+// 5. These macros evaluate their arguments exactly once.
+//
+// Examples:
+//
+// EXPECT_NE(Foo(), 5);
+// EXPECT_EQ(a_pointer, NULL);
+// ASSERT_LT(i, array_size);
+// ASSERT_GT(records.size(), 0) << "There is no record left.";
+
+#define EXPECT_EQ(val1, val2) \
+ EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
+#define EXPECT_NE(val1, val2) \
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
+#define EXPECT_LE(val1, val2) \
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
+#define EXPECT_LT(val1, val2) \
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
+#define EXPECT_GE(val1, val2) \
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
+#define EXPECT_GT(val1, val2) \
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
+
+#define GTEST_ASSERT_EQ(val1, val2) \
+ ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
+#define GTEST_ASSERT_NE(val1, val2) \
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
+#define GTEST_ASSERT_LE(val1, val2) \
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
+#define GTEST_ASSERT_LT(val1, val2) \
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
+#define GTEST_ASSERT_GE(val1, val2) \
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
+#define GTEST_ASSERT_GT(val1, val2) \
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
+
+// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
+// ASSERT_XY(), which clashes with some users' own code.
+
+#if !GTEST_DONT_DEFINE_ASSERT_EQ
+# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
+#endif
+
+#if !GTEST_DONT_DEFINE_ASSERT_NE
+# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
+#endif
+
+#if !GTEST_DONT_DEFINE_ASSERT_LE
+# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
+#endif
+
+#if !GTEST_DONT_DEFINE_ASSERT_LT
+# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
+#endif
+
+#if !GTEST_DONT_DEFINE_ASSERT_GE
+# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
+#endif
+
+#if !GTEST_DONT_DEFINE_ASSERT_GT
+# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
+#endif
+
+// C-string Comparisons. All tests treat NULL and any non-NULL string
+// as different. Two NULLs are equal.
+//
+// * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2
+// * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2
+// * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
+// * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
+//
+// For wide or narrow string objects, you can use the
+// {ASSERT|EXPECT}_??() macros.
+//
+// Don't depend on the order in which the arguments are evaluated,
+// which is undefined.
+//
+// These macros evaluate their arguments exactly once.
+
+#define EXPECT_STREQ(s1, s2) \
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
+#define EXPECT_STRNE(s1, s2) \
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
+#define EXPECT_STRCASEEQ(s1, s2) \
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
+#define EXPECT_STRCASENE(s1, s2)\
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
+
+#define ASSERT_STREQ(s1, s2) \
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
+#define ASSERT_STRNE(s1, s2) \
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
+#define ASSERT_STRCASEEQ(s1, s2) \
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
+#define ASSERT_STRCASENE(s1, s2)\
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
+
+// Macros for comparing floating-point numbers.
+//
+// * {ASSERT|EXPECT}_FLOAT_EQ(val1, val2):
+// Tests that two float values are almost equal.
+// * {ASSERT|EXPECT}_DOUBLE_EQ(val1, val2):
+// Tests that two double values are almost equal.
+// * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
+// Tests that v1 and v2 are within the given distance to each other.
+//
+// Google Test uses ULP-based comparison to automatically pick a default
+// error bound that is appropriate for the operands. See the
+// FloatingPoint template class in gtest-internal.h if you are
+// interested in the implementation details.
+
+#define EXPECT_FLOAT_EQ(val1, val2)\
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
+ val1, val2)
+
+#define EXPECT_DOUBLE_EQ(val1, val2)\
+ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
+ val1, val2)
+
+#define ASSERT_FLOAT_EQ(val1, val2)\
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
+ val1, val2)
+
+#define ASSERT_DOUBLE_EQ(val1, val2)\
+ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
+ val1, val2)
+
+#define EXPECT_NEAR(val1, val2, abs_error)\
+ EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
+ val1, val2, abs_error)
+
+#define ASSERT_NEAR(val1, val2, abs_error)\
+ ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
+ val1, val2, abs_error)
+
+// These predicate format functions work on floating-point values, and
+// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
+//
+// EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
+
+// Asserts that val1 is less than, or almost equal to, val2. Fails
+// otherwise. In particular, it fails if either val1 or val2 is NaN.
+GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
+ float val1, float val2);
+GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
+ double val1, double val2);
+
+
+#if GTEST_OS_WINDOWS
+
+// Macros that test for HRESULT failure and success, these are only useful
+// on Windows, and rely on Windows SDK macros and APIs to compile.
+//
+// * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
+//
+// When expr unexpectedly fails or succeeds, Google Test prints the
+// expected result and the actual result with both a human-readable
+// string representation of the error, if available, as well as the
+// hex result code.
+# define EXPECT_HRESULT_SUCCEEDED(expr) \
+ EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
+
+# define ASSERT_HRESULT_SUCCEEDED(expr) \
+ ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
+
+# define EXPECT_HRESULT_FAILED(expr) \
+ EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
+
+# define ASSERT_HRESULT_FAILED(expr) \
+ ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
+
+#endif // GTEST_OS_WINDOWS
+
+// Macros that execute statement and check that it doesn't generate new fatal
+// failures in the current thread.
+//
+// * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
+//
+// Examples:
+//
+// EXPECT_NO_FATAL_FAILURE(Process());
+// ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
+//
+#define ASSERT_NO_FATAL_FAILURE(statement) \
+ GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
+#define EXPECT_NO_FATAL_FAILURE(statement) \
+ GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
+
+// Causes a trace (including the given source file path and line number,
+// and the given message) to be included in every test failure message generated
+// by code in the scope of the lifetime of an instance of this class. The effect
+// is undone with the destruction of the instance.
+//
+// The message argument can be anything streamable to std::ostream.
+//
+// Example:
+// testing::ScopedTrace trace("file.cc", 123, "message");
+//
+class GTEST_API_ ScopedTrace {
+ public:
+ // The c'tor pushes the given source file location and message onto
+ // a trace stack maintained by Google Test.
+
+ // Template version. Uses Message() to convert the values into strings.
+ // Slow, but flexible.
+ template <typename T>
+ ScopedTrace(const char* file, int line, const T& message) {
+ PushTrace(file, line, (Message() << message).GetString());
+ }
+
+ // Optimize for some known types.
+ ScopedTrace(const char* file, int line, const char* message) {
+ PushTrace(file, line, message ? message : "(null)");
+ }
+
+ ScopedTrace(const char* file, int line, const std::string& message) {
+ PushTrace(file, line, message);
+ }
+
+ // The d'tor pops the info pushed by the c'tor.
+ //
+ // Note that the d'tor is not virtual in order to be efficient.
+ // Don't inherit from ScopedTrace!
+ ~ScopedTrace();
+
+ private:
+ void PushTrace(const char* file, int line, std::string message);
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace);
+} GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its
+ // c'tor and d'tor. Therefore it doesn't
+ // need to be used otherwise.
+
+// Causes a trace (including the source file path, the current line
+// number, and the given message) to be included in every test failure
+// message generated by code in the current scope. The effect is
+// undone when the control leaves the current scope.
+//
+// The message argument can be anything streamable to std::ostream.
+//
+// In the implementation, we include the current line number as part
+// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
+// to appear in the same block - as long as they are on different
+// lines.
+//
+// Assuming that each thread maintains its own stack of traces.
+// Therefore, a SCOPED_TRACE() would (correctly) only affect the
+// assertions in its own thread.
+#define SCOPED_TRACE(message) \
+ ::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
+ __FILE__, __LINE__, (message))
+
+
+// Compile-time assertion for type equality.
+// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
+// the same type. The value it returns is not interesting.
+//
+// Instead of making StaticAssertTypeEq a class template, we make it a
+// function template that invokes a helper class template. This
+// prevents a user from misusing StaticAssertTypeEq<T1, T2> by
+// defining objects of that type.
+//
+// CAVEAT:
+//
+// When used inside a method of a class template,
+// StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
+// instantiated. For example, given:
+//
+// template <typename T> class Foo {
+// public:
+// void Bar() { testing::StaticAssertTypeEq<int, T>(); }
+// };
+//
+// the code:
+//
+// void Test1() { Foo<bool> foo; }
+//
+// will NOT generate a compiler error, as Foo<bool>::Bar() is never
+// actually instantiated. Instead, you need:
+//
+// void Test2() { Foo<bool> foo; foo.Bar(); }
+//
+// to cause a compiler error.
+template <typename T1, typename T2>
+bool StaticAssertTypeEq() {
+ (void)internal::StaticAssertTypeEqHelper<T1, T2>();
+ return true;
+}
+
+// Defines a test.
+//
+// The first parameter is the name of the test suite, and the second
+// parameter is the name of the test within the test suite.
+//
+// The convention is to end the test suite name with "Test". For
+// example, a test suite for the Foo class can be named FooTest.
+//
+// Test code should appear between braces after an invocation of
+// this macro. Example:
+//
+// TEST(FooTest, InitializesCorrectly) {
+// Foo foo;
+// EXPECT_TRUE(foo.StatusIsOK());
+// }
+
+// Note that we call GetTestTypeId() instead of GetTypeId<
+// ::testing::Test>() here to get the type ID of testing::Test. This
+// is to work around a suspected linker bug when using Google Test as
+// a framework on Mac OS X. The bug causes GetTypeId<
+// ::testing::Test>() to return different values depending on whether
+// the call is from the Google Test framework itself or from user test
+// code. GetTestTypeId() is guaranteed to always return the same
+// value, as it always calls GetTypeId<>() from the Google Test
+// framework.
+#define GTEST_TEST(test_suite_name, test_name) \
+ GTEST_TEST_(test_suite_name, test_name, ::testing::Test, \
+ ::testing::internal::GetTestTypeId())
+
+// Define this macro to 1 to omit the definition of TEST(), which
+// is a generic name and clashes with some other libraries.
+#if !GTEST_DONT_DEFINE_TEST
+#define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name)
+#endif
+
+// Defines a test that uses a test fixture.
+//
+// The first parameter is the name of the test fixture class, which
+// also doubles as the test suite name. The second parameter is the
+// name of the test within the test suite.
+//
+// A test fixture class must be declared earlier. The user should put
+// the test code between braces after using this macro. Example:
+//
+// class FooTest : public testing::Test {
+// protected:
+// void SetUp() override { b_.AddElement(3); }
+//
+// Foo a_;
+// Foo b_;
+// };
+//
+// TEST_F(FooTest, InitializesCorrectly) {
+// EXPECT_TRUE(a_.StatusIsOK());
+// }
+//
+// TEST_F(FooTest, ReturnsElementCountCorrectly) {
+// EXPECT_EQ(a_.size(), 0);
+// EXPECT_EQ(b_.size(), 1);
+// }
+//
+// GOOGLETEST_CM0011 DO NOT DELETE
+#define TEST_F(test_fixture, test_name)\
+ GTEST_TEST_(test_fixture, test_name, test_fixture, \
+ ::testing::internal::GetTypeId<test_fixture>())
+
+// Returns a path to temporary directory.
+// Tries to determine an appropriate directory for the platform.
+GTEST_API_ std::string TempDir();
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+// Dynamically registers a test with the framework.
+//
+// This is an advanced API only to be used when the `TEST` macros are
+// insufficient. The macros should be preferred when possible, as they avoid
+// most of the complexity of calling this function.
+//
+// The `factory` argument is a factory callable (move-constructible) object or
+// function pointer that creates a new instance of the Test object. It
+// handles ownership to the caller. The signature of the callable is
+// `Fixture*()`, where `Fixture` is the test fixture class for the test. All
+// tests registered with the same `test_suite_name` must return the same
+// fixture type. This is checked at runtime.
+//
+// The framework will infer the fixture class from the factory and will call
+// the `SetUpTestSuite` and `TearDownTestSuite` for it.
+//
+// Must be called before `RUN_ALL_TESTS()` is invoked, otherwise behavior is
+// undefined.
+//
+// Use case example:
+//
+// class MyFixture : public ::testing::Test {
+// public:
+// // All of these optional, just like in regular macro usage.
+// static void SetUpTestSuite() { ... }
+// static void TearDownTestSuite() { ... }
+// void SetUp() override { ... }
+// void TearDown() override { ... }
+// };
+//
+// class MyTest : public MyFixture {
+// public:
+// explicit MyTest(int data) : data_(data) {}
+// void TestBody() override { ... }
+//
+// private:
+// int data_;
+// };
+//
+// void RegisterMyTests(const std::vector<int>& values) {
+// for (int v : values) {
+// ::testing::RegisterTest(
+// "MyFixture", ("Test" + std::to_string(v)).c_str(), nullptr,
+// std::to_string(v).c_str(),
+// __FILE__, __LINE__,
+// // Important to use the fixture type as the return type here.
+// [=]() -> MyFixture* { return new MyTest(v); });
+// }
+// }
+// ...
+// int main(int argc, char** argv) {
+// std::vector<int> values_to_test = LoadValuesFromConfig();
+// RegisterMyTests(values_to_test);
+// ...
+// return RUN_ALL_TESTS();
+// }
+//
+template <int&... ExplicitParameterBarrier, typename Factory>
+TestInfo* RegisterTest(const char* test_suite_name, const char* test_name,
+ const char* type_param, const char* value_param,
+ const char* file, int line, Factory factory) {
+ using TestT = typename std::remove_pointer<decltype(factory())>::type;
+
+ class FactoryImpl : public internal::TestFactoryBase {
+ public:
+ explicit FactoryImpl(Factory f) : factory_(std::move(f)) {}
+ Test* CreateTest() override { return factory_(); }
+
+ private:
+ Factory factory_;
+ };
+
+ return internal::MakeAndRegisterTestInfo(
+ test_suite_name, test_name, type_param, value_param,
+ internal::CodeLocation(file, line), internal::GetTypeId<TestT>(),
+ internal::SuiteApiResolver<TestT>::GetSetUpCaseOrSuite(file, line),
+ internal::SuiteApiResolver<TestT>::GetTearDownCaseOrSuite(file, line),
+ new FactoryImpl{std::move(factory)});
+}
+
+} // namespace testing
+
+// Use this function in main() to run all tests. It returns 0 if all
+// tests are successful, or 1 otherwise.
+//
+// RUN_ALL_TESTS() should be invoked after the command line has been
+// parsed by InitGoogleTest().
+//
+// This function was formerly a macro; thus, it is in the global
+// namespace and has an all-caps name.
+int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_;
+
+inline int RUN_ALL_TESTS() {
+ return ::testing::UnitTest::GetInstance()->Run();
+}
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_H_
--- /dev/null
+// Copyright 2006, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
+// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
+//
+// Implements a family of generic predicate assertion macros.
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
+#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
+
+#include "gtest/gtest.h"
+
+namespace testing {
+
+// This header implements a family of generic predicate assertion
+// macros:
+//
+// ASSERT_PRED_FORMAT1(pred_format, v1)
+// ASSERT_PRED_FORMAT2(pred_format, v1, v2)
+// ...
+//
+// where pred_format is a function or functor that takes n (in the
+// case of ASSERT_PRED_FORMATn) values and their source expression
+// text, and returns a testing::AssertionResult. See the definition
+// of ASSERT_EQ in gtest.h for an example.
+//
+// If you don't care about formatting, you can use the more
+// restrictive version:
+//
+// ASSERT_PRED1(pred, v1)
+// ASSERT_PRED2(pred, v1, v2)
+// ...
+//
+// where pred is an n-ary function or functor that returns bool,
+// and the values v1, v2, ..., must support the << operator for
+// streaming to std::ostream.
+//
+// We also define the EXPECT_* variations.
+//
+// For now we only support predicates whose arity is at most 5.
+// Please email googletestframework@googlegroups.com if you need
+// support for higher arities.
+
+// GTEST_ASSERT_ is the basic statement to which all of the assertions
+// in this file reduce. Don't use this in your code.
+
+#define GTEST_ASSERT_(expression, on_failure) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (const ::testing::AssertionResult gtest_ar = (expression)) \
+ ; \
+ else \
+ on_failure(gtest_ar.failure_message())
+
+
+// Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
+// this in your code.
+template <typename Pred,
+ typename T1>
+AssertionResult AssertPred1Helper(const char* pred_text,
+ const char* e1,
+ Pred pred,
+ const T1& v1) {
+ if (pred(v1)) return AssertionSuccess();
+
+ return AssertionFailure()
+ << pred_text << "(" << e1 << ") evaluates to false, where"
+ << "\n"
+ << e1 << " evaluates to " << ::testing::PrintToString(v1);
+}
+
+// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
+// Don't use this in your code.
+#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
+ GTEST_ASSERT_(pred_format(#v1, v1), \
+ on_failure)
+
+// Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
+// this in your code.
+#define GTEST_PRED1_(pred, v1, on_failure)\
+ GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \
+ #v1, \
+ pred, \
+ v1), on_failure)
+
+// Unary predicate assertion macros.
+#define EXPECT_PRED_FORMAT1(pred_format, v1) \
+ GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
+#define EXPECT_PRED1(pred, v1) \
+ GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_PRED_FORMAT1(pred_format, v1) \
+ GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
+#define ASSERT_PRED1(pred, v1) \
+ GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
+
+
+
+// Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use
+// this in your code.
+template <typename Pred,
+ typename T1,
+ typename T2>
+AssertionResult AssertPred2Helper(const char* pred_text,
+ const char* e1,
+ const char* e2,
+ Pred pred,
+ const T1& v1,
+ const T2& v2) {
+ if (pred(v1, v2)) return AssertionSuccess();
+
+ return AssertionFailure()
+ << pred_text << "(" << e1 << ", " << e2
+ << ") evaluates to false, where"
+ << "\n"
+ << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
+ << e2 << " evaluates to " << ::testing::PrintToString(v2);
+}
+
+// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
+// Don't use this in your code.
+#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
+ GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
+ on_failure)
+
+// Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
+// this in your code.
+#define GTEST_PRED2_(pred, v1, v2, on_failure)\
+ GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
+ #v1, \
+ #v2, \
+ pred, \
+ v1, \
+ v2), on_failure)
+
+// Binary predicate assertion macros.
+#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
+ GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
+#define EXPECT_PRED2(pred, v1, v2) \
+ GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
+ GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
+#define ASSERT_PRED2(pred, v1, v2) \
+ GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
+
+
+
+// Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use
+// this in your code.
+template <typename Pred,
+ typename T1,
+ typename T2,
+ typename T3>
+AssertionResult AssertPred3Helper(const char* pred_text,
+ const char* e1,
+ const char* e2,
+ const char* e3,
+ Pred pred,
+ const T1& v1,
+ const T2& v2,
+ const T3& v3) {
+ if (pred(v1, v2, v3)) return AssertionSuccess();
+
+ return AssertionFailure()
+ << pred_text << "(" << e1 << ", " << e2 << ", " << e3
+ << ") evaluates to false, where"
+ << "\n"
+ << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
+ << e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
+ << e3 << " evaluates to " << ::testing::PrintToString(v3);
+}
+
+// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
+// Don't use this in your code.
+#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
+ GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \
+ on_failure)
+
+// Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
+// this in your code.
+#define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
+ GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
+ #v1, \
+ #v2, \
+ #v3, \
+ pred, \
+ v1, \
+ v2, \
+ v3), on_failure)
+
+// Ternary predicate assertion macros.
+#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
+ GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
+#define EXPECT_PRED3(pred, v1, v2, v3) \
+ GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
+ GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
+#define ASSERT_PRED3(pred, v1, v2, v3) \
+ GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
+
+
+
+// Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use
+// this in your code.
+template <typename Pred,
+ typename T1,
+ typename T2,
+ typename T3,
+ typename T4>
+AssertionResult AssertPred4Helper(const char* pred_text,
+ const char* e1,
+ const char* e2,
+ const char* e3,
+ const char* e4,
+ Pred pred,
+ const T1& v1,
+ const T2& v2,
+ const T3& v3,
+ const T4& v4) {
+ if (pred(v1, v2, v3, v4)) return AssertionSuccess();
+
+ return AssertionFailure()
+ << pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
+ << ") evaluates to false, where"
+ << "\n"
+ << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
+ << e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
+ << e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
+ << e4 << " evaluates to " << ::testing::PrintToString(v4);
+}
+
+// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
+// Don't use this in your code.
+#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
+ GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \
+ on_failure)
+
+// Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
+// this in your code.
+#define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\
+ GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \
+ #v1, \
+ #v2, \
+ #v3, \
+ #v4, \
+ pred, \
+ v1, \
+ v2, \
+ v3, \
+ v4), on_failure)
+
+// 4-ary predicate assertion macros.
+#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
+ GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
+#define EXPECT_PRED4(pred, v1, v2, v3, v4) \
+ GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
+ GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
+#define ASSERT_PRED4(pred, v1, v2, v3, v4) \
+ GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
+
+
+
+// Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use
+// this in your code.
+template <typename Pred,
+ typename T1,
+ typename T2,
+ typename T3,
+ typename T4,
+ typename T5>
+AssertionResult AssertPred5Helper(const char* pred_text,
+ const char* e1,
+ const char* e2,
+ const char* e3,
+ const char* e4,
+ const char* e5,
+ Pred pred,
+ const T1& v1,
+ const T2& v2,
+ const T3& v3,
+ const T4& v4,
+ const T5& v5) {
+ if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
+
+ return AssertionFailure()
+ << pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
+ << ", " << e5 << ") evaluates to false, where"
+ << "\n"
+ << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
+ << e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
+ << e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
+ << e4 << " evaluates to " << ::testing::PrintToString(v4) << "\n"
+ << e5 << " evaluates to " << ::testing::PrintToString(v5);
+}
+
+// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
+// Don't use this in your code.
+#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
+ GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
+ on_failure)
+
+// Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
+// this in your code.
+#define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
+ GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
+ #v1, \
+ #v2, \
+ #v3, \
+ #v4, \
+ #v5, \
+ pred, \
+ v1, \
+ v2, \
+ v3, \
+ v4, \
+ v5), on_failure)
+
+// 5-ary predicate assertion macros.
+#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
+ GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
+#define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
+ GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
+ GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
+#define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
+ GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
+
+
+
+} // namespace testing
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
--- /dev/null
+// Copyright 2006, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// Google C++ Testing and Mocking Framework definitions useful in production code.
+// GOOGLETEST_CM0003 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_
+#define GTEST_INCLUDE_GTEST_GTEST_PROD_H_
+
+// When you need to test the private or protected members of a class,
+// use the FRIEND_TEST macro to declare your tests as friends of the
+// class. For example:
+//
+// class MyClass {
+// private:
+// void PrivateMethod();
+// FRIEND_TEST(MyClassTest, PrivateMethodWorks);
+// };
+//
+// class MyClassTest : public testing::Test {
+// // ...
+// };
+//
+// TEST_F(MyClassTest, PrivateMethodWorks) {
+// // Can call MyClass::PrivateMethod() here.
+// }
+//
+// Note: The test class must be in the same namespace as the class being tested.
+// For example, putting MyClassTest in an anonymous namespace will not work.
+
+#define FRIEND_TEST(test_case_name, test_name)\
+friend class test_case_name##_##test_name##_Test
+
+#endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_
--- /dev/null
+# Customization Points
+
+The custom directory is an injection point for custom user configurations.
+
+## Header `gtest.h`
+
+### The following macros can be defined:
+
+* `GTEST_OS_STACK_TRACE_GETTER_` - The name of an implementation of
+ `OsStackTraceGetterInterface`.
+* `GTEST_CUSTOM_TEMPDIR_FUNCTION_` - An override for `testing::TempDir()`. See
+ `testing::TempDir` for semantics and signature.
+
+## Header `gtest-port.h`
+
+The following macros can be defined:
+
+### Flag related macros:
+
+* `GTEST_FLAG(flag_name)`
+* `GTEST_USE_OWN_FLAGFILE_FLAG_` - Define to 0 when the system provides its
+ own flagfile flag parsing.
+* `GTEST_DECLARE_bool_(name)`
+* `GTEST_DECLARE_int32_(name)`
+* `GTEST_DECLARE_string_(name)`
+* `GTEST_DEFINE_bool_(name, default_val, doc)`
+* `GTEST_DEFINE_int32_(name, default_val, doc)`
+* `GTEST_DEFINE_string_(name, default_val, doc)`
+
+### Logging:
+
+* `GTEST_LOG_(severity)`
+* `GTEST_CHECK_(condition)`
+* Functions `LogToStderr()` and `FlushInfoLog()` have to be provided too.
+
+### Threading:
+
+* `GTEST_HAS_NOTIFICATION_` - Enabled if Notification is already provided.
+* `GTEST_HAS_MUTEX_AND_THREAD_LOCAL_` - Enabled if `Mutex` and `ThreadLocal`
+ are already provided. Must also provide `GTEST_DECLARE_STATIC_MUTEX_(mutex)`
+ and `GTEST_DEFINE_STATIC_MUTEX_(mutex)`
+* `GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)`
+* `GTEST_LOCK_EXCLUDED_(locks)`
+
+### Underlying library support features
+
+* `GTEST_HAS_CXXABI_H_`
+
+### Exporting API symbols:
+
+* `GTEST_API_` - Specifier for exported symbols.
+
+## Header `gtest-printers.h`
+
+* See documentation at `gtest/gtest-printers.h` for details on how to define a
+ custom printer.
--- /dev/null
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Injection point for custom user configurations. See README for details
+//
+// ** Custom implementation starts here **
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
--- /dev/null
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// This file provides an injection point for custom printers in a local
+// installation of gTest.
+// It will be included from gtest-printers.h and the overrides in this file
+// will be visible to everyone.
+//
+// Injection point for custom user configurations. See README for details
+//
+// ** Custom implementation starts here **
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
--- /dev/null
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Injection point for custom user configurations. See README for details
+//
+// ** Custom implementation starts here **
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
--- /dev/null
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// The Google C++ Testing and Mocking Framework (Google Test)
+//
+// This header file defines internal utilities needed for implementing
+// death tests. They are subject to change without notice.
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
+
+#include "gtest/gtest-matchers.h"
+#include "gtest/internal/gtest-internal.h"
+
+#include <stdio.h>
+#include <memory>
+
+namespace testing {
+namespace internal {
+
+GTEST_DECLARE_string_(internal_run_death_test);
+
+// Names of the flags (needed for parsing Google Test flags).
+const char kDeathTestStyleFlag[] = "death_test_style";
+const char kDeathTestUseFork[] = "death_test_use_fork";
+const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
+
+#if GTEST_HAS_DEATH_TEST
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
+/* class A needs to have dll-interface to be used by clients of class B */)
+
+// DeathTest is a class that hides much of the complexity of the
+// GTEST_DEATH_TEST_ macro. It is abstract; its static Create method
+// returns a concrete class that depends on the prevailing death test
+// style, as defined by the --gtest_death_test_style and/or
+// --gtest_internal_run_death_test flags.
+
+// In describing the results of death tests, these terms are used with
+// the corresponding definitions:
+//
+// exit status: The integer exit information in the format specified
+// by wait(2)
+// exit code: The integer code passed to exit(3), _exit(2), or
+// returned from main()
+class GTEST_API_ DeathTest {
+ public:
+ // Create returns false if there was an error determining the
+ // appropriate action to take for the current death test; for example,
+ // if the gtest_death_test_style flag is set to an invalid value.
+ // The LastMessage method will return a more detailed message in that
+ // case. Otherwise, the DeathTest pointer pointed to by the "test"
+ // argument is set. If the death test should be skipped, the pointer
+ // is set to NULL; otherwise, it is set to the address of a new concrete
+ // DeathTest object that controls the execution of the current test.
+ static bool Create(const char* statement, Matcher<const std::string&> matcher,
+ const char* file, int line, DeathTest** test);
+ DeathTest();
+ virtual ~DeathTest() { }
+
+ // A helper class that aborts a death test when it's deleted.
+ class ReturnSentinel {
+ public:
+ explicit ReturnSentinel(DeathTest* test) : test_(test) { }
+ ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
+ private:
+ DeathTest* const test_;
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel);
+ } GTEST_ATTRIBUTE_UNUSED_;
+
+ // An enumeration of possible roles that may be taken when a death
+ // test is encountered. EXECUTE means that the death test logic should
+ // be executed immediately. OVERSEE means that the program should prepare
+ // the appropriate environment for a child process to execute the death
+ // test, then wait for it to complete.
+ enum TestRole { OVERSEE_TEST, EXECUTE_TEST };
+
+ // An enumeration of the three reasons that a test might be aborted.
+ enum AbortReason {
+ TEST_ENCOUNTERED_RETURN_STATEMENT,
+ TEST_THREW_EXCEPTION,
+ TEST_DID_NOT_DIE
+ };
+
+ // Assumes one of the above roles.
+ virtual TestRole AssumeRole() = 0;
+
+ // Waits for the death test to finish and returns its status.
+ virtual int Wait() = 0;
+
+ // Returns true if the death test passed; that is, the test process
+ // exited during the test, its exit status matches a user-supplied
+ // predicate, and its stderr output matches a user-supplied regular
+ // expression.
+ // The user-supplied predicate may be a macro expression rather
+ // than a function pointer or functor, or else Wait and Passed could
+ // be combined.
+ virtual bool Passed(bool exit_status_ok) = 0;
+
+ // Signals that the death test did not die as expected.
+ virtual void Abort(AbortReason reason) = 0;
+
+ // Returns a human-readable outcome message regarding the outcome of
+ // the last death test.
+ static const char* LastMessage();
+
+ static void set_last_death_test_message(const std::string& message);
+
+ private:
+ // A string containing a description of the outcome of the last death test.
+ static std::string last_death_test_message_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
+};
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
+
+// Factory interface for death tests. May be mocked out for testing.
+class DeathTestFactory {
+ public:
+ virtual ~DeathTestFactory() { }
+ virtual bool Create(const char* statement,
+ Matcher<const std::string&> matcher, const char* file,
+ int line, DeathTest** test) = 0;
+};
+
+// A concrete DeathTestFactory implementation for normal use.
+class DefaultDeathTestFactory : public DeathTestFactory {
+ public:
+ bool Create(const char* statement, Matcher<const std::string&> matcher,
+ const char* file, int line, DeathTest** test) override;
+};
+
+// Returns true if exit_status describes a process that was terminated
+// by a signal, or exited normally with a nonzero exit code.
+GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
+
+// A string passed to EXPECT_DEATH (etc.) is caught by one of these overloads
+// and interpreted as a regex (rather than an Eq matcher) for legacy
+// compatibility.
+inline Matcher<const ::std::string&> MakeDeathTestMatcher(
+ ::testing::internal::RE regex) {
+ return ContainsRegex(regex.pattern());
+}
+inline Matcher<const ::std::string&> MakeDeathTestMatcher(const char* regex) {
+ return ContainsRegex(regex);
+}
+inline Matcher<const ::std::string&> MakeDeathTestMatcher(
+ const ::std::string& regex) {
+ return ContainsRegex(regex);
+}
+
+// If a Matcher<const ::std::string&> is passed to EXPECT_DEATH (etc.), it's
+// used directly.
+inline Matcher<const ::std::string&> MakeDeathTestMatcher(
+ Matcher<const ::std::string&> matcher) {
+ return matcher;
+}
+
+// Traps C++ exceptions escaping statement and reports them as test
+// failures. Note that trapping SEH exceptions is not implemented here.
+# if GTEST_HAS_EXCEPTIONS
+# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
+ try { \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ } catch (const ::std::exception& gtest_exception) { \
+ fprintf(\
+ stderr, \
+ "\n%s: Caught std::exception-derived exception escaping the " \
+ "death test statement. Exception message: %s\n", \
+ ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \
+ gtest_exception.what()); \
+ fflush(stderr); \
+ death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
+ } catch (...) { \
+ death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
+ }
+
+# else
+# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
+
+# endif
+
+// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
+// ASSERT_EXIT*, and EXPECT_EXIT*.
+#define GTEST_DEATH_TEST_(statement, predicate, regex_or_matcher, fail) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::AlwaysTrue()) { \
+ ::testing::internal::DeathTest* gtest_dt; \
+ if (!::testing::internal::DeathTest::Create( \
+ #statement, \
+ ::testing::internal::MakeDeathTestMatcher(regex_or_matcher), \
+ __FILE__, __LINE__, >est_dt)) { \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
+ } \
+ if (gtest_dt != nullptr) { \
+ std::unique_ptr< ::testing::internal::DeathTest> gtest_dt_ptr(gtest_dt); \
+ switch (gtest_dt->AssumeRole()) { \
+ case ::testing::internal::DeathTest::OVERSEE_TEST: \
+ if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
+ } \
+ break; \
+ case ::testing::internal::DeathTest::EXECUTE_TEST: { \
+ ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \
+ gtest_dt); \
+ GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
+ gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
+ break; \
+ } \
+ default: \
+ break; \
+ } \
+ } \
+ } else \
+ GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__) \
+ : fail(::testing::internal::DeathTest::LastMessage())
+// The symbol "fail" here expands to something into which a message
+// can be streamed.
+
+// This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in
+// NDEBUG mode. In this case we need the statements to be executed and the macro
+// must accept a streamed message even though the message is never printed.
+// The regex object is not evaluated, but it is used to prevent "unused"
+// warnings and to avoid an expression that doesn't compile in debug mode.
+#define GTEST_EXECUTE_STATEMENT_(statement, regex_or_matcher) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::AlwaysTrue()) { \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ } else if (!::testing::internal::AlwaysTrue()) { \
+ ::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \
+ } else \
+ ::testing::Message()
+
+// A class representing the parsed contents of the
+// --gtest_internal_run_death_test flag, as it existed when
+// RUN_ALL_TESTS was called.
+class InternalRunDeathTestFlag {
+ public:
+ InternalRunDeathTestFlag(const std::string& a_file,
+ int a_line,
+ int an_index,
+ int a_write_fd)
+ : file_(a_file), line_(a_line), index_(an_index),
+ write_fd_(a_write_fd) {}
+
+ ~InternalRunDeathTestFlag() {
+ if (write_fd_ >= 0)
+ posix::Close(write_fd_);
+ }
+
+ const std::string& file() const { return file_; }
+ int line() const { return line_; }
+ int index() const { return index_; }
+ int write_fd() const { return write_fd_; }
+
+ private:
+ std::string file_;
+ int line_;
+ int index_;
+ int write_fd_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag);
+};
+
+// Returns a newly created InternalRunDeathTestFlag object with fields
+// initialized from the GTEST_FLAG(internal_run_death_test) flag if
+// the flag is specified; otherwise returns NULL.
+InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
+
+#endif // GTEST_HAS_DEATH_TEST
+
+} // namespace internal
+} // namespace testing
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Google Test filepath utilities
+//
+// This header file declares classes and functions used internally by
+// Google Test. They are subject to change without notice.
+//
+// This file is #included in gtest/internal/gtest-internal.h.
+// Do not include this header file separately!
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
+
+#include "gtest/internal/gtest-string.h"
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
+/* class A needs to have dll-interface to be used by clients of class B */)
+
+namespace testing {
+namespace internal {
+
+// FilePath - a class for file and directory pathname manipulation which
+// handles platform-specific conventions (like the pathname separator).
+// Used for helper functions for naming files in a directory for xml output.
+// Except for Set methods, all methods are const or static, which provides an
+// "immutable value object" -- useful for peace of mind.
+// A FilePath with a value ending in a path separator ("like/this/") represents
+// a directory, otherwise it is assumed to represent a file. In either case,
+// it may or may not represent an actual file or directory in the file system.
+// Names are NOT checked for syntax correctness -- no checking for illegal
+// characters, malformed paths, etc.
+
+class GTEST_API_ FilePath {
+ public:
+ FilePath() : pathname_("") { }
+ FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
+
+ explicit FilePath(const std::string& pathname) : pathname_(pathname) {
+ Normalize();
+ }
+
+ FilePath& operator=(const FilePath& rhs) {
+ Set(rhs);
+ return *this;
+ }
+
+ void Set(const FilePath& rhs) {
+ pathname_ = rhs.pathname_;
+ }
+
+ const std::string& string() const { return pathname_; }
+ const char* c_str() const { return pathname_.c_str(); }
+
+ // Returns the current working directory, or "" if unsuccessful.
+ static FilePath GetCurrentDir();
+
+ // Given directory = "dir", base_name = "test", number = 0,
+ // extension = "xml", returns "dir/test.xml". If number is greater
+ // than zero (e.g., 12), returns "dir/test_12.xml".
+ // On Windows platform, uses \ as the separator rather than /.
+ static FilePath MakeFileName(const FilePath& directory,
+ const FilePath& base_name,
+ int number,
+ const char* extension);
+
+ // Given directory = "dir", relative_path = "test.xml",
+ // returns "dir/test.xml".
+ // On Windows, uses \ as the separator rather than /.
+ static FilePath ConcatPaths(const FilePath& directory,
+ const FilePath& relative_path);
+
+ // Returns a pathname for a file that does not currently exist. The pathname
+ // will be directory/base_name.extension or
+ // directory/base_name_<number>.extension if directory/base_name.extension
+ // already exists. The number will be incremented until a pathname is found
+ // that does not already exist.
+ // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
+ // There could be a race condition if two or more processes are calling this
+ // function at the same time -- they could both pick the same filename.
+ static FilePath GenerateUniqueFileName(const FilePath& directory,
+ const FilePath& base_name,
+ const char* extension);
+
+ // Returns true iff the path is "".
+ bool IsEmpty() const { return pathname_.empty(); }
+
+ // If input name has a trailing separator character, removes it and returns
+ // the name, otherwise return the name string unmodified.
+ // On Windows platform, uses \ as the separator, other platforms use /.
+ FilePath RemoveTrailingPathSeparator() const;
+
+ // Returns a copy of the FilePath with the directory part removed.
+ // Example: FilePath("path/to/file").RemoveDirectoryName() returns
+ // FilePath("file"). If there is no directory part ("just_a_file"), it returns
+ // the FilePath unmodified. If there is no file part ("just_a_dir/") it
+ // returns an empty FilePath ("").
+ // On Windows platform, '\' is the path separator, otherwise it is '/'.
+ FilePath RemoveDirectoryName() const;
+
+ // RemoveFileName returns the directory path with the filename removed.
+ // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
+ // If the FilePath is "a_file" or "/a_file", RemoveFileName returns
+ // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
+ // not have a file, like "just/a/dir/", it returns the FilePath unmodified.
+ // On Windows platform, '\' is the path separator, otherwise it is '/'.
+ FilePath RemoveFileName() const;
+
+ // Returns a copy of the FilePath with the case-insensitive extension removed.
+ // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
+ // FilePath("dir/file"). If a case-insensitive extension is not
+ // found, returns a copy of the original FilePath.
+ FilePath RemoveExtension(const char* extension) const;
+
+ // Creates directories so that path exists. Returns true if successful or if
+ // the directories already exist; returns false if unable to create
+ // directories for any reason. Will also return false if the FilePath does
+ // not represent a directory (that is, it doesn't end with a path separator).
+ bool CreateDirectoriesRecursively() const;
+
+ // Create the directory so that path exists. Returns true if successful or
+ // if the directory already exists; returns false if unable to create the
+ // directory for any reason, including if the parent directory does not
+ // exist. Not named "CreateDirectory" because that's a macro on Windows.
+ bool CreateFolder() const;
+
+ // Returns true if FilePath describes something in the file-system,
+ // either a file, directory, or whatever, and that something exists.
+ bool FileOrDirectoryExists() const;
+
+ // Returns true if pathname describes a directory in the file-system
+ // that exists.
+ bool DirectoryExists() const;
+
+ // Returns true if FilePath ends with a path separator, which indicates that
+ // it is intended to represent a directory. Returns false otherwise.
+ // This does NOT check that a directory (or file) actually exists.
+ bool IsDirectory() const;
+
+ // Returns true if pathname describes a root directory. (Windows has one
+ // root directory per disk drive.)
+ bool IsRootDirectory() const;
+
+ // Returns true if pathname describes an absolute path.
+ bool IsAbsolutePath() const;
+
+ private:
+ // Replaces multiple consecutive separators with a single separator.
+ // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
+ // redundancies that might be in a pathname involving "." or "..".
+ //
+ // A pathname with multiple consecutive separators may occur either through
+ // user error or as a result of some scripts or APIs that generate a pathname
+ // with a trailing separator. On other platforms the same API or script
+ // may NOT generate a pathname with a trailing "/". Then elsewhere that
+ // pathname may have another "/" and pathname components added to it,
+ // without checking for the separator already being there.
+ // The script language and operating system may allow paths like "foo//bar"
+ // but some of the functions in FilePath will not handle that correctly. In
+ // particular, RemoveTrailingPathSeparator() only removes one separator, and
+ // it is called in CreateDirectoriesRecursively() assuming that it will change
+ // a pathname from directory syntax (trailing separator) to filename syntax.
+ //
+ // On Windows this method also replaces the alternate path separator '/' with
+ // the primary path separator '\\', so that for example "bar\\/\\foo" becomes
+ // "bar\\foo".
+
+ void Normalize();
+
+ // Returns a pointer to the last occurence of a valid path separator in
+ // the FilePath. On Windows, for example, both '/' and '\' are valid path
+ // separators. Returns NULL if no path separator was found.
+ const char* FindLastPathSeparator() const;
+
+ std::string pathname_;
+}; // class FilePath
+
+} // namespace internal
+} // namespace testing
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
--- /dev/null
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// The Google C++ Testing and Mocking Framework (Google Test)
+//
+// This header file declares functions and macros used internally by
+// Google Test. They are subject to change without notice.
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
+
+#include "gtest/internal/gtest-port.h"
+
+#if GTEST_OS_LINUX
+# include <stdlib.h>
+# include <sys/types.h>
+# include <sys/wait.h>
+# include <unistd.h>
+#endif // GTEST_OS_LINUX
+
+#if GTEST_HAS_EXCEPTIONS
+# include <stdexcept>
+#endif
+
+#include <ctype.h>
+#include <float.h>
+#include <string.h>
+#include <iomanip>
+#include <limits>
+#include <map>
+#include <set>
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#include "gtest/gtest-message.h"
+#include "gtest/internal/gtest-filepath.h"
+#include "gtest/internal/gtest-string.h"
+#include "gtest/internal/gtest-type-util.h"
+
+// Due to C++ preprocessor weirdness, we need double indirection to
+// concatenate two tokens when one of them is __LINE__. Writing
+//
+// foo ## __LINE__
+//
+// will result in the token foo__LINE__, instead of foo followed by
+// the current line number. For more details, see
+// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
+#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
+#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
+
+// Stringifies its argument.
+#define GTEST_STRINGIFY_(name) #name
+
+namespace proto2 { class Message; }
+
+namespace testing {
+
+// Forward declarations.
+
+class AssertionResult; // Result of an assertion.
+class Message; // Represents a failure message.
+class Test; // Represents a test.
+class TestInfo; // Information about a test.
+class TestPartResult; // Result of a test part.
+class UnitTest; // A collection of test suites.
+
+template <typename T>
+::std::string PrintToString(const T& value);
+
+namespace internal {
+
+struct TraceInfo; // Information about a trace point.
+class TestInfoImpl; // Opaque implementation of TestInfo
+class UnitTestImpl; // Opaque implementation of UnitTest
+
+// The text used in failure messages to indicate the start of the
+// stack trace.
+GTEST_API_ extern const char kStackTraceMarker[];
+
+// An IgnoredValue object can be implicitly constructed from ANY value.
+class IgnoredValue {
+ struct Sink {};
+ public:
+ // This constructor template allows any value to be implicitly
+ // converted to IgnoredValue. The object has no data member and
+ // doesn't try to remember anything about the argument. We
+ // deliberately omit the 'explicit' keyword in order to allow the
+ // conversion to be implicit.
+ // Disable the conversion if T already has a magical conversion operator.
+ // Otherwise we get ambiguity.
+ template <typename T,
+ typename std::enable_if<!std::is_convertible<T, Sink>::value,
+ int>::type = 0>
+ IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit)
+};
+
+// Appends the user-supplied message to the Google-Test-generated message.
+GTEST_API_ std::string AppendUserMessage(
+ const std::string& gtest_msg, const Message& user_msg);
+
+#if GTEST_HAS_EXCEPTIONS
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4275 \
+/* an exported class was derived from a class that was not exported */)
+
+// This exception is thrown by (and only by) a failed Google Test
+// assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions
+// are enabled). We derive it from std::runtime_error, which is for
+// errors presumably detectable only at run time. Since
+// std::runtime_error inherits from std::exception, many testing
+// frameworks know how to extract and print the message inside it.
+class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error {
+ public:
+ explicit GoogleTestFailureException(const TestPartResult& failure);
+};
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4275
+
+#endif // GTEST_HAS_EXCEPTIONS
+
+namespace edit_distance {
+// Returns the optimal edits to go from 'left' to 'right'.
+// All edits cost the same, with replace having lower priority than
+// add/remove.
+// Simple implementation of the Wagner-Fischer algorithm.
+// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
+enum EditType { kMatch, kAdd, kRemove, kReplace };
+GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
+ const std::vector<size_t>& left, const std::vector<size_t>& right);
+
+// Same as above, but the input is represented as strings.
+GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
+ const std::vector<std::string>& left,
+ const std::vector<std::string>& right);
+
+// Create a diff of the input strings in Unified diff format.
+GTEST_API_ std::string CreateUnifiedDiff(const std::vector<std::string>& left,
+ const std::vector<std::string>& right,
+ size_t context = 2);
+
+} // namespace edit_distance
+
+// Calculate the diff between 'left' and 'right' and return it in unified diff
+// format.
+// If not null, stores in 'total_line_count' the total number of lines found
+// in left + right.
+GTEST_API_ std::string DiffStrings(const std::string& left,
+ const std::string& right,
+ size_t* total_line_count);
+
+// Constructs and returns the message for an equality assertion
+// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
+//
+// The first four parameters are the expressions used in the assertion
+// and their values, as strings. For example, for ASSERT_EQ(foo, bar)
+// where foo is 5 and bar is 6, we have:
+//
+// expected_expression: "foo"
+// actual_expression: "bar"
+// expected_value: "5"
+// actual_value: "6"
+//
+// The ignoring_case parameter is true iff the assertion is a
+// *_STRCASEEQ*. When it's true, the string " (ignoring case)" will
+// be inserted into the message.
+GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
+ const char* actual_expression,
+ const std::string& expected_value,
+ const std::string& actual_value,
+ bool ignoring_case);
+
+// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
+GTEST_API_ std::string GetBoolAssertionFailureMessage(
+ const AssertionResult& assertion_result,
+ const char* expression_text,
+ const char* actual_predicate_value,
+ const char* expected_predicate_value);
+
+// This template class represents an IEEE floating-point number
+// (either single-precision or double-precision, depending on the
+// template parameters).
+//
+// The purpose of this class is to do more sophisticated number
+// comparison. (Due to round-off error, etc, it's very unlikely that
+// two floating-points will be equal exactly. Hence a naive
+// comparison by the == operation often doesn't work.)
+//
+// Format of IEEE floating-point:
+//
+// The most-significant bit being the leftmost, an IEEE
+// floating-point looks like
+//
+// sign_bit exponent_bits fraction_bits
+//
+// Here, sign_bit is a single bit that designates the sign of the
+// number.
+//
+// For float, there are 8 exponent bits and 23 fraction bits.
+//
+// For double, there are 11 exponent bits and 52 fraction bits.
+//
+// More details can be found at
+// http://en.wikipedia.org/wiki/IEEE_floating-point_standard.
+//
+// Template parameter:
+//
+// RawType: the raw floating-point type (either float or double)
+template <typename RawType>
+class FloatingPoint {
+ public:
+ // Defines the unsigned integer type that has the same size as the
+ // floating point number.
+ typedef typename TypeWithSize<sizeof(RawType)>::UInt Bits;
+
+ // Constants.
+
+ // # of bits in a number.
+ static const size_t kBitCount = 8*sizeof(RawType);
+
+ // # of fraction bits in a number.
+ static const size_t kFractionBitCount =
+ std::numeric_limits<RawType>::digits - 1;
+
+ // # of exponent bits in a number.
+ static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount;
+
+ // The mask for the sign bit.
+ static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1);
+
+ // The mask for the fraction bits.
+ static const Bits kFractionBitMask =
+ ~static_cast<Bits>(0) >> (kExponentBitCount + 1);
+
+ // The mask for the exponent bits.
+ static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask);
+
+ // How many ULP's (Units in the Last Place) we want to tolerate when
+ // comparing two numbers. The larger the value, the more error we
+ // allow. A 0 value means that two numbers must be exactly the same
+ // to be considered equal.
+ //
+ // The maximum error of a single floating-point operation is 0.5
+ // units in the last place. On Intel CPU's, all floating-point
+ // calculations are done with 80-bit precision, while double has 64
+ // bits. Therefore, 4 should be enough for ordinary use.
+ //
+ // See the following article for more details on ULP:
+ // http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
+ static const size_t kMaxUlps = 4;
+
+ // Constructs a FloatingPoint from a raw floating-point number.
+ //
+ // On an Intel CPU, passing a non-normalized NAN (Not a Number)
+ // around may change its bits, although the new value is guaranteed
+ // to be also a NAN. Therefore, don't expect this constructor to
+ // preserve the bits in x when x is a NAN.
+ explicit FloatingPoint(const RawType& x) { u_.value_ = x; }
+
+ // Static methods
+
+ // Reinterprets a bit pattern as a floating-point number.
+ //
+ // This function is needed to test the AlmostEquals() method.
+ static RawType ReinterpretBits(const Bits bits) {
+ FloatingPoint fp(0);
+ fp.u_.bits_ = bits;
+ return fp.u_.value_;
+ }
+
+ // Returns the floating-point number that represent positive infinity.
+ static RawType Infinity() {
+ return ReinterpretBits(kExponentBitMask);
+ }
+
+ // Returns the maximum representable finite floating-point number.
+ static RawType Max();
+
+ // Non-static methods
+
+ // Returns the bits that represents this number.
+ const Bits &bits() const { return u_.bits_; }
+
+ // Returns the exponent bits of this number.
+ Bits exponent_bits() const { return kExponentBitMask & u_.bits_; }
+
+ // Returns the fraction bits of this number.
+ Bits fraction_bits() const { return kFractionBitMask & u_.bits_; }
+
+ // Returns the sign bit of this number.
+ Bits sign_bit() const { return kSignBitMask & u_.bits_; }
+
+ // Returns true iff this is NAN (not a number).
+ bool is_nan() const {
+ // It's a NAN if the exponent bits are all ones and the fraction
+ // bits are not entirely zeros.
+ return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);
+ }
+
+ // Returns true iff this number is at most kMaxUlps ULP's away from
+ // rhs. In particular, this function:
+ //
+ // - returns false if either number is (or both are) NAN.
+ // - treats really large numbers as almost equal to infinity.
+ // - thinks +0.0 and -0.0 are 0 DLP's apart.
+ bool AlmostEquals(const FloatingPoint& rhs) const {
+ // The IEEE standard says that any comparison operation involving
+ // a NAN must return false.
+ if (is_nan() || rhs.is_nan()) return false;
+
+ return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
+ <= kMaxUlps;
+ }
+
+ private:
+ // The data type used to store the actual floating-point number.
+ union FloatingPointUnion {
+ RawType value_; // The raw floating-point number.
+ Bits bits_; // The bits that represent the number.
+ };
+
+ // Converts an integer from the sign-and-magnitude representation to
+ // the biased representation. More precisely, let N be 2 to the
+ // power of (kBitCount - 1), an integer x is represented by the
+ // unsigned number x + N.
+ //
+ // For instance,
+ //
+ // -N + 1 (the most negative number representable using
+ // sign-and-magnitude) is represented by 1;
+ // 0 is represented by N; and
+ // N - 1 (the biggest number representable using
+ // sign-and-magnitude) is represented by 2N - 1.
+ //
+ // Read http://en.wikipedia.org/wiki/Signed_number_representations
+ // for more details on signed number representations.
+ static Bits SignAndMagnitudeToBiased(const Bits &sam) {
+ if (kSignBitMask & sam) {
+ // sam represents a negative number.
+ return ~sam + 1;
+ } else {
+ // sam represents a positive number.
+ return kSignBitMask | sam;
+ }
+ }
+
+ // Given two numbers in the sign-and-magnitude representation,
+ // returns the distance between them as an unsigned number.
+ static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1,
+ const Bits &sam2) {
+ const Bits biased1 = SignAndMagnitudeToBiased(sam1);
+ const Bits biased2 = SignAndMagnitudeToBiased(sam2);
+ return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
+ }
+
+ FloatingPointUnion u_;
+};
+
+// We cannot use std::numeric_limits<T>::max() as it clashes with the max()
+// macro defined by <windows.h>.
+template <>
+inline float FloatingPoint<float>::Max() { return FLT_MAX; }
+template <>
+inline double FloatingPoint<double>::Max() { return DBL_MAX; }
+
+// Typedefs the instances of the FloatingPoint template class that we
+// care to use.
+typedef FloatingPoint<float> Float;
+typedef FloatingPoint<double> Double;
+
+// In order to catch the mistake of putting tests that use different
+// test fixture classes in the same test suite, we need to assign
+// unique IDs to fixture classes and compare them. The TypeId type is
+// used to hold such IDs. The user should treat TypeId as an opaque
+// type: the only operation allowed on TypeId values is to compare
+// them for equality using the == operator.
+typedef const void* TypeId;
+
+template <typename T>
+class TypeIdHelper {
+ public:
+ // dummy_ must not have a const type. Otherwise an overly eager
+ // compiler (e.g. MSVC 7.1 & 8.0) may try to merge
+ // TypeIdHelper<T>::dummy_ for different Ts as an "optimization".
+ static bool dummy_;
+};
+
+template <typename T>
+bool TypeIdHelper<T>::dummy_ = false;
+
+// GetTypeId<T>() returns the ID of type T. Different values will be
+// returned for different types. Calling the function twice with the
+// same type argument is guaranteed to return the same ID.
+template <typename T>
+TypeId GetTypeId() {
+ // The compiler is required to allocate a different
+ // TypeIdHelper<T>::dummy_ variable for each T used to instantiate
+ // the template. Therefore, the address of dummy_ is guaranteed to
+ // be unique.
+ return &(TypeIdHelper<T>::dummy_);
+}
+
+// Returns the type ID of ::testing::Test. Always call this instead
+// of GetTypeId< ::testing::Test>() to get the type ID of
+// ::testing::Test, as the latter may give the wrong result due to a
+// suspected linker bug when compiling Google Test as a Mac OS X
+// framework.
+GTEST_API_ TypeId GetTestTypeId();
+
+// Defines the abstract factory interface that creates instances
+// of a Test object.
+class TestFactoryBase {
+ public:
+ virtual ~TestFactoryBase() {}
+
+ // Creates a test instance to run. The instance is both created and destroyed
+ // within TestInfoImpl::Run()
+ virtual Test* CreateTest() = 0;
+
+ protected:
+ TestFactoryBase() {}
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase);
+};
+
+// This class provides implementation of TeastFactoryBase interface.
+// It is used in TEST and TEST_F macros.
+template <class TestClass>
+class TestFactoryImpl : public TestFactoryBase {
+ public:
+ Test* CreateTest() override { return new TestClass; }
+};
+
+#if GTEST_OS_WINDOWS
+
+// Predicate-formatters for implementing the HRESULT checking macros
+// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}
+// We pass a long instead of HRESULT to avoid causing an
+// include dependency for the HRESULT type.
+GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr,
+ long hr); // NOLINT
+GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
+ long hr); // NOLINT
+
+#endif // GTEST_OS_WINDOWS
+
+// Types of SetUpTestSuite() and TearDownTestSuite() functions.
+using SetUpTestSuiteFunc = void (*)();
+using TearDownTestSuiteFunc = void (*)();
+
+struct CodeLocation {
+ CodeLocation(const std::string& a_file, int a_line)
+ : file(a_file), line(a_line) {}
+
+ std::string file;
+ int line;
+};
+
+// Helper to identify which setup function for TestCase / TestSuite to call.
+// Only one function is allowed, either TestCase or TestSute but not both.
+
+// Utility functions to help SuiteApiResolver
+using SetUpTearDownSuiteFuncType = void (*)();
+
+inline SetUpTearDownSuiteFuncType GetNotDefaultOrNull(
+ SetUpTearDownSuiteFuncType a, SetUpTearDownSuiteFuncType def) {
+ return a == def ? nullptr : a;
+}
+
+template <typename T>
+// Note that SuiteApiResolver inherits from T because
+// SetUpTestSuite()/TearDownTestSuite() could be protected. Ths way
+// SuiteApiResolver can access them.
+struct SuiteApiResolver : T {
+ // testing::Test is only forward declared at this point. So we make it a
+ // dependend class for the compiler to be OK with it.
+ using Test =
+ typename std::conditional<sizeof(T) != 0, ::testing::Test, void>::type;
+
+ static SetUpTearDownSuiteFuncType GetSetUpCaseOrSuite(const char* filename,
+ int line_num) {
+ SetUpTearDownSuiteFuncType test_case_fp =
+ GetNotDefaultOrNull(&T::SetUpTestCase, &Test::SetUpTestCase);
+ SetUpTearDownSuiteFuncType test_suite_fp =
+ GetNotDefaultOrNull(&T::SetUpTestSuite, &Test::SetUpTestSuite);
+
+ GTEST_CHECK_(!test_case_fp || !test_suite_fp)
+ << "Test can not provide both SetUpTestSuite and SetUpTestCase, please "
+ "make sure there is only one present at "
+ << filename << ":" << line_num;
+
+ return test_case_fp != nullptr ? test_case_fp : test_suite_fp;
+ }
+
+ static SetUpTearDownSuiteFuncType GetTearDownCaseOrSuite(const char* filename,
+ int line_num) {
+ SetUpTearDownSuiteFuncType test_case_fp =
+ GetNotDefaultOrNull(&T::TearDownTestCase, &Test::TearDownTestCase);
+ SetUpTearDownSuiteFuncType test_suite_fp =
+ GetNotDefaultOrNull(&T::TearDownTestSuite, &Test::TearDownTestSuite);
+
+ GTEST_CHECK_(!test_case_fp || !test_suite_fp)
+ << "Test can not provide both TearDownTestSuite and TearDownTestCase,"
+ " please make sure there is only one present at"
+ << filename << ":" << line_num;
+
+ return test_case_fp != nullptr ? test_case_fp : test_suite_fp;
+ }
+};
+
+// Creates a new TestInfo object and registers it with Google Test;
+// returns the created object.
+//
+// Arguments:
+//
+// test_suite_name: name of the test suite
+// name: name of the test
+// type_param the name of the test's type parameter, or NULL if
+// this is not a typed or a type-parameterized test.
+// value_param text representation of the test's value parameter,
+// or NULL if this is not a type-parameterized test.
+// code_location: code location where the test is defined
+// fixture_class_id: ID of the test fixture class
+// set_up_tc: pointer to the function that sets up the test suite
+// tear_down_tc: pointer to the function that tears down the test suite
+// factory: pointer to the factory that creates a test object.
+// The newly created TestInfo instance will assume
+// ownership of the factory object.
+GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
+ const char* test_suite_name, const char* name, const char* type_param,
+ const char* value_param, CodeLocation code_location,
+ TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc,
+ TearDownTestSuiteFunc tear_down_tc, TestFactoryBase* factory);
+
+// If *pstr starts with the given prefix, modifies *pstr to be right
+// past the prefix and returns true; otherwise leaves *pstr unchanged
+// and returns false. None of pstr, *pstr, and prefix can be NULL.
+GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
+
+#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
+/* class A needs to have dll-interface to be used by clients of class B */)
+
+// State of the definition of a type-parameterized test suite.
+class GTEST_API_ TypedTestSuitePState {
+ public:
+ TypedTestSuitePState() : registered_(false) {}
+
+ // Adds the given test name to defined_test_names_ and return true
+ // if the test suite hasn't been registered; otherwise aborts the
+ // program.
+ bool AddTestName(const char* file, int line, const char* case_name,
+ const char* test_name) {
+ if (registered_) {
+ fprintf(stderr,
+ "%s Test %s must be defined before "
+ "REGISTER_TYPED_TEST_SUITE_P(%s, ...).\n",
+ FormatFileLocation(file, line).c_str(), test_name, case_name);
+ fflush(stderr);
+ posix::Abort();
+ }
+ registered_tests_.insert(
+ ::std::make_pair(test_name, CodeLocation(file, line)));
+ return true;
+ }
+
+ bool TestExists(const std::string& test_name) const {
+ return registered_tests_.count(test_name) > 0;
+ }
+
+ const CodeLocation& GetCodeLocation(const std::string& test_name) const {
+ RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
+ GTEST_CHECK_(it != registered_tests_.end());
+ return it->second;
+ }
+
+ // Verifies that registered_tests match the test names in
+ // defined_test_names_; returns registered_tests if successful, or
+ // aborts the program otherwise.
+ const char* VerifyRegisteredTestNames(
+ const char* file, int line, const char* registered_tests);
+
+ private:
+ typedef ::std::map<std::string, CodeLocation> RegisteredTestsMap;
+
+ bool registered_;
+ RegisteredTestsMap registered_tests_;
+};
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+using TypedTestCasePState = TypedTestSuitePState;
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
+
+// Skips to the first non-space char after the first comma in 'str';
+// returns NULL if no comma is found in 'str'.
+inline const char* SkipComma(const char* str) {
+ const char* comma = strchr(str, ',');
+ if (comma == nullptr) {
+ return nullptr;
+ }
+ while (IsSpace(*(++comma))) {}
+ return comma;
+}
+
+// Returns the prefix of 'str' before the first comma in it; returns
+// the entire string if it contains no comma.
+inline std::string GetPrefixUntilComma(const char* str) {
+ const char* comma = strchr(str, ',');
+ return comma == nullptr ? str : std::string(str, comma);
+}
+
+// Splits a given string on a given delimiter, populating a given
+// vector with the fields.
+void SplitString(const ::std::string& str, char delimiter,
+ ::std::vector< ::std::string>* dest);
+
+// The default argument to the template below for the case when the user does
+// not provide a name generator.
+struct DefaultNameGenerator {
+ template <typename T>
+ static std::string GetName(int i) {
+ return StreamableToString(i);
+ }
+};
+
+template <typename Provided = DefaultNameGenerator>
+struct NameGeneratorSelector {
+ typedef Provided type;
+};
+
+template <typename NameGenerator>
+void GenerateNamesRecursively(Types0, std::vector<std::string>*, int) {}
+
+template <typename NameGenerator, typename Types>
+void GenerateNamesRecursively(Types, std::vector<std::string>* result, int i) {
+ result->push_back(NameGenerator::template GetName<typename Types::Head>(i));
+ GenerateNamesRecursively<NameGenerator>(typename Types::Tail(), result,
+ i + 1);
+}
+
+template <typename NameGenerator, typename Types>
+std::vector<std::string> GenerateNames() {
+ std::vector<std::string> result;
+ GenerateNamesRecursively<NameGenerator>(Types(), &result, 0);
+ return result;
+}
+
+// TypeParameterizedTest<Fixture, TestSel, Types>::Register()
+// registers a list of type-parameterized tests with Google Test. The
+// return value is insignificant - we just need to return something
+// such that we can call this function in a namespace scope.
+//
+// Implementation note: The GTEST_TEMPLATE_ macro declares a template
+// template parameter. It's defined in gtest-type-util.h.
+template <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>
+class TypeParameterizedTest {
+ public:
+ // 'index' is the index of the test in the type list 'Types'
+ // specified in INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, TestSuite,
+ // Types). Valid values for 'index' are [0, N - 1] where N is the
+ // length of Types.
+ static bool Register(const char* prefix, const CodeLocation& code_location,
+ const char* case_name, const char* test_names, int index,
+ const std::vector<std::string>& type_names =
+ GenerateNames<DefaultNameGenerator, Types>()) {
+ typedef typename Types::Head Type;
+ typedef Fixture<Type> FixtureClass;
+ typedef typename GTEST_BIND_(TestSel, Type) TestClass;
+
+ // First, registers the first type-parameterized test in the type
+ // list.
+ MakeAndRegisterTestInfo(
+ (std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name +
+ "/" + type_names[static_cast<size_t>(index)])
+ .c_str(),
+ StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(),
+ GetTypeName<Type>().c_str(),
+ nullptr, // No value parameter.
+ code_location, GetTypeId<FixtureClass>(),
+ SuiteApiResolver<TestClass>::GetSetUpCaseOrSuite(
+ code_location.file.c_str(), code_location.line),
+ SuiteApiResolver<TestClass>::GetTearDownCaseOrSuite(
+ code_location.file.c_str(), code_location.line),
+ new TestFactoryImpl<TestClass>);
+
+ // Next, recurses (at compile time) with the tail of the type list.
+ return TypeParameterizedTest<Fixture, TestSel,
+ typename Types::Tail>::Register(prefix,
+ code_location,
+ case_name,
+ test_names,
+ index + 1,
+ type_names);
+ }
+};
+
+// The base case for the compile time recursion.
+template <GTEST_TEMPLATE_ Fixture, class TestSel>
+class TypeParameterizedTest<Fixture, TestSel, Types0> {
+ public:
+ static bool Register(const char* /*prefix*/, const CodeLocation&,
+ const char* /*case_name*/, const char* /*test_names*/,
+ int /*index*/,
+ const std::vector<std::string>& =
+ std::vector<std::string>() /*type_names*/) {
+ return true;
+ }
+};
+
+// TypeParameterizedTestSuite<Fixture, Tests, Types>::Register()
+// registers *all combinations* of 'Tests' and 'Types' with Google
+// Test. The return value is insignificant - we just need to return
+// something such that we can call this function in a namespace scope.
+template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
+class TypeParameterizedTestSuite {
+ public:
+ static bool Register(const char* prefix, CodeLocation code_location,
+ const TypedTestSuitePState* state, const char* case_name,
+ const char* test_names,
+ const std::vector<std::string>& type_names =
+ GenerateNames<DefaultNameGenerator, Types>()) {
+ std::string test_name = StripTrailingSpaces(
+ GetPrefixUntilComma(test_names));
+ if (!state->TestExists(test_name)) {
+ fprintf(stderr, "Failed to get code location for test %s.%s at %s.",
+ case_name, test_name.c_str(),
+ FormatFileLocation(code_location.file.c_str(),
+ code_location.line).c_str());
+ fflush(stderr);
+ posix::Abort();
+ }
+ const CodeLocation& test_location = state->GetCodeLocation(test_name);
+
+ typedef typename Tests::Head Head;
+
+ // First, register the first test in 'Test' for each type in 'Types'.
+ TypeParameterizedTest<Fixture, Head, Types>::Register(
+ prefix, test_location, case_name, test_names, 0, type_names);
+
+ // Next, recurses (at compile time) with the tail of the test list.
+ return TypeParameterizedTestSuite<Fixture, typename Tests::Tail,
+ Types>::Register(prefix, code_location,
+ state, case_name,
+ SkipComma(test_names),
+ type_names);
+ }
+};
+
+// The base case for the compile time recursion.
+template <GTEST_TEMPLATE_ Fixture, typename Types>
+class TypeParameterizedTestSuite<Fixture, Templates0, Types> {
+ public:
+ static bool Register(const char* /*prefix*/, const CodeLocation&,
+ const TypedTestSuitePState* /*state*/,
+ const char* /*case_name*/, const char* /*test_names*/,
+ const std::vector<std::string>& =
+ std::vector<std::string>() /*type_names*/) {
+ return true;
+ }
+};
+
+#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
+
+// Returns the current OS stack trace as an std::string.
+//
+// The maximum number of stack frames to be included is specified by
+// the gtest_stack_trace_depth flag. The skip_count parameter
+// specifies the number of top frames to be skipped, which doesn't
+// count against the number of frames to be included.
+//
+// For example, if Foo() calls Bar(), which in turn calls
+// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
+// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
+GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(
+ UnitTest* unit_test, int skip_count);
+
+// Helpers for suppressing warnings on unreachable code or constant
+// condition.
+
+// Always returns true.
+GTEST_API_ bool AlwaysTrue();
+
+// Always returns false.
+inline bool AlwaysFalse() { return !AlwaysTrue(); }
+
+// Helper for suppressing false warning from Clang on a const char*
+// variable declared in a conditional expression always being NULL in
+// the else branch.
+struct GTEST_API_ ConstCharPtr {
+ ConstCharPtr(const char* str) : value(str) {}
+ operator bool() const { return true; }
+ const char* value;
+};
+
+// A simple Linear Congruential Generator for generating random
+// numbers with a uniform distribution. Unlike rand() and srand(), it
+// doesn't use global state (and therefore can't interfere with user
+// code). Unlike rand_r(), it's portable. An LCG isn't very random,
+// but it's good enough for our purposes.
+class GTEST_API_ Random {
+ public:
+ static const UInt32 kMaxRange = 1u << 31;
+
+ explicit Random(UInt32 seed) : state_(seed) {}
+
+ void Reseed(UInt32 seed) { state_ = seed; }
+
+ // Generates a random number from [0, range). Crashes if 'range' is
+ // 0 or greater than kMaxRange.
+ UInt32 Generate(UInt32 range);
+
+ private:
+ UInt32 state_;
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
+};
+
+// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
+// compiler error iff T1 and T2 are different types.
+template <typename T1, typename T2>
+struct CompileAssertTypesEqual;
+
+template <typename T>
+struct CompileAssertTypesEqual<T, T> {
+};
+
+// Removes the reference from a type if it is a reference type,
+// otherwise leaves it unchanged. This is the same as
+// tr1::remove_reference, which is not widely available yet.
+template <typename T>
+struct RemoveReference { typedef T type; }; // NOLINT
+template <typename T>
+struct RemoveReference<T&> { typedef T type; }; // NOLINT
+
+// A handy wrapper around RemoveReference that works when the argument
+// T depends on template parameters.
+#define GTEST_REMOVE_REFERENCE_(T) \
+ typename ::testing::internal::RemoveReference<T>::type
+
+// Removes const from a type if it is a const type, otherwise leaves
+// it unchanged. This is the same as tr1::remove_const, which is not
+// widely available yet.
+template <typename T>
+struct RemoveConst { typedef T type; }; // NOLINT
+template <typename T>
+struct RemoveConst<const T> { typedef T type; }; // NOLINT
+
+// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above
+// definition to fail to remove the const in 'const int[3]' and 'const
+// char[3][4]'. The following specialization works around the bug.
+template <typename T, size_t N>
+struct RemoveConst<const T[N]> {
+ typedef typename RemoveConst<T>::type type[N];
+};
+
+// A handy wrapper around RemoveConst that works when the argument
+// T depends on template parameters.
+#define GTEST_REMOVE_CONST_(T) \
+ typename ::testing::internal::RemoveConst<T>::type
+
+// Turns const U&, U&, const U, and U all into U.
+#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
+ GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
+
+// IsAProtocolMessage<T>::value is a compile-time bool constant that's
+// true iff T is type proto2::Message or a subclass of it.
+template <typename T>
+struct IsAProtocolMessage
+ : public bool_constant<
+ std::is_convertible<const T*, const ::proto2::Message*>::value> {
+};
+
+// When the compiler sees expression IsContainerTest<C>(0), if C is an
+// STL-style container class, the first overload of IsContainerTest
+// will be viable (since both C::iterator* and C::const_iterator* are
+// valid types and NULL can be implicitly converted to them). It will
+// be picked over the second overload as 'int' is a perfect match for
+// the type of argument 0. If C::iterator or C::const_iterator is not
+// a valid type, the first overload is not viable, and the second
+// overload will be picked. Therefore, we can determine whether C is
+// a container class by checking the type of IsContainerTest<C>(0).
+// The value of the expression is insignificant.
+//
+// In C++11 mode we check the existence of a const_iterator and that an
+// iterator is properly implemented for the container.
+//
+// For pre-C++11 that we look for both C::iterator and C::const_iterator.
+// The reason is that C++ injects the name of a class as a member of the
+// class itself (e.g. you can refer to class iterator as either
+// 'iterator' or 'iterator::iterator'). If we look for C::iterator
+// only, for example, we would mistakenly think that a class named
+// iterator is an STL container.
+//
+// Also note that the simpler approach of overloading
+// IsContainerTest(typename C::const_iterator*) and
+// IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++.
+typedef int IsContainer;
+template <class C,
+ class Iterator = decltype(::std::declval<const C&>().begin()),
+ class = decltype(::std::declval<const C&>().end()),
+ class = decltype(++::std::declval<Iterator&>()),
+ class = decltype(*::std::declval<Iterator>()),
+ class = typename C::const_iterator>
+IsContainer IsContainerTest(int /* dummy */) {
+ return 0;
+}
+
+typedef char IsNotContainer;
+template <class C>
+IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; }
+
+// Trait to detect whether a type T is a hash table.
+// The heuristic used is that the type contains an inner type `hasher` and does
+// not contain an inner type `reverse_iterator`.
+// If the container is iterable in reverse, then order might actually matter.
+template <typename T>
+struct IsHashTable {
+ private:
+ template <typename U>
+ static char test(typename U::hasher*, typename U::reverse_iterator*);
+ template <typename U>
+ static int test(typename U::hasher*, ...);
+ template <typename U>
+ static char test(...);
+
+ public:
+ static const bool value = sizeof(test<T>(nullptr, nullptr)) == sizeof(int);
+};
+
+template <typename T>
+const bool IsHashTable<T>::value;
+
+template <typename C,
+ bool = sizeof(IsContainerTest<C>(0)) == sizeof(IsContainer)>
+struct IsRecursiveContainerImpl;
+
+template <typename C>
+struct IsRecursiveContainerImpl<C, false> : public false_type {};
+
+// Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to
+// obey the same inconsistencies as the IsContainerTest, namely check if
+// something is a container is relying on only const_iterator in C++11 and
+// is relying on both const_iterator and iterator otherwise
+template <typename C>
+struct IsRecursiveContainerImpl<C, true> {
+ using value_type = decltype(*std::declval<typename C::const_iterator>());
+ using type =
+ is_same<typename std::remove_const<
+ typename std::remove_reference<value_type>::type>::type,
+ C>;
+};
+
+// IsRecursiveContainer<Type> is a unary compile-time predicate that
+// evaluates whether C is a recursive container type. A recursive container
+// type is a container type whose value_type is equal to the container type
+// itself. An example for a recursive container type is
+// boost::filesystem::path, whose iterator has a value_type that is equal to
+// boost::filesystem::path.
+template <typename C>
+struct IsRecursiveContainer : public IsRecursiveContainerImpl<C>::type {};
+
+// EnableIf<condition>::type is void when 'Cond' is true, and
+// undefined when 'Cond' is false. To use SFINAE to make a function
+// overload only apply when a particular expression is true, add
+// "typename EnableIf<expression>::type* = 0" as the last parameter.
+template<bool> struct EnableIf;
+template<> struct EnableIf<true> { typedef void type; }; // NOLINT
+
+// Utilities for native arrays.
+
+// ArrayEq() compares two k-dimensional native arrays using the
+// elements' operator==, where k can be any integer >= 0. When k is
+// 0, ArrayEq() degenerates into comparing a single pair of values.
+
+template <typename T, typename U>
+bool ArrayEq(const T* lhs, size_t size, const U* rhs);
+
+// This generic version is used when k is 0.
+template <typename T, typename U>
+inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; }
+
+// This overload is used when k >= 1.
+template <typename T, typename U, size_t N>
+inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {
+ return internal::ArrayEq(lhs, N, rhs);
+}
+
+// This helper reduces code bloat. If we instead put its logic inside
+// the previous ArrayEq() function, arrays with different sizes would
+// lead to different copies of the template code.
+template <typename T, typename U>
+bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
+ for (size_t i = 0; i != size; i++) {
+ if (!internal::ArrayEq(lhs[i], rhs[i]))
+ return false;
+ }
+ return true;
+}
+
+// Finds the first element in the iterator range [begin, end) that
+// equals elem. Element may be a native array type itself.
+template <typename Iter, typename Element>
+Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {
+ for (Iter it = begin; it != end; ++it) {
+ if (internal::ArrayEq(*it, elem))
+ return it;
+ }
+ return end;
+}
+
+// CopyArray() copies a k-dimensional native array using the elements'
+// operator=, where k can be any integer >= 0. When k is 0,
+// CopyArray() degenerates into copying a single value.
+
+template <typename T, typename U>
+void CopyArray(const T* from, size_t size, U* to);
+
+// This generic version is used when k is 0.
+template <typename T, typename U>
+inline void CopyArray(const T& from, U* to) { *to = from; }
+
+// This overload is used when k >= 1.
+template <typename T, typename U, size_t N>
+inline void CopyArray(const T(&from)[N], U(*to)[N]) {
+ internal::CopyArray(from, N, *to);
+}
+
+// This helper reduces code bloat. If we instead put its logic inside
+// the previous CopyArray() function, arrays with different sizes
+// would lead to different copies of the template code.
+template <typename T, typename U>
+void CopyArray(const T* from, size_t size, U* to) {
+ for (size_t i = 0; i != size; i++) {
+ internal::CopyArray(from[i], to + i);
+ }
+}
+
+// The relation between an NativeArray object (see below) and the
+// native array it represents.
+// We use 2 different structs to allow non-copyable types to be used, as long
+// as RelationToSourceReference() is passed.
+struct RelationToSourceReference {};
+struct RelationToSourceCopy {};
+
+// Adapts a native array to a read-only STL-style container. Instead
+// of the complete STL container concept, this adaptor only implements
+// members useful for Google Mock's container matchers. New members
+// should be added as needed. To simplify the implementation, we only
+// support Element being a raw type (i.e. having no top-level const or
+// reference modifier). It's the client's responsibility to satisfy
+// this requirement. Element can be an array type itself (hence
+// multi-dimensional arrays are supported).
+template <typename Element>
+class NativeArray {
+ public:
+ // STL-style container typedefs.
+ typedef Element value_type;
+ typedef Element* iterator;
+ typedef const Element* const_iterator;
+
+ // Constructs from a native array. References the source.
+ NativeArray(const Element* array, size_t count, RelationToSourceReference) {
+ InitRef(array, count);
+ }
+
+ // Constructs from a native array. Copies the source.
+ NativeArray(const Element* array, size_t count, RelationToSourceCopy) {
+ InitCopy(array, count);
+ }
+
+ // Copy constructor.
+ NativeArray(const NativeArray& rhs) {
+ (this->*rhs.clone_)(rhs.array_, rhs.size_);
+ }
+
+ ~NativeArray() {
+ if (clone_ != &NativeArray::InitRef)
+ delete[] array_;
+ }
+
+ // STL-style container methods.
+ size_t size() const { return size_; }
+ const_iterator begin() const { return array_; }
+ const_iterator end() const { return array_ + size_; }
+ bool operator==(const NativeArray& rhs) const {
+ return size() == rhs.size() &&
+ ArrayEq(begin(), size(), rhs.begin());
+ }
+
+ private:
+ enum {
+ kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper<
+ Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value
+ };
+
+ // Initializes this object with a copy of the input.
+ void InitCopy(const Element* array, size_t a_size) {
+ Element* const copy = new Element[a_size];
+ CopyArray(array, a_size, copy);
+ array_ = copy;
+ size_ = a_size;
+ clone_ = &NativeArray::InitCopy;
+ }
+
+ // Initializes this object with a reference of the input.
+ void InitRef(const Element* array, size_t a_size) {
+ array_ = array;
+ size_ = a_size;
+ clone_ = &NativeArray::InitRef;
+ }
+
+ const Element* array_;
+ size_t size_;
+ void (NativeArray::*clone_)(const Element*, size_t);
+
+ GTEST_DISALLOW_ASSIGN_(NativeArray);
+};
+
+// Backport of std::index_sequence.
+template <size_t... Is>
+struct IndexSequence {
+ using type = IndexSequence;
+};
+
+// Double the IndexSequence, and one if plus_one is true.
+template <bool plus_one, typename T, size_t sizeofT>
+struct DoubleSequence;
+template <size_t... I, size_t sizeofT>
+struct DoubleSequence<true, IndexSequence<I...>, sizeofT> {
+ using type = IndexSequence<I..., (sizeofT + I)..., 2 * sizeofT>;
+};
+template <size_t... I, size_t sizeofT>
+struct DoubleSequence<false, IndexSequence<I...>, sizeofT> {
+ using type = IndexSequence<I..., (sizeofT + I)...>;
+};
+
+// Backport of std::make_index_sequence.
+// It uses O(ln(N)) instantiation depth.
+template <size_t N>
+struct MakeIndexSequence
+ : DoubleSequence<N % 2 == 1, typename MakeIndexSequence<N / 2>::type,
+ N / 2>::type {};
+
+template <>
+struct MakeIndexSequence<0> : IndexSequence<> {};
+
+// FIXME: This implementation of ElemFromList is O(1) in instantiation depth,
+// but it is O(N^2) in total instantiations. Not sure if this is the best
+// tradeoff, as it will make it somewhat slow to compile.
+template <typename T, size_t, size_t>
+struct ElemFromListImpl {};
+
+template <typename T, size_t I>
+struct ElemFromListImpl<T, I, I> {
+ using type = T;
+};
+
+// Get the Nth element from T...
+// It uses O(1) instantiation depth.
+template <size_t N, typename I, typename... T>
+struct ElemFromList;
+
+template <size_t N, size_t... I, typename... T>
+struct ElemFromList<N, IndexSequence<I...>, T...>
+ : ElemFromListImpl<T, N, I>... {};
+
+template <typename... T>
+class FlatTuple;
+
+template <typename Derived, size_t I>
+struct FlatTupleElemBase;
+
+template <typename... T, size_t I>
+struct FlatTupleElemBase<FlatTuple<T...>, I> {
+ using value_type =
+ typename ElemFromList<I, typename MakeIndexSequence<sizeof...(T)>::type,
+ T...>::type;
+ FlatTupleElemBase() = default;
+ explicit FlatTupleElemBase(value_type t) : value(std::move(t)) {}
+ value_type value;
+};
+
+template <typename Derived, typename Idx>
+struct FlatTupleBase;
+
+template <size_t... Idx, typename... T>
+struct FlatTupleBase<FlatTuple<T...>, IndexSequence<Idx...>>
+ : FlatTupleElemBase<FlatTuple<T...>, Idx>... {
+ using Indices = IndexSequence<Idx...>;
+ FlatTupleBase() = default;
+ explicit FlatTupleBase(T... t)
+ : FlatTupleElemBase<FlatTuple<T...>, Idx>(std::move(t))... {}
+};
+
+// Analog to std::tuple but with different tradeoffs.
+// This class minimizes the template instantiation depth, thus allowing more
+// elements that std::tuple would. std::tuple has been seen to require an
+// instantiation depth of more than 10x the number of elements in some
+// implementations.
+// FlatTuple and ElemFromList are not recursive and have a fixed depth
+// regardless of T...
+// MakeIndexSequence, on the other hand, it is recursive but with an
+// instantiation depth of O(ln(N)).
+template <typename... T>
+class FlatTuple
+ : private FlatTupleBase<FlatTuple<T...>,
+ typename MakeIndexSequence<sizeof...(T)>::type> {
+ using Indices = typename FlatTuple::FlatTupleBase::Indices;
+
+ public:
+ FlatTuple() = default;
+ explicit FlatTuple(T... t) : FlatTuple::FlatTupleBase(std::move(t)...) {}
+
+ template <size_t I>
+ const typename ElemFromList<I, Indices, T...>::type& Get() const {
+ return static_cast<const FlatTupleElemBase<FlatTuple, I>*>(this)->value;
+ }
+
+ template <size_t I>
+ typename ElemFromList<I, Indices, T...>::type& Get() {
+ return static_cast<FlatTupleElemBase<FlatTuple, I>*>(this)->value;
+ }
+};
+
+// Utility functions to be called with static_assert to induce deprecation
+// warnings.
+GTEST_INTERNAL_DEPRECATED(
+ "INSTANTIATE_TEST_CASE_P is deprecated, please use "
+ "INSTANTIATE_TEST_SUITE_P")
+constexpr bool InstantiateTestCase_P_IsDeprecated() { return true; }
+
+GTEST_INTERNAL_DEPRECATED(
+ "TYPED_TEST_CASE_P is deprecated, please use "
+ "TYPED_TEST_SUITE_P")
+constexpr bool TypedTestCase_P_IsDeprecated() { return true; }
+
+GTEST_INTERNAL_DEPRECATED(
+ "TYPED_TEST_CASE is deprecated, please use "
+ "TYPED_TEST_SUITE")
+constexpr bool TypedTestCaseIsDeprecated() { return true; }
+
+GTEST_INTERNAL_DEPRECATED(
+ "REGISTER_TYPED_TEST_CASE_P is deprecated, please use "
+ "REGISTER_TYPED_TEST_SUITE_P")
+constexpr bool RegisterTypedTestCase_P_IsDeprecated() { return true; }
+
+GTEST_INTERNAL_DEPRECATED(
+ "INSTANTIATE_TYPED_TEST_CASE_P is deprecated, please use "
+ "INSTANTIATE_TYPED_TEST_SUITE_P")
+constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; }
+
+} // namespace internal
+} // namespace testing
+
+#define GTEST_MESSAGE_AT_(file, line, message, result_type) \
+ ::testing::internal::AssertHelper(result_type, file, line, message) \
+ = ::testing::Message()
+
+#define GTEST_MESSAGE_(message, result_type) \
+ GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
+
+#define GTEST_FATAL_FAILURE_(message) \
+ return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
+
+#define GTEST_NONFATAL_FAILURE_(message) \
+ GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
+
+#define GTEST_SUCCESS_(message) \
+ GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
+
+#define GTEST_SKIP_(message) \
+ return GTEST_MESSAGE_(message, ::testing::TestPartResult::kSkip)
+
+// Suppress MSVC warning 4072 (unreachable code) for the code following
+// statement if it returns or throws (or doesn't return or throw in some
+// situations).
+#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
+ if (::testing::internal::AlwaysTrue()) { statement; }
+
+#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::ConstCharPtr gtest_msg = "") { \
+ bool gtest_caught_expected = false; \
+ try { \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ } \
+ catch (expected_exception const&) { \
+ gtest_caught_expected = true; \
+ } \
+ catch (...) { \
+ gtest_msg.value = \
+ "Expected: " #statement " throws an exception of type " \
+ #expected_exception ".\n Actual: it throws a different type."; \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
+ } \
+ if (!gtest_caught_expected) { \
+ gtest_msg.value = \
+ "Expected: " #statement " throws an exception of type " \
+ #expected_exception ".\n Actual: it throws nothing."; \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
+ } \
+ } else \
+ GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
+ fail(gtest_msg.value)
+
+#define GTEST_TEST_NO_THROW_(statement, fail) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::AlwaysTrue()) { \
+ try { \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ } \
+ catch (...) { \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
+ } \
+ } else \
+ GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
+ fail("Expected: " #statement " doesn't throw an exception.\n" \
+ " Actual: it throws.")
+
+#define GTEST_TEST_ANY_THROW_(statement, fail) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::AlwaysTrue()) { \
+ bool gtest_caught_any = false; \
+ try { \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ } \
+ catch (...) { \
+ gtest_caught_any = true; \
+ } \
+ if (!gtest_caught_any) { \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
+ } \
+ } else \
+ GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
+ fail("Expected: " #statement " throws an exception.\n" \
+ " Actual: it doesn't.")
+
+
+// Implements Boolean test assertions such as EXPECT_TRUE. expression can be
+// either a boolean expression or an AssertionResult. text is a textual
+// represenation of expression as it was passed into the EXPECT_TRUE.
+#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (const ::testing::AssertionResult gtest_ar_ = \
+ ::testing::AssertionResult(expression)) \
+ ; \
+ else \
+ fail(::testing::internal::GetBoolAssertionFailureMessage(\
+ gtest_ar_, text, #actual, #expected).c_str())
+
+#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::AlwaysTrue()) { \
+ ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
+ } \
+ } else \
+ GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
+ fail("Expected: " #statement " doesn't generate new fatal " \
+ "failures in the current thread.\n" \
+ " Actual: it does.")
+
+// Expands to the name of the class that implements the given test.
+#define GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
+ test_suite_name##_##test_name##_Test
+
+// Helper macro for defining tests.
+#define GTEST_TEST_(test_suite_name, test_name, parent_class, parent_id) \
+ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
+ : public parent_class { \
+ public: \
+ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
+ \
+ private: \
+ virtual void TestBody(); \
+ static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \
+ test_name)); \
+ }; \
+ \
+ ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \
+ test_name)::test_info_ = \
+ ::testing::internal::MakeAndRegisterTestInfo( \
+ #test_suite_name, #test_name, nullptr, nullptr, \
+ ::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \
+ ::testing::internal::SuiteApiResolver< \
+ parent_class>::GetSetUpCaseOrSuite(__FILE__, __LINE__), \
+ ::testing::internal::SuiteApiResolver< \
+ parent_class>::GetTearDownCaseOrSuite(__FILE__, __LINE__), \
+ new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
+ test_suite_name, test_name)>); \
+ void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
--- /dev/null
+// Copyright 2008 Google Inc.
+// All Rights Reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Type and function utilities for implementing parameterized tests.
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
+
+#include <ctype.h>
+
+#include <cassert>
+#include <iterator>
+#include <memory>
+#include <set>
+#include <tuple>
+#include <utility>
+#include <vector>
+
+#include "gtest/internal/gtest-internal.h"
+#include "gtest/internal/gtest-port.h"
+#include "gtest/gtest-printers.h"
+
+namespace testing {
+// Input to a parameterized test name generator, describing a test parameter.
+// Consists of the parameter value and the integer parameter index.
+template <class ParamType>
+struct TestParamInfo {
+ TestParamInfo(const ParamType& a_param, size_t an_index) :
+ param(a_param),
+ index(an_index) {}
+ ParamType param;
+ size_t index;
+};
+
+// A builtin parameterized test name generator which returns the result of
+// testing::PrintToString.
+struct PrintToStringParamName {
+ template <class ParamType>
+ std::string operator()(const TestParamInfo<ParamType>& info) const {
+ return PrintToString(info.param);
+ }
+};
+
+namespace internal {
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+// Utility Functions
+
+// Outputs a message explaining invalid registration of different
+// fixture class for the same test suite. This may happen when
+// TEST_P macro is used to define two tests with the same name
+// but in different namespaces.
+GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name,
+ CodeLocation code_location);
+
+template <typename> class ParamGeneratorInterface;
+template <typename> class ParamGenerator;
+
+// Interface for iterating over elements provided by an implementation
+// of ParamGeneratorInterface<T>.
+template <typename T>
+class ParamIteratorInterface {
+ public:
+ virtual ~ParamIteratorInterface() {}
+ // A pointer to the base generator instance.
+ // Used only for the purposes of iterator comparison
+ // to make sure that two iterators belong to the same generator.
+ virtual const ParamGeneratorInterface<T>* BaseGenerator() const = 0;
+ // Advances iterator to point to the next element
+ // provided by the generator. The caller is responsible
+ // for not calling Advance() on an iterator equal to
+ // BaseGenerator()->End().
+ virtual void Advance() = 0;
+ // Clones the iterator object. Used for implementing copy semantics
+ // of ParamIterator<T>.
+ virtual ParamIteratorInterface* Clone() const = 0;
+ // Dereferences the current iterator and provides (read-only) access
+ // to the pointed value. It is the caller's responsibility not to call
+ // Current() on an iterator equal to BaseGenerator()->End().
+ // Used for implementing ParamGenerator<T>::operator*().
+ virtual const T* Current() const = 0;
+ // Determines whether the given iterator and other point to the same
+ // element in the sequence generated by the generator.
+ // Used for implementing ParamGenerator<T>::operator==().
+ virtual bool Equals(const ParamIteratorInterface& other) const = 0;
+};
+
+// Class iterating over elements provided by an implementation of
+// ParamGeneratorInterface<T>. It wraps ParamIteratorInterface<T>
+// and implements the const forward iterator concept.
+template <typename T>
+class ParamIterator {
+ public:
+ typedef T value_type;
+ typedef const T& reference;
+ typedef ptrdiff_t difference_type;
+
+ // ParamIterator assumes ownership of the impl_ pointer.
+ ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {}
+ ParamIterator& operator=(const ParamIterator& other) {
+ if (this != &other)
+ impl_.reset(other.impl_->Clone());
+ return *this;
+ }
+
+ const T& operator*() const { return *impl_->Current(); }
+ const T* operator->() const { return impl_->Current(); }
+ // Prefix version of operator++.
+ ParamIterator& operator++() {
+ impl_->Advance();
+ return *this;
+ }
+ // Postfix version of operator++.
+ ParamIterator operator++(int /*unused*/) {
+ ParamIteratorInterface<T>* clone = impl_->Clone();
+ impl_->Advance();
+ return ParamIterator(clone);
+ }
+ bool operator==(const ParamIterator& other) const {
+ return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_);
+ }
+ bool operator!=(const ParamIterator& other) const {
+ return !(*this == other);
+ }
+
+ private:
+ friend class ParamGenerator<T>;
+ explicit ParamIterator(ParamIteratorInterface<T>* impl) : impl_(impl) {}
+ std::unique_ptr<ParamIteratorInterface<T> > impl_;
+};
+
+// ParamGeneratorInterface<T> is the binary interface to access generators
+// defined in other translation units.
+template <typename T>
+class ParamGeneratorInterface {
+ public:
+ typedef T ParamType;
+
+ virtual ~ParamGeneratorInterface() {}
+
+ // Generator interface definition
+ virtual ParamIteratorInterface<T>* Begin() const = 0;
+ virtual ParamIteratorInterface<T>* End() const = 0;
+};
+
+// Wraps ParamGeneratorInterface<T> and provides general generator syntax
+// compatible with the STL Container concept.
+// This class implements copy initialization semantics and the contained
+// ParamGeneratorInterface<T> instance is shared among all copies
+// of the original object. This is possible because that instance is immutable.
+template<typename T>
+class ParamGenerator {
+ public:
+ typedef ParamIterator<T> iterator;
+
+ explicit ParamGenerator(ParamGeneratorInterface<T>* impl) : impl_(impl) {}
+ ParamGenerator(const ParamGenerator& other) : impl_(other.impl_) {}
+
+ ParamGenerator& operator=(const ParamGenerator& other) {
+ impl_ = other.impl_;
+ return *this;
+ }
+
+ iterator begin() const { return iterator(impl_->Begin()); }
+ iterator end() const { return iterator(impl_->End()); }
+
+ private:
+ std::shared_ptr<const ParamGeneratorInterface<T> > impl_;
+};
+
+// Generates values from a range of two comparable values. Can be used to
+// generate sequences of user-defined types that implement operator+() and
+// operator<().
+// This class is used in the Range() function.
+template <typename T, typename IncrementT>
+class RangeGenerator : public ParamGeneratorInterface<T> {
+ public:
+ RangeGenerator(T begin, T end, IncrementT step)
+ : begin_(begin), end_(end),
+ step_(step), end_index_(CalculateEndIndex(begin, end, step)) {}
+ ~RangeGenerator() override {}
+
+ ParamIteratorInterface<T>* Begin() const override {
+ return new Iterator(this, begin_, 0, step_);
+ }
+ ParamIteratorInterface<T>* End() const override {
+ return new Iterator(this, end_, end_index_, step_);
+ }
+
+ private:
+ class Iterator : public ParamIteratorInterface<T> {
+ public:
+ Iterator(const ParamGeneratorInterface<T>* base, T value, int index,
+ IncrementT step)
+ : base_(base), value_(value), index_(index), step_(step) {}
+ ~Iterator() override {}
+
+ const ParamGeneratorInterface<T>* BaseGenerator() const override {
+ return base_;
+ }
+ void Advance() override {
+ value_ = static_cast<T>(value_ + step_);
+ index_++;
+ }
+ ParamIteratorInterface<T>* Clone() const override {
+ return new Iterator(*this);
+ }
+ const T* Current() const override { return &value_; }
+ bool Equals(const ParamIteratorInterface<T>& other) const override {
+ // Having the same base generator guarantees that the other
+ // iterator is of the same type and we can downcast.
+ GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
+ << "The program attempted to compare iterators "
+ << "from different generators." << std::endl;
+ const int other_index =
+ CheckedDowncastToActualType<const Iterator>(&other)->index_;
+ return index_ == other_index;
+ }
+
+ private:
+ Iterator(const Iterator& other)
+ : ParamIteratorInterface<T>(),
+ base_(other.base_), value_(other.value_), index_(other.index_),
+ step_(other.step_) {}
+
+ // No implementation - assignment is unsupported.
+ void operator=(const Iterator& other);
+
+ const ParamGeneratorInterface<T>* const base_;
+ T value_;
+ int index_;
+ const IncrementT step_;
+ }; // class RangeGenerator::Iterator
+
+ static int CalculateEndIndex(const T& begin,
+ const T& end,
+ const IncrementT& step) {
+ int end_index = 0;
+ for (T i = begin; i < end; i = static_cast<T>(i + step))
+ end_index++;
+ return end_index;
+ }
+
+ // No implementation - assignment is unsupported.
+ void operator=(const RangeGenerator& other);
+
+ const T begin_;
+ const T end_;
+ const IncrementT step_;
+ // The index for the end() iterator. All the elements in the generated
+ // sequence are indexed (0-based) to aid iterator comparison.
+ const int end_index_;
+}; // class RangeGenerator
+
+
+// Generates values from a pair of STL-style iterators. Used in the
+// ValuesIn() function. The elements are copied from the source range
+// since the source can be located on the stack, and the generator
+// is likely to persist beyond that stack frame.
+template <typename T>
+class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
+ public:
+ template <typename ForwardIterator>
+ ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
+ : container_(begin, end) {}
+ ~ValuesInIteratorRangeGenerator() override {}
+
+ ParamIteratorInterface<T>* Begin() const override {
+ return new Iterator(this, container_.begin());
+ }
+ ParamIteratorInterface<T>* End() const override {
+ return new Iterator(this, container_.end());
+ }
+
+ private:
+ typedef typename ::std::vector<T> ContainerType;
+
+ class Iterator : public ParamIteratorInterface<T> {
+ public:
+ Iterator(const ParamGeneratorInterface<T>* base,
+ typename ContainerType::const_iterator iterator)
+ : base_(base), iterator_(iterator) {}
+ ~Iterator() override {}
+
+ const ParamGeneratorInterface<T>* BaseGenerator() const override {
+ return base_;
+ }
+ void Advance() override {
+ ++iterator_;
+ value_.reset();
+ }
+ ParamIteratorInterface<T>* Clone() const override {
+ return new Iterator(*this);
+ }
+ // We need to use cached value referenced by iterator_ because *iterator_
+ // can return a temporary object (and of type other then T), so just
+ // having "return &*iterator_;" doesn't work.
+ // value_ is updated here and not in Advance() because Advance()
+ // can advance iterator_ beyond the end of the range, and we cannot
+ // detect that fact. The client code, on the other hand, is
+ // responsible for not calling Current() on an out-of-range iterator.
+ const T* Current() const override {
+ if (value_.get() == nullptr) value_.reset(new T(*iterator_));
+ return value_.get();
+ }
+ bool Equals(const ParamIteratorInterface<T>& other) const override {
+ // Having the same base generator guarantees that the other
+ // iterator is of the same type and we can downcast.
+ GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
+ << "The program attempted to compare iterators "
+ << "from different generators." << std::endl;
+ return iterator_ ==
+ CheckedDowncastToActualType<const Iterator>(&other)->iterator_;
+ }
+
+ private:
+ Iterator(const Iterator& other)
+ // The explicit constructor call suppresses a false warning
+ // emitted by gcc when supplied with the -Wextra option.
+ : ParamIteratorInterface<T>(),
+ base_(other.base_),
+ iterator_(other.iterator_) {}
+
+ const ParamGeneratorInterface<T>* const base_;
+ typename ContainerType::const_iterator iterator_;
+ // A cached value of *iterator_. We keep it here to allow access by
+ // pointer in the wrapping iterator's operator->().
+ // value_ needs to be mutable to be accessed in Current().
+ // Use of std::unique_ptr helps manage cached value's lifetime,
+ // which is bound by the lifespan of the iterator itself.
+ mutable std::unique_ptr<const T> value_;
+ }; // class ValuesInIteratorRangeGenerator::Iterator
+
+ // No implementation - assignment is unsupported.
+ void operator=(const ValuesInIteratorRangeGenerator& other);
+
+ const ContainerType container_;
+}; // class ValuesInIteratorRangeGenerator
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// Default parameterized test name generator, returns a string containing the
+// integer test parameter index.
+template <class ParamType>
+std::string DefaultParamName(const TestParamInfo<ParamType>& info) {
+ Message name_stream;
+ name_stream << info.index;
+ return name_stream.GetString();
+}
+
+template <typename T = int>
+void TestNotEmpty() {
+ static_assert(sizeof(T) == 0, "Empty arguments are not allowed.");
+}
+template <typename T = int>
+void TestNotEmpty(const T&) {}
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// Stores a parameter value and later creates tests parameterized with that
+// value.
+template <class TestClass>
+class ParameterizedTestFactory : public TestFactoryBase {
+ public:
+ typedef typename TestClass::ParamType ParamType;
+ explicit ParameterizedTestFactory(ParamType parameter) :
+ parameter_(parameter) {}
+ Test* CreateTest() override {
+ TestClass::SetParam(¶meter_);
+ return new TestClass();
+ }
+
+ private:
+ const ParamType parameter_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory);
+};
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// TestMetaFactoryBase is a base class for meta-factories that create
+// test factories for passing into MakeAndRegisterTestInfo function.
+template <class ParamType>
+class TestMetaFactoryBase {
+ public:
+ virtual ~TestMetaFactoryBase() {}
+
+ virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0;
+};
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// TestMetaFactory creates test factories for passing into
+// MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives
+// ownership of test factory pointer, same factory object cannot be passed
+// into that method twice. But ParameterizedTestSuiteInfo is going to call
+// it for each Test/Parameter value combination. Thus it needs meta factory
+// creator class.
+template <class TestSuite>
+class TestMetaFactory
+ : public TestMetaFactoryBase<typename TestSuite::ParamType> {
+ public:
+ using ParamType = typename TestSuite::ParamType;
+
+ TestMetaFactory() {}
+
+ TestFactoryBase* CreateTestFactory(ParamType parameter) override {
+ return new ParameterizedTestFactory<TestSuite>(parameter);
+ }
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(TestMetaFactory);
+};
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// ParameterizedTestSuiteInfoBase is a generic interface
+// to ParameterizedTestSuiteInfo classes. ParameterizedTestSuiteInfoBase
+// accumulates test information provided by TEST_P macro invocations
+// and generators provided by INSTANTIATE_TEST_SUITE_P macro invocations
+// and uses that information to register all resulting test instances
+// in RegisterTests method. The ParameterizeTestSuiteRegistry class holds
+// a collection of pointers to the ParameterizedTestSuiteInfo objects
+// and calls RegisterTests() on each of them when asked.
+class ParameterizedTestSuiteInfoBase {
+ public:
+ virtual ~ParameterizedTestSuiteInfoBase() {}
+
+ // Base part of test suite name for display purposes.
+ virtual const std::string& GetTestSuiteName() const = 0;
+ // Test case id to verify identity.
+ virtual TypeId GetTestSuiteTypeId() const = 0;
+ // UnitTest class invokes this method to register tests in this
+ // test suite right before running them in RUN_ALL_TESTS macro.
+ // This method should not be called more than once on any single
+ // instance of a ParameterizedTestSuiteInfoBase derived class.
+ virtual void RegisterTests() = 0;
+
+ protected:
+ ParameterizedTestSuiteInfoBase() {}
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase);
+};
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// ParameterizedTestSuiteInfo accumulates tests obtained from TEST_P
+// macro invocations for a particular test suite and generators
+// obtained from INSTANTIATE_TEST_SUITE_P macro invocations for that
+// test suite. It registers tests with all values generated by all
+// generators when asked.
+template <class TestSuite>
+class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
+ public:
+ // ParamType and GeneratorCreationFunc are private types but are required
+ // for declarations of public methods AddTestPattern() and
+ // AddTestSuiteInstantiation().
+ using ParamType = typename TestSuite::ParamType;
+ // A function that returns an instance of appropriate generator type.
+ typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
+ using ParamNameGeneratorFunc = std::string(const TestParamInfo<ParamType>&);
+
+ explicit ParameterizedTestSuiteInfo(const char* name,
+ CodeLocation code_location)
+ : test_suite_name_(name), code_location_(code_location) {}
+
+ // Test case base name for display purposes.
+ const std::string& GetTestSuiteName() const override {
+ return test_suite_name_;
+ }
+ // Test case id to verify identity.
+ TypeId GetTestSuiteTypeId() const override { return GetTypeId<TestSuite>(); }
+ // TEST_P macro uses AddTestPattern() to record information
+ // about a single test in a LocalTestInfo structure.
+ // test_suite_name is the base name of the test suite (without invocation
+ // prefix). test_base_name is the name of an individual test without
+ // parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
+ // test suite base name and DoBar is test base name.
+ void AddTestPattern(const char* test_suite_name, const char* test_base_name,
+ TestMetaFactoryBase<ParamType>* meta_factory) {
+ tests_.push_back(std::shared_ptr<TestInfo>(
+ new TestInfo(test_suite_name, test_base_name, meta_factory)));
+ }
+ // INSTANTIATE_TEST_SUITE_P macro uses AddGenerator() to record information
+ // about a generator.
+ int AddTestSuiteInstantiation(const std::string& instantiation_name,
+ GeneratorCreationFunc* func,
+ ParamNameGeneratorFunc* name_func,
+ const char* file, int line) {
+ instantiations_.push_back(
+ InstantiationInfo(instantiation_name, func, name_func, file, line));
+ return 0; // Return value used only to run this method in namespace scope.
+ }
+ // UnitTest class invokes this method to register tests in this test suite
+ // test suites right before running tests in RUN_ALL_TESTS macro.
+ // This method should not be called more than once on any single
+ // instance of a ParameterizedTestSuiteInfoBase derived class.
+ // UnitTest has a guard to prevent from calling this method more than once.
+ void RegisterTests() override {
+ for (typename TestInfoContainer::iterator test_it = tests_.begin();
+ test_it != tests_.end(); ++test_it) {
+ std::shared_ptr<TestInfo> test_info = *test_it;
+ for (typename InstantiationContainer::iterator gen_it =
+ instantiations_.begin(); gen_it != instantiations_.end();
+ ++gen_it) {
+ const std::string& instantiation_name = gen_it->name;
+ ParamGenerator<ParamType> generator((*gen_it->generator)());
+ ParamNameGeneratorFunc* name_func = gen_it->name_func;
+ const char* file = gen_it->file;
+ int line = gen_it->line;
+
+ std::string test_suite_name;
+ if ( !instantiation_name.empty() )
+ test_suite_name = instantiation_name + "/";
+ test_suite_name += test_info->test_suite_base_name;
+
+ size_t i = 0;
+ std::set<std::string> test_param_names;
+ for (typename ParamGenerator<ParamType>::iterator param_it =
+ generator.begin();
+ param_it != generator.end(); ++param_it, ++i) {
+ Message test_name_stream;
+
+ std::string param_name = name_func(
+ TestParamInfo<ParamType>(*param_it, i));
+
+ GTEST_CHECK_(IsValidParamName(param_name))
+ << "Parameterized test name '" << param_name
+ << "' is invalid, in " << file
+ << " line " << line << std::endl;
+
+ GTEST_CHECK_(test_param_names.count(param_name) == 0)
+ << "Duplicate parameterized test name '" << param_name
+ << "', in " << file << " line " << line << std::endl;
+
+ test_param_names.insert(param_name);
+
+ test_name_stream << test_info->test_base_name << "/" << param_name;
+ MakeAndRegisterTestInfo(
+ test_suite_name.c_str(), test_name_stream.GetString().c_str(),
+ nullptr, // No type parameter.
+ PrintToString(*param_it).c_str(), code_location_,
+ GetTestSuiteTypeId(),
+ SuiteApiResolver<TestSuite>::GetSetUpCaseOrSuite(file, line),
+ SuiteApiResolver<TestSuite>::GetTearDownCaseOrSuite(file, line),
+ test_info->test_meta_factory->CreateTestFactory(*param_it));
+ } // for param_it
+ } // for gen_it
+ } // for test_it
+ } // RegisterTests
+
+ private:
+ // LocalTestInfo structure keeps information about a single test registered
+ // with TEST_P macro.
+ struct TestInfo {
+ TestInfo(const char* a_test_suite_base_name, const char* a_test_base_name,
+ TestMetaFactoryBase<ParamType>* a_test_meta_factory)
+ : test_suite_base_name(a_test_suite_base_name),
+ test_base_name(a_test_base_name),
+ test_meta_factory(a_test_meta_factory) {}
+
+ const std::string test_suite_base_name;
+ const std::string test_base_name;
+ const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
+ };
+ using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >;
+ // Records data received from INSTANTIATE_TEST_SUITE_P macros:
+ // <Instantiation name, Sequence generator creation function,
+ // Name generator function, Source file, Source line>
+ struct InstantiationInfo {
+ InstantiationInfo(const std::string &name_in,
+ GeneratorCreationFunc* generator_in,
+ ParamNameGeneratorFunc* name_func_in,
+ const char* file_in,
+ int line_in)
+ : name(name_in),
+ generator(generator_in),
+ name_func(name_func_in),
+ file(file_in),
+ line(line_in) {}
+
+ std::string name;
+ GeneratorCreationFunc* generator;
+ ParamNameGeneratorFunc* name_func;
+ const char* file;
+ int line;
+ };
+ typedef ::std::vector<InstantiationInfo> InstantiationContainer;
+
+ static bool IsValidParamName(const std::string& name) {
+ // Check for empty string
+ if (name.empty())
+ return false;
+
+ // Check for invalid characters
+ for (std::string::size_type index = 0; index < name.size(); ++index) {
+ if (!isalnum(name[index]) && name[index] != '_')
+ return false;
+ }
+
+ return true;
+ }
+
+ const std::string test_suite_name_;
+ CodeLocation code_location_;
+ TestInfoContainer tests_;
+ InstantiationContainer instantiations_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfo);
+}; // class ParameterizedTestSuiteInfo
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+template <class TestCase>
+using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo<TestCase>;
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// ParameterizedTestSuiteRegistry contains a map of
+// ParameterizedTestSuiteInfoBase classes accessed by test suite names. TEST_P
+// and INSTANTIATE_TEST_SUITE_P macros use it to locate their corresponding
+// ParameterizedTestSuiteInfo descriptors.
+class ParameterizedTestSuiteRegistry {
+ public:
+ ParameterizedTestSuiteRegistry() {}
+ ~ParameterizedTestSuiteRegistry() {
+ for (auto& test_suite_info : test_suite_infos_) {
+ delete test_suite_info;
+ }
+ }
+
+ // Looks up or creates and returns a structure containing information about
+ // tests and instantiations of a particular test suite.
+ template <class TestSuite>
+ ParameterizedTestSuiteInfo<TestSuite>* GetTestSuitePatternHolder(
+ const char* test_suite_name, CodeLocation code_location) {
+ ParameterizedTestSuiteInfo<TestSuite>* typed_test_info = nullptr;
+ for (auto& test_suite_info : test_suite_infos_) {
+ if (test_suite_info->GetTestSuiteName() == test_suite_name) {
+ if (test_suite_info->GetTestSuiteTypeId() != GetTypeId<TestSuite>()) {
+ // Complain about incorrect usage of Google Test facilities
+ // and terminate the program since we cannot guaranty correct
+ // test suite setup and tear-down in this case.
+ ReportInvalidTestSuiteType(test_suite_name, code_location);
+ posix::Abort();
+ } else {
+ // At this point we are sure that the object we found is of the same
+ // type we are looking for, so we downcast it to that type
+ // without further checks.
+ typed_test_info = CheckedDowncastToActualType<
+ ParameterizedTestSuiteInfo<TestSuite> >(test_suite_info);
+ }
+ break;
+ }
+ }
+ if (typed_test_info == nullptr) {
+ typed_test_info = new ParameterizedTestSuiteInfo<TestSuite>(
+ test_suite_name, code_location);
+ test_suite_infos_.push_back(typed_test_info);
+ }
+ return typed_test_info;
+ }
+ void RegisterTests() {
+ for (auto& test_suite_info : test_suite_infos_) {
+ test_suite_info->RegisterTests();
+ }
+ }
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ template <class TestCase>
+ ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(
+ const char* test_case_name, CodeLocation code_location) {
+ return GetTestSuitePatternHolder<TestCase>(test_case_name, code_location);
+ }
+
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+ private:
+ using TestSuiteInfoContainer = ::std::vector<ParameterizedTestSuiteInfoBase*>;
+
+ TestSuiteInfoContainer test_suite_infos_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteRegistry);
+};
+
+} // namespace internal
+
+// Forward declarations of ValuesIn(), which is implemented in
+// include/gtest/gtest-param-test.h.
+template <class Container>
+internal::ParamGenerator<typename Container::value_type> ValuesIn(
+ const Container& container);
+
+namespace internal {
+// Used in the Values() function to provide polymorphic capabilities.
+
+template <typename... Ts>
+class ValueArray {
+ public:
+ ValueArray(Ts... v) : v_{std::move(v)...} {}
+
+ template <typename T>
+ operator ParamGenerator<T>() const { // NOLINT
+ return ValuesIn(MakeVector<T>(MakeIndexSequence<sizeof...(Ts)>()));
+ }
+
+ private:
+ template <typename T, size_t... I>
+ std::vector<T> MakeVector(IndexSequence<I...>) const {
+ return std::vector<T>{static_cast<T>(v_.template Get<I>())...};
+ }
+
+ FlatTuple<Ts...> v_;
+};
+
+template <typename... T>
+class CartesianProductGenerator
+ : public ParamGeneratorInterface<::std::tuple<T...>> {
+ public:
+ typedef ::std::tuple<T...> ParamType;
+
+ CartesianProductGenerator(const std::tuple<ParamGenerator<T>...>& g)
+ : generators_(g) {}
+ ~CartesianProductGenerator() override {}
+
+ ParamIteratorInterface<ParamType>* Begin() const override {
+ return new Iterator(this, generators_, false);
+ }
+ ParamIteratorInterface<ParamType>* End() const override {
+ return new Iterator(this, generators_, true);
+ }
+
+ private:
+ template <class I>
+ class IteratorImpl;
+ template <size_t... I>
+ class IteratorImpl<IndexSequence<I...>>
+ : public ParamIteratorInterface<ParamType> {
+ public:
+ IteratorImpl(const ParamGeneratorInterface<ParamType>* base,
+ const std::tuple<ParamGenerator<T>...>& generators, bool is_end)
+ : base_(base),
+ begin_(std::get<I>(generators).begin()...),
+ end_(std::get<I>(generators).end()...),
+ current_(is_end ? end_ : begin_) {
+ ComputeCurrentValue();
+ }
+ ~IteratorImpl() override {}
+
+ const ParamGeneratorInterface<ParamType>* BaseGenerator() const override {
+ return base_;
+ }
+ // Advance should not be called on beyond-of-range iterators
+ // so no component iterators must be beyond end of range, either.
+ void Advance() override {
+ assert(!AtEnd());
+ // Advance the last iterator.
+ ++std::get<sizeof...(T) - 1>(current_);
+ // if that reaches end, propagate that up.
+ AdvanceIfEnd<sizeof...(T) - 1>();
+ ComputeCurrentValue();
+ }
+ ParamIteratorInterface<ParamType>* Clone() const override {
+ return new IteratorImpl(*this);
+ }
+
+ const ParamType* Current() const override { return current_value_.get(); }
+
+ bool Equals(const ParamIteratorInterface<ParamType>& other) const override {
+ // Having the same base generator guarantees that the other
+ // iterator is of the same type and we can downcast.
+ GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
+ << "The program attempted to compare iterators "
+ << "from different generators." << std::endl;
+ const IteratorImpl* typed_other =
+ CheckedDowncastToActualType<const IteratorImpl>(&other);
+
+ // We must report iterators equal if they both point beyond their
+ // respective ranges. That can happen in a variety of fashions,
+ // so we have to consult AtEnd().
+ if (AtEnd() && typed_other->AtEnd()) return true;
+
+ bool same = true;
+ bool dummy[] = {
+ (same = same && std::get<I>(current_) ==
+ std::get<I>(typed_other->current_))...};
+ (void)dummy;
+ return same;
+ }
+
+ private:
+ template <size_t ThisI>
+ void AdvanceIfEnd() {
+ if (std::get<ThisI>(current_) != std::get<ThisI>(end_)) return;
+
+ bool last = ThisI == 0;
+ if (last) {
+ // We are done. Nothing else to propagate.
+ return;
+ }
+
+ constexpr size_t NextI = ThisI - (ThisI != 0);
+ std::get<ThisI>(current_) = std::get<ThisI>(begin_);
+ ++std::get<NextI>(current_);
+ AdvanceIfEnd<NextI>();
+ }
+
+ void ComputeCurrentValue() {
+ if (!AtEnd())
+ current_value_ = std::make_shared<ParamType>(*std::get<I>(current_)...);
+ }
+ bool AtEnd() const {
+ bool at_end = false;
+ bool dummy[] = {
+ (at_end = at_end || std::get<I>(current_) == std::get<I>(end_))...};
+ (void)dummy;
+ return at_end;
+ }
+
+ const ParamGeneratorInterface<ParamType>* const base_;
+ std::tuple<typename ParamGenerator<T>::iterator...> begin_;
+ std::tuple<typename ParamGenerator<T>::iterator...> end_;
+ std::tuple<typename ParamGenerator<T>::iterator...> current_;
+ std::shared_ptr<ParamType> current_value_;
+ };
+
+ using Iterator = IteratorImpl<typename MakeIndexSequence<sizeof...(T)>::type>;
+
+ std::tuple<ParamGenerator<T>...> generators_;
+};
+
+template <class... Gen>
+class CartesianProductHolder {
+ public:
+ CartesianProductHolder(const Gen&... g) : generators_(g...) {}
+ template <typename... T>
+ operator ParamGenerator<::std::tuple<T...>>() const {
+ return ParamGenerator<::std::tuple<T...>>(
+ new CartesianProductGenerator<T...>(generators_));
+ }
+
+ private:
+ std::tuple<Gen...> generators_;
+};
+
+} // namespace internal
+} // namespace testing
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
--- /dev/null
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// The Google C++ Testing and Mocking Framework (Google Test)
+//
+// This header file defines the GTEST_OS_* macro.
+// It is separate from gtest-port.h so that custom/gtest-port.h can include it.
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
+
+// Determines the platform on which Google Test is compiled.
+#ifdef __CYGWIN__
+# define GTEST_OS_CYGWIN 1
+# elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)
+# define GTEST_OS_WINDOWS_MINGW 1
+# define GTEST_OS_WINDOWS 1
+#elif defined _WIN32
+# define GTEST_OS_WINDOWS 1
+# ifdef _WIN32_WCE
+# define GTEST_OS_WINDOWS_MOBILE 1
+# elif defined(WINAPI_FAMILY)
+# include <winapifamily.h>
+# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+# define GTEST_OS_WINDOWS_DESKTOP 1
+# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
+# define GTEST_OS_WINDOWS_PHONE 1
+# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
+# define GTEST_OS_WINDOWS_RT 1
+# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE)
+# define GTEST_OS_WINDOWS_PHONE 1
+# define GTEST_OS_WINDOWS_TV_TITLE 1
+# else
+ // WINAPI_FAMILY defined but no known partition matched.
+ // Default to desktop.
+# define GTEST_OS_WINDOWS_DESKTOP 1
+# endif
+# else
+# define GTEST_OS_WINDOWS_DESKTOP 1
+# endif // _WIN32_WCE
+#elif defined __OS2__
+# define GTEST_OS_OS2 1
+#elif defined __APPLE__
+# define GTEST_OS_MAC 1
+# if TARGET_OS_IPHONE
+# define GTEST_OS_IOS 1
+# endif
+#elif defined __DragonFly__
+# define GTEST_OS_DRAGONFLY 1
+#elif defined __FreeBSD__
+# define GTEST_OS_FREEBSD 1
+#elif defined __Fuchsia__
+# define GTEST_OS_FUCHSIA 1
+#elif defined(__GLIBC__) && defined(__FreeBSD_kernel__)
+# define GTEST_OS_GNU_KFREEBSD 1
+#elif defined __linux__
+# define GTEST_OS_LINUX 1
+# if defined __ANDROID__
+# define GTEST_OS_LINUX_ANDROID 1
+# endif
+#elif defined __MVS__
+# define GTEST_OS_ZOS 1
+#elif defined(__sun) && defined(__SVR4)
+# define GTEST_OS_SOLARIS 1
+#elif defined(_AIX)
+# define GTEST_OS_AIX 1
+#elif defined(__hpux)
+# define GTEST_OS_HPUX 1
+#elif defined __native_client__
+# define GTEST_OS_NACL 1
+#elif defined __NetBSD__
+# define GTEST_OS_NETBSD 1
+#elif defined __OpenBSD__
+# define GTEST_OS_OPENBSD 1
+#elif defined __QNX__
+# define GTEST_OS_QNX 1
+#elif defined(__HAIKU__)
+#define GTEST_OS_HAIKU 1
+#endif // __CYGWIN__
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
--- /dev/null
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Low-level types and utilities for porting Google Test to various
+// platforms. All macros ending with _ and symbols defined in an
+// internal namespace are subject to change without notice. Code
+// outside Google Test MUST NOT USE THEM DIRECTLY. Macros that don't
+// end with _ are part of Google Test's public API and can be used by
+// code outside Google Test.
+//
+// This file is fundamental to Google Test. All other Google Test source
+// files are expected to #include this. Therefore, it cannot #include
+// any other Google Test header.
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
+
+// Environment-describing macros
+// -----------------------------
+//
+// Google Test can be used in many different environments. Macros in
+// this section tell Google Test what kind of environment it is being
+// used in, such that Google Test can provide environment-specific
+// features and implementations.
+//
+// Google Test tries to automatically detect the properties of its
+// environment, so users usually don't need to worry about these
+// macros. However, the automatic detection is not perfect.
+// Sometimes it's necessary for a user to define some of the following
+// macros in the build script to override Google Test's decisions.
+//
+// If the user doesn't define a macro in the list, Google Test will
+// provide a default definition. After this header is #included, all
+// macros in this list will be defined to either 1 or 0.
+//
+// Notes to maintainers:
+// - Each macro here is a user-tweakable knob; do not grow the list
+// lightly.
+// - Use #if to key off these macros. Don't use #ifdef or "#if
+// defined(...)", which will not work as these macros are ALWAYS
+// defined.
+//
+// GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2)
+// is/isn't available.
+// GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exceptions
+// are enabled.
+// GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX regular
+// expressions are/aren't available.
+// GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h>
+// is/isn't available.
+// GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't
+// enabled.
+// GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that
+// std::wstring does/doesn't work (Google Test can
+// be used where std::wstring is unavailable).
+// GTEST_HAS_SEH - Define it to 1/0 to indicate whether the
+// compiler supports Microsoft's "Structured
+// Exception Handling".
+// GTEST_HAS_STREAM_REDIRECTION
+// - Define it to 1/0 to indicate whether the
+// platform supports I/O stream redirection using
+// dup() and dup2().
+// GTEST_LINKED_AS_SHARED_LIBRARY
+// - Define to 1 when compiling tests that use
+// Google Test as a shared library (known as
+// DLL on Windows).
+// GTEST_CREATE_SHARED_LIBRARY
+// - Define to 1 when compiling Google Test itself
+// as a shared library.
+// GTEST_DEFAULT_DEATH_TEST_STYLE
+// - The default value of --gtest_death_test_style.
+// The legacy default has been "fast" in the open
+// source version since 2008. The recommended value
+// is "threadsafe", and can be set in
+// custom/gtest-port.h.
+
+// Platform-indicating macros
+// --------------------------
+//
+// Macros indicating the platform on which Google Test is being used
+// (a macro is defined to 1 if compiled on the given platform;
+// otherwise UNDEFINED -- it's never defined to 0.). Google Test
+// defines these macros automatically. Code outside Google Test MUST
+// NOT define them.
+//
+// GTEST_OS_AIX - IBM AIX
+// GTEST_OS_CYGWIN - Cygwin
+// GTEST_OS_DRAGONFLY - DragonFlyBSD
+// GTEST_OS_FREEBSD - FreeBSD
+// GTEST_OS_FUCHSIA - Fuchsia
+// GTEST_OS_GNU_KFREEBSD - GNU/kFreeBSD
+// GTEST_OS_HAIKU - Haiku
+// GTEST_OS_HPUX - HP-UX
+// GTEST_OS_LINUX - Linux
+// GTEST_OS_LINUX_ANDROID - Google Android
+// GTEST_OS_MAC - Mac OS X
+// GTEST_OS_IOS - iOS
+// GTEST_OS_NACL - Google Native Client (NaCl)
+// GTEST_OS_NETBSD - NetBSD
+// GTEST_OS_OPENBSD - OpenBSD
+// GTEST_OS_OS2 - OS/2
+// GTEST_OS_QNX - QNX
+// GTEST_OS_SOLARIS - Sun Solaris
+// GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile)
+// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop
+// GTEST_OS_WINDOWS_MINGW - MinGW
+// GTEST_OS_WINDOWS_MOBILE - Windows Mobile
+// GTEST_OS_WINDOWS_PHONE - Windows Phone
+// GTEST_OS_WINDOWS_RT - Windows Store App/WinRT
+// GTEST_OS_ZOS - z/OS
+//
+// Among the platforms, Cygwin, Linux, Mac OS X, and Windows have the
+// most stable support. Since core members of the Google Test project
+// don't have access to other platforms, support for them may be less
+// stable. If you notice any problems on your platform, please notify
+// googletestframework@googlegroups.com (patches for fixing them are
+// even more welcome!).
+//
+// It is possible that none of the GTEST_OS_* macros are defined.
+
+// Feature-indicating macros
+// -------------------------
+//
+// Macros indicating which Google Test features are available (a macro
+// is defined to 1 if the corresponding feature is supported;
+// otherwise UNDEFINED -- it's never defined to 0.). Google Test
+// defines these macros automatically. Code outside Google Test MUST
+// NOT define them.
+//
+// These macros are public so that portable tests can be written.
+// Such tests typically surround code using a feature with an #if
+// which controls that code. For example:
+//
+// #if GTEST_HAS_DEATH_TEST
+// EXPECT_DEATH(DoSomethingDeadly());
+// #endif
+//
+// GTEST_HAS_DEATH_TEST - death tests
+// GTEST_HAS_TYPED_TEST - typed tests
+// GTEST_HAS_TYPED_TEST_P - type-parameterized tests
+// GTEST_IS_THREADSAFE - Google Test is thread-safe.
+// GOOGLETEST_CM0007 DO NOT DELETE
+// GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse with
+// GTEST_HAS_POSIX_RE (see above) which users can
+// define themselves.
+// GTEST_USES_SIMPLE_RE - our own simple regex is used;
+// the above RE\b(s) are mutually exclusive.
+
+// Misc public macros
+// ------------------
+//
+// GTEST_FLAG(flag_name) - references the variable corresponding to
+// the given Google Test flag.
+
+// Internal utilities
+// ------------------
+//
+// The following macros and utilities are for Google Test's INTERNAL
+// use only. Code outside Google Test MUST NOT USE THEM DIRECTLY.
+//
+// Macros for basic C++ coding:
+// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
+// GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a
+// variable don't have to be used.
+// GTEST_DISALLOW_ASSIGN_ - disables operator=.
+// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
+// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used.
+// GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is
+// suppressed (constant conditional).
+// GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127
+// is suppressed.
+//
+// Synchronization:
+// Mutex, MutexLock, ThreadLocal, GetThreadCount()
+// - synchronization primitives.
+//
+// Template meta programming:
+// IteratorTraits - partial implementation of std::iterator_traits, which
+// is not available in libCstd when compiled with Sun C++.
+//
+//
+// Regular expressions:
+// RE - a simple regular expression class using the POSIX
+// Extended Regular Expression syntax on UNIX-like platforms
+// GOOGLETEST_CM0008 DO NOT DELETE
+// or a reduced regular exception syntax on other
+// platforms, including Windows.
+// Logging:
+// GTEST_LOG_() - logs messages at the specified severity level.
+// LogToStderr() - directs all log messages to stderr.
+// FlushInfoLog() - flushes informational log messages.
+//
+// Stdout and stderr capturing:
+// CaptureStdout() - starts capturing stdout.
+// GetCapturedStdout() - stops capturing stdout and returns the captured
+// string.
+// CaptureStderr() - starts capturing stderr.
+// GetCapturedStderr() - stops capturing stderr and returns the captured
+// string.
+//
+// Integer types:
+// TypeWithSize - maps an integer to a int type.
+// Int32, UInt32, Int64, UInt64, TimeInMillis
+// - integers of known sizes.
+// BiggestInt - the biggest signed integer type.
+//
+// Command-line utilities:
+// GTEST_DECLARE_*() - declares a flag.
+// GTEST_DEFINE_*() - defines a flag.
+// GetInjectableArgvs() - returns the command line as a vector of strings.
+//
+// Environment variable utilities:
+// GetEnv() - gets the value of an environment variable.
+// BoolFromGTestEnv() - parses a bool environment variable.
+// Int32FromGTestEnv() - parses an Int32 environment variable.
+// StringFromGTestEnv() - parses a string environment variable.
+//
+// Deprecation warnings:
+// GTEST_INTERNAL_DEPRECATED(message) - attribute marking a function as
+// deprecated; calling a marked function
+// should generate a compiler warning
+
+#include <ctype.h> // for isspace, etc
+#include <stddef.h> // for ptrdiff_t
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory>
+#include <type_traits>
+
+#ifndef _WIN32_WCE
+# include <sys/types.h>
+# include <sys/stat.h>
+#endif // !_WIN32_WCE
+
+#if defined __APPLE__
+# include <AvailabilityMacros.h>
+# include <TargetConditionals.h>
+#endif
+
+#include <algorithm> // NOLINT
+#include <iostream> // NOLINT
+#include <sstream> // NOLINT
+#include <string> // NOLINT
+#include <tuple>
+#include <utility>
+#include <vector> // NOLINT
+
+#include "gtest/internal/gtest-port-arch.h"
+#include "gtest/internal/custom/gtest-port.h"
+
+#if !defined(GTEST_DEV_EMAIL_)
+# define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
+# define GTEST_FLAG_PREFIX_ "gtest_"
+# define GTEST_FLAG_PREFIX_DASH_ "gtest-"
+# define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
+# define GTEST_NAME_ "Google Test"
+# define GTEST_PROJECT_URL_ "https://github.com/google/googletest/"
+#endif // !defined(GTEST_DEV_EMAIL_)
+
+#if !defined(GTEST_INIT_GOOGLE_TEST_NAME_)
+# define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest"
+#endif // !defined(GTEST_INIT_GOOGLE_TEST_NAME_)
+
+// Determines the version of gcc that is used to compile this.
+#ifdef __GNUC__
+// 40302 means version 4.3.2.
+# define GTEST_GCC_VER_ \
+ (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
+#endif // __GNUC__
+
+// Macros for disabling Microsoft Visual C++ warnings.
+//
+// GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385)
+// /* code that triggers warnings C4800 and C4385 */
+// GTEST_DISABLE_MSC_WARNINGS_POP_()
+#if defined(_MSC_VER)
+# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
+ __pragma(warning(push)) \
+ __pragma(warning(disable: warnings))
+# define GTEST_DISABLE_MSC_WARNINGS_POP_() \
+ __pragma(warning(pop))
+#else
+// Not all compilers are MSVC
+# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
+# define GTEST_DISABLE_MSC_WARNINGS_POP_()
+#endif
+
+// Clang on Windows does not understand MSVC's pragma warning.
+// We need clang-specific way to disable function deprecation warning.
+#ifdef __clang__
+# define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \
+ _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
+ _Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"")
+#define GTEST_DISABLE_MSC_DEPRECATED_POP_() \
+ _Pragma("clang diagnostic pop")
+#else
+# define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
+# define GTEST_DISABLE_MSC_DEPRECATED_POP_() \
+ GTEST_DISABLE_MSC_WARNINGS_POP_()
+#endif
+
+// Brings in definitions for functions used in the testing::internal::posix
+// namespace (read, write, close, chdir, isatty, stat). We do not currently
+// use them on Windows Mobile.
+#if GTEST_OS_WINDOWS
+# if !GTEST_OS_WINDOWS_MOBILE
+# include <direct.h>
+# include <io.h>
+# endif
+// In order to avoid having to include <windows.h>, use forward declaration
+#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR)
+// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
+// separate (equivalent) structs, instead of using typedef
+typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
+#else
+// Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
+// This assumption is verified by
+// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
+typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
+#endif
+#else
+// This assumes that non-Windows OSes provide unistd.h. For OSes where this
+// is not the case, we need to include headers that provide the functions
+// mentioned above.
+# include <unistd.h>
+# include <strings.h>
+#endif // GTEST_OS_WINDOWS
+
+#if GTEST_OS_LINUX_ANDROID
+// Used to define __ANDROID_API__ matching the target NDK API level.
+# include <android/api-level.h> // NOLINT
+#endif
+
+// Defines this to true iff Google Test can use POSIX regular expressions.
+#ifndef GTEST_HAS_POSIX_RE
+# if GTEST_OS_LINUX_ANDROID
+// On Android, <regex.h> is only available starting with Gingerbread.
+# define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
+# else
+# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
+# endif
+#endif
+
+#if GTEST_USES_PCRE
+// The appropriate headers have already been included.
+
+#elif GTEST_HAS_POSIX_RE
+
+// On some platforms, <regex.h> needs someone to define size_t, and
+// won't compile otherwise. We can #include it here as we already
+// included <stdlib.h>, which is guaranteed to define size_t through
+// <stddef.h>.
+# include <regex.h> // NOLINT
+
+# define GTEST_USES_POSIX_RE 1
+
+#elif GTEST_OS_WINDOWS
+
+// <regex.h> is not available on Windows. Use our own simple regex
+// implementation instead.
+# define GTEST_USES_SIMPLE_RE 1
+
+#else
+
+// <regex.h> may not be available on this platform. Use our own
+// simple regex implementation instead.
+# define GTEST_USES_SIMPLE_RE 1
+
+#endif // GTEST_USES_PCRE
+
+#ifndef GTEST_HAS_EXCEPTIONS
+// The user didn't tell us whether exceptions are enabled, so we need
+// to figure it out.
+# if defined(_MSC_VER) && defined(_CPPUNWIND)
+// MSVC defines _CPPUNWIND to 1 iff exceptions are enabled.
+# define GTEST_HAS_EXCEPTIONS 1
+# elif defined(__BORLANDC__)
+// C++Builder's implementation of the STL uses the _HAS_EXCEPTIONS
+// macro to enable exceptions, so we'll do the same.
+// Assumes that exceptions are enabled by default.
+# ifndef _HAS_EXCEPTIONS
+# define _HAS_EXCEPTIONS 1
+# endif // _HAS_EXCEPTIONS
+# define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
+# elif defined(__clang__)
+// clang defines __EXCEPTIONS iff exceptions are enabled before clang 220714,
+// but iff cleanups are enabled after that. In Obj-C++ files, there can be
+// cleanups for ObjC exceptions which also need cleanups, even if C++ exceptions
+// are disabled. clang has __has_feature(cxx_exceptions) which checks for C++
+// exceptions starting at clang r206352, but which checked for cleanups prior to
+// that. To reliably check for C++ exception availability with clang, check for
+// __EXCEPTIONS && __has_feature(cxx_exceptions).
+# define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions))
+# elif defined(__GNUC__) && __EXCEPTIONS
+// gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
+# define GTEST_HAS_EXCEPTIONS 1
+# elif defined(__SUNPRO_CC)
+// Sun Pro CC supports exceptions. However, there is no compile-time way of
+// detecting whether they are enabled or not. Therefore, we assume that
+// they are enabled unless the user tells us otherwise.
+# define GTEST_HAS_EXCEPTIONS 1
+# elif defined(__IBMCPP__) && __EXCEPTIONS
+// xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
+# define GTEST_HAS_EXCEPTIONS 1
+# elif defined(__HP_aCC)
+// Exception handling is in effect by default in HP aCC compiler. It has to
+// be turned of by +noeh compiler option if desired.
+# define GTEST_HAS_EXCEPTIONS 1
+# else
+// For other compilers, we assume exceptions are disabled to be
+// conservative.
+# define GTEST_HAS_EXCEPTIONS 0
+# endif // defined(_MSC_VER) || defined(__BORLANDC__)
+#endif // GTEST_HAS_EXCEPTIONS
+
+#if !defined(GTEST_HAS_STD_STRING)
+// Even though we don't use this macro any longer, we keep it in case
+// some clients still depend on it.
+# define GTEST_HAS_STD_STRING 1
+#elif !GTEST_HAS_STD_STRING
+// The user told us that ::std::string isn't available.
+# error "::std::string isn't available."
+#endif // !defined(GTEST_HAS_STD_STRING)
+
+#ifndef GTEST_HAS_STD_WSTRING
+// The user didn't tell us whether ::std::wstring is available, so we need
+// to figure it out.
+// Cygwin 1.7 and below doesn't support ::std::wstring.
+// Solaris' libc++ doesn't support it either. Android has
+// no support for it at least as recent as Froyo (2.2).
+#define GTEST_HAS_STD_WSTRING \
+ (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
+ GTEST_OS_HAIKU))
+
+#endif // GTEST_HAS_STD_WSTRING
+
+// Determines whether RTTI is available.
+#ifndef GTEST_HAS_RTTI
+// The user didn't tell us whether RTTI is enabled, so we need to
+// figure it out.
+
+# ifdef _MSC_VER
+
+# ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled.
+# define GTEST_HAS_RTTI 1
+# else
+# define GTEST_HAS_RTTI 0
+# endif
+
+// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
+# elif defined(__GNUC__)
+
+# ifdef __GXX_RTTI
+// When building against STLport with the Android NDK and with
+// -frtti -fno-exceptions, the build fails at link time with undefined
+// references to __cxa_bad_typeid. Note sure if STL or toolchain bug,
+// so disable RTTI when detected.
+# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \
+ !defined(__EXCEPTIONS)
+# define GTEST_HAS_RTTI 0
+# else
+# define GTEST_HAS_RTTI 1
+# endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS
+# else
+# define GTEST_HAS_RTTI 0
+# endif // __GXX_RTTI
+
+// Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends
+// using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the
+// first version with C++ support.
+# elif defined(__clang__)
+
+# define GTEST_HAS_RTTI __has_feature(cxx_rtti)
+
+// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
+// both the typeid and dynamic_cast features are present.
+# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
+
+# ifdef __RTTI_ALL__
+# define GTEST_HAS_RTTI 1
+# else
+# define GTEST_HAS_RTTI 0
+# endif
+
+# else
+
+// For all other compilers, we assume RTTI is enabled.
+# define GTEST_HAS_RTTI 1
+
+# endif // _MSC_VER
+
+#endif // GTEST_HAS_RTTI
+
+// It's this header's responsibility to #include <typeinfo> when RTTI
+// is enabled.
+#if GTEST_HAS_RTTI
+# include <typeinfo>
+#endif
+
+// Determines whether Google Test can use the pthreads library.
+#ifndef GTEST_HAS_PTHREAD
+// The user didn't tell us explicitly, so we make reasonable assumptions about
+// which platforms have pthreads support.
+//
+// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
+// to your compiler flags.
+#define GTEST_HAS_PTHREAD \
+ (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX || \
+ GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \
+ GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_OPENBSD || \
+ GTEST_OS_HAIKU)
+#endif // GTEST_HAS_PTHREAD
+
+#if GTEST_HAS_PTHREAD
+// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
+// true.
+# include <pthread.h> // NOLINT
+
+// For timespec and nanosleep, used below.
+# include <time.h> // NOLINT
+#endif
+
+// Determines whether clone(2) is supported.
+// Usually it will only be available on Linux, excluding
+// Linux on the Itanium architecture.
+// Also see http://linux.die.net/man/2/clone.
+#ifndef GTEST_HAS_CLONE
+// The user didn't tell us, so we need to figure it out.
+
+# if GTEST_OS_LINUX && !defined(__ia64__)
+# if GTEST_OS_LINUX_ANDROID
+// On Android, clone() became available at different API levels for each 32-bit
+// architecture.
+# if defined(__LP64__) || \
+ (defined(__arm__) && __ANDROID_API__ >= 9) || \
+ (defined(__mips__) && __ANDROID_API__ >= 12) || \
+ (defined(__i386__) && __ANDROID_API__ >= 17)
+# define GTEST_HAS_CLONE 1
+# else
+# define GTEST_HAS_CLONE 0
+# endif
+# else
+# define GTEST_HAS_CLONE 1
+# endif
+# else
+# define GTEST_HAS_CLONE 0
+# endif // GTEST_OS_LINUX && !defined(__ia64__)
+
+#endif // GTEST_HAS_CLONE
+
+// Determines whether to support stream redirection. This is used to test
+// output correctness and to implement death tests.
+#ifndef GTEST_HAS_STREAM_REDIRECTION
+// By default, we assume that stream redirection is supported on all
+// platforms except known mobile ones.
+# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
+# define GTEST_HAS_STREAM_REDIRECTION 0
+# else
+# define GTEST_HAS_STREAM_REDIRECTION 1
+# endif // !GTEST_OS_WINDOWS_MOBILE
+#endif // GTEST_HAS_STREAM_REDIRECTION
+
+// Determines whether to support death tests.
+// pops up a dialog window that cannot be suppressed programmatically.
+#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
+ (GTEST_OS_MAC && !GTEST_OS_IOS) || \
+ (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || GTEST_OS_WINDOWS_MINGW || \
+ GTEST_OS_AIX || GTEST_OS_HPUX || GTEST_OS_OPENBSD || GTEST_OS_QNX || \
+ GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \
+ GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU)
+# define GTEST_HAS_DEATH_TEST 1
+#endif
+
+// Determines whether to support type-driven tests.
+
+// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
+// Sun Pro CC, IBM Visual Age, and HP aCC support.
+#if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \
+ defined(__IBMCPP__) || defined(__HP_aCC)
+# define GTEST_HAS_TYPED_TEST 1
+# define GTEST_HAS_TYPED_TEST_P 1
+#endif
+
+// Determines whether the system compiler uses UTF-16 for encoding wide strings.
+#define GTEST_WIDE_STRING_USES_UTF16_ \
+ (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2)
+
+// Determines whether test results can be streamed to a socket.
+#if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \
+ GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD
+# define GTEST_CAN_STREAM_RESULTS_ 1
+#endif
+
+// Defines some utility macros.
+
+// The GNU compiler emits a warning if nested "if" statements are followed by
+// an "else" statement and braces are not used to explicitly disambiguate the
+// "else" binding. This leads to problems with code like:
+//
+// if (gate)
+// ASSERT_*(condition) << "Some message";
+//
+// The "switch (0) case 0:" idiom is used to suppress this.
+#ifdef __INTEL_COMPILER
+# define GTEST_AMBIGUOUS_ELSE_BLOCKER_
+#else
+# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT
+#endif
+
+// Use this annotation at the end of a struct/class definition to
+// prevent the compiler from optimizing away instances that are never
+// used. This is useful when all interesting logic happens inside the
+// c'tor and / or d'tor. Example:
+//
+// struct Foo {
+// Foo() { ... }
+// } GTEST_ATTRIBUTE_UNUSED_;
+//
+// Also use it after a variable or parameter declaration to tell the
+// compiler the variable/parameter does not have to be used.
+#if defined(__GNUC__) && !defined(COMPILER_ICC)
+# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
+#elif defined(__clang__)
+# if __has_attribute(unused)
+# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
+# endif
+#endif
+#ifndef GTEST_ATTRIBUTE_UNUSED_
+# define GTEST_ATTRIBUTE_UNUSED_
+#endif
+
+// Use this annotation before a function that takes a printf format string.
+#if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC)
+# if defined(__MINGW_PRINTF_FORMAT)
+// MinGW has two different printf implementations. Ensure the format macro
+// matches the selected implementation. See
+// https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/.
+# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
+ __attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \
+ first_to_check)))
+# else
+# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
+ __attribute__((__format__(__printf__, string_index, first_to_check)))
+# endif
+#else
+# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)
+#endif
+
+
+// A macro to disallow operator=
+// This should be used in the private: declarations for a class.
+#define GTEST_DISALLOW_ASSIGN_(type) \
+ void operator=(type const &) = delete
+
+// A macro to disallow copy constructor and operator=
+// This should be used in the private: declarations for a class.
+#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \
+ type(type const &) = delete; \
+ GTEST_DISALLOW_ASSIGN_(type)
+
+// Tell the compiler to warn about unused return values for functions declared
+// with this macro. The macro should be used on function declarations
+// following the argument list:
+//
+// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
+#if defined(__GNUC__) && !defined(COMPILER_ICC)
+# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
+#else
+# define GTEST_MUST_USE_RESULT_
+#endif // __GNUC__ && !COMPILER_ICC
+
+// MS C++ compiler emits warning when a conditional expression is compile time
+// constant. In some contexts this warning is false positive and needs to be
+// suppressed. Use the following two macros in such cases:
+//
+// GTEST_INTENTIONAL_CONST_COND_PUSH_()
+// while (true) {
+// GTEST_INTENTIONAL_CONST_COND_POP_()
+// }
+# define GTEST_INTENTIONAL_CONST_COND_PUSH_() \
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127)
+# define GTEST_INTENTIONAL_CONST_COND_POP_() \
+ GTEST_DISABLE_MSC_WARNINGS_POP_()
+
+// Determine whether the compiler supports Microsoft's Structured Exception
+// Handling. This is supported by several Windows compilers but generally
+// does not exist on any other system.
+#ifndef GTEST_HAS_SEH
+// The user didn't tell us, so we need to figure it out.
+
+# if defined(_MSC_VER) || defined(__BORLANDC__)
+// These two compilers are known to support SEH.
+# define GTEST_HAS_SEH 1
+# else
+// Assume no SEH.
+# define GTEST_HAS_SEH 0
+# endif
+
+#endif // GTEST_HAS_SEH
+
+#ifndef GTEST_IS_THREADSAFE
+
+#define GTEST_IS_THREADSAFE \
+ (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \
+ (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) || \
+ GTEST_HAS_PTHREAD)
+
+#endif // GTEST_IS_THREADSAFE
+
+// GTEST_API_ qualifies all symbols that must be exported. The definitions below
+// are guarded by #ifndef to give embedders a chance to define GTEST_API_ in
+// gtest/internal/custom/gtest-port.h
+#ifndef GTEST_API_
+
+#ifdef _MSC_VER
+# if GTEST_LINKED_AS_SHARED_LIBRARY
+# define GTEST_API_ __declspec(dllimport)
+# elif GTEST_CREATE_SHARED_LIBRARY
+# define GTEST_API_ __declspec(dllexport)
+# endif
+#elif __GNUC__ >= 4 || defined(__clang__)
+# define GTEST_API_ __attribute__((visibility ("default")))
+#endif // _MSC_VER
+
+#endif // GTEST_API_
+
+#ifndef GTEST_API_
+# define GTEST_API_
+#endif // GTEST_API_
+
+#ifndef GTEST_DEFAULT_DEATH_TEST_STYLE
+# define GTEST_DEFAULT_DEATH_TEST_STYLE "fast"
+#endif // GTEST_DEFAULT_DEATH_TEST_STYLE
+
+#ifdef __GNUC__
+// Ask the compiler to never inline a given function.
+# define GTEST_NO_INLINE_ __attribute__((noinline))
+#else
+# define GTEST_NO_INLINE_
+#endif
+
+// _LIBCPP_VERSION is defined by the libc++ library from the LLVM project.
+#if !defined(GTEST_HAS_CXXABI_H_)
+# if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER))
+# define GTEST_HAS_CXXABI_H_ 1
+# else
+# define GTEST_HAS_CXXABI_H_ 0
+# endif
+#endif
+
+// A function level attribute to disable checking for use of uninitialized
+// memory when built with MemorySanitizer.
+#if defined(__clang__)
+# if __has_feature(memory_sanitizer)
+# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \
+ __attribute__((no_sanitize_memory))
+# else
+# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
+# endif // __has_feature(memory_sanitizer)
+#else
+# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
+#endif // __clang__
+
+// A function level attribute to disable AddressSanitizer instrumentation.
+#if defined(__clang__)
+# if __has_feature(address_sanitizer)
+# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \
+ __attribute__((no_sanitize_address))
+# else
+# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
+# endif // __has_feature(address_sanitizer)
+#else
+# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
+#endif // __clang__
+
+// A function level attribute to disable HWAddressSanitizer instrumentation.
+#if defined(__clang__)
+# if __has_feature(hwaddress_sanitizer)
+# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \
+ __attribute__((no_sanitize("hwaddress")))
+# else
+# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
+# endif // __has_feature(hwaddress_sanitizer)
+#else
+# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
+#endif // __clang__
+
+// A function level attribute to disable ThreadSanitizer instrumentation.
+#if defined(__clang__)
+# if __has_feature(thread_sanitizer)
+# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \
+ __attribute__((no_sanitize_thread))
+# else
+# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
+# endif // __has_feature(thread_sanitizer)
+#else
+# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
+#endif // __clang__
+
+namespace testing {
+
+class Message;
+
+// Legacy imports for backwards compatibility.
+// New code should use std:: names directly.
+using std::get;
+using std::make_tuple;
+using std::tuple;
+using std::tuple_element;
+using std::tuple_size;
+
+namespace internal {
+
+// A secret type that Google Test users don't know about. It has no
+// definition on purpose. Therefore it's impossible to create a
+// Secret object, which is what we want.
+class Secret;
+
+// The GTEST_COMPILE_ASSERT_ is a legacy macro used to verify that a compile
+// time expression is true (in new code, use static_assert instead). For
+// example, you could use it to verify the size of a static array:
+//
+// GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES,
+// names_incorrect_size);
+//
+// The second argument to the macro must be a valid C++ identifier. If the
+// expression is false, compiler will issue an error containing this identifier.
+#define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
+
+// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
+//
+// This template is declared, but intentionally undefined.
+template <typename T1, typename T2>
+struct StaticAssertTypeEqHelper;
+
+template <typename T>
+struct StaticAssertTypeEqHelper<T, T> {
+ enum { value = true };
+};
+
+// Same as std::is_same<>.
+template <typename T, typename U>
+struct IsSame {
+ enum { value = false };
+};
+template <typename T>
+struct IsSame<T, T> {
+ enum { value = true };
+};
+
+// Evaluates to the number of elements in 'array'.
+#define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))
+
+// A helper for suppressing warnings on constant condition. It just
+// returns 'condition'.
+GTEST_API_ bool IsTrue(bool condition);
+
+// Defines RE.
+
+#if GTEST_USES_PCRE
+// if used, PCRE is injected by custom/gtest-port.h
+#elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE
+
+// A simple C++ wrapper for <regex.h>. It uses the POSIX Extended
+// Regular Expression syntax.
+class GTEST_API_ RE {
+ public:
+ // A copy constructor is required by the Standard to initialize object
+ // references from r-values.
+ RE(const RE& other) { Init(other.pattern()); }
+
+ // Constructs an RE from a string.
+ RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT
+
+ RE(const char* regex) { Init(regex); } // NOLINT
+ ~RE();
+
+ // Returns the string representation of the regex.
+ const char* pattern() const { return pattern_; }
+
+ // FullMatch(str, re) returns true iff regular expression re matches
+ // the entire str.
+ // PartialMatch(str, re) returns true iff regular expression re
+ // matches a substring of str (including str itself).
+ static bool FullMatch(const ::std::string& str, const RE& re) {
+ return FullMatch(str.c_str(), re);
+ }
+ static bool PartialMatch(const ::std::string& str, const RE& re) {
+ return PartialMatch(str.c_str(), re);
+ }
+
+ static bool FullMatch(const char* str, const RE& re);
+ static bool PartialMatch(const char* str, const RE& re);
+
+ private:
+ void Init(const char* regex);
+ const char* pattern_;
+ bool is_valid_;
+
+# if GTEST_USES_POSIX_RE
+
+ regex_t full_regex_; // For FullMatch().
+ regex_t partial_regex_; // For PartialMatch().
+
+# else // GTEST_USES_SIMPLE_RE
+
+ const char* full_pattern_; // For FullMatch();
+
+# endif
+
+ GTEST_DISALLOW_ASSIGN_(RE);
+};
+
+#endif // GTEST_USES_PCRE
+
+// Formats a source file path and a line number as they would appear
+// in an error message from the compiler used to compile this code.
+GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
+
+// Formats a file location for compiler-independent XML output.
+// Although this function is not platform dependent, we put it next to
+// FormatFileLocation in order to contrast the two functions.
+GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
+ int line);
+
+// Defines logging utilities:
+// GTEST_LOG_(severity) - logs messages at the specified severity level. The
+// message itself is streamed into the macro.
+// LogToStderr() - directs all log messages to stderr.
+// FlushInfoLog() - flushes informational log messages.
+
+enum GTestLogSeverity {
+ GTEST_INFO,
+ GTEST_WARNING,
+ GTEST_ERROR,
+ GTEST_FATAL
+};
+
+// Formats log entry severity, provides a stream object for streaming the
+// log message, and terminates the message with a newline when going out of
+// scope.
+class GTEST_API_ GTestLog {
+ public:
+ GTestLog(GTestLogSeverity severity, const char* file, int line);
+
+ // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
+ ~GTestLog();
+
+ ::std::ostream& GetStream() { return ::std::cerr; }
+
+ private:
+ const GTestLogSeverity severity_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
+};
+
+#if !defined(GTEST_LOG_)
+
+# define GTEST_LOG_(severity) \
+ ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
+ __FILE__, __LINE__).GetStream()
+
+inline void LogToStderr() {}
+inline void FlushInfoLog() { fflush(nullptr); }
+
+#endif // !defined(GTEST_LOG_)
+
+#if !defined(GTEST_CHECK_)
+// INTERNAL IMPLEMENTATION - DO NOT USE.
+//
+// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
+// is not satisfied.
+// Synopsys:
+// GTEST_CHECK_(boolean_condition);
+// or
+// GTEST_CHECK_(boolean_condition) << "Additional message";
+//
+// This checks the condition and if the condition is not satisfied
+// it prints message about the condition violation, including the
+// condition itself, plus additional message streamed into it, if any,
+// and then it aborts the program. It aborts the program irrespective of
+// whether it is built in the debug mode or not.
+# define GTEST_CHECK_(condition) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::IsTrue(condition)) \
+ ; \
+ else \
+ GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
+#endif // !defined(GTEST_CHECK_)
+
+// An all-mode assert to verify that the given POSIX-style function
+// call returns 0 (indicating success). Known limitation: this
+// doesn't expand to a balanced 'if' statement, so enclose the macro
+// in {} if you need to use it as the only statement in an 'if'
+// branch.
+#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
+ if (const int gtest_error = (posix_call)) \
+ GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
+ << gtest_error
+
+// Adds reference to a type if it is not a reference type,
+// otherwise leaves it unchanged. This is the same as
+// tr1::add_reference, which is not widely available yet.
+template <typename T>
+struct AddReference { typedef T& type; }; // NOLINT
+template <typename T>
+struct AddReference<T&> { typedef T& type; }; // NOLINT
+
+// A handy wrapper around AddReference that works when the argument T
+// depends on template parameters.
+#define GTEST_ADD_REFERENCE_(T) \
+ typename ::testing::internal::AddReference<T>::type
+
+// Transforms "T" into "const T&" according to standard reference collapsing
+// rules (this is only needed as a backport for C++98 compilers that do not
+// support reference collapsing). Specifically, it transforms:
+//
+// char ==> const char&
+// const char ==> const char&
+// char& ==> char&
+// const char& ==> const char&
+//
+// Note that the non-const reference will not have "const" added. This is
+// standard, and necessary so that "T" can always bind to "const T&".
+template <typename T>
+struct ConstRef { typedef const T& type; };
+template <typename T>
+struct ConstRef<T&> { typedef T& type; };
+
+// The argument T must depend on some template parameters.
+#define GTEST_REFERENCE_TO_CONST_(T) \
+ typename ::testing::internal::ConstRef<T>::type
+
+// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
+//
+// Use ImplicitCast_ as a safe version of static_cast for upcasting in
+// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
+// const Foo*). When you use ImplicitCast_, the compiler checks that
+// the cast is safe. Such explicit ImplicitCast_s are necessary in
+// surprisingly many situations where C++ demands an exact type match
+// instead of an argument type convertable to a target type.
+//
+// The syntax for using ImplicitCast_ is the same as for static_cast:
+//
+// ImplicitCast_<ToType>(expr)
+//
+// ImplicitCast_ would have been part of the C++ standard library,
+// but the proposal was submitted too late. It will probably make
+// its way into the language in the future.
+//
+// This relatively ugly name is intentional. It prevents clashes with
+// similar functions users may have (e.g., implicit_cast). The internal
+// namespace alone is not enough because the function can be found by ADL.
+template<typename To>
+inline To ImplicitCast_(To x) { return x; }
+
+// When you upcast (that is, cast a pointer from type Foo to type
+// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
+// always succeed. When you downcast (that is, cast a pointer from
+// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
+// how do you know the pointer is really of type SubclassOfFoo? It
+// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus,
+// when you downcast, you should use this macro. In debug mode, we
+// use dynamic_cast<> to double-check the downcast is legal (we die
+// if it's not). In normal mode, we do the efficient static_cast<>
+// instead. Thus, it's important to test in debug mode to make sure
+// the cast is legal!
+// This is the only place in the code we should use dynamic_cast<>.
+// In particular, you SHOULDN'T be using dynamic_cast<> in order to
+// do RTTI (eg code like this:
+// if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
+// if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
+// You should design the code some other way not to need this.
+//
+// This relatively ugly name is intentional. It prevents clashes with
+// similar functions users may have (e.g., down_cast). The internal
+// namespace alone is not enough because the function can be found by ADL.
+template<typename To, typename From> // use like this: DownCast_<T*>(foo);
+inline To DownCast_(From* f) { // so we only accept pointers
+ // Ensures that To is a sub-type of From *. This test is here only
+ // for compile-time type checking, and has no overhead in an
+ // optimized build at run-time, as it will be optimized away
+ // completely.
+ GTEST_INTENTIONAL_CONST_COND_PUSH_()
+ if (false) {
+ GTEST_INTENTIONAL_CONST_COND_POP_()
+ const To to = nullptr;
+ ::testing::internal::ImplicitCast_<From*>(to);
+ }
+
+#if GTEST_HAS_RTTI
+ // RTTI: debug mode only!
+ GTEST_CHECK_(f == nullptr || dynamic_cast<To>(f) != nullptr);
+#endif
+ return static_cast<To>(f);
+}
+
+// Downcasts the pointer of type Base to Derived.
+// Derived must be a subclass of Base. The parameter MUST
+// point to a class of type Derived, not any subclass of it.
+// When RTTI is available, the function performs a runtime
+// check to enforce this.
+template <class Derived, class Base>
+Derived* CheckedDowncastToActualType(Base* base) {
+#if GTEST_HAS_RTTI
+ GTEST_CHECK_(typeid(*base) == typeid(Derived));
+#endif
+
+#if GTEST_HAS_DOWNCAST_
+ return ::down_cast<Derived*>(base);
+#elif GTEST_HAS_RTTI
+ return dynamic_cast<Derived*>(base); // NOLINT
+#else
+ return static_cast<Derived*>(base); // Poor man's downcast.
+#endif
+}
+
+#if GTEST_HAS_STREAM_REDIRECTION
+
+// Defines the stderr capturer:
+// CaptureStdout - starts capturing stdout.
+// GetCapturedStdout - stops capturing stdout and returns the captured string.
+// CaptureStderr - starts capturing stderr.
+// GetCapturedStderr - stops capturing stderr and returns the captured string.
+//
+GTEST_API_ void CaptureStdout();
+GTEST_API_ std::string GetCapturedStdout();
+GTEST_API_ void CaptureStderr();
+GTEST_API_ std::string GetCapturedStderr();
+
+#endif // GTEST_HAS_STREAM_REDIRECTION
+// Returns the size (in bytes) of a file.
+GTEST_API_ size_t GetFileSize(FILE* file);
+
+// Reads the entire content of a file as a string.
+GTEST_API_ std::string ReadEntireFile(FILE* file);
+
+// All command line arguments.
+GTEST_API_ std::vector<std::string> GetArgvs();
+
+#if GTEST_HAS_DEATH_TEST
+
+std::vector<std::string> GetInjectableArgvs();
+// Deprecated: pass the args vector by value instead.
+void SetInjectableArgvs(const std::vector<std::string>* new_argvs);
+void SetInjectableArgvs(const std::vector<std::string>& new_argvs);
+void ClearInjectableArgvs();
+
+#endif // GTEST_HAS_DEATH_TEST
+
+// Defines synchronization primitives.
+#if GTEST_IS_THREADSAFE
+# if GTEST_HAS_PTHREAD
+// Sleeps for (roughly) n milliseconds. This function is only for testing
+// Google Test's own constructs. Don't use it in user tests, either
+// directly or indirectly.
+inline void SleepMilliseconds(int n) {
+ const timespec time = {
+ 0, // 0 seconds.
+ n * 1000L * 1000L, // And n ms.
+ };
+ nanosleep(&time, nullptr);
+}
+# endif // GTEST_HAS_PTHREAD
+
+# if GTEST_HAS_NOTIFICATION_
+// Notification has already been imported into the namespace.
+// Nothing to do here.
+
+# elif GTEST_HAS_PTHREAD
+// Allows a controller thread to pause execution of newly created
+// threads until notified. Instances of this class must be created
+// and destroyed in the controller thread.
+//
+// This class is only for testing Google Test's own constructs. Do not
+// use it in user tests, either directly or indirectly.
+class Notification {
+ public:
+ Notification() : notified_(false) {
+ GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr));
+ }
+ ~Notification() {
+ pthread_mutex_destroy(&mutex_);
+ }
+
+ // Notifies all threads created with this notification to start. Must
+ // be called from the controller thread.
+ void Notify() {
+ pthread_mutex_lock(&mutex_);
+ notified_ = true;
+ pthread_mutex_unlock(&mutex_);
+ }
+
+ // Blocks until the controller thread notifies. Must be called from a test
+ // thread.
+ void WaitForNotification() {
+ for (;;) {
+ pthread_mutex_lock(&mutex_);
+ const bool notified = notified_;
+ pthread_mutex_unlock(&mutex_);
+ if (notified)
+ break;
+ SleepMilliseconds(10);
+ }
+ }
+
+ private:
+ pthread_mutex_t mutex_;
+ bool notified_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
+};
+
+# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
+
+GTEST_API_ void SleepMilliseconds(int n);
+
+// Provides leak-safe Windows kernel handle ownership.
+// Used in death tests and in threading support.
+class GTEST_API_ AutoHandle {
+ public:
+ // Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to
+ // avoid including <windows.h> in this header file. Including <windows.h> is
+ // undesirable because it defines a lot of symbols and macros that tend to
+ // conflict with client code. This assumption is verified by
+ // WindowsTypesTest.HANDLEIsVoidStar.
+ typedef void* Handle;
+ AutoHandle();
+ explicit AutoHandle(Handle handle);
+
+ ~AutoHandle();
+
+ Handle Get() const;
+ void Reset();
+ void Reset(Handle handle);
+
+ private:
+ // Returns true iff the handle is a valid handle object that can be closed.
+ bool IsCloseable() const;
+
+ Handle handle_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
+};
+
+// Allows a controller thread to pause execution of newly created
+// threads until notified. Instances of this class must be created
+// and destroyed in the controller thread.
+//
+// This class is only for testing Google Test's own constructs. Do not
+// use it in user tests, either directly or indirectly.
+class GTEST_API_ Notification {
+ public:
+ Notification();
+ void Notify();
+ void WaitForNotification();
+
+ private:
+ AutoHandle event_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
+};
+# endif // GTEST_HAS_NOTIFICATION_
+
+// On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD
+// defined, but we don't want to use MinGW's pthreads implementation, which
+// has conformance problems with some versions of the POSIX standard.
+# if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
+
+// As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
+// Consequently, it cannot select a correct instantiation of ThreadWithParam
+// in order to call its Run(). Introducing ThreadWithParamBase as a
+// non-templated base class for ThreadWithParam allows us to bypass this
+// problem.
+class ThreadWithParamBase {
+ public:
+ virtual ~ThreadWithParamBase() {}
+ virtual void Run() = 0;
+};
+
+// pthread_create() accepts a pointer to a function type with the C linkage.
+// According to the Standard (7.5/1), function types with different linkages
+// are different even if they are otherwise identical. Some compilers (for
+// example, SunStudio) treat them as different types. Since class methods
+// cannot be defined with C-linkage we need to define a free C-function to
+// pass into pthread_create().
+extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
+ static_cast<ThreadWithParamBase*>(thread)->Run();
+ return nullptr;
+}
+
+// Helper class for testing Google Test's multi-threading constructs.
+// To use it, write:
+//
+// void ThreadFunc(int param) { /* Do things with param */ }
+// Notification thread_can_start;
+// ...
+// // The thread_can_start parameter is optional; you can supply NULL.
+// ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);
+// thread_can_start.Notify();
+//
+// These classes are only for testing Google Test's own constructs. Do
+// not use them in user tests, either directly or indirectly.
+template <typename T>
+class ThreadWithParam : public ThreadWithParamBase {
+ public:
+ typedef void UserThreadFunc(T);
+
+ ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
+ : func_(func),
+ param_(param),
+ thread_can_start_(thread_can_start),
+ finished_(false) {
+ ThreadWithParamBase* const base = this;
+ // The thread can be created only after all fields except thread_
+ // have been initialized.
+ GTEST_CHECK_POSIX_SUCCESS_(
+ pthread_create(&thread_, nullptr, &ThreadFuncWithCLinkage, base));
+ }
+ ~ThreadWithParam() override { Join(); }
+
+ void Join() {
+ if (!finished_) {
+ GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, nullptr));
+ finished_ = true;
+ }
+ }
+
+ void Run() override {
+ if (thread_can_start_ != nullptr) thread_can_start_->WaitForNotification();
+ func_(param_);
+ }
+
+ private:
+ UserThreadFunc* const func_; // User-supplied thread function.
+ const T param_; // User-supplied parameter to the thread function.
+ // When non-NULL, used to block execution until the controller thread
+ // notifies.
+ Notification* const thread_can_start_;
+ bool finished_; // true iff we know that the thread function has finished.
+ pthread_t thread_; // The native thread object.
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
+};
+# endif // !GTEST_OS_WINDOWS && GTEST_HAS_PTHREAD ||
+ // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
+
+# if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
+// Mutex and ThreadLocal have already been imported into the namespace.
+// Nothing to do here.
+
+# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
+
+// Mutex implements mutex on Windows platforms. It is used in conjunction
+// with class MutexLock:
+//
+// Mutex mutex;
+// ...
+// MutexLock lock(&mutex); // Acquires the mutex and releases it at the
+// // end of the current scope.
+//
+// A static Mutex *must* be defined or declared using one of the following
+// macros:
+// GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);
+// GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
+//
+// (A non-static Mutex is defined/declared in the usual way).
+class GTEST_API_ Mutex {
+ public:
+ enum MutexType { kStatic = 0, kDynamic = 1 };
+ // We rely on kStaticMutex being 0 as it is to what the linker initializes
+ // type_ in static mutexes. critical_section_ will be initialized lazily
+ // in ThreadSafeLazyInit().
+ enum StaticConstructorSelector { kStaticMutex = 0 };
+
+ // This constructor intentionally does nothing. It relies on type_ being
+ // statically initialized to 0 (effectively setting it to kStatic) and on
+ // ThreadSafeLazyInit() to lazily initialize the rest of the members.
+ explicit Mutex(StaticConstructorSelector /*dummy*/) {}
+
+ Mutex();
+ ~Mutex();
+
+ void Lock();
+
+ void Unlock();
+
+ // Does nothing if the current thread holds the mutex. Otherwise, crashes
+ // with high probability.
+ void AssertHeld();
+
+ private:
+ // Initializes owner_thread_id_ and critical_section_ in static mutexes.
+ void ThreadSafeLazyInit();
+
+ // Per https://blogs.msdn.microsoft.com/oldnewthing/20040223-00/?p=40503,
+ // we assume that 0 is an invalid value for thread IDs.
+ unsigned int owner_thread_id_;
+
+ // For static mutexes, we rely on these members being initialized to zeros
+ // by the linker.
+ MutexType type_;
+ long critical_section_init_phase_; // NOLINT
+ GTEST_CRITICAL_SECTION* critical_section_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
+};
+
+# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
+ extern ::testing::internal::Mutex mutex
+
+# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
+ ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex)
+
+// We cannot name this class MutexLock because the ctor declaration would
+// conflict with a macro named MutexLock, which is defined on some
+// platforms. That macro is used as a defensive measure to prevent against
+// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
+// "MutexLock l(&mu)". Hence the typedef trick below.
+class GTestMutexLock {
+ public:
+ explicit GTestMutexLock(Mutex* mutex)
+ : mutex_(mutex) { mutex_->Lock(); }
+
+ ~GTestMutexLock() { mutex_->Unlock(); }
+
+ private:
+ Mutex* const mutex_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
+};
+
+typedef GTestMutexLock MutexLock;
+
+// Base class for ValueHolder<T>. Allows a caller to hold and delete a value
+// without knowing its type.
+class ThreadLocalValueHolderBase {
+ public:
+ virtual ~ThreadLocalValueHolderBase() {}
+};
+
+// Provides a way for a thread to send notifications to a ThreadLocal
+// regardless of its parameter type.
+class ThreadLocalBase {
+ public:
+ // Creates a new ValueHolder<T> object holding a default value passed to
+ // this ThreadLocal<T>'s constructor and returns it. It is the caller's
+ // responsibility not to call this when the ThreadLocal<T> instance already
+ // has a value on the current thread.
+ virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const = 0;
+
+ protected:
+ ThreadLocalBase() {}
+ virtual ~ThreadLocalBase() {}
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocalBase);
+};
+
+// Maps a thread to a set of ThreadLocals that have values instantiated on that
+// thread and notifies them when the thread exits. A ThreadLocal instance is
+// expected to persist until all threads it has values on have terminated.
+class GTEST_API_ ThreadLocalRegistry {
+ public:
+ // Registers thread_local_instance as having value on the current thread.
+ // Returns a value that can be used to identify the thread from other threads.
+ static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
+ const ThreadLocalBase* thread_local_instance);
+
+ // Invoked when a ThreadLocal instance is destroyed.
+ static void OnThreadLocalDestroyed(
+ const ThreadLocalBase* thread_local_instance);
+};
+
+class GTEST_API_ ThreadWithParamBase {
+ public:
+ void Join();
+
+ protected:
+ class Runnable {
+ public:
+ virtual ~Runnable() {}
+ virtual void Run() = 0;
+ };
+
+ ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start);
+ virtual ~ThreadWithParamBase();
+
+ private:
+ AutoHandle thread_;
+};
+
+// Helper class for testing Google Test's multi-threading constructs.
+template <typename T>
+class ThreadWithParam : public ThreadWithParamBase {
+ public:
+ typedef void UserThreadFunc(T);
+
+ ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
+ : ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) {
+ }
+ virtual ~ThreadWithParam() {}
+
+ private:
+ class RunnableImpl : public Runnable {
+ public:
+ RunnableImpl(UserThreadFunc* func, T param)
+ : func_(func),
+ param_(param) {
+ }
+ virtual ~RunnableImpl() {}
+ virtual void Run() {
+ func_(param_);
+ }
+
+ private:
+ UserThreadFunc* const func_;
+ const T param_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(RunnableImpl);
+ };
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
+};
+
+// Implements thread-local storage on Windows systems.
+//
+// // Thread 1
+// ThreadLocal<int> tl(100); // 100 is the default value for each thread.
+//
+// // Thread 2
+// tl.set(150); // Changes the value for thread 2 only.
+// EXPECT_EQ(150, tl.get());
+//
+// // Thread 1
+// EXPECT_EQ(100, tl.get()); // In thread 1, tl has the original value.
+// tl.set(200);
+// EXPECT_EQ(200, tl.get());
+//
+// The template type argument T must have a public copy constructor.
+// In addition, the default ThreadLocal constructor requires T to have
+// a public default constructor.
+//
+// The users of a TheadLocal instance have to make sure that all but one
+// threads (including the main one) using that instance have exited before
+// destroying it. Otherwise, the per-thread objects managed for them by the
+// ThreadLocal instance are not guaranteed to be destroyed on all platforms.
+//
+// Google Test only uses global ThreadLocal objects. That means they
+// will die after main() has returned. Therefore, no per-thread
+// object managed by Google Test will be leaked as long as all threads
+// using Google Test have exited when main() returns.
+template <typename T>
+class ThreadLocal : public ThreadLocalBase {
+ public:
+ ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {}
+ explicit ThreadLocal(const T& value)
+ : default_factory_(new InstanceValueHolderFactory(value)) {}
+
+ ~ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(this); }
+
+ T* pointer() { return GetOrCreateValue(); }
+ const T* pointer() const { return GetOrCreateValue(); }
+ const T& get() const { return *pointer(); }
+ void set(const T& value) { *pointer() = value; }
+
+ private:
+ // Holds a value of T. Can be deleted via its base class without the caller
+ // knowing the type of T.
+ class ValueHolder : public ThreadLocalValueHolderBase {
+ public:
+ ValueHolder() : value_() {}
+ explicit ValueHolder(const T& value) : value_(value) {}
+
+ T* pointer() { return &value_; }
+
+ private:
+ T value_;
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
+ };
+
+
+ T* GetOrCreateValue() const {
+ return static_cast<ValueHolder*>(
+ ThreadLocalRegistry::GetValueOnCurrentThread(this))->pointer();
+ }
+
+ virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const {
+ return default_factory_->MakeNewHolder();
+ }
+
+ class ValueHolderFactory {
+ public:
+ ValueHolderFactory() {}
+ virtual ~ValueHolderFactory() {}
+ virtual ValueHolder* MakeNewHolder() const = 0;
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory);
+ };
+
+ class DefaultValueHolderFactory : public ValueHolderFactory {
+ public:
+ DefaultValueHolderFactory() {}
+ virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); }
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory);
+ };
+
+ class InstanceValueHolderFactory : public ValueHolderFactory {
+ public:
+ explicit InstanceValueHolderFactory(const T& value) : value_(value) {}
+ virtual ValueHolder* MakeNewHolder() const {
+ return new ValueHolder(value_);
+ }
+
+ private:
+ const T value_; // The value for each thread.
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory);
+ };
+
+ std::unique_ptr<ValueHolderFactory> default_factory_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
+};
+
+# elif GTEST_HAS_PTHREAD
+
+// MutexBase and Mutex implement mutex on pthreads-based platforms.
+class MutexBase {
+ public:
+ // Acquires this mutex.
+ void Lock() {
+ GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
+ owner_ = pthread_self();
+ has_owner_ = true;
+ }
+
+ // Releases this mutex.
+ void Unlock() {
+ // Since the lock is being released the owner_ field should no longer be
+ // considered valid. We don't protect writing to has_owner_ here, as it's
+ // the caller's responsibility to ensure that the current thread holds the
+ // mutex when this is called.
+ has_owner_ = false;
+ GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
+ }
+
+ // Does nothing if the current thread holds the mutex. Otherwise, crashes
+ // with high probability.
+ void AssertHeld() const {
+ GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
+ << "The current thread is not holding the mutex @" << this;
+ }
+
+ // A static mutex may be used before main() is entered. It may even
+ // be used before the dynamic initialization stage. Therefore we
+ // must be able to initialize a static mutex object at link time.
+ // This means MutexBase has to be a POD and its member variables
+ // have to be public.
+ public:
+ pthread_mutex_t mutex_; // The underlying pthread mutex.
+ // has_owner_ indicates whether the owner_ field below contains a valid thread
+ // ID and is therefore safe to inspect (e.g., to use in pthread_equal()). All
+ // accesses to the owner_ field should be protected by a check of this field.
+ // An alternative might be to memset() owner_ to all zeros, but there's no
+ // guarantee that a zero'd pthread_t is necessarily invalid or even different
+ // from pthread_self().
+ bool has_owner_;
+ pthread_t owner_; // The thread holding the mutex.
+};
+
+// Forward-declares a static mutex.
+# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
+ extern ::testing::internal::MutexBase mutex
+
+// Defines and statically (i.e. at link time) initializes a static mutex.
+// The initialization list here does not explicitly initialize each field,
+// instead relying on default initialization for the unspecified fields. In
+// particular, the owner_ field (a pthread_t) is not explicitly initialized.
+// This allows initialization to work whether pthread_t is a scalar or struct.
+// The flag -Wmissing-field-initializers must not be specified for this to work.
+#define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
+ ::testing::internal::MutexBase mutex = {PTHREAD_MUTEX_INITIALIZER, false, 0}
+
+// The Mutex class can only be used for mutexes created at runtime. It
+// shares its API with MutexBase otherwise.
+class Mutex : public MutexBase {
+ public:
+ Mutex() {
+ GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr));
+ has_owner_ = false;
+ }
+ ~Mutex() {
+ GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
+ }
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
+};
+
+// We cannot name this class MutexLock because the ctor declaration would
+// conflict with a macro named MutexLock, which is defined on some
+// platforms. That macro is used as a defensive measure to prevent against
+// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
+// "MutexLock l(&mu)". Hence the typedef trick below.
+class GTestMutexLock {
+ public:
+ explicit GTestMutexLock(MutexBase* mutex)
+ : mutex_(mutex) { mutex_->Lock(); }
+
+ ~GTestMutexLock() { mutex_->Unlock(); }
+
+ private:
+ MutexBase* const mutex_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
+};
+
+typedef GTestMutexLock MutexLock;
+
+// Helpers for ThreadLocal.
+
+// pthread_key_create() requires DeleteThreadLocalValue() to have
+// C-linkage. Therefore it cannot be templatized to access
+// ThreadLocal<T>. Hence the need for class
+// ThreadLocalValueHolderBase.
+class ThreadLocalValueHolderBase {
+ public:
+ virtual ~ThreadLocalValueHolderBase() {}
+};
+
+// Called by pthread to delete thread-local data stored by
+// pthread_setspecific().
+extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
+ delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
+}
+
+// Implements thread-local storage on pthreads-based systems.
+template <typename T>
+class GTEST_API_ ThreadLocal {
+ public:
+ ThreadLocal()
+ : key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {}
+ explicit ThreadLocal(const T& value)
+ : key_(CreateKey()),
+ default_factory_(new InstanceValueHolderFactory(value)) {}
+
+ ~ThreadLocal() {
+ // Destroys the managed object for the current thread, if any.
+ DeleteThreadLocalValue(pthread_getspecific(key_));
+
+ // Releases resources associated with the key. This will *not*
+ // delete managed objects for other threads.
+ GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
+ }
+
+ T* pointer() { return GetOrCreateValue(); }
+ const T* pointer() const { return GetOrCreateValue(); }
+ const T& get() const { return *pointer(); }
+ void set(const T& value) { *pointer() = value; }
+
+ private:
+ // Holds a value of type T.
+ class ValueHolder : public ThreadLocalValueHolderBase {
+ public:
+ ValueHolder() : value_() {}
+ explicit ValueHolder(const T& value) : value_(value) {}
+
+ T* pointer() { return &value_; }
+
+ private:
+ T value_;
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
+ };
+
+ static pthread_key_t CreateKey() {
+ pthread_key_t key;
+ // When a thread exits, DeleteThreadLocalValue() will be called on
+ // the object managed for that thread.
+ GTEST_CHECK_POSIX_SUCCESS_(
+ pthread_key_create(&key, &DeleteThreadLocalValue));
+ return key;
+ }
+
+ T* GetOrCreateValue() const {
+ ThreadLocalValueHolderBase* const holder =
+ static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
+ if (holder != nullptr) {
+ return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
+ }
+
+ ValueHolder* const new_holder = default_factory_->MakeNewHolder();
+ ThreadLocalValueHolderBase* const holder_base = new_holder;
+ GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
+ return new_holder->pointer();
+ }
+
+ class ValueHolderFactory {
+ public:
+ ValueHolderFactory() {}
+ virtual ~ValueHolderFactory() {}
+ virtual ValueHolder* MakeNewHolder() const = 0;
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory);
+ };
+
+ class DefaultValueHolderFactory : public ValueHolderFactory {
+ public:
+ DefaultValueHolderFactory() {}
+ virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); }
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory);
+ };
+
+ class InstanceValueHolderFactory : public ValueHolderFactory {
+ public:
+ explicit InstanceValueHolderFactory(const T& value) : value_(value) {}
+ virtual ValueHolder* MakeNewHolder() const {
+ return new ValueHolder(value_);
+ }
+
+ private:
+ const T value_; // The value for each thread.
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory);
+ };
+
+ // A key pthreads uses for looking up per-thread values.
+ const pthread_key_t key_;
+ std::unique_ptr<ValueHolderFactory> default_factory_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
+};
+
+# endif // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
+
+#else // GTEST_IS_THREADSAFE
+
+// A dummy implementation of synchronization primitives (mutex, lock,
+// and thread-local variable). Necessary for compiling Google Test where
+// mutex is not supported - using Google Test in multiple threads is not
+// supported on such platforms.
+
+class Mutex {
+ public:
+ Mutex() {}
+ void Lock() {}
+ void Unlock() {}
+ void AssertHeld() const {}
+};
+
+# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
+ extern ::testing::internal::Mutex mutex
+
+# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
+
+// We cannot name this class MutexLock because the ctor declaration would
+// conflict with a macro named MutexLock, which is defined on some
+// platforms. That macro is used as a defensive measure to prevent against
+// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
+// "MutexLock l(&mu)". Hence the typedef trick below.
+class GTestMutexLock {
+ public:
+ explicit GTestMutexLock(Mutex*) {} // NOLINT
+};
+
+typedef GTestMutexLock MutexLock;
+
+template <typename T>
+class GTEST_API_ ThreadLocal {
+ public:
+ ThreadLocal() : value_() {}
+ explicit ThreadLocal(const T& value) : value_(value) {}
+ T* pointer() { return &value_; }
+ const T* pointer() const { return &value_; }
+ const T& get() const { return value_; }
+ void set(const T& value) { value_ = value; }
+ private:
+ T value_;
+};
+
+#endif // GTEST_IS_THREADSAFE
+
+// Returns the number of threads running in the process, or 0 to indicate that
+// we cannot detect it.
+GTEST_API_ size_t GetThreadCount();
+
+template <bool bool_value>
+struct bool_constant {
+ typedef bool_constant<bool_value> type;
+ static const bool value = bool_value;
+};
+template <bool bool_value> const bool bool_constant<bool_value>::value;
+
+typedef bool_constant<false> false_type;
+typedef bool_constant<true> true_type;
+
+template <typename T, typename U>
+struct is_same : public false_type {};
+
+template <typename T>
+struct is_same<T, T> : public true_type {};
+
+template <typename Iterator>
+struct IteratorTraits {
+ typedef typename Iterator::value_type value_type;
+};
+
+
+template <typename T>
+struct IteratorTraits<T*> {
+ typedef T value_type;
+};
+
+template <typename T>
+struct IteratorTraits<const T*> {
+ typedef T value_type;
+};
+
+#if GTEST_OS_WINDOWS
+# define GTEST_PATH_SEP_ "\\"
+# define GTEST_HAS_ALT_PATH_SEP_ 1
+// The biggest signed integer type the compiler supports.
+typedef __int64 BiggestInt;
+#else
+# define GTEST_PATH_SEP_ "/"
+# define GTEST_HAS_ALT_PATH_SEP_ 0
+typedef long long BiggestInt; // NOLINT
+#endif // GTEST_OS_WINDOWS
+
+// Utilities for char.
+
+// isspace(int ch) and friends accept an unsigned char or EOF. char
+// may be signed, depending on the compiler (or compiler flags).
+// Therefore we need to cast a char to unsigned char before calling
+// isspace(), etc.
+
+inline bool IsAlpha(char ch) {
+ return isalpha(static_cast<unsigned char>(ch)) != 0;
+}
+inline bool IsAlNum(char ch) {
+ return isalnum(static_cast<unsigned char>(ch)) != 0;
+}
+inline bool IsDigit(char ch) {
+ return isdigit(static_cast<unsigned char>(ch)) != 0;
+}
+inline bool IsLower(char ch) {
+ return islower(static_cast<unsigned char>(ch)) != 0;
+}
+inline bool IsSpace(char ch) {
+ return isspace(static_cast<unsigned char>(ch)) != 0;
+}
+inline bool IsUpper(char ch) {
+ return isupper(static_cast<unsigned char>(ch)) != 0;
+}
+inline bool IsXDigit(char ch) {
+ return isxdigit(static_cast<unsigned char>(ch)) != 0;
+}
+inline bool IsXDigit(wchar_t ch) {
+ const unsigned char low_byte = static_cast<unsigned char>(ch);
+ return ch == low_byte && isxdigit(low_byte) != 0;
+}
+
+inline char ToLower(char ch) {
+ return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
+}
+inline char ToUpper(char ch) {
+ return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
+}
+
+inline std::string StripTrailingSpaces(std::string str) {
+ std::string::iterator it = str.end();
+ while (it != str.begin() && IsSpace(*--it))
+ it = str.erase(it);
+ return str;
+}
+
+// The testing::internal::posix namespace holds wrappers for common
+// POSIX functions. These wrappers hide the differences between
+// Windows/MSVC and POSIX systems. Since some compilers define these
+// standard functions as macros, the wrapper cannot have the same name
+// as the wrapped function.
+
+namespace posix {
+
+// Functions with a different name on Windows.
+
+#if GTEST_OS_WINDOWS
+
+typedef struct _stat StatStruct;
+
+# ifdef __BORLANDC__
+inline int IsATTY(int fd) { return isatty(fd); }
+inline int StrCaseCmp(const char* s1, const char* s2) {
+ return stricmp(s1, s2);
+}
+inline char* StrDup(const char* src) { return strdup(src); }
+# else // !__BORLANDC__
+# if GTEST_OS_WINDOWS_MOBILE
+inline int IsATTY(int /* fd */) { return 0; }
+# else
+inline int IsATTY(int fd) { return _isatty(fd); }
+# endif // GTEST_OS_WINDOWS_MOBILE
+inline int StrCaseCmp(const char* s1, const char* s2) {
+ return _stricmp(s1, s2);
+}
+inline char* StrDup(const char* src) { return _strdup(src); }
+# endif // __BORLANDC__
+
+# if GTEST_OS_WINDOWS_MOBILE
+inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
+// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
+// time and thus not defined there.
+# else
+inline int FileNo(FILE* file) { return _fileno(file); }
+inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
+inline int RmDir(const char* dir) { return _rmdir(dir); }
+inline bool IsDir(const StatStruct& st) {
+ return (_S_IFDIR & st.st_mode) != 0;
+}
+# endif // GTEST_OS_WINDOWS_MOBILE
+
+#else
+
+typedef struct stat StatStruct;
+
+inline int FileNo(FILE* file) { return fileno(file); }
+inline int IsATTY(int fd) { return isatty(fd); }
+inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
+inline int StrCaseCmp(const char* s1, const char* s2) {
+ return strcasecmp(s1, s2);
+}
+inline char* StrDup(const char* src) { return strdup(src); }
+inline int RmDir(const char* dir) { return rmdir(dir); }
+inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
+
+#endif // GTEST_OS_WINDOWS
+
+// Functions deprecated by MSVC 8.0.
+
+GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
+
+inline const char* StrNCpy(char* dest, const char* src, size_t n) {
+ return strncpy(dest, src, n);
+}
+
+// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
+// StrError() aren't needed on Windows CE at this time and thus not
+// defined there.
+
+#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
+inline int ChDir(const char* dir) { return chdir(dir); }
+#endif
+inline FILE* FOpen(const char* path, const char* mode) {
+ return fopen(path, mode);
+}
+#if !GTEST_OS_WINDOWS_MOBILE
+inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
+ return freopen(path, mode, stream);
+}
+inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
+#endif
+inline int FClose(FILE* fp) { return fclose(fp); }
+#if !GTEST_OS_WINDOWS_MOBILE
+inline int Read(int fd, void* buf, unsigned int count) {
+ return static_cast<int>(read(fd, buf, count));
+}
+inline int Write(int fd, const void* buf, unsigned int count) {
+ return static_cast<int>(write(fd, buf, count));
+}
+inline int Close(int fd) { return close(fd); }
+inline const char* StrError(int errnum) { return strerror(errnum); }
+#endif
+inline const char* GetEnv(const char* name) {
+#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
+ // We are on Windows CE, which has no environment variables.
+ static_cast<void>(name); // To prevent 'unused argument' warning.
+ return nullptr;
+#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
+ // Environment variables which we programmatically clear will be set to the
+ // empty string rather than unset (NULL). Handle that case.
+ const char* const env = getenv(name);
+ return (env != nullptr && env[0] != '\0') ? env : nullptr;
+#else
+ return getenv(name);
+#endif
+}
+
+GTEST_DISABLE_MSC_DEPRECATED_POP_()
+
+#if GTEST_OS_WINDOWS_MOBILE
+// Windows CE has no C library. The abort() function is used in
+// several places in Google Test. This implementation provides a reasonable
+// imitation of standard behaviour.
+[[noreturn]] void Abort();
+#else
+[[noreturn]] inline void Abort() { abort(); }
+#endif // GTEST_OS_WINDOWS_MOBILE
+
+} // namespace posix
+
+// MSVC "deprecates" snprintf and issues warnings wherever it is used. In
+// order to avoid these warnings, we need to use _snprintf or _snprintf_s on
+// MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate
+// function in order to achieve that. We use macro definition here because
+// snprintf is a variadic function.
+#if _MSC_VER && !GTEST_OS_WINDOWS_MOBILE
+// MSVC 2005 and above support variadic macros.
+# define GTEST_SNPRINTF_(buffer, size, format, ...) \
+ _snprintf_s(buffer, size, size, format, __VA_ARGS__)
+#elif defined(_MSC_VER)
+// Windows CE does not define _snprintf_s
+# define GTEST_SNPRINTF_ _snprintf
+#else
+# define GTEST_SNPRINTF_ snprintf
+#endif
+
+// The maximum number a BiggestInt can represent. This definition
+// works no matter BiggestInt is represented in one's complement or
+// two's complement.
+//
+// We cannot rely on numeric_limits in STL, as __int64 and long long
+// are not part of standard C++ and numeric_limits doesn't need to be
+// defined for them.
+const BiggestInt kMaxBiggestInt =
+ ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
+
+// This template class serves as a compile-time function from size to
+// type. It maps a size in bytes to a primitive type with that
+// size. e.g.
+//
+// TypeWithSize<4>::UInt
+//
+// is typedef-ed to be unsigned int (unsigned integer made up of 4
+// bytes).
+//
+// Such functionality should belong to STL, but I cannot find it
+// there.
+//
+// Google Test uses this class in the implementation of floating-point
+// comparison.
+//
+// For now it only handles UInt (unsigned int) as that's all Google Test
+// needs. Other types can be easily added in the future if need
+// arises.
+template <size_t size>
+class TypeWithSize {
+ public:
+ // This prevents the user from using TypeWithSize<N> with incorrect
+ // values of N.
+ typedef void UInt;
+};
+
+// The specialization for size 4.
+template <>
+class TypeWithSize<4> {
+ public:
+ // unsigned int has size 4 in both gcc and MSVC.
+ //
+ // As base/basictypes.h doesn't compile on Windows, we cannot use
+ // uint32, uint64, and etc here.
+ typedef int Int;
+ typedef unsigned int UInt;
+};
+
+// The specialization for size 8.
+template <>
+class TypeWithSize<8> {
+ public:
+#if GTEST_OS_WINDOWS
+ typedef __int64 Int;
+ typedef unsigned __int64 UInt;
+#else
+ typedef long long Int; // NOLINT
+ typedef unsigned long long UInt; // NOLINT
+#endif // GTEST_OS_WINDOWS
+};
+
+// Integer types of known sizes.
+typedef TypeWithSize<4>::Int Int32;
+typedef TypeWithSize<4>::UInt UInt32;
+typedef TypeWithSize<8>::Int Int64;
+typedef TypeWithSize<8>::UInt UInt64;
+typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
+
+// Utilities for command line flags and environment variables.
+
+// Macro for referencing flags.
+#if !defined(GTEST_FLAG)
+# define GTEST_FLAG(name) FLAGS_gtest_##name
+#endif // !defined(GTEST_FLAG)
+
+#if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_)
+# define GTEST_USE_OWN_FLAGFILE_FLAG_ 1
+#endif // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_)
+
+#if !defined(GTEST_DECLARE_bool_)
+# define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver
+
+// Macros for declaring flags.
+# define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
+# define GTEST_DECLARE_int32_(name) \
+ GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
+# define GTEST_DECLARE_string_(name) \
+ GTEST_API_ extern ::std::string GTEST_FLAG(name)
+
+// Macros for defining flags.
+# define GTEST_DEFINE_bool_(name, default_val, doc) \
+ GTEST_API_ bool GTEST_FLAG(name) = (default_val)
+# define GTEST_DEFINE_int32_(name, default_val, doc) \
+ GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
+# define GTEST_DEFINE_string_(name, default_val, doc) \
+ GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
+
+#endif // !defined(GTEST_DECLARE_bool_)
+
+// Thread annotations
+#if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
+# define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
+# define GTEST_LOCK_EXCLUDED_(locks)
+#endif // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
+
+// Parses 'str' for a 32-bit signed integer. If successful, writes the result
+// to *value and returns true; otherwise leaves *value unchanged and returns
+// false.
+bool ParseInt32(const Message& src_text, const char* str, Int32* value);
+
+// Parses a bool/Int32/string from the environment variable
+// corresponding to the given Google Test flag.
+bool BoolFromGTestEnv(const char* flag, bool default_val);
+GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
+std::string OutputFlagAlsoCheckEnvVar();
+const char* StringFromGTestEnv(const char* flag, const char* default_val);
+
+} // namespace internal
+} // namespace testing
+
+#if !defined(GTEST_INTERNAL_DEPRECATED)
+
+// Internal Macro to mark an API deprecated, for googletest usage only
+// Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or
+// GTEST_INTERNAL_DEPRECATED(message) <return_type> myFunction(); Every usage of
+// a deprecated entity will trigger a warning when compiled with
+// `-Wdeprecated-declarations` option (clang, gcc, any __GNUC__ compiler).
+// For msvc /W3 option will need to be used
+// Note that for 'other' compilers this macro evaluates to nothing to prevent
+// compilations errors.
+#if defined(_MSC_VER)
+#define GTEST_INTERNAL_DEPRECATED(message) __declspec(deprecated(message))
+#elif defined(__GNUC__)
+#define GTEST_INTERNAL_DEPRECATED(message) __attribute__((deprecated(message)))
+#else
+#define GTEST_INTERNAL_DEPRECATED(message)
+#endif
+
+#endif // !defined(GTEST_INTERNAL_DEPRECATED)
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
--- /dev/null
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// The Google C++ Testing and Mocking Framework (Google Test)
+//
+// This header file declares the String class and functions used internally by
+// Google Test. They are subject to change without notice. They should not used
+// by code external to Google Test.
+//
+// This header file is #included by gtest-internal.h.
+// It should not be #included by other files.
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
+
+#ifdef __BORLANDC__
+// string.h is not guaranteed to provide strcpy on C++ Builder.
+# include <mem.h>
+#endif
+
+#include <string.h>
+#include <string>
+
+#include "gtest/internal/gtest-port.h"
+
+namespace testing {
+namespace internal {
+
+// String - an abstract class holding static string utilities.
+class GTEST_API_ String {
+ public:
+ // Static utility methods
+
+ // Clones a 0-terminated C string, allocating memory using new. The
+ // caller is responsible for deleting the return value using
+ // delete[]. Returns the cloned string, or NULL if the input is
+ // NULL.
+ //
+ // This is different from strdup() in string.h, which allocates
+ // memory using malloc().
+ static const char* CloneCString(const char* c_str);
+
+#if GTEST_OS_WINDOWS_MOBILE
+ // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be
+ // able to pass strings to Win32 APIs on CE we need to convert them
+ // to 'Unicode', UTF-16.
+
+ // Creates a UTF-16 wide string from the given ANSI string, allocating
+ // memory using new. The caller is responsible for deleting the return
+ // value using delete[]. Returns the wide string, or NULL if the
+ // input is NULL.
+ //
+ // The wide string is created using the ANSI codepage (CP_ACP) to
+ // match the behaviour of the ANSI versions of Win32 calls and the
+ // C runtime.
+ static LPCWSTR AnsiToUtf16(const char* c_str);
+
+ // Creates an ANSI string from the given wide string, allocating
+ // memory using new. The caller is responsible for deleting the return
+ // value using delete[]. Returns the ANSI string, or NULL if the
+ // input is NULL.
+ //
+ // The returned string is created using the ANSI codepage (CP_ACP) to
+ // match the behaviour of the ANSI versions of Win32 calls and the
+ // C runtime.
+ static const char* Utf16ToAnsi(LPCWSTR utf16_str);
+#endif
+
+ // Compares two C strings. Returns true iff they have the same content.
+ //
+ // Unlike strcmp(), this function can handle NULL argument(s). A
+ // NULL C string is considered different to any non-NULL C string,
+ // including the empty string.
+ static bool CStringEquals(const char* lhs, const char* rhs);
+
+ // Converts a wide C string to a String using the UTF-8 encoding.
+ // NULL will be converted to "(null)". If an error occurred during
+ // the conversion, "(failed to convert from wide string)" is
+ // returned.
+ static std::string ShowWideCString(const wchar_t* wide_c_str);
+
+ // Compares two wide C strings. Returns true iff they have the same
+ // content.
+ //
+ // Unlike wcscmp(), this function can handle NULL argument(s). A
+ // NULL C string is considered different to any non-NULL C string,
+ // including the empty string.
+ static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs);
+
+ // Compares two C strings, ignoring case. Returns true iff they
+ // have the same content.
+ //
+ // Unlike strcasecmp(), this function can handle NULL argument(s).
+ // A NULL C string is considered different to any non-NULL C string,
+ // including the empty string.
+ static bool CaseInsensitiveCStringEquals(const char* lhs,
+ const char* rhs);
+
+ // Compares two wide C strings, ignoring case. Returns true iff they
+ // have the same content.
+ //
+ // Unlike wcscasecmp(), this function can handle NULL argument(s).
+ // A NULL C string is considered different to any non-NULL wide C string,
+ // including the empty string.
+ // NB: The implementations on different platforms slightly differ.
+ // On windows, this method uses _wcsicmp which compares according to LC_CTYPE
+ // environment variable. On GNU platform this method uses wcscasecmp
+ // which compares according to LC_CTYPE category of the current locale.
+ // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the
+ // current locale.
+ static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
+ const wchar_t* rhs);
+
+ // Returns true iff the given string ends with the given suffix, ignoring
+ // case. Any string is considered to end with an empty suffix.
+ static bool EndsWithCaseInsensitive(
+ const std::string& str, const std::string& suffix);
+
+ // Formats an int value as "%02d".
+ static std::string FormatIntWidth2(int value); // "%02d" for width == 2
+
+ // Formats an int value as "%X".
+ static std::string FormatHexInt(int value);
+
+ // Formats an int value as "%X".
+ static std::string FormatHexUInt32(UInt32 value);
+
+ // Formats a byte as "%02X".
+ static std::string FormatByte(unsigned char value);
+
+ private:
+ String(); // Not meant to be instantiated.
+}; // class String
+
+// Gets the content of the stringstream's buffer as an std::string. Each '\0'
+// character in the buffer is replaced with "\\0".
+GTEST_API_ std::string StringStreamToString(::std::stringstream* stream);
+
+} // namespace internal
+} // namespace testing
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
--- /dev/null
+// This file was GENERATED by command:
+// pump.py gtest-type-util.h.pump
+// DO NOT EDIT BY HAND!!!
+
+// Copyright 2008 Google Inc.
+// All Rights Reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Type utilities needed for implementing typed and type-parameterized
+// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
+//
+// Currently we support at most 50 types in a list, and at most 50
+// type-parameterized tests in one type-parameterized test suite.
+// Please contact googletestframework@googlegroups.com if you need
+// more.
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
+
+#include "gtest/internal/gtest-port.h"
+
+// #ifdef __GNUC__ is too general here. It is possible to use gcc without using
+// libstdc++ (which is where cxxabi.h comes from).
+# if GTEST_HAS_CXXABI_H_
+# include <cxxabi.h>
+# elif defined(__HP_aCC)
+# include <acxx_demangle.h>
+# endif // GTEST_HASH_CXXABI_H_
+
+namespace testing {
+namespace internal {
+
+// Canonicalizes a given name with respect to the Standard C++ Library.
+// This handles removing the inline namespace within `std` that is
+// used by various standard libraries (e.g., `std::__1`). Names outside
+// of namespace std are returned unmodified.
+inline std::string CanonicalizeForStdLibVersioning(std::string s) {
+ static const char prefix[] = "std::__";
+ if (s.compare(0, strlen(prefix), prefix) == 0) {
+ std::string::size_type end = s.find("::", strlen(prefix));
+ if (end != s.npos) {
+ // Erase everything between the initial `std` and the second `::`.
+ s.erase(strlen("std"), end - strlen("std"));
+ }
+ }
+ return s;
+}
+
+// GetTypeName<T>() returns a human-readable name of type T.
+// NB: This function is also used in Google Mock, so don't move it inside of
+// the typed-test-only section below.
+template <typename T>
+std::string GetTypeName() {
+# if GTEST_HAS_RTTI
+
+ const char* const name = typeid(T).name();
+# if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
+ int status = 0;
+ // gcc's implementation of typeid(T).name() mangles the type name,
+ // so we have to demangle it.
+# if GTEST_HAS_CXXABI_H_
+ using abi::__cxa_demangle;
+# endif // GTEST_HAS_CXXABI_H_
+ char* const readable_name = __cxa_demangle(name, nullptr, nullptr, &status);
+ const std::string name_str(status == 0 ? readable_name : name);
+ free(readable_name);
+ return CanonicalizeForStdLibVersioning(name_str);
+# else
+ return name;
+# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
+
+# else
+
+ return "<type>";
+
+# endif // GTEST_HAS_RTTI
+}
+
+#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
+
+// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
+// type. This can be used as a compile-time assertion to ensure that
+// two types are equal.
+
+template <typename T1, typename T2>
+struct AssertTypeEq;
+
+template <typename T>
+struct AssertTypeEq<T, T> {
+ typedef bool type;
+};
+
+// A unique type used as the default value for the arguments of class
+// template Types. This allows us to simulate variadic templates
+// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
+// support directly.
+struct None {};
+
+// The following family of struct and struct templates are used to
+// represent type lists. In particular, TypesN<T1, T2, ..., TN>
+// represents a type list with N types (T1, T2, ..., and TN) in it.
+// Except for Types0, every struct in the family has two member types:
+// Head for the first type in the list, and Tail for the rest of the
+// list.
+
+// The empty type list.
+struct Types0 {};
+
+// Type lists of length 1, 2, 3, and so on.
+
+template <typename T1>
+struct Types1 {
+ typedef T1 Head;
+ typedef Types0 Tail;
+};
+template <typename T1, typename T2>
+struct Types2 {
+ typedef T1 Head;
+ typedef Types1<T2> Tail;
+};
+
+template <typename T1, typename T2, typename T3>
+struct Types3 {
+ typedef T1 Head;
+ typedef Types2<T2, T3> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4>
+struct Types4 {
+ typedef T1 Head;
+ typedef Types3<T2, T3, T4> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5>
+struct Types5 {
+ typedef T1 Head;
+ typedef Types4<T2, T3, T4, T5> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6>
+struct Types6 {
+ typedef T1 Head;
+ typedef Types5<T2, T3, T4, T5, T6> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7>
+struct Types7 {
+ typedef T1 Head;
+ typedef Types6<T2, T3, T4, T5, T6, T7> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8>
+struct Types8 {
+ typedef T1 Head;
+ typedef Types7<T2, T3, T4, T5, T6, T7, T8> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9>
+struct Types9 {
+ typedef T1 Head;
+ typedef Types8<T2, T3, T4, T5, T6, T7, T8, T9> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10>
+struct Types10 {
+ typedef T1 Head;
+ typedef Types9<T2, T3, T4, T5, T6, T7, T8, T9, T10> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11>
+struct Types11 {
+ typedef T1 Head;
+ typedef Types10<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12>
+struct Types12 {
+ typedef T1 Head;
+ typedef Types11<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13>
+struct Types13 {
+ typedef T1 Head;
+ typedef Types12<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14>
+struct Types14 {
+ typedef T1 Head;
+ typedef Types13<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15>
+struct Types15 {
+ typedef T1 Head;
+ typedef Types14<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16>
+struct Types16 {
+ typedef T1 Head;
+ typedef Types15<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17>
+struct Types17 {
+ typedef T1 Head;
+ typedef Types16<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18>
+struct Types18 {
+ typedef T1 Head;
+ typedef Types17<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19>
+struct Types19 {
+ typedef T1 Head;
+ typedef Types18<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20>
+struct Types20 {
+ typedef T1 Head;
+ typedef Types19<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21>
+struct Types21 {
+ typedef T1 Head;
+ typedef Types20<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22>
+struct Types22 {
+ typedef T1 Head;
+ typedef Types21<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23>
+struct Types23 {
+ typedef T1 Head;
+ typedef Types22<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24>
+struct Types24 {
+ typedef T1 Head;
+ typedef Types23<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25>
+struct Types25 {
+ typedef T1 Head;
+ typedef Types24<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26>
+struct Types26 {
+ typedef T1 Head;
+ typedef Types25<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27>
+struct Types27 {
+ typedef T1 Head;
+ typedef Types26<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28>
+struct Types28 {
+ typedef T1 Head;
+ typedef Types27<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29>
+struct Types29 {
+ typedef T1 Head;
+ typedef Types28<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30>
+struct Types30 {
+ typedef T1 Head;
+ typedef Types29<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31>
+struct Types31 {
+ typedef T1 Head;
+ typedef Types30<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32>
+struct Types32 {
+ typedef T1 Head;
+ typedef Types31<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33>
+struct Types33 {
+ typedef T1 Head;
+ typedef Types32<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34>
+struct Types34 {
+ typedef T1 Head;
+ typedef Types33<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35>
+struct Types35 {
+ typedef T1 Head;
+ typedef Types34<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36>
+struct Types36 {
+ typedef T1 Head;
+ typedef Types35<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37>
+struct Types37 {
+ typedef T1 Head;
+ typedef Types36<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38>
+struct Types38 {
+ typedef T1 Head;
+ typedef Types37<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39>
+struct Types39 {
+ typedef T1 Head;
+ typedef Types38<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40>
+struct Types40 {
+ typedef T1 Head;
+ typedef Types39<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41>
+struct Types41 {
+ typedef T1 Head;
+ typedef Types40<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42>
+struct Types42 {
+ typedef T1 Head;
+ typedef Types41<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43>
+struct Types43 {
+ typedef T1 Head;
+ typedef Types42<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
+ T43> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44>
+struct Types44 {
+ typedef T1 Head;
+ typedef Types43<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
+ T44> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45>
+struct Types45 {
+ typedef T1 Head;
+ typedef Types44<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
+ T44, T45> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45,
+ typename T46>
+struct Types46 {
+ typedef T1 Head;
+ typedef Types45<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
+ T44, T45, T46> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45,
+ typename T46, typename T47>
+struct Types47 {
+ typedef T1 Head;
+ typedef Types46<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
+ T44, T45, T46, T47> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45,
+ typename T46, typename T47, typename T48>
+struct Types48 {
+ typedef T1 Head;
+ typedef Types47<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
+ T44, T45, T46, T47, T48> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45,
+ typename T46, typename T47, typename T48, typename T49>
+struct Types49 {
+ typedef T1 Head;
+ typedef Types48<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
+ T44, T45, T46, T47, T48, T49> Tail;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45,
+ typename T46, typename T47, typename T48, typename T49, typename T50>
+struct Types50 {
+ typedef T1 Head;
+ typedef Types49<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
+ T44, T45, T46, T47, T48, T49, T50> Tail;
+};
+
+
+} // namespace internal
+
+// We don't want to require the users to write TypesN<...> directly,
+// as that would require them to count the length. Types<...> is much
+// easier to write, but generates horrible messages when there is a
+// compiler error, as gcc insists on printing out each template
+// argument, even if it has the default value (this means Types<int>
+// will appear as Types<int, None, None, ..., None> in the compiler
+// errors).
+//
+// Our solution is to combine the best part of the two approaches: a
+// user would write Types<T1, ..., TN>, and Google Test will translate
+// that to TypesN<T1, ..., TN> internally to make error messages
+// readable. The translation is done by the 'type' member of the
+// Types template.
+template <typename T1 = internal::None, typename T2 = internal::None,
+ typename T3 = internal::None, typename T4 = internal::None,
+ typename T5 = internal::None, typename T6 = internal::None,
+ typename T7 = internal::None, typename T8 = internal::None,
+ typename T9 = internal::None, typename T10 = internal::None,
+ typename T11 = internal::None, typename T12 = internal::None,
+ typename T13 = internal::None, typename T14 = internal::None,
+ typename T15 = internal::None, typename T16 = internal::None,
+ typename T17 = internal::None, typename T18 = internal::None,
+ typename T19 = internal::None, typename T20 = internal::None,
+ typename T21 = internal::None, typename T22 = internal::None,
+ typename T23 = internal::None, typename T24 = internal::None,
+ typename T25 = internal::None, typename T26 = internal::None,
+ typename T27 = internal::None, typename T28 = internal::None,
+ typename T29 = internal::None, typename T30 = internal::None,
+ typename T31 = internal::None, typename T32 = internal::None,
+ typename T33 = internal::None, typename T34 = internal::None,
+ typename T35 = internal::None, typename T36 = internal::None,
+ typename T37 = internal::None, typename T38 = internal::None,
+ typename T39 = internal::None, typename T40 = internal::None,
+ typename T41 = internal::None, typename T42 = internal::None,
+ typename T43 = internal::None, typename T44 = internal::None,
+ typename T45 = internal::None, typename T46 = internal::None,
+ typename T47 = internal::None, typename T48 = internal::None,
+ typename T49 = internal::None, typename T50 = internal::None>
+struct Types {
+ typedef internal::Types50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41, T42, T43, T44, T45, T46, T47, T48, T49, T50> type;
+};
+
+template <>
+struct Types<internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types0 type;
+};
+template <typename T1>
+struct Types<T1, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types1<T1> type;
+};
+template <typename T1, typename T2>
+struct Types<T1, T2, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types2<T1, T2> type;
+};
+template <typename T1, typename T2, typename T3>
+struct Types<T1, T2, T3, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types3<T1, T2, T3> type;
+};
+template <typename T1, typename T2, typename T3, typename T4>
+struct Types<T1, T2, T3, T4, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types4<T1, T2, T3, T4> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5>
+struct Types<T1, T2, T3, T4, T5, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types5<T1, T2, T3, T4, T5> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6>
+struct Types<T1, T2, T3, T4, T5, T6, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types6<T1, T2, T3, T4, T5, T6> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7>
+struct Types<T1, T2, T3, T4, T5, T6, T7, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types7<T1, T2, T3, T4, T5, T6, T7> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types8<T1, T2, T3, T4, T5, T6, T7, T8> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types9<T1, T2, T3, T4, T5, T6, T7, T8, T9> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
+ T12> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
+ T26> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
+ T40> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, internal::None,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41, T42> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None, internal::None> {
+ typedef internal::Types43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41, T42, T43> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None, internal::None> {
+ typedef internal::Types44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41, T42, T43, T44> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
+ internal::None, internal::None, internal::None, internal::None,
+ internal::None> {
+ typedef internal::Types45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41, T42, T43, T44, T45> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45,
+ typename T46>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
+ T46, internal::None, internal::None, internal::None, internal::None> {
+ typedef internal::Types46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41, T42, T43, T44, T45, T46> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45,
+ typename T46, typename T47>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
+ T46, T47, internal::None, internal::None, internal::None> {
+ typedef internal::Types47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41, T42, T43, T44, T45, T46, T47> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45,
+ typename T46, typename T47, typename T48>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
+ T46, T47, T48, internal::None, internal::None> {
+ typedef internal::Types48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41, T42, T43, T44, T45, T46, T47, T48> type;
+};
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45,
+ typename T46, typename T47, typename T48, typename T49>
+struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
+ T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
+ T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
+ T46, T47, T48, T49, internal::None> {
+ typedef internal::Types49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41, T42, T43, T44, T45, T46, T47, T48, T49> type;
+};
+
+namespace internal {
+
+# define GTEST_TEMPLATE_ template <typename T> class
+
+// The template "selector" struct TemplateSel<Tmpl> is used to
+// represent Tmpl, which must be a class template with one type
+// parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
+// as the type Tmpl<T>. This allows us to actually instantiate the
+// template "selected" by TemplateSel<Tmpl>.
+//
+// This trick is necessary for simulating typedef for class templates,
+// which C++ doesn't support directly.
+template <GTEST_TEMPLATE_ Tmpl>
+struct TemplateSel {
+ template <typename T>
+ struct Bind {
+ typedef Tmpl<T> type;
+ };
+};
+
+# define GTEST_BIND_(TmplSel, T) \
+ TmplSel::template Bind<T>::type
+
+// A unique struct template used as the default value for the
+// arguments of class template Templates. This allows us to simulate
+// variadic templates (e.g. Templates<int>, Templates<int, double>,
+// and etc), which C++ doesn't support directly.
+template <typename T>
+struct NoneT {};
+
+// The following family of struct and struct templates are used to
+// represent template lists. In particular, TemplatesN<T1, T2, ...,
+// TN> represents a list of N templates (T1, T2, ..., and TN). Except
+// for Templates0, every struct in the family has two member types:
+// Head for the selector of the first template in the list, and Tail
+// for the rest of the list.
+
+// The empty template list.
+struct Templates0 {};
+
+// Template lists of length 1, 2, 3, and so on.
+
+template <GTEST_TEMPLATE_ T1>
+struct Templates1 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates0 Tail;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2>
+struct Templates2 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates1<T2> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3>
+struct Templates3 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates2<T2, T3> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4>
+struct Templates4 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates3<T2, T3, T4> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5>
+struct Templates5 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates4<T2, T3, T4, T5> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6>
+struct Templates6 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates5<T2, T3, T4, T5, T6> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7>
+struct Templates7 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates6<T2, T3, T4, T5, T6, T7> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8>
+struct Templates8 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates7<T2, T3, T4, T5, T6, T7, T8> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9>
+struct Templates9 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates8<T2, T3, T4, T5, T6, T7, T8, T9> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10>
+struct Templates10 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates9<T2, T3, T4, T5, T6, T7, T8, T9, T10> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11>
+struct Templates11 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates10<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12>
+struct Templates12 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates11<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13>
+struct Templates13 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates12<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14>
+struct Templates14 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates13<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15>
+struct Templates15 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates14<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16>
+struct Templates16 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates15<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17>
+struct Templates17 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates16<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18>
+struct Templates18 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates17<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19>
+struct Templates19 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates18<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20>
+struct Templates20 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates19<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21>
+struct Templates21 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates20<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22>
+struct Templates22 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates21<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23>
+struct Templates23 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates22<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24>
+struct Templates24 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates23<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25>
+struct Templates25 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates24<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26>
+struct Templates26 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates25<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27>
+struct Templates27 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates26<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28>
+struct Templates28 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates27<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29>
+struct Templates29 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates28<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30>
+struct Templates30 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates29<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31>
+struct Templates31 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates30<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32>
+struct Templates32 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates31<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33>
+struct Templates33 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates32<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34>
+struct Templates34 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates33<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35>
+struct Templates35 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates34<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36>
+struct Templates36 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates35<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37>
+struct Templates37 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates36<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38>
+struct Templates38 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates37<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39>
+struct Templates39 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates38<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40>
+struct Templates40 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates39<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41>
+struct Templates41 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates40<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42>
+struct Templates42 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates41<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
+ T42> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43>
+struct Templates43 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates42<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
+ T43> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44>
+struct Templates44 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates43<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
+ T43, T44> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45>
+struct Templates45 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates44<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
+ T43, T44, T45> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
+ GTEST_TEMPLATE_ T46>
+struct Templates46 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates45<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
+ T43, T44, T45, T46> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
+ GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47>
+struct Templates47 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates46<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
+ T43, T44, T45, T46, T47> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
+ GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48>
+struct Templates48 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates47<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
+ T43, T44, T45, T46, T47, T48> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
+ GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48,
+ GTEST_TEMPLATE_ T49>
+struct Templates49 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates48<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
+ T43, T44, T45, T46, T47, T48, T49> Tail;
+};
+
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
+ GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48,
+ GTEST_TEMPLATE_ T49, GTEST_TEMPLATE_ T50>
+struct Templates50 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates49<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
+ T43, T44, T45, T46, T47, T48, T49, T50> Tail;
+};
+
+
+// We don't want to require the users to write TemplatesN<...> directly,
+// as that would require them to count the length. Templates<...> is much
+// easier to write, but generates horrible messages when there is a
+// compiler error, as gcc insists on printing out each template
+// argument, even if it has the default value (this means Templates<list>
+// will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
+// errors).
+//
+// Our solution is to combine the best part of the two approaches: a
+// user would write Templates<T1, ..., TN>, and Google Test will translate
+// that to TemplatesN<T1, ..., TN> internally to make error messages
+// readable. The translation is done by the 'type' member of the
+// Templates template.
+template <GTEST_TEMPLATE_ T1 = NoneT, GTEST_TEMPLATE_ T2 = NoneT,
+ GTEST_TEMPLATE_ T3 = NoneT, GTEST_TEMPLATE_ T4 = NoneT,
+ GTEST_TEMPLATE_ T5 = NoneT, GTEST_TEMPLATE_ T6 = NoneT,
+ GTEST_TEMPLATE_ T7 = NoneT, GTEST_TEMPLATE_ T8 = NoneT,
+ GTEST_TEMPLATE_ T9 = NoneT, GTEST_TEMPLATE_ T10 = NoneT,
+ GTEST_TEMPLATE_ T11 = NoneT, GTEST_TEMPLATE_ T12 = NoneT,
+ GTEST_TEMPLATE_ T13 = NoneT, GTEST_TEMPLATE_ T14 = NoneT,
+ GTEST_TEMPLATE_ T15 = NoneT, GTEST_TEMPLATE_ T16 = NoneT,
+ GTEST_TEMPLATE_ T17 = NoneT, GTEST_TEMPLATE_ T18 = NoneT,
+ GTEST_TEMPLATE_ T19 = NoneT, GTEST_TEMPLATE_ T20 = NoneT,
+ GTEST_TEMPLATE_ T21 = NoneT, GTEST_TEMPLATE_ T22 = NoneT,
+ GTEST_TEMPLATE_ T23 = NoneT, GTEST_TEMPLATE_ T24 = NoneT,
+ GTEST_TEMPLATE_ T25 = NoneT, GTEST_TEMPLATE_ T26 = NoneT,
+ GTEST_TEMPLATE_ T27 = NoneT, GTEST_TEMPLATE_ T28 = NoneT,
+ GTEST_TEMPLATE_ T29 = NoneT, GTEST_TEMPLATE_ T30 = NoneT,
+ GTEST_TEMPLATE_ T31 = NoneT, GTEST_TEMPLATE_ T32 = NoneT,
+ GTEST_TEMPLATE_ T33 = NoneT, GTEST_TEMPLATE_ T34 = NoneT,
+ GTEST_TEMPLATE_ T35 = NoneT, GTEST_TEMPLATE_ T36 = NoneT,
+ GTEST_TEMPLATE_ T37 = NoneT, GTEST_TEMPLATE_ T38 = NoneT,
+ GTEST_TEMPLATE_ T39 = NoneT, GTEST_TEMPLATE_ T40 = NoneT,
+ GTEST_TEMPLATE_ T41 = NoneT, GTEST_TEMPLATE_ T42 = NoneT,
+ GTEST_TEMPLATE_ T43 = NoneT, GTEST_TEMPLATE_ T44 = NoneT,
+ GTEST_TEMPLATE_ T45 = NoneT, GTEST_TEMPLATE_ T46 = NoneT,
+ GTEST_TEMPLATE_ T47 = NoneT, GTEST_TEMPLATE_ T48 = NoneT,
+ GTEST_TEMPLATE_ T49 = NoneT, GTEST_TEMPLATE_ T50 = NoneT>
+struct Templates {
+ typedef Templates50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
+ T42, T43, T44, T45, T46, T47, T48, T49, T50> type;
+};
+
+template <>
+struct Templates<NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT> {
+ typedef Templates0 type;
+};
+template <GTEST_TEMPLATE_ T1>
+struct Templates<T1, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT> {
+ typedef Templates1<T1> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2>
+struct Templates<T1, T2, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT> {
+ typedef Templates2<T1, T2> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3>
+struct Templates<T1, T2, T3, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates3<T1, T2, T3> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4>
+struct Templates<T1, T2, T3, T4, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates4<T1, T2, T3, T4> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5>
+struct Templates<T1, T2, T3, T4, T5, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates5<T1, T2, T3, T4, T5> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6>
+struct Templates<T1, T2, T3, T4, T5, T6, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates6<T1, T2, T3, T4, T5, T6> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates7<T1, T2, T3, T4, T5, T6, T7> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates8<T1, T2, T3, T4, T5, T6, T7, T8> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates9<T1, T2, T3, T4, T5, T6, T7, T8, T9> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT> {
+ typedef Templates22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT> {
+ typedef Templates23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT> {
+ typedef Templates24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT> {
+ typedef Templates25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT> {
+ typedef Templates26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT> {
+ typedef Templates27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT> {
+ typedef Templates28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT> {
+ typedef Templates29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, NoneT, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, NoneT, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, NoneT, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, NoneT, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, NoneT,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
+ T42> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
+ T42, T43> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
+ NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
+ T42, T43, T44> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
+ T45, NoneT, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
+ T42, T43, T44, T45> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
+ GTEST_TEMPLATE_ T46>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
+ T45, T46, NoneT, NoneT, NoneT, NoneT> {
+ typedef Templates46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
+ T42, T43, T44, T45, T46> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
+ GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
+ T45, T46, T47, NoneT, NoneT, NoneT> {
+ typedef Templates47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
+ T42, T43, T44, T45, T46, T47> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
+ GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
+ T45, T46, T47, T48, NoneT, NoneT> {
+ typedef Templates48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
+ T42, T43, T44, T45, T46, T47, T48> type;
+};
+template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
+ GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
+ GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
+ GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
+ GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
+ GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
+ GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
+ GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
+ GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
+ GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
+ GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
+ GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
+ GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
+ GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
+ GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
+ GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48,
+ GTEST_TEMPLATE_ T49>
+struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
+ T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
+ T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
+ T45, T46, T47, T48, T49, NoneT> {
+ typedef Templates49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
+ T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
+ T42, T43, T44, T45, T46, T47, T48, T49> type;
+};
+
+// The TypeList template makes it possible to use either a single type
+// or a Types<...> list in TYPED_TEST_SUITE() and
+// INSTANTIATE_TYPED_TEST_SUITE_P().
+
+template <typename T>
+struct TypeList {
+ typedef Types1<T> type;
+};
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5,
+ typename T6, typename T7, typename T8, typename T9, typename T10,
+ typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19, typename T20,
+ typename T21, typename T22, typename T23, typename T24, typename T25,
+ typename T26, typename T27, typename T28, typename T29, typename T30,
+ typename T31, typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39, typename T40,
+ typename T41, typename T42, typename T43, typename T44, typename T45,
+ typename T46, typename T47, typename T48, typename T49, typename T50>
+struct TypeList<Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
+ T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
+ T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
+ T44, T45, T46, T47, T48, T49, T50> > {
+ typedef typename Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
+ T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
+ T41, T42, T43, T44, T45, T46, T47, T48, T49, T50>::type type;
+};
+
+#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
+
+} // namespace internal
+} // namespace testing
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
--- /dev/null
+$$ -*- mode: c++; -*-
+$var n = 50 $$ Maximum length of type lists we want to support.
+// Copyright 2008 Google Inc.
+// All Rights Reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Type utilities needed for implementing typed and type-parameterized
+// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
+//
+// Currently we support at most $n types in a list, and at most $n
+// type-parameterized tests in one type-parameterized test suite.
+// Please contact googletestframework@googlegroups.com if you need
+// more.
+
+// GOOGLETEST_CM0001 DO NOT DELETE
+
+#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
+#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
+
+#include "gtest/internal/gtest-port.h"
+
+// #ifdef __GNUC__ is too general here. It is possible to use gcc without using
+// libstdc++ (which is where cxxabi.h comes from).
+# if GTEST_HAS_CXXABI_H_
+# include <cxxabi.h>
+# elif defined(__HP_aCC)
+# include <acxx_demangle.h>
+# endif // GTEST_HASH_CXXABI_H_
+
+namespace testing {
+namespace internal {
+
+// Canonicalizes a given name with respect to the Standard C++ Library.
+// This handles removing the inline namespace within `std` that is
+// used by various standard libraries (e.g., `std::__1`). Names outside
+// of namespace std are returned unmodified.
+inline std::string CanonicalizeForStdLibVersioning(std::string s) {
+ static const char prefix[] = "std::__";
+ if (s.compare(0, strlen(prefix), prefix) == 0) {
+ std::string::size_type end = s.find("::", strlen(prefix));
+ if (end != s.npos) {
+ // Erase everything between the initial `std` and the second `::`.
+ s.erase(strlen("std"), end - strlen("std"));
+ }
+ }
+ return s;
+}
+
+// GetTypeName<T>() returns a human-readable name of type T.
+// NB: This function is also used in Google Mock, so don't move it inside of
+// the typed-test-only section below.
+template <typename T>
+std::string GetTypeName() {
+# if GTEST_HAS_RTTI
+
+ const char* const name = typeid(T).name();
+# if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
+ int status = 0;
+ // gcc's implementation of typeid(T).name() mangles the type name,
+ // so we have to demangle it.
+# if GTEST_HAS_CXXABI_H_
+ using abi::__cxa_demangle;
+# endif // GTEST_HAS_CXXABI_H_
+ char* const readable_name = __cxa_demangle(name, nullptr, nullptr, &status);
+ const std::string name_str(status == 0 ? readable_name : name);
+ free(readable_name);
+ return CanonicalizeForStdLibVersioning(name_str);
+# else
+ return name;
+# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
+
+# else
+
+ return "<type>";
+
+# endif // GTEST_HAS_RTTI
+}
+
+#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
+
+// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
+// type. This can be used as a compile-time assertion to ensure that
+// two types are equal.
+
+template <typename T1, typename T2>
+struct AssertTypeEq;
+
+template <typename T>
+struct AssertTypeEq<T, T> {
+ typedef bool type;
+};
+
+// A unique type used as the default value for the arguments of class
+// template Types. This allows us to simulate variadic templates
+// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
+// support directly.
+struct None {};
+
+// The following family of struct and struct templates are used to
+// represent type lists. In particular, TypesN<T1, T2, ..., TN>
+// represents a type list with N types (T1, T2, ..., and TN) in it.
+// Except for Types0, every struct in the family has two member types:
+// Head for the first type in the list, and Tail for the rest of the
+// list.
+
+// The empty type list.
+struct Types0 {};
+
+// Type lists of length 1, 2, 3, and so on.
+
+template <typename T1>
+struct Types1 {
+ typedef T1 Head;
+ typedef Types0 Tail;
+};
+
+$range i 2..n
+
+$for i [[
+$range j 1..i
+$range k 2..i
+template <$for j, [[typename T$j]]>
+struct Types$i {
+ typedef T1 Head;
+ typedef Types$(i-1)<$for k, [[T$k]]> Tail;
+};
+
+
+]]
+
+} // namespace internal
+
+// We don't want to require the users to write TypesN<...> directly,
+// as that would require them to count the length. Types<...> is much
+// easier to write, but generates horrible messages when there is a
+// compiler error, as gcc insists on printing out each template
+// argument, even if it has the default value (this means Types<int>
+// will appear as Types<int, None, None, ..., None> in the compiler
+// errors).
+//
+// Our solution is to combine the best part of the two approaches: a
+// user would write Types<T1, ..., TN>, and Google Test will translate
+// that to TypesN<T1, ..., TN> internally to make error messages
+// readable. The translation is done by the 'type' member of the
+// Types template.
+
+$range i 1..n
+template <$for i, [[typename T$i = internal::None]]>
+struct Types {
+ typedef internal::Types$n<$for i, [[T$i]]> type;
+};
+
+template <>
+struct Types<$for i, [[internal::None]]> {
+ typedef internal::Types0 type;
+};
+
+$range i 1..n-1
+$for i [[
+$range j 1..i
+$range k i+1..n
+template <$for j, [[typename T$j]]>
+struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
+ typedef internal::Types$i<$for j, [[T$j]]> type;
+};
+
+]]
+
+namespace internal {
+
+# define GTEST_TEMPLATE_ template <typename T> class
+
+// The template "selector" struct TemplateSel<Tmpl> is used to
+// represent Tmpl, which must be a class template with one type
+// parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
+// as the type Tmpl<T>. This allows us to actually instantiate the
+// template "selected" by TemplateSel<Tmpl>.
+//
+// This trick is necessary for simulating typedef for class templates,
+// which C++ doesn't support directly.
+template <GTEST_TEMPLATE_ Tmpl>
+struct TemplateSel {
+ template <typename T>
+ struct Bind {
+ typedef Tmpl<T> type;
+ };
+};
+
+# define GTEST_BIND_(TmplSel, T) \
+ TmplSel::template Bind<T>::type
+
+// A unique struct template used as the default value for the
+// arguments of class template Templates. This allows us to simulate
+// variadic templates (e.g. Templates<int>, Templates<int, double>,
+// and etc), which C++ doesn't support directly.
+template <typename T>
+struct NoneT {};
+
+// The following family of struct and struct templates are used to
+// represent template lists. In particular, TemplatesN<T1, T2, ...,
+// TN> represents a list of N templates (T1, T2, ..., and TN). Except
+// for Templates0, every struct in the family has two member types:
+// Head for the selector of the first template in the list, and Tail
+// for the rest of the list.
+
+// The empty template list.
+struct Templates0 {};
+
+// Template lists of length 1, 2, 3, and so on.
+
+template <GTEST_TEMPLATE_ T1>
+struct Templates1 {
+ typedef TemplateSel<T1> Head;
+ typedef Templates0 Tail;
+};
+
+$range i 2..n
+
+$for i [[
+$range j 1..i
+$range k 2..i
+template <$for j, [[GTEST_TEMPLATE_ T$j]]>
+struct Templates$i {
+ typedef TemplateSel<T1> Head;
+ typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
+};
+
+
+]]
+
+// We don't want to require the users to write TemplatesN<...> directly,
+// as that would require them to count the length. Templates<...> is much
+// easier to write, but generates horrible messages when there is a
+// compiler error, as gcc insists on printing out each template
+// argument, even if it has the default value (this means Templates<list>
+// will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
+// errors).
+//
+// Our solution is to combine the best part of the two approaches: a
+// user would write Templates<T1, ..., TN>, and Google Test will translate
+// that to TemplatesN<T1, ..., TN> internally to make error messages
+// readable. The translation is done by the 'type' member of the
+// Templates template.
+
+$range i 1..n
+template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
+struct Templates {
+ typedef Templates$n<$for i, [[T$i]]> type;
+};
+
+template <>
+struct Templates<$for i, [[NoneT]]> {
+ typedef Templates0 type;
+};
+
+$range i 1..n-1
+$for i [[
+$range j 1..i
+$range k i+1..n
+template <$for j, [[GTEST_TEMPLATE_ T$j]]>
+struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
+ typedef Templates$i<$for j, [[T$j]]> type;
+};
+
+]]
+
+// The TypeList template makes it possible to use either a single type
+// or a Types<...> list in TYPED_TEST_SUITE() and
+// INSTANTIATE_TYPED_TEST_SUITE_P().
+
+template <typename T>
+struct TypeList {
+ typedef Types1<T> type;
+};
+
+
+$range i 1..n
+template <$for i, [[typename T$i]]>
+struct TypeList<Types<$for i, [[T$i]]> > {
+ typedef typename Types<$for i, [[T$i]]>::type type;
+};
+
+#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
+
+} // namespace internal
+} // namespace testing
+
+#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// Google C++ Testing and Mocking Framework (Google Test)
+//
+// Sometimes it's desirable to build Google Test by compiling a single file.
+// This file serves this purpose.
+
+// This line ensures that gtest.h can be compiled on its own, even
+// when it's fused.
+#include "gtest/gtest.h"
+
+// The following lines pull in the real gtest *.cc files.
+#include "src/gtest.cc"
+#include "src/gtest-death-test.cc"
+#include "src/gtest-filepath.cc"
+#include "src/gtest-matchers.cc"
+#include "src/gtest-port.cc"
+#include "src/gtest-printers.cc"
+#include "src/gtest-test-part.cc"
+#include "src/gtest-typed-test.cc"
--- /dev/null
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// This file implements death tests.
+
+#include "gtest/gtest-death-test.h"
+
+#include <utility>
+
+#include "gtest/internal/gtest-port.h"
+#include "gtest/internal/custom/gtest.h"
+
+#if GTEST_HAS_DEATH_TEST
+
+# if GTEST_OS_MAC
+# include <crt_externs.h>
+# endif // GTEST_OS_MAC
+
+# include <errno.h>
+# include <fcntl.h>
+# include <limits.h>
+
+# if GTEST_OS_LINUX
+# include <signal.h>
+# endif // GTEST_OS_LINUX
+
+# include <stdarg.h>
+
+# if GTEST_OS_WINDOWS
+# include <windows.h>
+# else
+# include <sys/mman.h>
+# include <sys/wait.h>
+# endif // GTEST_OS_WINDOWS
+
+# if GTEST_OS_QNX
+# include <spawn.h>
+# endif // GTEST_OS_QNX
+
+# if GTEST_OS_FUCHSIA
+# include <lib/fdio/fd.h>
+# include <lib/fdio/io.h>
+# include <lib/fdio/spawn.h>
+# include <lib/zx/port.h>
+# include <lib/zx/process.h>
+# include <lib/zx/socket.h>
+# include <zircon/processargs.h>
+# include <zircon/syscalls.h>
+# include <zircon/syscalls/policy.h>
+# include <zircon/syscalls/port.h>
+# endif // GTEST_OS_FUCHSIA
+
+#endif // GTEST_HAS_DEATH_TEST
+
+#include "gtest/gtest-message.h"
+#include "gtest/internal/gtest-string.h"
+#include "src/gtest-internal-inl.h"
+
+namespace testing {
+
+// Constants.
+
+// The default death test style.
+//
+// This is defined in internal/gtest-port.h as "fast", but can be overridden by
+// a definition in internal/custom/gtest-port.h. The recommended value, which is
+// used internally at Google, is "threadsafe".
+static const char kDefaultDeathTestStyle[] = GTEST_DEFAULT_DEATH_TEST_STYLE;
+
+GTEST_DEFINE_string_(
+ death_test_style,
+ internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle),
+ "Indicates how to run a death test in a forked child process: "
+ "\"threadsafe\" (child process re-executes the test binary "
+ "from the beginning, running only the specific death test) or "
+ "\"fast\" (child process runs the death test immediately "
+ "after forking).");
+
+GTEST_DEFINE_bool_(
+ death_test_use_fork,
+ internal::BoolFromGTestEnv("death_test_use_fork", false),
+ "Instructs to use fork()/_exit() instead of clone() in death tests. "
+ "Ignored and always uses fork() on POSIX systems where clone() is not "
+ "implemented. Useful when running under valgrind or similar tools if "
+ "those do not support clone(). Valgrind 3.3.1 will just fail if "
+ "it sees an unsupported combination of clone() flags. "
+ "It is not recommended to use this flag w/o valgrind though it will "
+ "work in 99% of the cases. Once valgrind is fixed, this flag will "
+ "most likely be removed.");
+
+namespace internal {
+GTEST_DEFINE_string_(
+ internal_run_death_test, "",
+ "Indicates the file, line number, temporal index of "
+ "the single death test to run, and a file descriptor to "
+ "which a success code may be sent, all separated by "
+ "the '|' characters. This flag is specified if and only if the current "
+ "process is a sub-process launched for running a thread-safe "
+ "death test. FOR INTERNAL USE ONLY.");
+} // namespace internal
+
+#if GTEST_HAS_DEATH_TEST
+
+namespace internal {
+
+// Valid only for fast death tests. Indicates the code is running in the
+// child process of a fast style death test.
+# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
+static bool g_in_fast_death_test_child = false;
+# endif
+
+// Returns a Boolean value indicating whether the caller is currently
+// executing in the context of the death test child process. Tools such as
+// Valgrind heap checkers may need this to modify their behavior in death
+// tests. IMPORTANT: This is an internal utility. Using it may break the
+// implementation of death tests. User code MUST NOT use it.
+bool InDeathTestChild() {
+# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
+
+ // On Windows and Fuchsia, death tests are thread-safe regardless of the value
+ // of the death_test_style flag.
+ return !GTEST_FLAG(internal_run_death_test).empty();
+
+# else
+
+ if (GTEST_FLAG(death_test_style) == "threadsafe")
+ return !GTEST_FLAG(internal_run_death_test).empty();
+ else
+ return g_in_fast_death_test_child;
+#endif
+}
+
+} // namespace internal
+
+// ExitedWithCode constructor.
+ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {
+}
+
+// ExitedWithCode function-call operator.
+bool ExitedWithCode::operator()(int exit_status) const {
+# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
+
+ return exit_status == exit_code_;
+
+# else
+
+ return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_;
+
+# endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
+}
+
+# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
+// KilledBySignal constructor.
+KilledBySignal::KilledBySignal(int signum) : signum_(signum) {
+}
+
+// KilledBySignal function-call operator.
+bool KilledBySignal::operator()(int exit_status) const {
+# if defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
+ {
+ bool result;
+ if (GTEST_KILLED_BY_SIGNAL_OVERRIDE_(signum_, exit_status, &result)) {
+ return result;
+ }
+ }
+# endif // defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
+ return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_;
+}
+# endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
+
+namespace internal {
+
+// Utilities needed for death tests.
+
+// Generates a textual description of a given exit code, in the format
+// specified by wait(2).
+static std::string ExitSummary(int exit_code) {
+ Message m;
+
+# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
+
+ m << "Exited with exit status " << exit_code;
+
+# else
+
+ if (WIFEXITED(exit_code)) {
+ m << "Exited with exit status " << WEXITSTATUS(exit_code);
+ } else if (WIFSIGNALED(exit_code)) {
+ m << "Terminated by signal " << WTERMSIG(exit_code);
+ }
+# ifdef WCOREDUMP
+ if (WCOREDUMP(exit_code)) {
+ m << " (core dumped)";
+ }
+# endif
+# endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
+
+ return m.GetString();
+}
+
+// Returns true if exit_status describes a process that was terminated
+// by a signal, or exited normally with a nonzero exit code.
+bool ExitedUnsuccessfully(int exit_status) {
+ return !ExitedWithCode(0)(exit_status);
+}
+
+# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
+// Generates a textual failure message when a death test finds more than
+// one thread running, or cannot determine the number of threads, prior
+// to executing the given statement. It is the responsibility of the
+// caller not to pass a thread_count of 1.
+static std::string DeathTestThreadWarning(size_t thread_count) {
+ Message msg;
+ msg << "Death tests use fork(), which is unsafe particularly"
+ << " in a threaded context. For this test, " << GTEST_NAME_ << " ";
+ if (thread_count == 0) {
+ msg << "couldn't detect the number of threads.";
+ } else {
+ msg << "detected " << thread_count << " threads.";
+ }
+ msg << " See "
+ "https://github.com/google/googletest/blob/master/googletest/docs/"
+ "advanced.md#death-tests-and-threads"
+ << " for more explanation and suggested solutions, especially if"
+ << " this is the last message you see before your test times out.";
+ return msg.GetString();
+}
+# endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
+
+// Flag characters for reporting a death test that did not die.
+static const char kDeathTestLived = 'L';
+static const char kDeathTestReturned = 'R';
+static const char kDeathTestThrew = 'T';
+static const char kDeathTestInternalError = 'I';
+
+#if GTEST_OS_FUCHSIA
+
+// File descriptor used for the pipe in the child process.
+static const int kFuchsiaReadPipeFd = 3;
+
+#endif
+
+// An enumeration describing all of the possible ways that a death test can
+// conclude. DIED means that the process died while executing the test
+// code; LIVED means that process lived beyond the end of the test code;
+// RETURNED means that the test statement attempted to execute a return
+// statement, which is not allowed; THREW means that the test statement
+// returned control by throwing an exception. IN_PROGRESS means the test
+// has not yet concluded.
+enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
+
+// Routine for aborting the program which is safe to call from an
+// exec-style death test child process, in which case the error
+// message is propagated back to the parent process. Otherwise, the
+// message is simply printed to stderr. In either case, the program
+// then exits with status 1.
+static void DeathTestAbort(const std::string& message) {
+ // On a POSIX system, this function may be called from a threadsafe-style
+ // death test child process, which operates on a very small stack. Use
+ // the heap for any additional non-minuscule memory requirements.
+ const InternalRunDeathTestFlag* const flag =
+ GetUnitTestImpl()->internal_run_death_test_flag();
+ if (flag != nullptr) {
+ FILE* parent = posix::FDOpen(flag->write_fd(), "w");
+ fputc(kDeathTestInternalError, parent);
+ fprintf(parent, "%s", message.c_str());
+ fflush(parent);
+ _exit(1);
+ } else {
+ fprintf(stderr, "%s", message.c_str());
+ fflush(stderr);
+ posix::Abort();
+ }
+}
+
+// A replacement for CHECK that calls DeathTestAbort if the assertion
+// fails.
+# define GTEST_DEATH_TEST_CHECK_(expression) \
+ do { \
+ if (!::testing::internal::IsTrue(expression)) { \
+ DeathTestAbort( \
+ ::std::string("CHECK failed: File ") + __FILE__ + ", line " \
+ + ::testing::internal::StreamableToString(__LINE__) + ": " \
+ + #expression); \
+ } \
+ } while (::testing::internal::AlwaysFalse())
+
+// This macro is similar to GTEST_DEATH_TEST_CHECK_, but it is meant for
+// evaluating any system call that fulfills two conditions: it must return
+// -1 on failure, and set errno to EINTR when it is interrupted and
+// should be tried again. The macro expands to a loop that repeatedly
+// evaluates the expression as long as it evaluates to -1 and sets
+// errno to EINTR. If the expression evaluates to -1 but errno is
+// something other than EINTR, DeathTestAbort is called.
+# define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \
+ do { \
+ int gtest_retval; \
+ do { \
+ gtest_retval = (expression); \
+ } while (gtest_retval == -1 && errno == EINTR); \
+ if (gtest_retval == -1) { \
+ DeathTestAbort( \
+ ::std::string("CHECK failed: File ") + __FILE__ + ", line " \
+ + ::testing::internal::StreamableToString(__LINE__) + ": " \
+ + #expression + " != -1"); \
+ } \
+ } while (::testing::internal::AlwaysFalse())
+
+// Returns the message describing the last system error in errno.
+std::string GetLastErrnoDescription() {
+ return errno == 0 ? "" : posix::StrError(errno);
+}
+
+// This is called from a death test parent process to read a failure
+// message from the death test child process and log it with the FATAL
+// severity. On Windows, the message is read from a pipe handle. On other
+// platforms, it is read from a file descriptor.
+static void FailFromInternalError(int fd) {
+ Message error;
+ char buffer[256];
+ int num_read;
+
+ do {
+ while ((num_read = posix::Read(fd, buffer, 255)) > 0) {
+ buffer[num_read] = '\0';
+ error << buffer;
+ }
+ } while (num_read == -1 && errno == EINTR);
+
+ if (num_read == 0) {
+ GTEST_LOG_(FATAL) << error.GetString();
+ } else {
+ const int last_error = errno;
+ GTEST_LOG_(FATAL) << "Error while reading death test internal: "
+ << GetLastErrnoDescription() << " [" << last_error << "]";
+ }
+}
+
+// Death test constructor. Increments the running death test count
+// for the current test.
+DeathTest::DeathTest() {
+ TestInfo* const info = GetUnitTestImpl()->current_test_info();
+ if (info == nullptr) {
+ DeathTestAbort("Cannot run a death test outside of a TEST or "
+ "TEST_F construct");
+ }
+}
+
+// Creates and returns a death test by dispatching to the current
+// death test factory.
+bool DeathTest::Create(const char* statement,
+ Matcher<const std::string&> matcher, const char* file,
+ int line, DeathTest** test) {
+ return GetUnitTestImpl()->death_test_factory()->Create(
+ statement, std::move(matcher), file, line, test);
+}
+
+const char* DeathTest::LastMessage() {
+ return last_death_test_message_.c_str();
+}
+
+void DeathTest::set_last_death_test_message(const std::string& message) {
+ last_death_test_message_ = message;
+}
+
+std::string DeathTest::last_death_test_message_;
+
+// Provides cross platform implementation for some death functionality.
+class DeathTestImpl : public DeathTest {
+ protected:
+ DeathTestImpl(const char* a_statement, Matcher<const std::string&> matcher)
+ : statement_(a_statement),
+ matcher_(std::move(matcher)),
+ spawned_(false),
+ status_(-1),
+ outcome_(IN_PROGRESS),
+ read_fd_(-1),
+ write_fd_(-1) {}
+
+ // read_fd_ is expected to be closed and cleared by a derived class.
+ ~DeathTestImpl() override { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }
+
+ void Abort(AbortReason reason) override;
+ bool Passed(bool status_ok) override;
+
+ const char* statement() const { return statement_; }
+ bool spawned() const { return spawned_; }
+ void set_spawned(bool is_spawned) { spawned_ = is_spawned; }
+ int status() const { return status_; }
+ void set_status(int a_status) { status_ = a_status; }
+ DeathTestOutcome outcome() const { return outcome_; }
+ void set_outcome(DeathTestOutcome an_outcome) { outcome_ = an_outcome; }
+ int read_fd() const { return read_fd_; }
+ void set_read_fd(int fd) { read_fd_ = fd; }
+ int write_fd() const { return write_fd_; }
+ void set_write_fd(int fd) { write_fd_ = fd; }
+
+ // Called in the parent process only. Reads the result code of the death
+ // test child process via a pipe, interprets it to set the outcome_
+ // member, and closes read_fd_. Outputs diagnostics and terminates in
+ // case of unexpected codes.
+ void ReadAndInterpretStatusByte();
+
+ // Returns stderr output from the child process.
+ virtual std::string GetErrorLogs();
+
+ private:
+ // The textual content of the code this object is testing. This class
+ // doesn't own this string and should not attempt to delete it.
+ const char* const statement_;
+ // A matcher that's expected to match the stderr output by the child process.
+ Matcher<const std::string&> matcher_;
+ // True if the death test child process has been successfully spawned.
+ bool spawned_;
+ // The exit status of the child process.
+ int status_;
+ // How the death test concluded.
+ DeathTestOutcome outcome_;
+ // Descriptor to the read end of the pipe to the child process. It is
+ // always -1 in the child process. The child keeps its write end of the
+ // pipe in write_fd_.
+ int read_fd_;
+ // Descriptor to the child's write end of the pipe to the parent process.
+ // It is always -1 in the parent process. The parent keeps its end of the
+ // pipe in read_fd_.
+ int write_fd_;
+};
+
+// Called in the parent process only. Reads the result code of the death
+// test child process via a pipe, interprets it to set the outcome_
+// member, and closes read_fd_. Outputs diagnostics and terminates in
+// case of unexpected codes.
+void DeathTestImpl::ReadAndInterpretStatusByte() {
+ char flag;
+ int bytes_read;
+
+ // The read() here blocks until data is available (signifying the
+ // failure of the death test) or until the pipe is closed (signifying
+ // its success), so it's okay to call this in the parent before
+ // the child process has exited.
+ do {
+ bytes_read = posix::Read(read_fd(), &flag, 1);
+ } while (bytes_read == -1 && errno == EINTR);
+
+ if (bytes_read == 0) {
+ set_outcome(DIED);
+ } else if (bytes_read == 1) {
+ switch (flag) {
+ case kDeathTestReturned:
+ set_outcome(RETURNED);
+ break;
+ case kDeathTestThrew:
+ set_outcome(THREW);
+ break;
+ case kDeathTestLived:
+ set_outcome(LIVED);
+ break;
+ case kDeathTestInternalError:
+ FailFromInternalError(read_fd()); // Does not return.
+ break;
+ default:
+ GTEST_LOG_(FATAL) << "Death test child process reported "
+ << "unexpected status byte ("
+ << static_cast<unsigned int>(flag) << ")";
+ }
+ } else {
+ GTEST_LOG_(FATAL) << "Read from death test child process failed: "
+ << GetLastErrnoDescription();
+ }
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Close(read_fd()));
+ set_read_fd(-1);
+}
+
+std::string DeathTestImpl::GetErrorLogs() {
+ return GetCapturedStderr();
+}
+
+// Signals that the death test code which should have exited, didn't.
+// Should be called only in a death test child process.
+// Writes a status byte to the child's status file descriptor, then
+// calls _exit(1).
+void DeathTestImpl::Abort(AbortReason reason) {
+ // The parent process considers the death test to be a failure if
+ // it finds any data in our pipe. So, here we write a single flag byte
+ // to the pipe, then exit.
+ const char status_ch =
+ reason == TEST_DID_NOT_DIE ? kDeathTestLived :
+ reason == TEST_THREW_EXCEPTION ? kDeathTestThrew : kDeathTestReturned;
+
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Write(write_fd(), &status_ch, 1));
+ // We are leaking the descriptor here because on some platforms (i.e.,
+ // when built as Windows DLL), destructors of global objects will still
+ // run after calling _exit(). On such systems, write_fd_ will be
+ // indirectly closed from the destructor of UnitTestImpl, causing double
+ // close if it is also closed here. On debug configurations, double close
+ // may assert. As there are no in-process buffers to flush here, we are
+ // relying on the OS to close the descriptor after the process terminates
+ // when the destructors are not run.
+ _exit(1); // Exits w/o any normal exit hooks (we were supposed to crash)
+}
+
+// Returns an indented copy of stderr output for a death test.
+// This makes distinguishing death test output lines from regular log lines
+// much easier.
+static ::std::string FormatDeathTestOutput(const ::std::string& output) {
+ ::std::string ret;
+ for (size_t at = 0; ; ) {
+ const size_t line_end = output.find('\n', at);
+ ret += "[ DEATH ] ";
+ if (line_end == ::std::string::npos) {
+ ret += output.substr(at);
+ break;
+ }
+ ret += output.substr(at, line_end + 1 - at);
+ at = line_end + 1;
+ }
+ return ret;
+}
+
+// Assesses the success or failure of a death test, using both private
+// members which have previously been set, and one argument:
+//
+// Private data members:
+// outcome: An enumeration describing how the death test
+// concluded: DIED, LIVED, THREW, or RETURNED. The death test
+// fails in the latter three cases.
+// status: The exit status of the child process. On *nix, it is in the
+// in the format specified by wait(2). On Windows, this is the
+// value supplied to the ExitProcess() API or a numeric code
+// of the exception that terminated the program.
+// matcher_: A matcher that's expected to match the stderr output by the child
+// process.
+//
+// Argument:
+// status_ok: true if exit_status is acceptable in the context of
+// this particular death test, which fails if it is false
+//
+// Returns true iff all of the above conditions are met. Otherwise, the
+// first failing condition, in the order given above, is the one that is
+// reported. Also sets the last death test message string.
+bool DeathTestImpl::Passed(bool status_ok) {
+ if (!spawned())
+ return false;
+
+ const std::string error_message = GetErrorLogs();
+
+ bool success = false;
+ Message buffer;
+
+ buffer << "Death test: " << statement() << "\n";
+ switch (outcome()) {
+ case LIVED:
+ buffer << " Result: failed to die.\n"
+ << " Error msg:\n" << FormatDeathTestOutput(error_message);
+ break;
+ case THREW:
+ buffer << " Result: threw an exception.\n"
+ << " Error msg:\n" << FormatDeathTestOutput(error_message);
+ break;
+ case RETURNED:
+ buffer << " Result: illegal return in test statement.\n"
+ << " Error msg:\n" << FormatDeathTestOutput(error_message);
+ break;
+ case DIED:
+ if (status_ok) {
+ if (matcher_.Matches(error_message)) {
+ success = true;
+ } else {
+ std::ostringstream stream;
+ matcher_.DescribeTo(&stream);
+ buffer << " Result: died but not with expected error.\n"
+ << " Expected: " << stream.str() << "\n"
+ << "Actual msg:\n"
+ << FormatDeathTestOutput(error_message);
+ }
+ } else {
+ buffer << " Result: died but not with expected exit code:\n"
+ << " " << ExitSummary(status()) << "\n"
+ << "Actual msg:\n" << FormatDeathTestOutput(error_message);
+ }
+ break;
+ case IN_PROGRESS:
+ default:
+ GTEST_LOG_(FATAL)
+ << "DeathTest::Passed somehow called before conclusion of test";
+ }
+
+ DeathTest::set_last_death_test_message(buffer.GetString());
+ return success;
+}
+
+# if GTEST_OS_WINDOWS
+// WindowsDeathTest implements death tests on Windows. Due to the
+// specifics of starting new processes on Windows, death tests there are
+// always threadsafe, and Google Test considers the
+// --gtest_death_test_style=fast setting to be equivalent to
+// --gtest_death_test_style=threadsafe there.
+//
+// A few implementation notes: Like the Linux version, the Windows
+// implementation uses pipes for child-to-parent communication. But due to
+// the specifics of pipes on Windows, some extra steps are required:
+//
+// 1. The parent creates a communication pipe and stores handles to both
+// ends of it.
+// 2. The parent starts the child and provides it with the information
+// necessary to acquire the handle to the write end of the pipe.
+// 3. The child acquires the write end of the pipe and signals the parent
+// using a Windows event.
+// 4. Now the parent can release the write end of the pipe on its side. If
+// this is done before step 3, the object's reference count goes down to
+// 0 and it is destroyed, preventing the child from acquiring it. The
+// parent now has to release it, or read operations on the read end of
+// the pipe will not return when the child terminates.
+// 5. The parent reads child's output through the pipe (outcome code and
+// any possible error messages) from the pipe, and its stderr and then
+// determines whether to fail the test.
+//
+// Note: to distinguish Win32 API calls from the local method and function
+// calls, the former are explicitly resolved in the global namespace.
+//
+class WindowsDeathTest : public DeathTestImpl {
+ public:
+ WindowsDeathTest(const char* a_statement, Matcher<const std::string&> matcher,
+ const char* file, int line)
+ : DeathTestImpl(a_statement, std::move(matcher)),
+ file_(file),
+ line_(line) {}
+
+ // All of these virtual functions are inherited from DeathTest.
+ virtual int Wait();
+ virtual TestRole AssumeRole();
+
+ private:
+ // The name of the file in which the death test is located.
+ const char* const file_;
+ // The line number on which the death test is located.
+ const int line_;
+ // Handle to the write end of the pipe to the child process.
+ AutoHandle write_handle_;
+ // Child process handle.
+ AutoHandle child_handle_;
+ // Event the child process uses to signal the parent that it has
+ // acquired the handle to the write end of the pipe. After seeing this
+ // event the parent can release its own handles to make sure its
+ // ReadFile() calls return when the child terminates.
+ AutoHandle event_handle_;
+};
+
+// Waits for the child in a death test to exit, returning its exit
+// status, or 0 if no child process exists. As a side effect, sets the
+// outcome data member.
+int WindowsDeathTest::Wait() {
+ if (!spawned())
+ return 0;
+
+ // Wait until the child either signals that it has acquired the write end
+ // of the pipe or it dies.
+ const HANDLE wait_handles[2] = { child_handle_.Get(), event_handle_.Get() };
+ switch (::WaitForMultipleObjects(2,
+ wait_handles,
+ FALSE, // Waits for any of the handles.
+ INFINITE)) {
+ case WAIT_OBJECT_0:
+ case WAIT_OBJECT_0 + 1:
+ break;
+ default:
+ GTEST_DEATH_TEST_CHECK_(false); // Should not get here.
+ }
+
+ // The child has acquired the write end of the pipe or exited.
+ // We release the handle on our side and continue.
+ write_handle_.Reset();
+ event_handle_.Reset();
+
+ ReadAndInterpretStatusByte();
+
+ // Waits for the child process to exit if it haven't already. This
+ // returns immediately if the child has already exited, regardless of
+ // whether previous calls to WaitForMultipleObjects synchronized on this
+ // handle or not.
+ GTEST_DEATH_TEST_CHECK_(
+ WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(),
+ INFINITE));
+ DWORD status_code;
+ GTEST_DEATH_TEST_CHECK_(
+ ::GetExitCodeProcess(child_handle_.Get(), &status_code) != FALSE);
+ child_handle_.Reset();
+ set_status(static_cast<int>(status_code));
+ return status();
+}
+
+// The AssumeRole process for a Windows death test. It creates a child
+// process with the same executable as the current process to run the
+// death test. The child process is given the --gtest_filter and
+// --gtest_internal_run_death_test flags such that it knows to run the
+// current death test only.
+DeathTest::TestRole WindowsDeathTest::AssumeRole() {
+ const UnitTestImpl* const impl = GetUnitTestImpl();
+ const InternalRunDeathTestFlag* const flag =
+ impl->internal_run_death_test_flag();
+ const TestInfo* const info = impl->current_test_info();
+ const int death_test_index = info->result()->death_test_count();
+
+ if (flag != nullptr) {
+ // ParseInternalRunDeathTestFlag() has performed all the necessary
+ // processing.
+ set_write_fd(flag->write_fd());
+ return EXECUTE_TEST;
+ }
+
+ // WindowsDeathTest uses an anonymous pipe to communicate results of
+ // a death test.
+ SECURITY_ATTRIBUTES handles_are_inheritable = {sizeof(SECURITY_ATTRIBUTES),
+ nullptr, TRUE};
+ HANDLE read_handle, write_handle;
+ GTEST_DEATH_TEST_CHECK_(
+ ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable,
+ 0) // Default buffer size.
+ != FALSE);
+ set_read_fd(::_open_osfhandle(reinterpret_cast<intptr_t>(read_handle),
+ O_RDONLY));
+ write_handle_.Reset(write_handle);
+ event_handle_.Reset(::CreateEvent(
+ &handles_are_inheritable,
+ TRUE, // The event will automatically reset to non-signaled state.
+ FALSE, // The initial state is non-signalled.
+ nullptr)); // The even is unnamed.
+ GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != nullptr);
+ const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
+ kFilterFlag + "=" + info->test_suite_name() +
+ "." + info->name();
+ const std::string internal_flag =
+ std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag +
+ "=" + file_ + "|" + StreamableToString(line_) + "|" +
+ StreamableToString(death_test_index) + "|" +
+ StreamableToString(static_cast<unsigned int>(::GetCurrentProcessId())) +
+ // size_t has the same width as pointers on both 32-bit and 64-bit
+ // Windows platforms.
+ // See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.
+ "|" + StreamableToString(reinterpret_cast<size_t>(write_handle)) +
+ "|" + StreamableToString(reinterpret_cast<size_t>(event_handle_.Get()));
+
+ char executable_path[_MAX_PATH + 1]; // NOLINT
+ GTEST_DEATH_TEST_CHECK_(_MAX_PATH + 1 != ::GetModuleFileNameA(nullptr,
+ executable_path,
+ _MAX_PATH));
+
+ std::string command_line =
+ std::string(::GetCommandLineA()) + " " + filter_flag + " \"" +
+ internal_flag + "\"";
+
+ DeathTest::set_last_death_test_message("");
+
+ CaptureStderr();
+ // Flush the log buffers since the log streams are shared with the child.
+ FlushInfoLog();
+
+ // The child process will share the standard handles with the parent.
+ STARTUPINFOA startup_info;
+ memset(&startup_info, 0, sizeof(STARTUPINFO));
+ startup_info.dwFlags = STARTF_USESTDHANDLES;
+ startup_info.hStdInput = ::GetStdHandle(STD_INPUT_HANDLE);
+ startup_info.hStdOutput = ::GetStdHandle(STD_OUTPUT_HANDLE);
+ startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE);
+
+ PROCESS_INFORMATION process_info;
+ GTEST_DEATH_TEST_CHECK_(
+ ::CreateProcessA(
+ executable_path, const_cast<char*>(command_line.c_str()),
+ nullptr, // Retuned process handle is not inheritable.
+ nullptr, // Retuned thread handle is not inheritable.
+ TRUE, // Child inherits all inheritable handles (for write_handle_).
+ 0x0, // Default creation flags.
+ nullptr, // Inherit the parent's environment.
+ UnitTest::GetInstance()->original_working_dir(), &startup_info,
+ &process_info) != FALSE);
+ child_handle_.Reset(process_info.hProcess);
+ ::CloseHandle(process_info.hThread);
+ set_spawned(true);
+ return OVERSEE_TEST;
+}
+
+# elif GTEST_OS_FUCHSIA
+
+class FuchsiaDeathTest : public DeathTestImpl {
+ public:
+ FuchsiaDeathTest(const char* a_statement, Matcher<const std::string&> matcher,
+ const char* file, int line)
+ : DeathTestImpl(a_statement, std::move(matcher)),
+ file_(file),
+ line_(line) {}
+
+ // All of these virtual functions are inherited from DeathTest.
+ int Wait() override;
+ TestRole AssumeRole() override;
+ std::string GetErrorLogs() override;
+
+ private:
+ // The name of the file in which the death test is located.
+ const char* const file_;
+ // The line number on which the death test is located.
+ const int line_;
+ // The stderr data captured by the child process.
+ std::string captured_stderr_;
+
+ zx::process child_process_;
+ zx::port port_;
+ zx::socket stderr_socket_;
+};
+
+// Utility class for accumulating command-line arguments.
+class Arguments {
+ public:
+ Arguments() { args_.push_back(nullptr); }
+
+ ~Arguments() {
+ for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
+ ++i) {
+ free(*i);
+ }
+ }
+ void AddArgument(const char* argument) {
+ args_.insert(args_.end() - 1, posix::StrDup(argument));
+ }
+
+ template <typename Str>
+ void AddArguments(const ::std::vector<Str>& arguments) {
+ for (typename ::std::vector<Str>::const_iterator i = arguments.begin();
+ i != arguments.end();
+ ++i) {
+ args_.insert(args_.end() - 1, posix::StrDup(i->c_str()));
+ }
+ }
+ char* const* Argv() {
+ return &args_[0];
+ }
+
+ int size() {
+ return args_.size() - 1;
+ }
+
+ private:
+ std::vector<char*> args_;
+};
+
+// Waits for the child in a death test to exit, returning its exit
+// status, or 0 if no child process exists. As a side effect, sets the
+// outcome data member.
+int FuchsiaDeathTest::Wait() {
+ const int kProcessKey = 0;
+ const int kSocketKey = 1;
+
+ if (!spawned())
+ return 0;
+
+ // Register to wait for the child process to terminate.
+ zx_status_t status_zx;
+ status_zx = child_process_.wait_async(
+ port_, kProcessKey, ZX_PROCESS_TERMINATED, ZX_WAIT_ASYNC_ONCE);
+ GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
+ // Register to wait for the socket to be readable or closed.
+ status_zx = stderr_socket_.wait_async(
+ port_, kSocketKey, ZX_SOCKET_READABLE | ZX_SOCKET_PEER_CLOSED,
+ ZX_WAIT_ASYNC_ONCE);
+ GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
+
+ bool process_terminated = false;
+ bool socket_closed = false;
+ do {
+ zx_port_packet_t packet = {};
+ status_zx = port_.wait(zx::time::infinite(), &packet);
+ GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
+
+ if (packet.key == kProcessKey) {
+ if (ZX_PKT_IS_EXCEPTION(packet.type)) {
+ // Process encountered an exception. Kill it directly rather than
+ // letting other handlers process the event. We will get a second
+ // kProcessKey event when the process actually terminates.
+ status_zx = child_process_.kill();
+ GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
+ } else {
+ // Process terminated.
+ GTEST_DEATH_TEST_CHECK_(ZX_PKT_IS_SIGNAL_ONE(packet.type));
+ GTEST_DEATH_TEST_CHECK_(packet.signal.observed & ZX_PROCESS_TERMINATED);
+ process_terminated = true;
+ }
+ } else if (packet.key == kSocketKey) {
+ GTEST_DEATH_TEST_CHECK_(ZX_PKT_IS_SIGNAL_ONE(packet.type));
+ if (packet.signal.observed & ZX_SOCKET_READABLE) {
+ // Read data from the socket.
+ constexpr size_t kBufferSize = 1024;
+ do {
+ size_t old_length = captured_stderr_.length();
+ size_t bytes_read = 0;
+ captured_stderr_.resize(old_length + kBufferSize);
+ status_zx = stderr_socket_.read(
+ 0, &captured_stderr_.front() + old_length, kBufferSize,
+ &bytes_read);
+ captured_stderr_.resize(old_length + bytes_read);
+ } while (status_zx == ZX_OK);
+ if (status_zx == ZX_ERR_PEER_CLOSED) {
+ socket_closed = true;
+ } else {
+ GTEST_DEATH_TEST_CHECK_(status_zx == ZX_ERR_SHOULD_WAIT);
+ status_zx = stderr_socket_.wait_async(
+ port_, kSocketKey, ZX_SOCKET_READABLE | ZX_SOCKET_PEER_CLOSED,
+ ZX_WAIT_ASYNC_ONCE);
+ GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
+ }
+ } else {
+ GTEST_DEATH_TEST_CHECK_(packet.signal.observed & ZX_SOCKET_PEER_CLOSED);
+ socket_closed = true;
+ }
+ }
+ } while (!process_terminated && !socket_closed);
+
+ ReadAndInterpretStatusByte();
+
+ zx_info_process_t buffer;
+ status_zx = child_process_.get_info(
+ ZX_INFO_PROCESS, &buffer, sizeof(buffer), nullptr, nullptr);
+ GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
+
+ GTEST_DEATH_TEST_CHECK_(buffer.exited);
+ set_status(buffer.return_code);
+ return status();
+}
+
+// The AssumeRole process for a Fuchsia death test. It creates a child
+// process with the same executable as the current process to run the
+// death test. The child process is given the --gtest_filter and
+// --gtest_internal_run_death_test flags such that it knows to run the
+// current death test only.
+DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
+ const UnitTestImpl* const impl = GetUnitTestImpl();
+ const InternalRunDeathTestFlag* const flag =
+ impl->internal_run_death_test_flag();
+ const TestInfo* const info = impl->current_test_info();
+ const int death_test_index = info->result()->death_test_count();
+
+ if (flag != nullptr) {
+ // ParseInternalRunDeathTestFlag() has performed all the necessary
+ // processing.
+ set_write_fd(kFuchsiaReadPipeFd);
+ return EXECUTE_TEST;
+ }
+
+ // Flush the log buffers since the log streams are shared with the child.
+ FlushInfoLog();
+
+ // Build the child process command line.
+ const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
+ kFilterFlag + "=" + info->test_suite_name() +
+ "." + info->name();
+ const std::string internal_flag =
+ std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
+ + file_ + "|"
+ + StreamableToString(line_) + "|"
+ + StreamableToString(death_test_index);
+ Arguments args;
+ args.AddArguments(GetInjectableArgvs());
+ args.AddArgument(filter_flag.c_str());
+ args.AddArgument(internal_flag.c_str());
+
+ // Build the pipe for communication with the child.
+ zx_status_t status;
+ zx_handle_t child_pipe_handle;
+ int child_pipe_fd;
+ status = fdio_pipe_half2(&child_pipe_fd, &child_pipe_handle);
+ GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
+ set_read_fd(child_pipe_fd);
+
+ // Set the pipe handle for the child.
+ fdio_spawn_action_t spawn_actions[2] = {};
+ fdio_spawn_action_t* add_handle_action = &spawn_actions[0];
+ add_handle_action->action = FDIO_SPAWN_ACTION_ADD_HANDLE;
+ add_handle_action->h.id = PA_HND(PA_FD, kFuchsiaReadPipeFd);
+ add_handle_action->h.handle = child_pipe_handle;
+
+ // Create a socket pair will be used to receive the child process' stderr.
+ zx::socket stderr_producer_socket;
+ status =
+ zx::socket::create(0, &stderr_producer_socket, &stderr_socket_);
+ GTEST_DEATH_TEST_CHECK_(status >= 0);
+ int stderr_producer_fd = -1;
+ status =
+ fdio_fd_create(stderr_producer_socket.release(), &stderr_producer_fd);
+ GTEST_DEATH_TEST_CHECK_(status >= 0);
+
+ // Make the stderr socket nonblocking.
+ GTEST_DEATH_TEST_CHECK_(fcntl(stderr_producer_fd, F_SETFL, 0) == 0);
+
+ fdio_spawn_action_t* add_stderr_action = &spawn_actions[1];
+ add_stderr_action->action = FDIO_SPAWN_ACTION_CLONE_FD;
+ add_stderr_action->fd.local_fd = stderr_producer_fd;
+ add_stderr_action->fd.target_fd = STDERR_FILENO;
+
+ // Create a child job.
+ zx_handle_t child_job = ZX_HANDLE_INVALID;
+ status = zx_job_create(zx_job_default(), 0, & child_job);
+ GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
+ zx_policy_basic_t policy;
+ policy.condition = ZX_POL_NEW_ANY;
+ policy.policy = ZX_POL_ACTION_ALLOW;
+ status = zx_job_set_policy(
+ child_job, ZX_JOB_POL_RELATIVE, ZX_JOB_POL_BASIC, &policy, 1);
+ GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
+
+ // Create an exception port and attach it to the |child_job|, to allow
+ // us to suppress the system default exception handler from firing.
+ status = zx::port::create(0, &port_);
+ GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
+ status = zx_task_bind_exception_port(
+ child_job, port_.get(), 0 /* key */, 0 /*options */);
+ GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
+
+ // Spawn the child process.
+ status = fdio_spawn_etc(
+ child_job, FDIO_SPAWN_CLONE_ALL, args.Argv()[0], args.Argv(), nullptr,
+ 2, spawn_actions, child_process_.reset_and_get_address(), nullptr);
+ GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
+
+ set_spawned(true);
+ return OVERSEE_TEST;
+}
+
+std::string FuchsiaDeathTest::GetErrorLogs() {
+ return captured_stderr_;
+}
+
+#else // We are neither on Windows, nor on Fuchsia.
+
+// ForkingDeathTest provides implementations for most of the abstract
+// methods of the DeathTest interface. Only the AssumeRole method is
+// left undefined.
+class ForkingDeathTest : public DeathTestImpl {
+ public:
+ ForkingDeathTest(const char* statement, Matcher<const std::string&> matcher);
+
+ // All of these virtual functions are inherited from DeathTest.
+ int Wait() override;
+
+ protected:
+ void set_child_pid(pid_t child_pid) { child_pid_ = child_pid; }
+
+ private:
+ // PID of child process during death test; 0 in the child process itself.
+ pid_t child_pid_;
+};
+
+// Constructs a ForkingDeathTest.
+ForkingDeathTest::ForkingDeathTest(const char* a_statement,
+ Matcher<const std::string&> matcher)
+ : DeathTestImpl(a_statement, std::move(matcher)), child_pid_(-1) {}
+
+// Waits for the child in a death test to exit, returning its exit
+// status, or 0 if no child process exists. As a side effect, sets the
+// outcome data member.
+int ForkingDeathTest::Wait() {
+ if (!spawned())
+ return 0;
+
+ ReadAndInterpretStatusByte();
+
+ int status_value;
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(waitpid(child_pid_, &status_value, 0));
+ set_status(status_value);
+ return status_value;
+}
+
+// A concrete death test class that forks, then immediately runs the test
+// in the child process.
+class NoExecDeathTest : public ForkingDeathTest {
+ public:
+ NoExecDeathTest(const char* a_statement, Matcher<const std::string&> matcher)
+ : ForkingDeathTest(a_statement, std::move(matcher)) {}
+ TestRole AssumeRole() override;
+};
+
+// The AssumeRole process for a fork-and-run death test. It implements a
+// straightforward fork, with a simple pipe to transmit the status byte.
+DeathTest::TestRole NoExecDeathTest::AssumeRole() {
+ const size_t thread_count = GetThreadCount();
+ if (thread_count != 1) {
+ GTEST_LOG_(WARNING) << DeathTestThreadWarning(thread_count);
+ }
+
+ int pipe_fd[2];
+ GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
+
+ DeathTest::set_last_death_test_message("");
+ CaptureStderr();
+ // When we fork the process below, the log file buffers are copied, but the
+ // file descriptors are shared. We flush all log files here so that closing
+ // the file descriptors in the child process doesn't throw off the
+ // synchronization between descriptors and buffers in the parent process.
+ // This is as close to the fork as possible to avoid a race condition in case
+ // there are multiple threads running before the death test, and another
+ // thread writes to the log file.
+ FlushInfoLog();
+
+ const pid_t child_pid = fork();
+ GTEST_DEATH_TEST_CHECK_(child_pid != -1);
+ set_child_pid(child_pid);
+ if (child_pid == 0) {
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[0]));
+ set_write_fd(pipe_fd[1]);
+ // Redirects all logging to stderr in the child process to prevent
+ // concurrent writes to the log files. We capture stderr in the parent
+ // process and append the child process' output to a log.
+ LogToStderr();
+ // Event forwarding to the listeners of event listener API mush be shut
+ // down in death test subprocesses.
+ GetUnitTestImpl()->listeners()->SuppressEventForwarding();
+ g_in_fast_death_test_child = true;
+ return EXECUTE_TEST;
+ } else {
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
+ set_read_fd(pipe_fd[0]);
+ set_spawned(true);
+ return OVERSEE_TEST;
+ }
+}
+
+// A concrete death test class that forks and re-executes the main
+// program from the beginning, with command-line flags set that cause
+// only this specific death test to be run.
+class ExecDeathTest : public ForkingDeathTest {
+ public:
+ ExecDeathTest(const char* a_statement, Matcher<const std::string&> matcher,
+ const char* file, int line)
+ : ForkingDeathTest(a_statement, std::move(matcher)),
+ file_(file),
+ line_(line) {}
+ TestRole AssumeRole() override;
+
+ private:
+ static ::std::vector<std::string> GetArgvsForDeathTestChildProcess() {
+ ::std::vector<std::string> args = GetInjectableArgvs();
+# if defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
+ ::std::vector<std::string> extra_args =
+ GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_();
+ args.insert(args.end(), extra_args.begin(), extra_args.end());
+# endif // defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
+ return args;
+ }
+ // The name of the file in which the death test is located.
+ const char* const file_;
+ // The line number on which the death test is located.
+ const int line_;
+};
+
+// Utility class for accumulating command-line arguments.
+class Arguments {
+ public:
+ Arguments() { args_.push_back(nullptr); }
+
+ ~Arguments() {
+ for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
+ ++i) {
+ free(*i);
+ }
+ }
+ void AddArgument(const char* argument) {
+ args_.insert(args_.end() - 1, posix::StrDup(argument));
+ }
+
+ template <typename Str>
+ void AddArguments(const ::std::vector<Str>& arguments) {
+ for (typename ::std::vector<Str>::const_iterator i = arguments.begin();
+ i != arguments.end();
+ ++i) {
+ args_.insert(args_.end() - 1, posix::StrDup(i->c_str()));
+ }
+ }
+ char* const* Argv() {
+ return &args_[0];
+ }
+
+ private:
+ std::vector<char*> args_;
+};
+
+// A struct that encompasses the arguments to the child process of a
+// threadsafe-style death test process.
+struct ExecDeathTestArgs {
+ char* const* argv; // Command-line arguments for the child's call to exec
+ int close_fd; // File descriptor to close; the read end of a pipe
+};
+
+# if GTEST_OS_MAC
+inline char** GetEnviron() {
+ // When Google Test is built as a framework on MacOS X, the environ variable
+ // is unavailable. Apple's documentation (man environ) recommends using
+ // _NSGetEnviron() instead.
+ return *_NSGetEnviron();
+}
+# else
+// Some POSIX platforms expect you to declare environ. extern "C" makes
+// it reside in the global namespace.
+extern "C" char** environ;
+inline char** GetEnviron() { return environ; }
+# endif // GTEST_OS_MAC
+
+# if !GTEST_OS_QNX
+// The main function for a threadsafe-style death test child process.
+// This function is called in a clone()-ed process and thus must avoid
+// any potentially unsafe operations like malloc or libc functions.
+static int ExecDeathTestChildMain(void* child_arg) {
+ ExecDeathTestArgs* const args = static_cast<ExecDeathTestArgs*>(child_arg);
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd));
+
+ // We need to execute the test program in the same environment where
+ // it was originally invoked. Therefore we change to the original
+ // working directory first.
+ const char* const original_dir =
+ UnitTest::GetInstance()->original_working_dir();
+ // We can safely call chdir() as it's a direct system call.
+ if (chdir(original_dir) != 0) {
+ DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " +
+ GetLastErrnoDescription());
+ return EXIT_FAILURE;
+ }
+
+ // We can safely call execve() as it's a direct system call. We
+ // cannot use execvp() as it's a libc function and thus potentially
+ // unsafe. Since execve() doesn't search the PATH, the user must
+ // invoke the test program via a valid path that contains at least
+ // one path separator.
+ execve(args->argv[0], args->argv, GetEnviron());
+ DeathTestAbort(std::string("execve(") + args->argv[0] + ", ...) in " +
+ original_dir + " failed: " +
+ GetLastErrnoDescription());
+ return EXIT_FAILURE;
+}
+# endif // !GTEST_OS_QNX
+
+# if GTEST_HAS_CLONE
+// Two utility routines that together determine the direction the stack
+// grows.
+// This could be accomplished more elegantly by a single recursive
+// function, but we want to guard against the unlikely possibility of
+// a smart compiler optimizing the recursion away.
+//
+// GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining
+// StackLowerThanAddress into StackGrowsDown, which then doesn't give
+// correct answer.
+static void StackLowerThanAddress(const void* ptr,
+ bool* result) GTEST_NO_INLINE_;
+// HWAddressSanitizer add a random tag to the MSB of the local variable address,
+// making comparison result unpredictable.
+GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
+static void StackLowerThanAddress(const void* ptr, bool* result) {
+ int dummy;
+ *result = (&dummy < ptr);
+}
+
+// Make sure AddressSanitizer does not tamper with the stack here.
+GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
+GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
+static bool StackGrowsDown() {
+ int dummy;
+ bool result;
+ StackLowerThanAddress(&dummy, &result);
+ return result;
+}
+# endif // GTEST_HAS_CLONE
+
+// Spawns a child process with the same executable as the current process in
+// a thread-safe manner and instructs it to run the death test. The
+// implementation uses fork(2) + exec. On systems where clone(2) is
+// available, it is used instead, being slightly more thread-safe. On QNX,
+// fork supports only single-threaded environments, so this function uses
+// spawn(2) there instead. The function dies with an error message if
+// anything goes wrong.
+static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
+ ExecDeathTestArgs args = { argv, close_fd };
+ pid_t child_pid = -1;
+
+# if GTEST_OS_QNX
+ // Obtains the current directory and sets it to be closed in the child
+ // process.
+ const int cwd_fd = open(".", O_RDONLY);
+ GTEST_DEATH_TEST_CHECK_(cwd_fd != -1);
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(cwd_fd, F_SETFD, FD_CLOEXEC));
+ // We need to execute the test program in the same environment where
+ // it was originally invoked. Therefore we change to the original
+ // working directory first.
+ const char* const original_dir =
+ UnitTest::GetInstance()->original_working_dir();
+ // We can safely call chdir() as it's a direct system call.
+ if (chdir(original_dir) != 0) {
+ DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " +
+ GetLastErrnoDescription());
+ return EXIT_FAILURE;
+ }
+
+ int fd_flags;
+ // Set close_fd to be closed after spawn.
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(fd_flags = fcntl(close_fd, F_GETFD));
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(close_fd, F_SETFD,
+ fd_flags | FD_CLOEXEC));
+ struct inheritance inherit = {0};
+ // spawn is a system call.
+ child_pid =
+ spawn(args.argv[0], 0, nullptr, &inherit, args.argv, GetEnviron());
+ // Restores the current working directory.
+ GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1);
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd));
+
+# else // GTEST_OS_QNX
+# if GTEST_OS_LINUX
+ // When a SIGPROF signal is received while fork() or clone() are executing,
+ // the process may hang. To avoid this, we ignore SIGPROF here and re-enable
+ // it after the call to fork()/clone() is complete.
+ struct sigaction saved_sigprof_action;
+ struct sigaction ignore_sigprof_action;
+ memset(&ignore_sigprof_action, 0, sizeof(ignore_sigprof_action));
+ sigemptyset(&ignore_sigprof_action.sa_mask);
+ ignore_sigprof_action.sa_handler = SIG_IGN;
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(sigaction(
+ SIGPROF, &ignore_sigprof_action, &saved_sigprof_action));
+# endif // GTEST_OS_LINUX
+
+# if GTEST_HAS_CLONE
+ const bool use_fork = GTEST_FLAG(death_test_use_fork);
+
+ if (!use_fork) {
+ static const bool stack_grows_down = StackGrowsDown();
+ const auto stack_size = static_cast<size_t>(getpagesize());
+ // MMAP_ANONYMOUS is not defined on Mac, so we use MAP_ANON instead.
+ void* const stack = mmap(nullptr, stack_size, PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE, -1, 0);
+ GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
+
+ // Maximum stack alignment in bytes: For a downward-growing stack, this
+ // amount is subtracted from size of the stack space to get an address
+ // that is within the stack space and is aligned on all systems we care
+ // about. As far as I know there is no ABI with stack alignment greater
+ // than 64. We assume stack and stack_size already have alignment of
+ // kMaxStackAlignment.
+ const size_t kMaxStackAlignment = 64;
+ void* const stack_top =
+ static_cast<char*>(stack) +
+ (stack_grows_down ? stack_size - kMaxStackAlignment : 0);
+ GTEST_DEATH_TEST_CHECK_(
+ static_cast<size_t>(stack_size) > kMaxStackAlignment &&
+ reinterpret_cast<uintptr_t>(stack_top) % kMaxStackAlignment == 0);
+
+ child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);
+
+ GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
+ }
+# else
+ const bool use_fork = true;
+# endif // GTEST_HAS_CLONE
+
+ if (use_fork && (child_pid = fork()) == 0) {
+ ExecDeathTestChildMain(&args);
+ _exit(0);
+ }
+# endif // GTEST_OS_QNX
+# if GTEST_OS_LINUX
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(
+ sigaction(SIGPROF, &saved_sigprof_action, nullptr));
+# endif // GTEST_OS_LINUX
+
+ GTEST_DEATH_TEST_CHECK_(child_pid != -1);
+ return child_pid;
+}
+
+// The AssumeRole process for a fork-and-exec death test. It re-executes the
+// main program from the beginning, setting the --gtest_filter
+// and --gtest_internal_run_death_test flags to cause only the current
+// death test to be re-run.
+DeathTest::TestRole ExecDeathTest::AssumeRole() {
+ const UnitTestImpl* const impl = GetUnitTestImpl();
+ const InternalRunDeathTestFlag* const flag =
+ impl->internal_run_death_test_flag();
+ const TestInfo* const info = impl->current_test_info();
+ const int death_test_index = info->result()->death_test_count();
+
+ if (flag != nullptr) {
+ set_write_fd(flag->write_fd());
+ return EXECUTE_TEST;
+ }
+
+ int pipe_fd[2];
+ GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
+ // Clear the close-on-exec flag on the write end of the pipe, lest
+ // it be closed when the child process does an exec:
+ GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
+
+ const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
+ kFilterFlag + "=" + info->test_suite_name() +
+ "." + info->name();
+ const std::string internal_flag =
+ std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
+ + file_ + "|" + StreamableToString(line_) + "|"
+ + StreamableToString(death_test_index) + "|"
+ + StreamableToString(pipe_fd[1]);
+ Arguments args;
+ args.AddArguments(GetArgvsForDeathTestChildProcess());
+ args.AddArgument(filter_flag.c_str());
+ args.AddArgument(internal_flag.c_str());
+
+ DeathTest::set_last_death_test_message("");
+
+ CaptureStderr();
+ // See the comment in NoExecDeathTest::AssumeRole for why the next line
+ // is necessary.
+ FlushInfoLog();
+
+ const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]);
+ GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
+ set_child_pid(child_pid);
+ set_read_fd(pipe_fd[0]);
+ set_spawned(true);
+ return OVERSEE_TEST;
+}
+
+# endif // !GTEST_OS_WINDOWS
+
+// Creates a concrete DeathTest-derived class that depends on the
+// --gtest_death_test_style flag, and sets the pointer pointed to
+// by the "test" argument to its address. If the test should be
+// skipped, sets that pointer to NULL. Returns true, unless the
+// flag is set to an invalid value.
+bool DefaultDeathTestFactory::Create(const char* statement,
+ Matcher<const std::string&> matcher,
+ const char* file, int line,
+ DeathTest** test) {
+ UnitTestImpl* const impl = GetUnitTestImpl();
+ const InternalRunDeathTestFlag* const flag =
+ impl->internal_run_death_test_flag();
+ const int death_test_index = impl->current_test_info()
+ ->increment_death_test_count();
+
+ if (flag != nullptr) {
+ if (death_test_index > flag->index()) {
+ DeathTest::set_last_death_test_message(
+ "Death test count (" + StreamableToString(death_test_index)
+ + ") somehow exceeded expected maximum ("
+ + StreamableToString(flag->index()) + ")");
+ return false;
+ }
+
+ if (!(flag->file() == file && flag->line() == line &&
+ flag->index() == death_test_index)) {
+ *test = nullptr;
+ return true;
+ }
+ }
+
+# if GTEST_OS_WINDOWS
+
+ if (GTEST_FLAG(death_test_style) == "threadsafe" ||
+ GTEST_FLAG(death_test_style) == "fast") {
+ *test = new WindowsDeathTest(statement, std::move(matcher), file, line);
+ }
+
+# elif GTEST_OS_FUCHSIA
+
+ if (GTEST_FLAG(death_test_style) == "threadsafe" ||
+ GTEST_FLAG(death_test_style) == "fast") {
+ *test = new FuchsiaDeathTest(statement, std::move(matcher), file, line);
+ }
+
+# else
+
+ if (GTEST_FLAG(death_test_style) == "threadsafe") {
+ *test = new ExecDeathTest(statement, std::move(matcher), file, line);
+ } else if (GTEST_FLAG(death_test_style) == "fast") {
+ *test = new NoExecDeathTest(statement, std::move(matcher));
+ }
+
+# endif // GTEST_OS_WINDOWS
+
+ else { // NOLINT - this is more readable than unbalanced brackets inside #if.
+ DeathTest::set_last_death_test_message(
+ "Unknown death test style \"" + GTEST_FLAG(death_test_style)
+ + "\" encountered");
+ return false;
+ }
+
+ return true;
+}
+
+# if GTEST_OS_WINDOWS
+// Recreates the pipe and event handles from the provided parameters,
+// signals the event, and returns a file descriptor wrapped around the pipe
+// handle. This function is called in the child process only.
+static int GetStatusFileDescriptor(unsigned int parent_process_id,
+ size_t write_handle_as_size_t,
+ size_t event_handle_as_size_t) {
+ AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE,
+ FALSE, // Non-inheritable.
+ parent_process_id));
+ if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) {
+ DeathTestAbort("Unable to open parent process " +
+ StreamableToString(parent_process_id));
+ }
+
+ GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t));
+
+ const HANDLE write_handle =
+ reinterpret_cast<HANDLE>(write_handle_as_size_t);
+ HANDLE dup_write_handle;
+
+ // The newly initialized handle is accessible only in the parent
+ // process. To obtain one accessible within the child, we need to use
+ // DuplicateHandle.
+ if (!::DuplicateHandle(parent_process_handle.Get(), write_handle,
+ ::GetCurrentProcess(), &dup_write_handle,
+ 0x0, // Requested privileges ignored since
+ // DUPLICATE_SAME_ACCESS is used.
+ FALSE, // Request non-inheritable handler.
+ DUPLICATE_SAME_ACCESS)) {
+ DeathTestAbort("Unable to duplicate the pipe handle " +
+ StreamableToString(write_handle_as_size_t) +
+ " from the parent process " +
+ StreamableToString(parent_process_id));
+ }
+
+ const HANDLE event_handle = reinterpret_cast<HANDLE>(event_handle_as_size_t);
+ HANDLE dup_event_handle;
+
+ if (!::DuplicateHandle(parent_process_handle.Get(), event_handle,
+ ::GetCurrentProcess(), &dup_event_handle,
+ 0x0,
+ FALSE,
+ DUPLICATE_SAME_ACCESS)) {
+ DeathTestAbort("Unable to duplicate the event handle " +
+ StreamableToString(event_handle_as_size_t) +
+ " from the parent process " +
+ StreamableToString(parent_process_id));
+ }
+
+ const int write_fd =
+ ::_open_osfhandle(reinterpret_cast<intptr_t>(dup_write_handle), O_APPEND);
+ if (write_fd == -1) {
+ DeathTestAbort("Unable to convert pipe handle " +
+ StreamableToString(write_handle_as_size_t) +
+ " to a file descriptor");
+ }
+
+ // Signals the parent that the write end of the pipe has been acquired
+ // so the parent can release its own write end.
+ ::SetEvent(dup_event_handle);
+
+ return write_fd;
+}
+# endif // GTEST_OS_WINDOWS
+
+// Returns a newly created InternalRunDeathTestFlag object with fields
+// initialized from the GTEST_FLAG(internal_run_death_test) flag if
+// the flag is specified; otherwise returns NULL.
+InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
+ if (GTEST_FLAG(internal_run_death_test) == "") return nullptr;
+
+ // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we
+ // can use it here.
+ int line = -1;
+ int index = -1;
+ ::std::vector< ::std::string> fields;
+ SplitString(GTEST_FLAG(internal_run_death_test).c_str(), '|', &fields);
+ int write_fd = -1;
+
+# if GTEST_OS_WINDOWS
+
+ unsigned int parent_process_id = 0;
+ size_t write_handle_as_size_t = 0;
+ size_t event_handle_as_size_t = 0;
+
+ if (fields.size() != 6
+ || !ParseNaturalNumber(fields[1], &line)
+ || !ParseNaturalNumber(fields[2], &index)
+ || !ParseNaturalNumber(fields[3], &parent_process_id)
+ || !ParseNaturalNumber(fields[4], &write_handle_as_size_t)
+ || !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) {
+ DeathTestAbort("Bad --gtest_internal_run_death_test flag: " +
+ GTEST_FLAG(internal_run_death_test));
+ }
+ write_fd = GetStatusFileDescriptor(parent_process_id,
+ write_handle_as_size_t,
+ event_handle_as_size_t);
+
+# elif GTEST_OS_FUCHSIA
+
+ if (fields.size() != 3
+ || !ParseNaturalNumber(fields[1], &line)
+ || !ParseNaturalNumber(fields[2], &index)) {
+ DeathTestAbort("Bad --gtest_internal_run_death_test flag: "
+ + GTEST_FLAG(internal_run_death_test));
+ }
+
+# else
+
+ if (fields.size() != 4
+ || !ParseNaturalNumber(fields[1], &line)
+ || !ParseNaturalNumber(fields[2], &index)
+ || !ParseNaturalNumber(fields[3], &write_fd)) {
+ DeathTestAbort("Bad --gtest_internal_run_death_test flag: "
+ + GTEST_FLAG(internal_run_death_test));
+ }
+
+# endif // GTEST_OS_WINDOWS
+
+ return new InternalRunDeathTestFlag(fields[0], line, index, write_fd);
+}
+
+} // namespace internal
+
+#endif // GTEST_HAS_DEATH_TEST
+
+} // namespace testing
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gtest/internal/gtest-filepath.h"
+
+#include <stdlib.h>
+#include "gtest/internal/gtest-port.h"
+#include "gtest/gtest-message.h"
+
+#if GTEST_OS_WINDOWS_MOBILE
+# include <windows.h>
+#elif GTEST_OS_WINDOWS
+# include <direct.h>
+# include <io.h>
+#else
+# include <limits.h>
+# include <climits> // Some Linux distributions define PATH_MAX here.
+#endif // GTEST_OS_WINDOWS_MOBILE
+
+#include "gtest/internal/gtest-string.h"
+
+#if GTEST_OS_WINDOWS
+# define GTEST_PATH_MAX_ _MAX_PATH
+#elif defined(PATH_MAX)
+# define GTEST_PATH_MAX_ PATH_MAX
+#elif defined(_XOPEN_PATH_MAX)
+# define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
+#else
+# define GTEST_PATH_MAX_ _POSIX_PATH_MAX
+#endif // GTEST_OS_WINDOWS
+
+namespace testing {
+namespace internal {
+
+#if GTEST_OS_WINDOWS
+// On Windows, '\\' is the standard path separator, but many tools and the
+// Windows API also accept '/' as an alternate path separator. Unless otherwise
+// noted, a file path can contain either kind of path separators, or a mixture
+// of them.
+const char kPathSeparator = '\\';
+const char kAlternatePathSeparator = '/';
+const char kAlternatePathSeparatorString[] = "/";
+# if GTEST_OS_WINDOWS_MOBILE
+// Windows CE doesn't have a current directory. You should not use
+// the current directory in tests on Windows CE, but this at least
+// provides a reasonable fallback.
+const char kCurrentDirectoryString[] = "\\";
+// Windows CE doesn't define INVALID_FILE_ATTRIBUTES
+const DWORD kInvalidFileAttributes = 0xffffffff;
+# else
+const char kCurrentDirectoryString[] = ".\\";
+# endif // GTEST_OS_WINDOWS_MOBILE
+#else
+const char kPathSeparator = '/';
+const char kCurrentDirectoryString[] = "./";
+#endif // GTEST_OS_WINDOWS
+
+// Returns whether the given character is a valid path separator.
+static bool IsPathSeparator(char c) {
+#if GTEST_HAS_ALT_PATH_SEP_
+ return (c == kPathSeparator) || (c == kAlternatePathSeparator);
+#else
+ return c == kPathSeparator;
+#endif
+}
+
+// Returns the current working directory, or "" if unsuccessful.
+FilePath FilePath::GetCurrentDir() {
+#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
+ GTEST_OS_WINDOWS_RT || ARDUINO
+ // Windows CE and Arduino don't have a current directory, so we just return
+ // something reasonable.
+ return FilePath(kCurrentDirectoryString);
+#elif GTEST_OS_WINDOWS
+ char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
+ return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd);
+#else
+ char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
+ char* result = getcwd(cwd, sizeof(cwd));
+# if GTEST_OS_NACL
+ // getcwd will likely fail in NaCl due to the sandbox, so return something
+ // reasonable. The user may have provided a shim implementation for getcwd,
+ // however, so fallback only when failure is detected.
+ return FilePath(result == nullptr ? kCurrentDirectoryString : cwd);
+# endif // GTEST_OS_NACL
+ return FilePath(result == nullptr ? "" : cwd);
+#endif // GTEST_OS_WINDOWS_MOBILE
+}
+
+// Returns a copy of the FilePath with the case-insensitive extension removed.
+// Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
+// FilePath("dir/file"). If a case-insensitive extension is not
+// found, returns a copy of the original FilePath.
+FilePath FilePath::RemoveExtension(const char* extension) const {
+ const std::string dot_extension = std::string(".") + extension;
+ if (String::EndsWithCaseInsensitive(pathname_, dot_extension)) {
+ return FilePath(pathname_.substr(
+ 0, pathname_.length() - dot_extension.length()));
+ }
+ return *this;
+}
+
+// Returns a pointer to the last occurrence of a valid path separator in
+// the FilePath. On Windows, for example, both '/' and '\' are valid path
+// separators. Returns NULL if no path separator was found.
+const char* FilePath::FindLastPathSeparator() const {
+ const char* const last_sep = strrchr(c_str(), kPathSeparator);
+#if GTEST_HAS_ALT_PATH_SEP_
+ const char* const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator);
+ // Comparing two pointers of which only one is NULL is undefined.
+ if (last_alt_sep != nullptr &&
+ (last_sep == nullptr || last_alt_sep > last_sep)) {
+ return last_alt_sep;
+ }
+#endif
+ return last_sep;
+}
+
+// Returns a copy of the FilePath with the directory part removed.
+// Example: FilePath("path/to/file").RemoveDirectoryName() returns
+// FilePath("file"). If there is no directory part ("just_a_file"), it returns
+// the FilePath unmodified. If there is no file part ("just_a_dir/") it
+// returns an empty FilePath ("").
+// On Windows platform, '\' is the path separator, otherwise it is '/'.
+FilePath FilePath::RemoveDirectoryName() const {
+ const char* const last_sep = FindLastPathSeparator();
+ return last_sep ? FilePath(last_sep + 1) : *this;
+}
+
+// RemoveFileName returns the directory path with the filename removed.
+// Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
+// If the FilePath is "a_file" or "/a_file", RemoveFileName returns
+// FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
+// not have a file, like "just/a/dir/", it returns the FilePath unmodified.
+// On Windows platform, '\' is the path separator, otherwise it is '/'.
+FilePath FilePath::RemoveFileName() const {
+ const char* const last_sep = FindLastPathSeparator();
+ std::string dir;
+ if (last_sep) {
+ dir = std::string(c_str(), static_cast<size_t>(last_sep + 1 - c_str()));
+ } else {
+ dir = kCurrentDirectoryString;
+ }
+ return FilePath(dir);
+}
+
+// Helper functions for naming files in a directory for xml output.
+
+// Given directory = "dir", base_name = "test", number = 0,
+// extension = "xml", returns "dir/test.xml". If number is greater
+// than zero (e.g., 12), returns "dir/test_12.xml".
+// On Windows platform, uses \ as the separator rather than /.
+FilePath FilePath::MakeFileName(const FilePath& directory,
+ const FilePath& base_name,
+ int number,
+ const char* extension) {
+ std::string file;
+ if (number == 0) {
+ file = base_name.string() + "." + extension;
+ } else {
+ file = base_name.string() + "_" + StreamableToString(number)
+ + "." + extension;
+ }
+ return ConcatPaths(directory, FilePath(file));
+}
+
+// Given directory = "dir", relative_path = "test.xml", returns "dir/test.xml".
+// On Windows, uses \ as the separator rather than /.
+FilePath FilePath::ConcatPaths(const FilePath& directory,
+ const FilePath& relative_path) {
+ if (directory.IsEmpty())
+ return relative_path;
+ const FilePath dir(directory.RemoveTrailingPathSeparator());
+ return FilePath(dir.string() + kPathSeparator + relative_path.string());
+}
+
+// Returns true if pathname describes something findable in the file-system,
+// either a file, directory, or whatever.
+bool FilePath::FileOrDirectoryExists() const {
+#if GTEST_OS_WINDOWS_MOBILE
+ LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
+ const DWORD attributes = GetFileAttributes(unicode);
+ delete [] unicode;
+ return attributes != kInvalidFileAttributes;
+#else
+ posix::StatStruct file_stat;
+ return posix::Stat(pathname_.c_str(), &file_stat) == 0;
+#endif // GTEST_OS_WINDOWS_MOBILE
+}
+
+// Returns true if pathname describes a directory in the file-system
+// that exists.
+bool FilePath::DirectoryExists() const {
+ bool result = false;
+#if GTEST_OS_WINDOWS
+ // Don't strip off trailing separator if path is a root directory on
+ // Windows (like "C:\\").
+ const FilePath& path(IsRootDirectory() ? *this :
+ RemoveTrailingPathSeparator());
+#else
+ const FilePath& path(*this);
+#endif
+
+#if GTEST_OS_WINDOWS_MOBILE
+ LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
+ const DWORD attributes = GetFileAttributes(unicode);
+ delete [] unicode;
+ if ((attributes != kInvalidFileAttributes) &&
+ (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
+ result = true;
+ }
+#else
+ posix::StatStruct file_stat;
+ result = posix::Stat(path.c_str(), &file_stat) == 0 &&
+ posix::IsDir(file_stat);
+#endif // GTEST_OS_WINDOWS_MOBILE
+
+ return result;
+}
+
+// Returns true if pathname describes a root directory. (Windows has one
+// root directory per disk drive.)
+bool FilePath::IsRootDirectory() const {
+#if GTEST_OS_WINDOWS
+ return pathname_.length() == 3 && IsAbsolutePath();
+#else
+ return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
+#endif
+}
+
+// Returns true if pathname describes an absolute path.
+bool FilePath::IsAbsolutePath() const {
+ const char* const name = pathname_.c_str();
+#if GTEST_OS_WINDOWS
+ return pathname_.length() >= 3 &&
+ ((name[0] >= 'a' && name[0] <= 'z') ||
+ (name[0] >= 'A' && name[0] <= 'Z')) &&
+ name[1] == ':' &&
+ IsPathSeparator(name[2]);
+#else
+ return IsPathSeparator(name[0]);
+#endif
+}
+
+// Returns a pathname for a file that does not currently exist. The pathname
+// will be directory/base_name.extension or
+// directory/base_name_<number>.extension if directory/base_name.extension
+// already exists. The number will be incremented until a pathname is found
+// that does not already exist.
+// Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
+// There could be a race condition if two or more processes are calling this
+// function at the same time -- they could both pick the same filename.
+FilePath FilePath::GenerateUniqueFileName(const FilePath& directory,
+ const FilePath& base_name,
+ const char* extension) {
+ FilePath full_pathname;
+ int number = 0;
+ do {
+ full_pathname.Set(MakeFileName(directory, base_name, number++, extension));
+ } while (full_pathname.FileOrDirectoryExists());
+ return full_pathname;
+}
+
+// Returns true if FilePath ends with a path separator, which indicates that
+// it is intended to represent a directory. Returns false otherwise.
+// This does NOT check that a directory (or file) actually exists.
+bool FilePath::IsDirectory() const {
+ return !pathname_.empty() &&
+ IsPathSeparator(pathname_.c_str()[pathname_.length() - 1]);
+}
+
+// Create directories so that path exists. Returns true if successful or if
+// the directories already exist; returns false if unable to create directories
+// for any reason.
+bool FilePath::CreateDirectoriesRecursively() const {
+ if (!this->IsDirectory()) {
+ return false;
+ }
+
+ if (pathname_.length() == 0 || this->DirectoryExists()) {
+ return true;
+ }
+
+ const FilePath parent(this->RemoveTrailingPathSeparator().RemoveFileName());
+ return parent.CreateDirectoriesRecursively() && this->CreateFolder();
+}
+
+// Create the directory so that path exists. Returns true if successful or
+// if the directory already exists; returns false if unable to create the
+// directory for any reason, including if the parent directory does not
+// exist. Not named "CreateDirectory" because that's a macro on Windows.
+bool FilePath::CreateFolder() const {
+#if GTEST_OS_WINDOWS_MOBILE
+ FilePath removed_sep(this->RemoveTrailingPathSeparator());
+ LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
+ int result = CreateDirectory(unicode, nullptr) ? 0 : -1;
+ delete [] unicode;
+#elif GTEST_OS_WINDOWS
+ int result = _mkdir(pathname_.c_str());
+#else
+ int result = mkdir(pathname_.c_str(), 0777);
+#endif // GTEST_OS_WINDOWS_MOBILE
+
+ if (result == -1) {
+ return this->DirectoryExists(); // An error is OK if the directory exists.
+ }
+ return true; // No error.
+}
+
+// If input name has a trailing separator character, remove it and return the
+// name, otherwise return the name string unmodified.
+// On Windows platform, uses \ as the separator, other platforms use /.
+FilePath FilePath::RemoveTrailingPathSeparator() const {
+ return IsDirectory()
+ ? FilePath(pathname_.substr(0, pathname_.length() - 1))
+ : *this;
+}
+
+// Removes any redundant separators that might be in the pathname.
+// For example, "bar///foo" becomes "bar/foo". Does not eliminate other
+// redundancies that might be in a pathname involving "." or "..".
+void FilePath::Normalize() {
+ if (pathname_.c_str() == nullptr) {
+ pathname_ = "";
+ return;
+ }
+ const char* src = pathname_.c_str();
+ char* const dest = new char[pathname_.length() + 1];
+ char* dest_ptr = dest;
+ memset(dest_ptr, 0, pathname_.length() + 1);
+
+ while (*src != '\0') {
+ *dest_ptr = *src;
+ if (!IsPathSeparator(*src)) {
+ src++;
+ } else {
+#if GTEST_HAS_ALT_PATH_SEP_
+ if (*dest_ptr == kAlternatePathSeparator) {
+ *dest_ptr = kPathSeparator;
+ }
+#endif
+ while (IsPathSeparator(*src))
+ src++;
+ }
+ dest_ptr++;
+ }
+ *dest_ptr = '\0';
+ pathname_ = dest;
+ delete[] dest;
+}
+
+} // namespace internal
+} // namespace testing
--- /dev/null
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Utility functions and classes used by the Google C++ testing framework.//
+// This file contains purely Google Test's internal implementation. Please
+// DO NOT #INCLUDE IT IN A USER PROGRAM.
+
+#ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
+#define GTEST_SRC_GTEST_INTERNAL_INL_H_
+
+#ifndef _WIN32_WCE
+# include <errno.h>
+#endif // !_WIN32_WCE
+#include <stddef.h>
+#include <stdlib.h> // For strtoll/_strtoul64/malloc/free.
+#include <string.h> // For memmove.
+
+#include <algorithm>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "gtest/internal/gtest-port.h"
+
+#if GTEST_CAN_STREAM_RESULTS_
+# include <arpa/inet.h> // NOLINT
+# include <netdb.h> // NOLINT
+#endif
+
+#if GTEST_OS_WINDOWS
+# include <windows.h> // NOLINT
+#endif // GTEST_OS_WINDOWS
+
+#include "gtest/gtest.h"
+#include "gtest/gtest-spi.h"
+
+GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
+/* class A needs to have dll-interface to be used by clients of class B */)
+
+namespace testing {
+
+// Declares the flags.
+//
+// We don't want the users to modify this flag in the code, but want
+// Google Test's own unit tests to be able to access it. Therefore we
+// declare it here as opposed to in gtest.h.
+GTEST_DECLARE_bool_(death_test_use_fork);
+
+namespace internal {
+
+// The value of GetTestTypeId() as seen from within the Google Test
+// library. This is solely for testing GetTestTypeId().
+GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
+
+// Names of the flags (needed for parsing Google Test flags).
+const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
+const char kBreakOnFailureFlag[] = "break_on_failure";
+const char kCatchExceptionsFlag[] = "catch_exceptions";
+const char kColorFlag[] = "color";
+const char kFilterFlag[] = "filter";
+const char kListTestsFlag[] = "list_tests";
+const char kOutputFlag[] = "output";
+const char kPrintTimeFlag[] = "print_time";
+const char kPrintUTF8Flag[] = "print_utf8";
+const char kRandomSeedFlag[] = "random_seed";
+const char kRepeatFlag[] = "repeat";
+const char kShuffleFlag[] = "shuffle";
+const char kStackTraceDepthFlag[] = "stack_trace_depth";
+const char kStreamResultToFlag[] = "stream_result_to";
+const char kThrowOnFailureFlag[] = "throw_on_failure";
+const char kFlagfileFlag[] = "flagfile";
+
+// A valid random seed must be in [1, kMaxRandomSeed].
+const int kMaxRandomSeed = 99999;
+
+// g_help_flag is true iff the --help flag or an equivalent form is
+// specified on the command line.
+GTEST_API_ extern bool g_help_flag;
+
+// Returns the current time in milliseconds.
+GTEST_API_ TimeInMillis GetTimeInMillis();
+
+// Returns true iff Google Test should use colors in the output.
+GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
+
+// Formats the given time in milliseconds as seconds.
+GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
+
+// Converts the given time in milliseconds to a date string in the ISO 8601
+// format, without the timezone information. N.B.: due to the use the
+// non-reentrant localtime() function, this function is not thread safe. Do
+// not use it in any code that can be called from multiple threads.
+GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms);
+
+// Parses a string for an Int32 flag, in the form of "--flag=value".
+//
+// On success, stores the value of the flag in *value, and returns
+// true. On failure, returns false without changing *value.
+GTEST_API_ bool ParseInt32Flag(
+ const char* str, const char* flag, Int32* value);
+
+// Returns a random seed in range [1, kMaxRandomSeed] based on the
+// given --gtest_random_seed flag value.
+inline int GetRandomSeedFromFlag(Int32 random_seed_flag) {
+ const unsigned int raw_seed = (random_seed_flag == 0) ?
+ static_cast<unsigned int>(GetTimeInMillis()) :
+ static_cast<unsigned int>(random_seed_flag);
+
+ // Normalizes the actual seed to range [1, kMaxRandomSeed] such that
+ // it's easy to type.
+ const int normalized_seed =
+ static_cast<int>((raw_seed - 1U) %
+ static_cast<unsigned int>(kMaxRandomSeed)) + 1;
+ return normalized_seed;
+}
+
+// Returns the first valid random seed after 'seed'. The behavior is
+// undefined if 'seed' is invalid. The seed after kMaxRandomSeed is
+// considered to be 1.
+inline int GetNextRandomSeed(int seed) {
+ GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
+ << "Invalid random seed " << seed << " - must be in [1, "
+ << kMaxRandomSeed << "].";
+ const int next_seed = seed + 1;
+ return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
+}
+
+// This class saves the values of all Google Test flags in its c'tor, and
+// restores them in its d'tor.
+class GTestFlagSaver {
+ public:
+ // The c'tor.
+ GTestFlagSaver() {
+ also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
+ break_on_failure_ = GTEST_FLAG(break_on_failure);
+ catch_exceptions_ = GTEST_FLAG(catch_exceptions);
+ color_ = GTEST_FLAG(color);
+ death_test_style_ = GTEST_FLAG(death_test_style);
+ death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
+ filter_ = GTEST_FLAG(filter);
+ internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
+ list_tests_ = GTEST_FLAG(list_tests);
+ output_ = GTEST_FLAG(output);
+ print_time_ = GTEST_FLAG(print_time);
+ print_utf8_ = GTEST_FLAG(print_utf8);
+ random_seed_ = GTEST_FLAG(random_seed);
+ repeat_ = GTEST_FLAG(repeat);
+ shuffle_ = GTEST_FLAG(shuffle);
+ stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
+ stream_result_to_ = GTEST_FLAG(stream_result_to);
+ throw_on_failure_ = GTEST_FLAG(throw_on_failure);
+ }
+
+ // The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
+ ~GTestFlagSaver() {
+ GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
+ GTEST_FLAG(break_on_failure) = break_on_failure_;
+ GTEST_FLAG(catch_exceptions) = catch_exceptions_;
+ GTEST_FLAG(color) = color_;
+ GTEST_FLAG(death_test_style) = death_test_style_;
+ GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
+ GTEST_FLAG(filter) = filter_;
+ GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
+ GTEST_FLAG(list_tests) = list_tests_;
+ GTEST_FLAG(output) = output_;
+ GTEST_FLAG(print_time) = print_time_;
+ GTEST_FLAG(print_utf8) = print_utf8_;
+ GTEST_FLAG(random_seed) = random_seed_;
+ GTEST_FLAG(repeat) = repeat_;
+ GTEST_FLAG(shuffle) = shuffle_;
+ GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
+ GTEST_FLAG(stream_result_to) = stream_result_to_;
+ GTEST_FLAG(throw_on_failure) = throw_on_failure_;
+ }
+
+ private:
+ // Fields for saving the original values of flags.
+ bool also_run_disabled_tests_;
+ bool break_on_failure_;
+ bool catch_exceptions_;
+ std::string color_;
+ std::string death_test_style_;
+ bool death_test_use_fork_;
+ std::string filter_;
+ std::string internal_run_death_test_;
+ bool list_tests_;
+ std::string output_;
+ bool print_time_;
+ bool print_utf8_;
+ internal::Int32 random_seed_;
+ internal::Int32 repeat_;
+ bool shuffle_;
+ internal::Int32 stack_trace_depth_;
+ std::string stream_result_to_;
+ bool throw_on_failure_;
+} GTEST_ATTRIBUTE_UNUSED_;
+
+// Converts a Unicode code point to a narrow string in UTF-8 encoding.
+// code_point parameter is of type UInt32 because wchar_t may not be
+// wide enough to contain a code point.
+// If the code_point is not a valid Unicode code point
+// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted
+// to "(Invalid Unicode 0xXXXXXXXX)".
+GTEST_API_ std::string CodePointToUtf8(UInt32 code_point);
+
+// Converts a wide string to a narrow string in UTF-8 encoding.
+// The wide string is assumed to have the following encoding:
+// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin)
+// UTF-32 if sizeof(wchar_t) == 4 (on Linux)
+// Parameter str points to a null-terminated wide string.
+// Parameter num_chars may additionally limit the number
+// of wchar_t characters processed. -1 is used when the entire string
+// should be processed.
+// If the string contains code points that are not valid Unicode code points
+// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
+// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
+// and contains invalid UTF-16 surrogate pairs, values in those pairs
+// will be encoded as individual Unicode characters from Basic Normal Plane.
+GTEST_API_ std::string WideStringToUtf8(const wchar_t* str, int num_chars);
+
+// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
+// if the variable is present. If a file already exists at this location, this
+// function will write over it. If the variable is present, but the file cannot
+// be created, prints an error and exits.
+void WriteToShardStatusFileIfNeeded();
+
+// Checks whether sharding is enabled by examining the relevant
+// environment variable values. If the variables are present,
+// but inconsistent (e.g., shard_index >= total_shards), prints
+// an error and exits. If in_subprocess_for_death_test, sharding is
+// disabled because it must only be applied to the original test
+// process. Otherwise, we could filter out death tests we intended to execute.
+GTEST_API_ bool ShouldShard(const char* total_shards_str,
+ const char* shard_index_str,
+ bool in_subprocess_for_death_test);
+
+// Parses the environment variable var as an Int32. If it is unset,
+// returns default_val. If it is not an Int32, prints an error and
+// and aborts.
+GTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val);
+
+// Given the total number of shards, the shard index, and the test id,
+// returns true iff the test should be run on this shard. The test id is
+// some arbitrary but unique non-negative integer assigned to each test
+// method. Assumes that 0 <= shard_index < total_shards.
+GTEST_API_ bool ShouldRunTestOnShard(
+ int total_shards, int shard_index, int test_id);
+
+// STL container utilities.
+
+// Returns the number of elements in the given container that satisfy
+// the given predicate.
+template <class Container, typename Predicate>
+inline int CountIf(const Container& c, Predicate predicate) {
+ // Implemented as an explicit loop since std::count_if() in libCstd on
+ // Solaris has a non-standard signature.
+ int count = 0;
+ for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
+ if (predicate(*it))
+ ++count;
+ }
+ return count;
+}
+
+// Applies a function/functor to each element in the container.
+template <class Container, typename Functor>
+void ForEach(const Container& c, Functor functor) {
+ std::for_each(c.begin(), c.end(), functor);
+}
+
+// Returns the i-th element of the vector, or default_value if i is not
+// in range [0, v.size()).
+template <typename E>
+inline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
+ return (i < 0 || i >= static_cast<int>(v.size())) ? default_value
+ : v[static_cast<size_t>(i)];
+}
+
+// Performs an in-place shuffle of a range of the vector's elements.
+// 'begin' and 'end' are element indices as an STL-style range;
+// i.e. [begin, end) are shuffled, where 'end' == size() means to
+// shuffle to the end of the vector.
+template <typename E>
+void ShuffleRange(internal::Random* random, int begin, int end,
+ std::vector<E>* v) {
+ const int size = static_cast<int>(v->size());
+ GTEST_CHECK_(0 <= begin && begin <= size)
+ << "Invalid shuffle range start " << begin << ": must be in range [0, "
+ << size << "].";
+ GTEST_CHECK_(begin <= end && end <= size)
+ << "Invalid shuffle range finish " << end << ": must be in range ["
+ << begin << ", " << size << "].";
+
+ // Fisher-Yates shuffle, from
+ // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
+ for (int range_width = end - begin; range_width >= 2; range_width--) {
+ const int last_in_range = begin + range_width - 1;
+ const int selected =
+ begin +
+ static_cast<int>(random->Generate(static_cast<UInt32>(range_width)));
+ std::swap((*v)[static_cast<size_t>(selected)],
+ (*v)[static_cast<size_t>(last_in_range)]);
+ }
+}
+
+// Performs an in-place shuffle of the vector's elements.
+template <typename E>
+inline void Shuffle(internal::Random* random, std::vector<E>* v) {
+ ShuffleRange(random, 0, static_cast<int>(v->size()), v);
+}
+
+// A function for deleting an object. Handy for being used as a
+// functor.
+template <typename T>
+static void Delete(T* x) {
+ delete x;
+}
+
+// A predicate that checks the key of a TestProperty against a known key.
+//
+// TestPropertyKeyIs is copyable.
+class TestPropertyKeyIs {
+ public:
+ // Constructor.
+ //
+ // TestPropertyKeyIs has NO default constructor.
+ explicit TestPropertyKeyIs(const std::string& key) : key_(key) {}
+
+ // Returns true iff the test name of test property matches on key_.
+ bool operator()(const TestProperty& test_property) const {
+ return test_property.key() == key_;
+ }
+
+ private:
+ std::string key_;
+};
+
+// Class UnitTestOptions.
+//
+// This class contains functions for processing options the user
+// specifies when running the tests. It has only static members.
+//
+// In most cases, the user can specify an option using either an
+// environment variable or a command line flag. E.g. you can set the
+// test filter using either GTEST_FILTER or --gtest_filter. If both
+// the variable and the flag are present, the latter overrides the
+// former.
+class GTEST_API_ UnitTestOptions {
+ public:
+ // Functions for processing the gtest_output flag.
+
+ // Returns the output format, or "" for normal printed output.
+ static std::string GetOutputFormat();
+
+ // Returns the absolute path of the requested output file, or the
+ // default (test_detail.xml in the original working directory) if
+ // none was explicitly specified.
+ static std::string GetAbsolutePathToOutputFile();
+
+ // Functions for processing the gtest_filter flag.
+
+ // Returns true iff the wildcard pattern matches the string. The
+ // first ':' or '\0' character in pattern marks the end of it.
+ //
+ // This recursive algorithm isn't very efficient, but is clear and
+ // works well enough for matching test names, which are short.
+ static bool PatternMatchesString(const char *pattern, const char *str);
+
+ // Returns true iff the user-specified filter matches the test suite
+ // name and the test name.
+ static bool FilterMatchesTest(const std::string& test_suite_name,
+ const std::string& test_name);
+
+#if GTEST_OS_WINDOWS
+ // Function for supporting the gtest_catch_exception flag.
+
+ // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
+ // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
+ // This function is useful as an __except condition.
+ static int GTestShouldProcessSEH(DWORD exception_code);
+#endif // GTEST_OS_WINDOWS
+
+ // Returns true if "name" matches the ':' separated list of glob-style
+ // filters in "filter".
+ static bool MatchesFilter(const std::string& name, const char* filter);
+};
+
+// Returns the current application's name, removing directory path if that
+// is present. Used by UnitTestOptions::GetOutputFile.
+GTEST_API_ FilePath GetCurrentExecutableName();
+
+// The role interface for getting the OS stack trace as a string.
+class OsStackTraceGetterInterface {
+ public:
+ OsStackTraceGetterInterface() {}
+ virtual ~OsStackTraceGetterInterface() {}
+
+ // Returns the current OS stack trace as an std::string. Parameters:
+ //
+ // max_depth - the maximum number of stack frames to be included
+ // in the trace.
+ // skip_count - the number of top frames to be skipped; doesn't count
+ // against max_depth.
+ virtual std::string CurrentStackTrace(int max_depth, int skip_count) = 0;
+
+ // UponLeavingGTest() should be called immediately before Google Test calls
+ // user code. It saves some information about the current stack that
+ // CurrentStackTrace() will use to find and hide Google Test stack frames.
+ virtual void UponLeavingGTest() = 0;
+
+ // This string is inserted in place of stack frames that are part of
+ // Google Test's implementation.
+ static const char* const kElidedFramesMarker;
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
+};
+
+// A working implementation of the OsStackTraceGetterInterface interface.
+class OsStackTraceGetter : public OsStackTraceGetterInterface {
+ public:
+ OsStackTraceGetter() {}
+
+ std::string CurrentStackTrace(int max_depth, int skip_count) override;
+ void UponLeavingGTest() override;
+
+ private:
+#if GTEST_HAS_ABSL
+ Mutex mutex_; // Protects all internal state.
+
+ // We save the stack frame below the frame that calls user code.
+ // We do this because the address of the frame immediately below
+ // the user code changes between the call to UponLeavingGTest()
+ // and any calls to the stack trace code from within the user code.
+ void* caller_frame_ = nullptr;
+#endif // GTEST_HAS_ABSL
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
+};
+
+// Information about a Google Test trace point.
+struct TraceInfo {
+ const char* file;
+ int line;
+ std::string message;
+};
+
+// This is the default global test part result reporter used in UnitTestImpl.
+// This class should only be used by UnitTestImpl.
+class DefaultGlobalTestPartResultReporter
+ : public TestPartResultReporterInterface {
+ public:
+ explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
+ // Implements the TestPartResultReporterInterface. Reports the test part
+ // result in the current test.
+ void ReportTestPartResult(const TestPartResult& result) override;
+
+ private:
+ UnitTestImpl* const unit_test_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);
+};
+
+// This is the default per thread test part result reporter used in
+// UnitTestImpl. This class should only be used by UnitTestImpl.
+class DefaultPerThreadTestPartResultReporter
+ : public TestPartResultReporterInterface {
+ public:
+ explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
+ // Implements the TestPartResultReporterInterface. The implementation just
+ // delegates to the current global test part result reporter of *unit_test_.
+ void ReportTestPartResult(const TestPartResult& result) override;
+
+ private:
+ UnitTestImpl* const unit_test_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);
+};
+
+// The private implementation of the UnitTest class. We don't protect
+// the methods under a mutex, as this class is not accessible by a
+// user and the UnitTest class that delegates work to this class does
+// proper locking.
+class GTEST_API_ UnitTestImpl {
+ public:
+ explicit UnitTestImpl(UnitTest* parent);
+ virtual ~UnitTestImpl();
+
+ // There are two different ways to register your own TestPartResultReporter.
+ // You can register your own repoter to listen either only for test results
+ // from the current thread or for results from all threads.
+ // By default, each per-thread test result repoter just passes a new
+ // TestPartResult to the global test result reporter, which registers the
+ // test part result for the currently running test.
+
+ // Returns the global test part result reporter.
+ TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
+
+ // Sets the global test part result reporter.
+ void SetGlobalTestPartResultReporter(
+ TestPartResultReporterInterface* reporter);
+
+ // Returns the test part result reporter for the current thread.
+ TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
+
+ // Sets the test part result reporter for the current thread.
+ void SetTestPartResultReporterForCurrentThread(
+ TestPartResultReporterInterface* reporter);
+
+ // Gets the number of successful test suites.
+ int successful_test_suite_count() const;
+
+ // Gets the number of failed test suites.
+ int failed_test_suite_count() const;
+
+ // Gets the number of all test suites.
+ int total_test_suite_count() const;
+
+ // Gets the number of all test suites that contain at least one test
+ // that should run.
+ int test_suite_to_run_count() const;
+
+ // Gets the number of successful tests.
+ int successful_test_count() const;
+
+ // Gets the number of skipped tests.
+ int skipped_test_count() const;
+
+ // Gets the number of failed tests.
+ int failed_test_count() const;
+
+ // Gets the number of disabled tests that will be reported in the XML report.
+ int reportable_disabled_test_count() const;
+
+ // Gets the number of disabled tests.
+ int disabled_test_count() const;
+
+ // Gets the number of tests to be printed in the XML report.
+ int reportable_test_count() const;
+
+ // Gets the number of all tests.
+ int total_test_count() const;
+
+ // Gets the number of tests that should run.
+ int test_to_run_count() const;
+
+ // Gets the time of the test program start, in ms from the start of the
+ // UNIX epoch.
+ TimeInMillis start_timestamp() const { return start_timestamp_; }
+
+ // Gets the elapsed time, in milliseconds.
+ TimeInMillis elapsed_time() const { return elapsed_time_; }
+
+ // Returns true iff the unit test passed (i.e. all test suites passed).
+ bool Passed() const { return !Failed(); }
+
+ // Returns true iff the unit test failed (i.e. some test suite failed
+ // or something outside of all tests failed).
+ bool Failed() const {
+ return failed_test_suite_count() > 0 || ad_hoc_test_result()->Failed();
+ }
+
+ // Gets the i-th test suite among all the test suites. i can range from 0 to
+ // total_test_suite_count() - 1. If i is not in that range, returns NULL.
+ const TestSuite* GetTestSuite(int i) const {
+ const int index = GetElementOr(test_suite_indices_, i, -1);
+ return index < 0 ? nullptr : test_suites_[static_cast<size_t>(i)];
+ }
+
+ // Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ const TestCase* GetTestCase(int i) const { return GetTestSuite(i); }
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+ // Gets the i-th test suite among all the test suites. i can range from 0 to
+ // total_test_suite_count() - 1. If i is not in that range, returns NULL.
+ TestSuite* GetMutableSuiteCase(int i) {
+ const int index = GetElementOr(test_suite_indices_, i, -1);
+ return index < 0 ? nullptr : test_suites_[static_cast<size_t>(index)];
+ }
+
+ // Provides access to the event listener list.
+ TestEventListeners* listeners() { return &listeners_; }
+
+ // Returns the TestResult for the test that's currently running, or
+ // the TestResult for the ad hoc test if no test is running.
+ TestResult* current_test_result();
+
+ // Returns the TestResult for the ad hoc test.
+ const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
+
+ // Sets the OS stack trace getter.
+ //
+ // Does nothing if the input and the current OS stack trace getter
+ // are the same; otherwise, deletes the old getter and makes the
+ // input the current getter.
+ void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);
+
+ // Returns the current OS stack trace getter if it is not NULL;
+ // otherwise, creates an OsStackTraceGetter, makes it the current
+ // getter, and returns it.
+ OsStackTraceGetterInterface* os_stack_trace_getter();
+
+ // Returns the current OS stack trace as an std::string.
+ //
+ // The maximum number of stack frames to be included is specified by
+ // the gtest_stack_trace_depth flag. The skip_count parameter
+ // specifies the number of top frames to be skipped, which doesn't
+ // count against the number of frames to be included.
+ //
+ // For example, if Foo() calls Bar(), which in turn calls
+ // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
+ // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
+ std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
+
+ // Finds and returns a TestSuite with the given name. If one doesn't
+ // exist, creates one and returns it.
+ //
+ // Arguments:
+ //
+ // test_suite_name: name of the test suite
+ // type_param: the name of the test's type parameter, or NULL if
+ // this is not a typed or a type-parameterized test.
+ // set_up_tc: pointer to the function that sets up the test suite
+ // tear_down_tc: pointer to the function that tears down the test suite
+ TestSuite* GetTestSuite(const char* test_suite_name, const char* type_param,
+ internal::SetUpTestSuiteFunc set_up_tc,
+ internal::TearDownTestSuiteFunc tear_down_tc);
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+ TestCase* GetTestCase(const char* test_case_name, const char* type_param,
+ internal::SetUpTestSuiteFunc set_up_tc,
+ internal::TearDownTestSuiteFunc tear_down_tc) {
+ return GetTestSuite(test_case_name, type_param, set_up_tc, tear_down_tc);
+ }
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+ // Adds a TestInfo to the unit test.
+ //
+ // Arguments:
+ //
+ // set_up_tc: pointer to the function that sets up the test suite
+ // tear_down_tc: pointer to the function that tears down the test suite
+ // test_info: the TestInfo object
+ void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc,
+ internal::TearDownTestSuiteFunc tear_down_tc,
+ TestInfo* test_info) {
+ // In order to support thread-safe death tests, we need to
+ // remember the original working directory when the test program
+ // was first invoked. We cannot do this in RUN_ALL_TESTS(), as
+ // the user may have changed the current directory before calling
+ // RUN_ALL_TESTS(). Therefore we capture the current directory in
+ // AddTestInfo(), which is called to register a TEST or TEST_F
+ // before main() is reached.
+ if (original_working_dir_.IsEmpty()) {
+ original_working_dir_.Set(FilePath::GetCurrentDir());
+ GTEST_CHECK_(!original_working_dir_.IsEmpty())
+ << "Failed to get the current working directory.";
+ }
+
+ GetTestSuite(test_info->test_suite_name(), test_info->type_param(),
+ set_up_tc, tear_down_tc)
+ ->AddTestInfo(test_info);
+ }
+
+ // Returns ParameterizedTestSuiteRegistry object used to keep track of
+ // value-parameterized tests and instantiate and register them.
+ internal::ParameterizedTestSuiteRegistry& parameterized_test_registry() {
+ return parameterized_test_registry_;
+ }
+
+ // Sets the TestSuite object for the test that's currently running.
+ void set_current_test_suite(TestSuite* a_current_test_suite) {
+ current_test_suite_ = a_current_test_suite;
+ }
+
+ // Sets the TestInfo object for the test that's currently running. If
+ // current_test_info is NULL, the assertion results will be stored in
+ // ad_hoc_test_result_.
+ void set_current_test_info(TestInfo* a_current_test_info) {
+ current_test_info_ = a_current_test_info;
+ }
+
+ // Registers all parameterized tests defined using TEST_P and
+ // INSTANTIATE_TEST_SUITE_P, creating regular tests for each test/parameter
+ // combination. This method can be called more then once; it has guards
+ // protecting from registering the tests more then once. If
+ // value-parameterized tests are disabled, RegisterParameterizedTests is
+ // present but does nothing.
+ void RegisterParameterizedTests();
+
+ // Runs all tests in this UnitTest object, prints the result, and
+ // returns true if all tests are successful. If any exception is
+ // thrown during a test, this test is considered to be failed, but
+ // the rest of the tests will still be run.
+ bool RunAllTests();
+
+ // Clears the results of all tests, except the ad hoc tests.
+ void ClearNonAdHocTestResult() {
+ ForEach(test_suites_, TestSuite::ClearTestSuiteResult);
+ }
+
+ // Clears the results of ad-hoc test assertions.
+ void ClearAdHocTestResult() {
+ ad_hoc_test_result_.Clear();
+ }
+
+ // Adds a TestProperty to the current TestResult object when invoked in a
+ // context of a test or a test suite, or to the global property set. If the
+ // result already contains a property with the same key, the value will be
+ // updated.
+ void RecordProperty(const TestProperty& test_property);
+
+ enum ReactionToSharding {
+ HONOR_SHARDING_PROTOCOL,
+ IGNORE_SHARDING_PROTOCOL
+ };
+
+ // Matches the full name of each test against the user-specified
+ // filter to decide whether the test should run, then records the
+ // result in each TestSuite and TestInfo object.
+ // If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
+ // based on sharding variables in the environment.
+ // Returns the number of tests that should run.
+ int FilterTests(ReactionToSharding shard_tests);
+
+ // Prints the names of the tests matching the user-specified filter flag.
+ void ListTestsMatchingFilter();
+
+ const TestSuite* current_test_suite() const { return current_test_suite_; }
+ TestInfo* current_test_info() { return current_test_info_; }
+ const TestInfo* current_test_info() const { return current_test_info_; }
+
+ // Returns the vector of environments that need to be set-up/torn-down
+ // before/after the tests are run.
+ std::vector<Environment*>& environments() { return environments_; }
+
+ // Getters for the per-thread Google Test trace stack.
+ std::vector<TraceInfo>& gtest_trace_stack() {
+ return *(gtest_trace_stack_.pointer());
+ }
+ const std::vector<TraceInfo>& gtest_trace_stack() const {
+ return gtest_trace_stack_.get();
+ }
+
+#if GTEST_HAS_DEATH_TEST
+ void InitDeathTestSubprocessControlInfo() {
+ internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
+ }
+ // Returns a pointer to the parsed --gtest_internal_run_death_test
+ // flag, or NULL if that flag was not specified.
+ // This information is useful only in a death test child process.
+ // Must not be called before a call to InitGoogleTest.
+ const InternalRunDeathTestFlag* internal_run_death_test_flag() const {
+ return internal_run_death_test_flag_.get();
+ }
+
+ // Returns a pointer to the current death test factory.
+ internal::DeathTestFactory* death_test_factory() {
+ return death_test_factory_.get();
+ }
+
+ void SuppressTestEventsIfInSubprocess();
+
+ friend class ReplaceDeathTestFactory;
+#endif // GTEST_HAS_DEATH_TEST
+
+ // Initializes the event listener performing XML output as specified by
+ // UnitTestOptions. Must not be called before InitGoogleTest.
+ void ConfigureXmlOutput();
+
+#if GTEST_CAN_STREAM_RESULTS_
+ // Initializes the event listener for streaming test results to a socket.
+ // Must not be called before InitGoogleTest.
+ void ConfigureStreamingOutput();
+#endif
+
+ // Performs initialization dependent upon flag values obtained in
+ // ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
+ // ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
+ // this function is also called from RunAllTests. Since this function can be
+ // called more than once, it has to be idempotent.
+ void PostFlagParsingInit();
+
+ // Gets the random seed used at the start of the current test iteration.
+ int random_seed() const { return random_seed_; }
+
+ // Gets the random number generator.
+ internal::Random* random() { return &random_; }
+
+ // Shuffles all test suites, and the tests within each test suite,
+ // making sure that death tests are still run first.
+ void ShuffleTests();
+
+ // Restores the test suites and tests to their order before the first shuffle.
+ void UnshuffleTests();
+
+ // Returns the value of GTEST_FLAG(catch_exceptions) at the moment
+ // UnitTest::Run() starts.
+ bool catch_exceptions() const { return catch_exceptions_; }
+
+ private:
+ friend class ::testing::UnitTest;
+
+ // Used by UnitTest::Run() to capture the state of
+ // GTEST_FLAG(catch_exceptions) at the moment it starts.
+ void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
+
+ // The UnitTest object that owns this implementation object.
+ UnitTest* const parent_;
+
+ // The working directory when the first TEST() or TEST_F() was
+ // executed.
+ internal::FilePath original_working_dir_;
+
+ // The default test part result reporters.
+ DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
+ DefaultPerThreadTestPartResultReporter
+ default_per_thread_test_part_result_reporter_;
+
+ // Points to (but doesn't own) the global test part result reporter.
+ TestPartResultReporterInterface* global_test_part_result_repoter_;
+
+ // Protects read and write access to global_test_part_result_reporter_.
+ internal::Mutex global_test_part_result_reporter_mutex_;
+
+ // Points to (but doesn't own) the per-thread test part result reporter.
+ internal::ThreadLocal<TestPartResultReporterInterface*>
+ per_thread_test_part_result_reporter_;
+
+ // The vector of environments that need to be set-up/torn-down
+ // before/after the tests are run.
+ std::vector<Environment*> environments_;
+
+ // The vector of TestSuites in their original order. It owns the
+ // elements in the vector.
+ std::vector<TestSuite*> test_suites_;
+
+ // Provides a level of indirection for the test suite list to allow
+ // easy shuffling and restoring the test suite order. The i-th
+ // element of this vector is the index of the i-th test suite in the
+ // shuffled order.
+ std::vector<int> test_suite_indices_;
+
+ // ParameterizedTestRegistry object used to register value-parameterized
+ // tests.
+ internal::ParameterizedTestSuiteRegistry parameterized_test_registry_;
+
+ // Indicates whether RegisterParameterizedTests() has been called already.
+ bool parameterized_tests_registered_;
+
+ // Index of the last death test suite registered. Initially -1.
+ int last_death_test_suite_;
+
+ // This points to the TestSuite for the currently running test. It
+ // changes as Google Test goes through one test suite after another.
+ // When no test is running, this is set to NULL and Google Test
+ // stores assertion results in ad_hoc_test_result_. Initially NULL.
+ TestSuite* current_test_suite_;
+
+ // This points to the TestInfo for the currently running test. It
+ // changes as Google Test goes through one test after another. When
+ // no test is running, this is set to NULL and Google Test stores
+ // assertion results in ad_hoc_test_result_. Initially NULL.
+ TestInfo* current_test_info_;
+
+ // Normally, a user only writes assertions inside a TEST or TEST_F,
+ // or inside a function called by a TEST or TEST_F. Since Google
+ // Test keeps track of which test is current running, it can
+ // associate such an assertion with the test it belongs to.
+ //
+ // If an assertion is encountered when no TEST or TEST_F is running,
+ // Google Test attributes the assertion result to an imaginary "ad hoc"
+ // test, and records the result in ad_hoc_test_result_.
+ TestResult ad_hoc_test_result_;
+
+ // The list of event listeners that can be used to track events inside
+ // Google Test.
+ TestEventListeners listeners_;
+
+ // The OS stack trace getter. Will be deleted when the UnitTest
+ // object is destructed. By default, an OsStackTraceGetter is used,
+ // but the user can set this field to use a custom getter if that is
+ // desired.
+ OsStackTraceGetterInterface* os_stack_trace_getter_;
+
+ // True iff PostFlagParsingInit() has been called.
+ bool post_flag_parse_init_performed_;
+
+ // The random number seed used at the beginning of the test run.
+ int random_seed_;
+
+ // Our random number generator.
+ internal::Random random_;
+
+ // The time of the test program start, in ms from the start of the
+ // UNIX epoch.
+ TimeInMillis start_timestamp_;
+
+ // How long the test took to run, in milliseconds.
+ TimeInMillis elapsed_time_;
+
+#if GTEST_HAS_DEATH_TEST
+ // The decomposed components of the gtest_internal_run_death_test flag,
+ // parsed when RUN_ALL_TESTS is called.
+ std::unique_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
+ std::unique_ptr<internal::DeathTestFactory> death_test_factory_;
+#endif // GTEST_HAS_DEATH_TEST
+
+ // A per-thread stack of traces created by the SCOPED_TRACE() macro.
+ internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
+
+ // The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
+ // starts.
+ bool catch_exceptions_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
+}; // class UnitTestImpl
+
+// Convenience function for accessing the global UnitTest
+// implementation object.
+inline UnitTestImpl* GetUnitTestImpl() {
+ return UnitTest::GetInstance()->impl();
+}
+
+#if GTEST_USES_SIMPLE_RE
+
+// Internal helper functions for implementing the simple regular
+// expression matcher.
+GTEST_API_ bool IsInSet(char ch, const char* str);
+GTEST_API_ bool IsAsciiDigit(char ch);
+GTEST_API_ bool IsAsciiPunct(char ch);
+GTEST_API_ bool IsRepeat(char ch);
+GTEST_API_ bool IsAsciiWhiteSpace(char ch);
+GTEST_API_ bool IsAsciiWordChar(char ch);
+GTEST_API_ bool IsValidEscape(char ch);
+GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
+GTEST_API_ bool ValidateRegex(const char* regex);
+GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
+GTEST_API_ bool MatchRepetitionAndRegexAtHead(
+ bool escaped, char ch, char repeat, const char* regex, const char* str);
+GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
+
+#endif // GTEST_USES_SIMPLE_RE
+
+// Parses the command line for Google Test flags, without initializing
+// other parts of Google Test.
+GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
+GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
+
+#if GTEST_HAS_DEATH_TEST
+
+// Returns the message describing the last system error, regardless of the
+// platform.
+GTEST_API_ std::string GetLastErrnoDescription();
+
+// Attempts to parse a string into a positive integer pointed to by the
+// number parameter. Returns true if that is possible.
+// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
+// it here.
+template <typename Integer>
+bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
+ // Fail fast if the given string does not begin with a digit;
+ // this bypasses strtoXXX's "optional leading whitespace and plus
+ // or minus sign" semantics, which are undesirable here.
+ if (str.empty() || !IsDigit(str[0])) {
+ return false;
+ }
+ errno = 0;
+
+ char* end;
+ // BiggestConvertible is the largest integer type that system-provided
+ // string-to-number conversion routines can return.
+
+# if GTEST_OS_WINDOWS && !defined(__GNUC__)
+
+ // MSVC and C++ Builder define __int64 instead of the standard long long.
+ typedef unsigned __int64 BiggestConvertible;
+ const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
+
+# else
+
+ typedef unsigned long long BiggestConvertible; // NOLINT
+ const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
+
+# endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
+
+ const bool parse_success = *end == '\0' && errno == 0;
+
+ GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
+
+ const Integer result = static_cast<Integer>(parsed);
+ if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
+ *number = result;
+ return true;
+ }
+ return false;
+}
+#endif // GTEST_HAS_DEATH_TEST
+
+// TestResult contains some private methods that should be hidden from
+// Google Test user but are required for testing. This class allow our tests
+// to access them.
+//
+// This class is supplied only for the purpose of testing Google Test's own
+// constructs. Do not use it in user tests, either directly or indirectly.
+class TestResultAccessor {
+ public:
+ static void RecordProperty(TestResult* test_result,
+ const std::string& xml_element,
+ const TestProperty& property) {
+ test_result->RecordProperty(xml_element, property);
+ }
+
+ static void ClearTestPartResults(TestResult* test_result) {
+ test_result->ClearTestPartResults();
+ }
+
+ static const std::vector<testing::TestPartResult>& test_part_results(
+ const TestResult& test_result) {
+ return test_result.test_part_results();
+ }
+};
+
+#if GTEST_CAN_STREAM_RESULTS_
+
+// Streams test results to the given port on the given host machine.
+class StreamingListener : public EmptyTestEventListener {
+ public:
+ // Abstract base class for writing strings to a socket.
+ class AbstractSocketWriter {
+ public:
+ virtual ~AbstractSocketWriter() {}
+
+ // Sends a string to the socket.
+ virtual void Send(const std::string& message) = 0;
+
+ // Closes the socket.
+ virtual void CloseConnection() {}
+
+ // Sends a string and a newline to the socket.
+ void SendLn(const std::string& message) { Send(message + "\n"); }
+ };
+
+ // Concrete class for actually writing strings to a socket.
+ class SocketWriter : public AbstractSocketWriter {
+ public:
+ SocketWriter(const std::string& host, const std::string& port)
+ : sockfd_(-1), host_name_(host), port_num_(port) {
+ MakeConnection();
+ }
+
+ ~SocketWriter() override {
+ if (sockfd_ != -1)
+ CloseConnection();
+ }
+
+ // Sends a string to the socket.
+ void Send(const std::string& message) override {
+ GTEST_CHECK_(sockfd_ != -1)
+ << "Send() can be called only when there is a connection.";
+
+ const auto len = static_cast<size_t>(message.length());
+ if (write(sockfd_, message.c_str(), len) != static_cast<ssize_t>(len)) {
+ GTEST_LOG_(WARNING)
+ << "stream_result_to: failed to stream to "
+ << host_name_ << ":" << port_num_;
+ }
+ }
+
+ private:
+ // Creates a client socket and connects to the server.
+ void MakeConnection();
+
+ // Closes the socket.
+ void CloseConnection() override {
+ GTEST_CHECK_(sockfd_ != -1)
+ << "CloseConnection() can be called only when there is a connection.";
+
+ close(sockfd_);
+ sockfd_ = -1;
+ }
+
+ int sockfd_; // socket file descriptor
+ const std::string host_name_;
+ const std::string port_num_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter);
+ }; // class SocketWriter
+
+ // Escapes '=', '&', '%', and '\n' characters in str as "%xx".
+ static std::string UrlEncode(const char* str);
+
+ StreamingListener(const std::string& host, const std::string& port)
+ : socket_writer_(new SocketWriter(host, port)) {
+ Start();
+ }
+
+ explicit StreamingListener(AbstractSocketWriter* socket_writer)
+ : socket_writer_(socket_writer) { Start(); }
+
+ void OnTestProgramStart(const UnitTest& /* unit_test */) override {
+ SendLn("event=TestProgramStart");
+ }
+
+ void OnTestProgramEnd(const UnitTest& unit_test) override {
+ // Note that Google Test current only report elapsed time for each
+ // test iteration, not for the entire test program.
+ SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
+
+ // Notify the streaming server to stop.
+ socket_writer_->CloseConnection();
+ }
+
+ void OnTestIterationStart(const UnitTest& /* unit_test */,
+ int iteration) override {
+ SendLn("event=TestIterationStart&iteration=" +
+ StreamableToString(iteration));
+ }
+
+ void OnTestIterationEnd(const UnitTest& unit_test,
+ int /* iteration */) override {
+ SendLn("event=TestIterationEnd&passed=" +
+ FormatBool(unit_test.Passed()) + "&elapsed_time=" +
+ StreamableToString(unit_test.elapsed_time()) + "ms");
+ }
+
+ // Note that "event=TestCaseStart" is a wire format and has to remain
+ // "case" for compatibilty
+ void OnTestCaseStart(const TestCase& test_case) override {
+ SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
+ }
+
+ // Note that "event=TestCaseEnd" is a wire format and has to remain
+ // "case" for compatibilty
+ void OnTestCaseEnd(const TestCase& test_case) override {
+ SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed()) +
+ "&elapsed_time=" + StreamableToString(test_case.elapsed_time()) +
+ "ms");
+ }
+
+ void OnTestStart(const TestInfo& test_info) override {
+ SendLn(std::string("event=TestStart&name=") + test_info.name());
+ }
+
+ void OnTestEnd(const TestInfo& test_info) override {
+ SendLn("event=TestEnd&passed=" +
+ FormatBool((test_info.result())->Passed()) +
+ "&elapsed_time=" +
+ StreamableToString((test_info.result())->elapsed_time()) + "ms");
+ }
+
+ void OnTestPartResult(const TestPartResult& test_part_result) override {
+ const char* file_name = test_part_result.file_name();
+ if (file_name == nullptr) file_name = "";
+ SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
+ "&line=" + StreamableToString(test_part_result.line_number()) +
+ "&message=" + UrlEncode(test_part_result.message()));
+ }
+
+ private:
+ // Sends the given message and a newline to the socket.
+ void SendLn(const std::string& message) { socket_writer_->SendLn(message); }
+
+ // Called at the start of streaming to notify the receiver what
+ // protocol we are using.
+ void Start() { SendLn("gtest_streaming_protocol_version=1.0"); }
+
+ std::string FormatBool(bool value) { return value ? "1" : "0"; }
+
+ const std::unique_ptr<AbstractSocketWriter> socket_writer_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);
+}; // class StreamingListener
+
+#endif // GTEST_CAN_STREAM_RESULTS_
+
+} // namespace internal
+} // namespace testing
+
+GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
+
+#endif // GTEST_SRC_GTEST_INTERNAL_INL_H_
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The Google C++ Testing and Mocking Framework (Google Test)
+//
+// This file implements just enough of the matcher interface to allow
+// EXPECT_DEATH and friends to accept a matcher argument.
+
+#include "gtest/internal/gtest-internal.h"
+#include "gtest/internal/gtest-port.h"
+#include "gtest/gtest-matchers.h"
+
+#include <string>
+
+namespace testing {
+
+// Constructs a matcher that matches a const std::string& whose value is
+// equal to s.
+Matcher<const std::string&>::Matcher(const std::string& s) { *this = Eq(s); }
+
+// Constructs a matcher that matches a const std::string& whose value is
+// equal to s.
+Matcher<const std::string&>::Matcher(const char* s) {
+ *this = Eq(std::string(s));
+}
+
+// Constructs a matcher that matches a std::string whose value is equal to
+// s.
+Matcher<std::string>::Matcher(const std::string& s) { *this = Eq(s); }
+
+// Constructs a matcher that matches a std::string whose value is equal to
+// s.
+Matcher<std::string>::Matcher(const char* s) { *this = Eq(std::string(s)); }
+
+#if GTEST_HAS_ABSL
+// Constructs a matcher that matches a const absl::string_view& whose value is
+// equal to s.
+Matcher<const absl::string_view&>::Matcher(const std::string& s) {
+ *this = Eq(s);
+}
+
+// Constructs a matcher that matches a const absl::string_view& whose value is
+// equal to s.
+Matcher<const absl::string_view&>::Matcher(const char* s) {
+ *this = Eq(std::string(s));
+}
+
+// Constructs a matcher that matches a const absl::string_view& whose value is
+// equal to s.
+Matcher<const absl::string_view&>::Matcher(absl::string_view s) {
+ *this = Eq(std::string(s));
+}
+
+// Constructs a matcher that matches a absl::string_view whose value is equal to
+// s.
+Matcher<absl::string_view>::Matcher(const std::string& s) { *this = Eq(s); }
+
+// Constructs a matcher that matches a absl::string_view whose value is equal to
+// s.
+Matcher<absl::string_view>::Matcher(const char* s) {
+ *this = Eq(std::string(s));
+}
+
+// Constructs a matcher that matches a absl::string_view whose value is equal to
+// s.
+Matcher<absl::string_view>::Matcher(absl::string_view s) {
+ *this = Eq(std::string(s));
+}
+#endif // GTEST_HAS_ABSL
+
+} // namespace testing
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+#include "gtest/internal/gtest-port.h"
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fstream>
+#include <memory>
+
+#if GTEST_OS_WINDOWS
+# include <windows.h>
+# include <io.h>
+# include <sys/stat.h>
+# include <map> // Used in ThreadLocal.
+# ifdef _MSC_VER
+# include <crtdbg.h>
+# endif // _MSC_VER
+#else
+# include <unistd.h>
+#endif // GTEST_OS_WINDOWS
+
+#if GTEST_OS_MAC
+# include <mach/mach_init.h>
+# include <mach/task.h>
+# include <mach/vm_map.h>
+#endif // GTEST_OS_MAC
+
+#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \
+ GTEST_OS_NETBSD || GTEST_OS_OPENBSD
+# include <sys/sysctl.h>
+# if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD
+# include <sys/user.h>
+# endif
+#endif
+
+#if GTEST_OS_QNX
+# include <devctl.h>
+# include <fcntl.h>
+# include <sys/procfs.h>
+#endif // GTEST_OS_QNX
+
+#if GTEST_OS_AIX
+# include <procinfo.h>
+# include <sys/types.h>
+#endif // GTEST_OS_AIX
+
+#if GTEST_OS_FUCHSIA
+# include <zircon/process.h>
+# include <zircon/syscalls.h>
+#endif // GTEST_OS_FUCHSIA
+
+#include "gtest/gtest-spi.h"
+#include "gtest/gtest-message.h"
+#include "gtest/internal/gtest-internal.h"
+#include "gtest/internal/gtest-string.h"
+#include "src/gtest-internal-inl.h"
+
+namespace testing {
+namespace internal {
+
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+// MSVC and C++Builder do not provide a definition of STDERR_FILENO.
+const int kStdOutFileno = 1;
+const int kStdErrFileno = 2;
+#else
+const int kStdOutFileno = STDOUT_FILENO;
+const int kStdErrFileno = STDERR_FILENO;
+#endif // _MSC_VER
+
+#if GTEST_OS_LINUX
+
+namespace {
+template <typename T>
+T ReadProcFileField(const std::string& filename, int field) {
+ std::string dummy;
+ std::ifstream file(filename.c_str());
+ while (field-- > 0) {
+ file >> dummy;
+ }
+ T output = 0;
+ file >> output;
+ return output;
+}
+} // namespace
+
+// Returns the number of active threads, or 0 when there is an error.
+size_t GetThreadCount() {
+ const std::string filename =
+ (Message() << "/proc/" << getpid() << "/stat").GetString();
+ return ReadProcFileField<size_t>(filename, 19);
+}
+
+#elif GTEST_OS_MAC
+
+size_t GetThreadCount() {
+ const task_t task = mach_task_self();
+ mach_msg_type_number_t thread_count;
+ thread_act_array_t thread_list;
+ const kern_return_t status = task_threads(task, &thread_list, &thread_count);
+ if (status == KERN_SUCCESS) {
+ // task_threads allocates resources in thread_list and we need to free them
+ // to avoid leaks.
+ vm_deallocate(task,
+ reinterpret_cast<vm_address_t>(thread_list),
+ sizeof(thread_t) * thread_count);
+ return static_cast<size_t>(thread_count);
+ } else {
+ return 0;
+ }
+}
+
+#elif GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \
+ GTEST_OS_NETBSD
+
+#if GTEST_OS_NETBSD
+#undef KERN_PROC
+#define KERN_PROC KERN_PROC2
+#define kinfo_proc kinfo_proc2
+#endif
+
+#if GTEST_OS_DRAGONFLY
+#define KP_NLWP(kp) (kp.kp_nthreads)
+#elif GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD
+#define KP_NLWP(kp) (kp.ki_numthreads)
+#elif GTEST_OS_NETBSD
+#define KP_NLWP(kp) (kp.p_nlwps)
+#endif
+
+// Returns the number of threads running in the process, or 0 to indicate that
+// we cannot detect it.
+size_t GetThreadCount() {
+ int mib[] = {
+ CTL_KERN,
+ KERN_PROC,
+ KERN_PROC_PID,
+ getpid(),
+#if GTEST_OS_NETBSD
+ sizeof(struct kinfo_proc),
+ 1,
+#endif
+ };
+ u_int miblen = sizeof(mib) / sizeof(mib[0]);
+ struct kinfo_proc info;
+ size_t size = sizeof(info);
+ if (sysctl(mib, miblen, &info, &size, NULL, 0)) {
+ return 0;
+ }
+ return static_cast<size_t>(KP_NLWP(info));
+}
+#elif GTEST_OS_OPENBSD
+
+// Returns the number of threads running in the process, or 0 to indicate that
+// we cannot detect it.
+size_t GetThreadCount() {
+ int mib[] = {
+ CTL_KERN,
+ KERN_PROC,
+ KERN_PROC_PID | KERN_PROC_SHOW_THREADS,
+ getpid(),
+ sizeof(struct kinfo_proc),
+ 0,
+ };
+ u_int miblen = sizeof(mib) / sizeof(mib[0]);
+
+ // get number of structs
+ size_t size;
+ if (sysctl(mib, miblen, NULL, &size, NULL, 0)) {
+ return 0;
+ }
+ mib[5] = size / mib[4];
+
+ // populate array of structs
+ struct kinfo_proc info[mib[5]];
+ if (sysctl(mib, miblen, &info, &size, NULL, 0)) {
+ return 0;
+ }
+
+ // exclude empty members
+ int nthreads = 0;
+ for (int i = 0; i < size / mib[4]; i++) {
+ if (info[i].p_tid != -1)
+ nthreads++;
+ }
+ return nthreads;
+}
+
+#elif GTEST_OS_QNX
+
+// Returns the number of threads running in the process, or 0 to indicate that
+// we cannot detect it.
+size_t GetThreadCount() {
+ const int fd = open("/proc/self/as", O_RDONLY);
+ if (fd < 0) {
+ return 0;
+ }
+ procfs_info process_info;
+ const int status =
+ devctl(fd, DCMD_PROC_INFO, &process_info, sizeof(process_info), nullptr);
+ close(fd);
+ if (status == EOK) {
+ return static_cast<size_t>(process_info.num_threads);
+ } else {
+ return 0;
+ }
+}
+
+#elif GTEST_OS_AIX
+
+size_t GetThreadCount() {
+ struct procentry64 entry;
+ pid_t pid = getpid();
+ int status = getprocs64(&entry, sizeof(entry), nullptr, 0, &pid, 1);
+ if (status == 1) {
+ return entry.pi_thcount;
+ } else {
+ return 0;
+ }
+}
+
+#elif GTEST_OS_FUCHSIA
+
+size_t GetThreadCount() {
+ int dummy_buffer;
+ size_t avail;
+ zx_status_t status = zx_object_get_info(
+ zx_process_self(),
+ ZX_INFO_PROCESS_THREADS,
+ &dummy_buffer,
+ 0,
+ nullptr,
+ &avail);
+ if (status == ZX_OK) {
+ return avail;
+ } else {
+ return 0;
+ }
+}
+
+#else
+
+size_t GetThreadCount() {
+ // There's no portable way to detect the number of threads, so we just
+ // return 0 to indicate that we cannot detect it.
+ return 0;
+}
+
+#endif // GTEST_OS_LINUX
+
+#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
+
+void SleepMilliseconds(int n) {
+ ::Sleep(static_cast<DWORD>(n));
+}
+
+AutoHandle::AutoHandle()
+ : handle_(INVALID_HANDLE_VALUE) {}
+
+AutoHandle::AutoHandle(Handle handle)
+ : handle_(handle) {}
+
+AutoHandle::~AutoHandle() {
+ Reset();
+}
+
+AutoHandle::Handle AutoHandle::Get() const {
+ return handle_;
+}
+
+void AutoHandle::Reset() {
+ Reset(INVALID_HANDLE_VALUE);
+}
+
+void AutoHandle::Reset(HANDLE handle) {
+ // Resetting with the same handle we already own is invalid.
+ if (handle_ != handle) {
+ if (IsCloseable()) {
+ ::CloseHandle(handle_);
+ }
+ handle_ = handle;
+ } else {
+ GTEST_CHECK_(!IsCloseable())
+ << "Resetting a valid handle to itself is likely a programmer error "
+ "and thus not allowed.";
+ }
+}
+
+bool AutoHandle::IsCloseable() const {
+ // Different Windows APIs may use either of these values to represent an
+ // invalid handle.
+ return handle_ != nullptr && handle_ != INVALID_HANDLE_VALUE;
+}
+
+Notification::Notification()
+ : event_(::CreateEvent(nullptr, // Default security attributes.
+ TRUE, // Do not reset automatically.
+ FALSE, // Initially unset.
+ nullptr)) { // Anonymous event.
+ GTEST_CHECK_(event_.Get() != nullptr);
+}
+
+void Notification::Notify() {
+ GTEST_CHECK_(::SetEvent(event_.Get()) != FALSE);
+}
+
+void Notification::WaitForNotification() {
+ GTEST_CHECK_(
+ ::WaitForSingleObject(event_.Get(), INFINITE) == WAIT_OBJECT_0);
+}
+
+Mutex::Mutex()
+ : owner_thread_id_(0),
+ type_(kDynamic),
+ critical_section_init_phase_(0),
+ critical_section_(new CRITICAL_SECTION) {
+ ::InitializeCriticalSection(critical_section_);
+}
+
+Mutex::~Mutex() {
+ // Static mutexes are leaked intentionally. It is not thread-safe to try
+ // to clean them up.
+ if (type_ == kDynamic) {
+ ::DeleteCriticalSection(critical_section_);
+ delete critical_section_;
+ critical_section_ = nullptr;
+ }
+}
+
+void Mutex::Lock() {
+ ThreadSafeLazyInit();
+ ::EnterCriticalSection(critical_section_);
+ owner_thread_id_ = ::GetCurrentThreadId();
+}
+
+void Mutex::Unlock() {
+ ThreadSafeLazyInit();
+ // We don't protect writing to owner_thread_id_ here, as it's the
+ // caller's responsibility to ensure that the current thread holds the
+ // mutex when this is called.
+ owner_thread_id_ = 0;
+ ::LeaveCriticalSection(critical_section_);
+}
+
+// Does nothing if the current thread holds the mutex. Otherwise, crashes
+// with high probability.
+void Mutex::AssertHeld() {
+ ThreadSafeLazyInit();
+ GTEST_CHECK_(owner_thread_id_ == ::GetCurrentThreadId())
+ << "The current thread is not holding the mutex @" << this;
+}
+
+namespace {
+
+#ifdef _MSC_VER
+// Use the RAII idiom to flag mem allocs that are intentionally never
+// deallocated. The motivation is to silence the false positive mem leaks
+// that are reported by the debug version of MS's CRT which can only detect
+// if an alloc is missing a matching deallocation.
+// Example:
+// MemoryIsNotDeallocated memory_is_not_deallocated;
+// critical_section_ = new CRITICAL_SECTION;
+//
+class MemoryIsNotDeallocated
+{
+ public:
+ MemoryIsNotDeallocated() : old_crtdbg_flag_(0) {
+ old_crtdbg_flag_ = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
+ // Set heap allocation block type to _IGNORE_BLOCK so that MS debug CRT
+ // doesn't report mem leak if there's no matching deallocation.
+ _CrtSetDbgFlag(old_crtdbg_flag_ & ~_CRTDBG_ALLOC_MEM_DF);
+ }
+
+ ~MemoryIsNotDeallocated() {
+ // Restore the original _CRTDBG_ALLOC_MEM_DF flag
+ _CrtSetDbgFlag(old_crtdbg_flag_);
+ }
+
+ private:
+ int old_crtdbg_flag_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MemoryIsNotDeallocated);
+};
+#endif // _MSC_VER
+
+} // namespace
+
+// Initializes owner_thread_id_ and critical_section_ in static mutexes.
+void Mutex::ThreadSafeLazyInit() {
+ // Dynamic mutexes are initialized in the constructor.
+ if (type_ == kStatic) {
+ switch (
+ ::InterlockedCompareExchange(&critical_section_init_phase_, 1L, 0L)) {
+ case 0:
+ // If critical_section_init_phase_ was 0 before the exchange, we
+ // are the first to test it and need to perform the initialization.
+ owner_thread_id_ = 0;
+ {
+ // Use RAII to flag that following mem alloc is never deallocated.
+#ifdef _MSC_VER
+ MemoryIsNotDeallocated memory_is_not_deallocated;
+#endif // _MSC_VER
+ critical_section_ = new CRITICAL_SECTION;
+ }
+ ::InitializeCriticalSection(critical_section_);
+ // Updates the critical_section_init_phase_ to 2 to signal
+ // initialization complete.
+ GTEST_CHECK_(::InterlockedCompareExchange(
+ &critical_section_init_phase_, 2L, 1L) ==
+ 1L);
+ break;
+ case 1:
+ // Somebody else is already initializing the mutex; spin until they
+ // are done.
+ while (::InterlockedCompareExchange(&critical_section_init_phase_,
+ 2L,
+ 2L) != 2L) {
+ // Possibly yields the rest of the thread's time slice to other
+ // threads.
+ ::Sleep(0);
+ }
+ break;
+
+ case 2:
+ break; // The mutex is already initialized and ready for use.
+
+ default:
+ GTEST_CHECK_(false)
+ << "Unexpected value of critical_section_init_phase_ "
+ << "while initializing a static mutex.";
+ }
+ }
+}
+
+namespace {
+
+class ThreadWithParamSupport : public ThreadWithParamBase {
+ public:
+ static HANDLE CreateThread(Runnable* runnable,
+ Notification* thread_can_start) {
+ ThreadMainParam* param = new ThreadMainParam(runnable, thread_can_start);
+ DWORD thread_id;
+ HANDLE thread_handle = ::CreateThread(
+ nullptr, // Default security.
+ 0, // Default stack size.
+ &ThreadWithParamSupport::ThreadMain,
+ param, // Parameter to ThreadMainStatic
+ 0x0, // Default creation flags.
+ &thread_id); // Need a valid pointer for the call to work under Win98.
+ GTEST_CHECK_(thread_handle != nullptr)
+ << "CreateThread failed with error " << ::GetLastError() << ".";
+ if (thread_handle == nullptr) {
+ delete param;
+ }
+ return thread_handle;
+ }
+
+ private:
+ struct ThreadMainParam {
+ ThreadMainParam(Runnable* runnable, Notification* thread_can_start)
+ : runnable_(runnable),
+ thread_can_start_(thread_can_start) {
+ }
+ std::unique_ptr<Runnable> runnable_;
+ // Does not own.
+ Notification* thread_can_start_;
+ };
+
+ static DWORD WINAPI ThreadMain(void* ptr) {
+ // Transfers ownership.
+ std::unique_ptr<ThreadMainParam> param(static_cast<ThreadMainParam*>(ptr));
+ if (param->thread_can_start_ != nullptr)
+ param->thread_can_start_->WaitForNotification();
+ param->runnable_->Run();
+ return 0;
+ }
+
+ // Prohibit instantiation.
+ ThreadWithParamSupport();
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParamSupport);
+};
+
+} // namespace
+
+ThreadWithParamBase::ThreadWithParamBase(Runnable *runnable,
+ Notification* thread_can_start)
+ : thread_(ThreadWithParamSupport::CreateThread(runnable,
+ thread_can_start)) {
+}
+
+ThreadWithParamBase::~ThreadWithParamBase() {
+ Join();
+}
+
+void ThreadWithParamBase::Join() {
+ GTEST_CHECK_(::WaitForSingleObject(thread_.Get(), INFINITE) == WAIT_OBJECT_0)
+ << "Failed to join the thread with error " << ::GetLastError() << ".";
+}
+
+// Maps a thread to a set of ThreadIdToThreadLocals that have values
+// instantiated on that thread and notifies them when the thread exits. A
+// ThreadLocal instance is expected to persist until all threads it has
+// values on have terminated.
+class ThreadLocalRegistryImpl {
+ public:
+ // Registers thread_local_instance as having value on the current thread.
+ // Returns a value that can be used to identify the thread from other threads.
+ static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
+ const ThreadLocalBase* thread_local_instance) {
+ DWORD current_thread = ::GetCurrentThreadId();
+ MutexLock lock(&mutex_);
+ ThreadIdToThreadLocals* const thread_to_thread_locals =
+ GetThreadLocalsMapLocked();
+ ThreadIdToThreadLocals::iterator thread_local_pos =
+ thread_to_thread_locals->find(current_thread);
+ if (thread_local_pos == thread_to_thread_locals->end()) {
+ thread_local_pos = thread_to_thread_locals->insert(
+ std::make_pair(current_thread, ThreadLocalValues())).first;
+ StartWatcherThreadFor(current_thread);
+ }
+ ThreadLocalValues& thread_local_values = thread_local_pos->second;
+ ThreadLocalValues::iterator value_pos =
+ thread_local_values.find(thread_local_instance);
+ if (value_pos == thread_local_values.end()) {
+ value_pos =
+ thread_local_values
+ .insert(std::make_pair(
+ thread_local_instance,
+ std::shared_ptr<ThreadLocalValueHolderBase>(
+ thread_local_instance->NewValueForCurrentThread())))
+ .first;
+ }
+ return value_pos->second.get();
+ }
+
+ static void OnThreadLocalDestroyed(
+ const ThreadLocalBase* thread_local_instance) {
+ std::vector<std::shared_ptr<ThreadLocalValueHolderBase> > value_holders;
+ // Clean up the ThreadLocalValues data structure while holding the lock, but
+ // defer the destruction of the ThreadLocalValueHolderBases.
+ {
+ MutexLock lock(&mutex_);
+ ThreadIdToThreadLocals* const thread_to_thread_locals =
+ GetThreadLocalsMapLocked();
+ for (ThreadIdToThreadLocals::iterator it =
+ thread_to_thread_locals->begin();
+ it != thread_to_thread_locals->end();
+ ++it) {
+ ThreadLocalValues& thread_local_values = it->second;
+ ThreadLocalValues::iterator value_pos =
+ thread_local_values.find(thread_local_instance);
+ if (value_pos != thread_local_values.end()) {
+ value_holders.push_back(value_pos->second);
+ thread_local_values.erase(value_pos);
+ // This 'if' can only be successful at most once, so theoretically we
+ // could break out of the loop here, but we don't bother doing so.
+ }
+ }
+ }
+ // Outside the lock, let the destructor for 'value_holders' deallocate the
+ // ThreadLocalValueHolderBases.
+ }
+
+ static void OnThreadExit(DWORD thread_id) {
+ GTEST_CHECK_(thread_id != 0) << ::GetLastError();
+ std::vector<std::shared_ptr<ThreadLocalValueHolderBase> > value_holders;
+ // Clean up the ThreadIdToThreadLocals data structure while holding the
+ // lock, but defer the destruction of the ThreadLocalValueHolderBases.
+ {
+ MutexLock lock(&mutex_);
+ ThreadIdToThreadLocals* const thread_to_thread_locals =
+ GetThreadLocalsMapLocked();
+ ThreadIdToThreadLocals::iterator thread_local_pos =
+ thread_to_thread_locals->find(thread_id);
+ if (thread_local_pos != thread_to_thread_locals->end()) {
+ ThreadLocalValues& thread_local_values = thread_local_pos->second;
+ for (ThreadLocalValues::iterator value_pos =
+ thread_local_values.begin();
+ value_pos != thread_local_values.end();
+ ++value_pos) {
+ value_holders.push_back(value_pos->second);
+ }
+ thread_to_thread_locals->erase(thread_local_pos);
+ }
+ }
+ // Outside the lock, let the destructor for 'value_holders' deallocate the
+ // ThreadLocalValueHolderBases.
+ }
+
+ private:
+ // In a particular thread, maps a ThreadLocal object to its value.
+ typedef std::map<const ThreadLocalBase*,
+ std::shared_ptr<ThreadLocalValueHolderBase> >
+ ThreadLocalValues;
+ // Stores all ThreadIdToThreadLocals having values in a thread, indexed by
+ // thread's ID.
+ typedef std::map<DWORD, ThreadLocalValues> ThreadIdToThreadLocals;
+
+ // Holds the thread id and thread handle that we pass from
+ // StartWatcherThreadFor to WatcherThreadFunc.
+ typedef std::pair<DWORD, HANDLE> ThreadIdAndHandle;
+
+ static void StartWatcherThreadFor(DWORD thread_id) {
+ // The returned handle will be kept in thread_map and closed by
+ // watcher_thread in WatcherThreadFunc.
+ HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION,
+ FALSE,
+ thread_id);
+ GTEST_CHECK_(thread != nullptr);
+ // We need to pass a valid thread ID pointer into CreateThread for it
+ // to work correctly under Win98.
+ DWORD watcher_thread_id;
+ HANDLE watcher_thread = ::CreateThread(
+ nullptr, // Default security.
+ 0, // Default stack size
+ &ThreadLocalRegistryImpl::WatcherThreadFunc,
+ reinterpret_cast<LPVOID>(new ThreadIdAndHandle(thread_id, thread)),
+ CREATE_SUSPENDED, &watcher_thread_id);
+ GTEST_CHECK_(watcher_thread != nullptr);
+ // Give the watcher thread the same priority as ours to avoid being
+ // blocked by it.
+ ::SetThreadPriority(watcher_thread,
+ ::GetThreadPriority(::GetCurrentThread()));
+ ::ResumeThread(watcher_thread);
+ ::CloseHandle(watcher_thread);
+ }
+
+ // Monitors exit from a given thread and notifies those
+ // ThreadIdToThreadLocals about thread termination.
+ static DWORD WINAPI WatcherThreadFunc(LPVOID param) {
+ const ThreadIdAndHandle* tah =
+ reinterpret_cast<const ThreadIdAndHandle*>(param);
+ GTEST_CHECK_(
+ ::WaitForSingleObject(tah->second, INFINITE) == WAIT_OBJECT_0);
+ OnThreadExit(tah->first);
+ ::CloseHandle(tah->second);
+ delete tah;
+ return 0;
+ }
+
+ // Returns map of thread local instances.
+ static ThreadIdToThreadLocals* GetThreadLocalsMapLocked() {
+ mutex_.AssertHeld();
+#ifdef _MSC_VER
+ MemoryIsNotDeallocated memory_is_not_deallocated;
+#endif // _MSC_VER
+ static ThreadIdToThreadLocals* map = new ThreadIdToThreadLocals();
+ return map;
+ }
+
+ // Protects access to GetThreadLocalsMapLocked() and its return value.
+ static Mutex mutex_;
+ // Protects access to GetThreadMapLocked() and its return value.
+ static Mutex thread_map_mutex_;
+};
+
+Mutex ThreadLocalRegistryImpl::mutex_(Mutex::kStaticMutex);
+Mutex ThreadLocalRegistryImpl::thread_map_mutex_(Mutex::kStaticMutex);
+
+ThreadLocalValueHolderBase* ThreadLocalRegistry::GetValueOnCurrentThread(
+ const ThreadLocalBase* thread_local_instance) {
+ return ThreadLocalRegistryImpl::GetValueOnCurrentThread(
+ thread_local_instance);
+}
+
+void ThreadLocalRegistry::OnThreadLocalDestroyed(
+ const ThreadLocalBase* thread_local_instance) {
+ ThreadLocalRegistryImpl::OnThreadLocalDestroyed(thread_local_instance);
+}
+
+#endif // GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
+
+#if GTEST_USES_POSIX_RE
+
+// Implements RE. Currently only needed for death tests.
+
+RE::~RE() {
+ if (is_valid_) {
+ // regfree'ing an invalid regex might crash because the content
+ // of the regex is undefined. Since the regex's are essentially
+ // the same, one cannot be valid (or invalid) without the other
+ // being so too.
+ regfree(&partial_regex_);
+ regfree(&full_regex_);
+ }
+ free(const_cast<char*>(pattern_));
+}
+
+// Returns true iff regular expression re matches the entire str.
+bool RE::FullMatch(const char* str, const RE& re) {
+ if (!re.is_valid_) return false;
+
+ regmatch_t match;
+ return regexec(&re.full_regex_, str, 1, &match, 0) == 0;
+}
+
+// Returns true iff regular expression re matches a substring of str
+// (including str itself).
+bool RE::PartialMatch(const char* str, const RE& re) {
+ if (!re.is_valid_) return false;
+
+ regmatch_t match;
+ return regexec(&re.partial_regex_, str, 1, &match, 0) == 0;
+}
+
+// Initializes an RE from its string representation.
+void RE::Init(const char* regex) {
+ pattern_ = posix::StrDup(regex);
+
+ // Reserves enough bytes to hold the regular expression used for a
+ // full match.
+ const size_t full_regex_len = strlen(regex) + 10;
+ char* const full_pattern = new char[full_regex_len];
+
+ snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
+ is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0;
+ // We want to call regcomp(&partial_regex_, ...) even if the
+ // previous expression returns false. Otherwise partial_regex_ may
+ // not be properly initialized can may cause trouble when it's
+ // freed.
+ //
+ // Some implementation of POSIX regex (e.g. on at least some
+ // versions of Cygwin) doesn't accept the empty string as a valid
+ // regex. We change it to an equivalent form "()" to be safe.
+ if (is_valid_) {
+ const char* const partial_regex = (*regex == '\0') ? "()" : regex;
+ is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0;
+ }
+ EXPECT_TRUE(is_valid_)
+ << "Regular expression \"" << regex
+ << "\" is not a valid POSIX Extended regular expression.";
+
+ delete[] full_pattern;
+}
+
+#elif GTEST_USES_SIMPLE_RE
+
+// Returns true iff ch appears anywhere in str (excluding the
+// terminating '\0' character).
+bool IsInSet(char ch, const char* str) {
+ return ch != '\0' && strchr(str, ch) != nullptr;
+}
+
+// Returns true iff ch belongs to the given classification. Unlike
+// similar functions in <ctype.h>, these aren't affected by the
+// current locale.
+bool IsAsciiDigit(char ch) { return '0' <= ch && ch <= '9'; }
+bool IsAsciiPunct(char ch) {
+ return IsInSet(ch, "^-!\"#$%&'()*+,./:;<=>?@[\\]_`{|}~");
+}
+bool IsRepeat(char ch) { return IsInSet(ch, "?*+"); }
+bool IsAsciiWhiteSpace(char ch) { return IsInSet(ch, " \f\n\r\t\v"); }
+bool IsAsciiWordChar(char ch) {
+ return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') ||
+ ('0' <= ch && ch <= '9') || ch == '_';
+}
+
+// Returns true iff "\\c" is a supported escape sequence.
+bool IsValidEscape(char c) {
+ return (IsAsciiPunct(c) || IsInSet(c, "dDfnrsStvwW"));
+}
+
+// Returns true iff the given atom (specified by escaped and pattern)
+// matches ch. The result is undefined if the atom is invalid.
+bool AtomMatchesChar(bool escaped, char pattern_char, char ch) {
+ if (escaped) { // "\\p" where p is pattern_char.
+ switch (pattern_char) {
+ case 'd': return IsAsciiDigit(ch);
+ case 'D': return !IsAsciiDigit(ch);
+ case 'f': return ch == '\f';
+ case 'n': return ch == '\n';
+ case 'r': return ch == '\r';
+ case 's': return IsAsciiWhiteSpace(ch);
+ case 'S': return !IsAsciiWhiteSpace(ch);
+ case 't': return ch == '\t';
+ case 'v': return ch == '\v';
+ case 'w': return IsAsciiWordChar(ch);
+ case 'W': return !IsAsciiWordChar(ch);
+ }
+ return IsAsciiPunct(pattern_char) && pattern_char == ch;
+ }
+
+ return (pattern_char == '.' && ch != '\n') || pattern_char == ch;
+}
+
+// Helper function used by ValidateRegex() to format error messages.
+static std::string FormatRegexSyntaxError(const char* regex, int index) {
+ return (Message() << "Syntax error at index " << index
+ << " in simple regular expression \"" << regex << "\": ").GetString();
+}
+
+// Generates non-fatal failures and returns false if regex is invalid;
+// otherwise returns true.
+bool ValidateRegex(const char* regex) {
+ if (regex == nullptr) {
+ ADD_FAILURE() << "NULL is not a valid simple regular expression.";
+ return false;
+ }
+
+ bool is_valid = true;
+
+ // True iff ?, *, or + can follow the previous atom.
+ bool prev_repeatable = false;
+ for (int i = 0; regex[i]; i++) {
+ if (regex[i] == '\\') { // An escape sequence
+ i++;
+ if (regex[i] == '\0') {
+ ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
+ << "'\\' cannot appear at the end.";
+ return false;
+ }
+
+ if (!IsValidEscape(regex[i])) {
+ ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
+ << "invalid escape sequence \"\\" << regex[i] << "\".";
+ is_valid = false;
+ }
+ prev_repeatable = true;
+ } else { // Not an escape sequence.
+ const char ch = regex[i];
+
+ if (ch == '^' && i > 0) {
+ ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
+ << "'^' can only appear at the beginning.";
+ is_valid = false;
+ } else if (ch == '$' && regex[i + 1] != '\0') {
+ ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
+ << "'$' can only appear at the end.";
+ is_valid = false;
+ } else if (IsInSet(ch, "()[]{}|")) {
+ ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
+ << "'" << ch << "' is unsupported.";
+ is_valid = false;
+ } else if (IsRepeat(ch) && !prev_repeatable) {
+ ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
+ << "'" << ch << "' can only follow a repeatable token.";
+ is_valid = false;
+ }
+
+ prev_repeatable = !IsInSet(ch, "^$?*+");
+ }
+ }
+
+ return is_valid;
+}
+
+// Matches a repeated regex atom followed by a valid simple regular
+// expression. The regex atom is defined as c if escaped is false,
+// or \c otherwise. repeat is the repetition meta character (?, *,
+// or +). The behavior is undefined if str contains too many
+// characters to be indexable by size_t, in which case the test will
+// probably time out anyway. We are fine with this limitation as
+// std::string has it too.
+bool MatchRepetitionAndRegexAtHead(
+ bool escaped, char c, char repeat, const char* regex,
+ const char* str) {
+ const size_t min_count = (repeat == '+') ? 1 : 0;
+ const size_t max_count = (repeat == '?') ? 1 :
+ static_cast<size_t>(-1) - 1;
+ // We cannot call numeric_limits::max() as it conflicts with the
+ // max() macro on Windows.
+
+ for (size_t i = 0; i <= max_count; ++i) {
+ // We know that the atom matches each of the first i characters in str.
+ if (i >= min_count && MatchRegexAtHead(regex, str + i)) {
+ // We have enough matches at the head, and the tail matches too.
+ // Since we only care about *whether* the pattern matches str
+ // (as opposed to *how* it matches), there is no need to find a
+ // greedy match.
+ return true;
+ }
+ if (str[i] == '\0' || !AtomMatchesChar(escaped, c, str[i]))
+ return false;
+ }
+ return false;
+}
+
+// Returns true iff regex matches a prefix of str. regex must be a
+// valid simple regular expression and not start with "^", or the
+// result is undefined.
+bool MatchRegexAtHead(const char* regex, const char* str) {
+ if (*regex == '\0') // An empty regex matches a prefix of anything.
+ return true;
+
+ // "$" only matches the end of a string. Note that regex being
+ // valid guarantees that there's nothing after "$" in it.
+ if (*regex == '$')
+ return *str == '\0';
+
+ // Is the first thing in regex an escape sequence?
+ const bool escaped = *regex == '\\';
+ if (escaped)
+ ++regex;
+ if (IsRepeat(regex[1])) {
+ // MatchRepetitionAndRegexAtHead() calls MatchRegexAtHead(), so
+ // here's an indirect recursion. It terminates as the regex gets
+ // shorter in each recursion.
+ return MatchRepetitionAndRegexAtHead(
+ escaped, regex[0], regex[1], regex + 2, str);
+ } else {
+ // regex isn't empty, isn't "$", and doesn't start with a
+ // repetition. We match the first atom of regex with the first
+ // character of str and recurse.
+ return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) &&
+ MatchRegexAtHead(regex + 1, str + 1);
+ }
+}
+
+// Returns true iff regex matches any substring of str. regex must be
+// a valid simple regular expression, or the result is undefined.
+//
+// The algorithm is recursive, but the recursion depth doesn't exceed
+// the regex length, so we won't need to worry about running out of
+// stack space normally. In rare cases the time complexity can be
+// exponential with respect to the regex length + the string length,
+// but usually it's must faster (often close to linear).
+bool MatchRegexAnywhere(const char* regex, const char* str) {
+ if (regex == nullptr || str == nullptr) return false;
+
+ if (*regex == '^')
+ return MatchRegexAtHead(regex + 1, str);
+
+ // A successful match can be anywhere in str.
+ do {
+ if (MatchRegexAtHead(regex, str))
+ return true;
+ } while (*str++ != '\0');
+ return false;
+}
+
+// Implements the RE class.
+
+RE::~RE() {
+ free(const_cast<char*>(pattern_));
+ free(const_cast<char*>(full_pattern_));
+}
+
+// Returns true iff regular expression re matches the entire str.
+bool RE::FullMatch(const char* str, const RE& re) {
+ return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_, str);
+}
+
+// Returns true iff regular expression re matches a substring of str
+// (including str itself).
+bool RE::PartialMatch(const char* str, const RE& re) {
+ return re.is_valid_ && MatchRegexAnywhere(re.pattern_, str);
+}
+
+// Initializes an RE from its string representation.
+void RE::Init(const char* regex) {
+ pattern_ = full_pattern_ = nullptr;
+ if (regex != nullptr) {
+ pattern_ = posix::StrDup(regex);
+ }
+
+ is_valid_ = ValidateRegex(regex);
+ if (!is_valid_) {
+ // No need to calculate the full pattern when the regex is invalid.
+ return;
+ }
+
+ const size_t len = strlen(regex);
+ // Reserves enough bytes to hold the regular expression used for a
+ // full match: we need space to prepend a '^', append a '$', and
+ // terminate the string with '\0'.
+ char* buffer = static_cast<char*>(malloc(len + 3));
+ full_pattern_ = buffer;
+
+ if (*regex != '^')
+ *buffer++ = '^'; // Makes sure full_pattern_ starts with '^'.
+
+ // We don't use snprintf or strncpy, as they trigger a warning when
+ // compiled with VC++ 8.0.
+ memcpy(buffer, regex, len);
+ buffer += len;
+
+ if (len == 0 || regex[len - 1] != '$')
+ *buffer++ = '$'; // Makes sure full_pattern_ ends with '$'.
+
+ *buffer = '\0';
+}
+
+#endif // GTEST_USES_POSIX_RE
+
+const char kUnknownFile[] = "unknown file";
+
+// Formats a source file path and a line number as they would appear
+// in an error message from the compiler used to compile this code.
+GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {
+ const std::string file_name(file == nullptr ? kUnknownFile : file);
+
+ if (line < 0) {
+ return file_name + ":";
+ }
+#ifdef _MSC_VER
+ return file_name + "(" + StreamableToString(line) + "):";
+#else
+ return file_name + ":" + StreamableToString(line) + ":";
+#endif // _MSC_VER
+}
+
+// Formats a file location for compiler-independent XML output.
+// Although this function is not platform dependent, we put it next to
+// FormatFileLocation in order to contrast the two functions.
+// Note that FormatCompilerIndependentFileLocation() does NOT append colon
+// to the file location it produces, unlike FormatFileLocation().
+GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(
+ const char* file, int line) {
+ const std::string file_name(file == nullptr ? kUnknownFile : file);
+
+ if (line < 0)
+ return file_name;
+ else
+ return file_name + ":" + StreamableToString(line);
+}
+
+GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line)
+ : severity_(severity) {
+ const char* const marker =
+ severity == GTEST_INFO ? "[ INFO ]" :
+ severity == GTEST_WARNING ? "[WARNING]" :
+ severity == GTEST_ERROR ? "[ ERROR ]" : "[ FATAL ]";
+ GetStream() << ::std::endl << marker << " "
+ << FormatFileLocation(file, line).c_str() << ": ";
+}
+
+// Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
+GTestLog::~GTestLog() {
+ GetStream() << ::std::endl;
+ if (severity_ == GTEST_FATAL) {
+ fflush(stderr);
+ posix::Abort();
+ }
+}
+
+// Disable Microsoft deprecation warnings for POSIX functions called from
+// this class (creat, dup, dup2, and close)
+GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
+
+#if GTEST_HAS_STREAM_REDIRECTION
+
+// Object that captures an output stream (stdout/stderr).
+class CapturedStream {
+ public:
+ // The ctor redirects the stream to a temporary file.
+ explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
+# if GTEST_OS_WINDOWS
+ char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT
+ char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT
+
+ ::GetTempPathA(sizeof(temp_dir_path), temp_dir_path);
+ const UINT success = ::GetTempFileNameA(temp_dir_path,
+ "gtest_redir",
+ 0, // Generate unique file name.
+ temp_file_path);
+ GTEST_CHECK_(success != 0)
+ << "Unable to create a temporary file in " << temp_dir_path;
+ const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE);
+ GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file "
+ << temp_file_path;
+ filename_ = temp_file_path;
+# else
+ // There's no guarantee that a test has write access to the current
+ // directory, so we create the temporary file in the /tmp directory
+ // instead. We use /tmp on most systems, and /sdcard on Android.
+ // That's because Android doesn't have /tmp.
+# if GTEST_OS_LINUX_ANDROID
+ // Note: Android applications are expected to call the framework's
+ // Context.getExternalStorageDirectory() method through JNI to get
+ // the location of the world-writable SD Card directory. However,
+ // this requires a Context handle, which cannot be retrieved
+ // globally from native code. Doing so also precludes running the
+ // code as part of a regular standalone executable, which doesn't
+ // run in a Dalvik process (e.g. when running it through 'adb shell').
+ //
+ // The location /sdcard is directly accessible from native code
+ // and is the only location (unofficially) supported by the Android
+ // team. It's generally a symlink to the real SD Card mount point
+ // which can be /mnt/sdcard, /mnt/sdcard0, /system/media/sdcard, or
+ // other OEM-customized locations. Never rely on these, and always
+ // use /sdcard.
+ char name_template[] = "/sdcard/gtest_captured_stream.XXXXXX";
+# else
+ char name_template[] = "/tmp/captured_stream.XXXXXX";
+# endif // GTEST_OS_LINUX_ANDROID
+ const int captured_fd = mkstemp(name_template);
+ filename_ = name_template;
+# endif // GTEST_OS_WINDOWS
+ fflush(nullptr);
+ dup2(captured_fd, fd_);
+ close(captured_fd);
+ }
+
+ ~CapturedStream() {
+ remove(filename_.c_str());
+ }
+
+ std::string GetCapturedString() {
+ if (uncaptured_fd_ != -1) {
+ // Restores the original stream.
+ fflush(nullptr);
+ dup2(uncaptured_fd_, fd_);
+ close(uncaptured_fd_);
+ uncaptured_fd_ = -1;
+ }
+
+ FILE* const file = posix::FOpen(filename_.c_str(), "r");
+ const std::string content = ReadEntireFile(file);
+ posix::FClose(file);
+ return content;
+ }
+
+ private:
+ const int fd_; // A stream to capture.
+ int uncaptured_fd_;
+ // Name of the temporary file holding the stderr output.
+ ::std::string filename_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(CapturedStream);
+};
+
+GTEST_DISABLE_MSC_DEPRECATED_POP_()
+
+static CapturedStream* g_captured_stderr = nullptr;
+static CapturedStream* g_captured_stdout = nullptr;
+
+// Starts capturing an output stream (stdout/stderr).
+static void CaptureStream(int fd, const char* stream_name,
+ CapturedStream** stream) {
+ if (*stream != nullptr) {
+ GTEST_LOG_(FATAL) << "Only one " << stream_name
+ << " capturer can exist at a time.";
+ }
+ *stream = new CapturedStream(fd);
+}
+
+// Stops capturing the output stream and returns the captured string.
+static std::string GetCapturedStream(CapturedStream** captured_stream) {
+ const std::string content = (*captured_stream)->GetCapturedString();
+
+ delete *captured_stream;
+ *captured_stream = nullptr;
+
+ return content;
+}
+
+// Starts capturing stdout.
+void CaptureStdout() {
+ CaptureStream(kStdOutFileno, "stdout", &g_captured_stdout);
+}
+
+// Starts capturing stderr.
+void CaptureStderr() {
+ CaptureStream(kStdErrFileno, "stderr", &g_captured_stderr);
+}
+
+// Stops capturing stdout and returns the captured string.
+std::string GetCapturedStdout() {
+ return GetCapturedStream(&g_captured_stdout);
+}
+
+// Stops capturing stderr and returns the captured string.
+std::string GetCapturedStderr() {
+ return GetCapturedStream(&g_captured_stderr);
+}
+
+#endif // GTEST_HAS_STREAM_REDIRECTION
+
+
+
+
+
+size_t GetFileSize(FILE* file) {
+ fseek(file, 0, SEEK_END);
+ return static_cast<size_t>(ftell(file));
+}
+
+std::string ReadEntireFile(FILE* file) {
+ const size_t file_size = GetFileSize(file);
+ char* const buffer = new char[file_size];
+
+ size_t bytes_last_read = 0; // # of bytes read in the last fread()
+ size_t bytes_read = 0; // # of bytes read so far
+
+ fseek(file, 0, SEEK_SET);
+
+ // Keeps reading the file until we cannot read further or the
+ // pre-determined file size is reached.
+ do {
+ bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file);
+ bytes_read += bytes_last_read;
+ } while (bytes_last_read > 0 && bytes_read < file_size);
+
+ const std::string content(buffer, bytes_read);
+ delete[] buffer;
+
+ return content;
+}
+
+#if GTEST_HAS_DEATH_TEST
+static const std::vector<std::string>* g_injected_test_argvs =
+ nullptr; // Owned.
+
+std::vector<std::string> GetInjectableArgvs() {
+ if (g_injected_test_argvs != nullptr) {
+ return *g_injected_test_argvs;
+ }
+ return GetArgvs();
+}
+
+void SetInjectableArgvs(const std::vector<std::string>* new_argvs) {
+ if (g_injected_test_argvs != new_argvs) delete g_injected_test_argvs;
+ g_injected_test_argvs = new_argvs;
+}
+
+void SetInjectableArgvs(const std::vector<std::string>& new_argvs) {
+ SetInjectableArgvs(
+ new std::vector<std::string>(new_argvs.begin(), new_argvs.end()));
+}
+
+void ClearInjectableArgvs() {
+ delete g_injected_test_argvs;
+ g_injected_test_argvs = nullptr;
+}
+#endif // GTEST_HAS_DEATH_TEST
+
+#if GTEST_OS_WINDOWS_MOBILE
+namespace posix {
+void Abort() {
+ DebugBreak();
+ TerminateProcess(GetCurrentProcess(), 1);
+}
+} // namespace posix
+#endif // GTEST_OS_WINDOWS_MOBILE
+
+// Returns the name of the environment variable corresponding to the
+// given flag. For example, FlagToEnvVar("foo") will return
+// "GTEST_FOO" in the open-source version.
+static std::string FlagToEnvVar(const char* flag) {
+ const std::string full_flag =
+ (Message() << GTEST_FLAG_PREFIX_ << flag).GetString();
+
+ Message env_var;
+ for (size_t i = 0; i != full_flag.length(); i++) {
+ env_var << ToUpper(full_flag.c_str()[i]);
+ }
+
+ return env_var.GetString();
+}
+
+// Parses 'str' for a 32-bit signed integer. If successful, writes
+// the result to *value and returns true; otherwise leaves *value
+// unchanged and returns false.
+bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
+ // Parses the environment variable as a decimal integer.
+ char* end = nullptr;
+ const long long_value = strtol(str, &end, 10); // NOLINT
+
+ // Has strtol() consumed all characters in the string?
+ if (*end != '\0') {
+ // No - an invalid character was encountered.
+ Message msg;
+ msg << "WARNING: " << src_text
+ << " is expected to be a 32-bit integer, but actually"
+ << " has value \"" << str << "\".\n";
+ printf("%s", msg.GetString().c_str());
+ fflush(stdout);
+ return false;
+ }
+
+ // Is the parsed value in the range of an Int32?
+ const Int32 result = static_cast<Int32>(long_value);
+ if (long_value == LONG_MAX || long_value == LONG_MIN ||
+ // The parsed value overflows as a long. (strtol() returns
+ // LONG_MAX or LONG_MIN when the input overflows.)
+ result != long_value
+ // The parsed value overflows as an Int32.
+ ) {
+ Message msg;
+ msg << "WARNING: " << src_text
+ << " is expected to be a 32-bit integer, but actually"
+ << " has value " << str << ", which overflows.\n";
+ printf("%s", msg.GetString().c_str());
+ fflush(stdout);
+ return false;
+ }
+
+ *value = result;
+ return true;
+}
+
+// Reads and returns the Boolean environment variable corresponding to
+// the given flag; if it's not set, returns default_value.
+//
+// The value is considered true iff it's not "0".
+bool BoolFromGTestEnv(const char* flag, bool default_value) {
+#if defined(GTEST_GET_BOOL_FROM_ENV_)
+ return GTEST_GET_BOOL_FROM_ENV_(flag, default_value);
+#else
+ const std::string env_var = FlagToEnvVar(flag);
+ const char* const string_value = posix::GetEnv(env_var.c_str());
+ return string_value == nullptr ? default_value
+ : strcmp(string_value, "0") != 0;
+#endif // defined(GTEST_GET_BOOL_FROM_ENV_)
+}
+
+// Reads and returns a 32-bit integer stored in the environment
+// variable corresponding to the given flag; if it isn't set or
+// doesn't represent a valid 32-bit integer, returns default_value.
+Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
+#if defined(GTEST_GET_INT32_FROM_ENV_)
+ return GTEST_GET_INT32_FROM_ENV_(flag, default_value);
+#else
+ const std::string env_var = FlagToEnvVar(flag);
+ const char* const string_value = posix::GetEnv(env_var.c_str());
+ if (string_value == nullptr) {
+ // The environment variable is not set.
+ return default_value;
+ }
+
+ Int32 result = default_value;
+ if (!ParseInt32(Message() << "Environment variable " << env_var,
+ string_value, &result)) {
+ printf("The default value %s is used.\n",
+ (Message() << default_value).GetString().c_str());
+ fflush(stdout);
+ return default_value;
+ }
+
+ return result;
+#endif // defined(GTEST_GET_INT32_FROM_ENV_)
+}
+
+// As a special case for the 'output' flag, if GTEST_OUTPUT is not
+// set, we look for XML_OUTPUT_FILE, which is set by the Bazel build
+// system. The value of XML_OUTPUT_FILE is a filename without the
+// "xml:" prefix of GTEST_OUTPUT.
+// Note that this is meant to be called at the call site so it does
+// not check that the flag is 'output'
+// In essence this checks an env variable called XML_OUTPUT_FILE
+// and if it is set we prepend "xml:" to its value, if it not set we return ""
+std::string OutputFlagAlsoCheckEnvVar(){
+ std::string default_value_for_output_flag = "";
+ const char* xml_output_file_env = posix::GetEnv("XML_OUTPUT_FILE");
+ if (nullptr != xml_output_file_env) {
+ default_value_for_output_flag = std::string("xml:") + xml_output_file_env;
+ }
+ return default_value_for_output_flag;
+}
+
+// Reads and returns the string environment variable corresponding to
+// the given flag; if it's not set, returns default_value.
+const char* StringFromGTestEnv(const char* flag, const char* default_value) {
+#if defined(GTEST_GET_STRING_FROM_ENV_)
+ return GTEST_GET_STRING_FROM_ENV_(flag, default_value);
+#else
+ const std::string env_var = FlagToEnvVar(flag);
+ const char* const value = posix::GetEnv(env_var.c_str());
+ return value == nullptr ? default_value : value;
+#endif // defined(GTEST_GET_STRING_FROM_ENV_)
+}
+
+} // namespace internal
+} // namespace testing
--- /dev/null
+// Copyright 2007, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Google Test - The Google C++ Testing and Mocking Framework
+//
+// This file implements a universal value printer that can print a
+// value of any type T:
+//
+// void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
+//
+// It uses the << operator when possible, and prints the bytes in the
+// object otherwise. A user can override its behavior for a class
+// type Foo by defining either operator<<(::std::ostream&, const Foo&)
+// or void PrintTo(const Foo&, ::std::ostream*) in the namespace that
+// defines Foo.
+
+#include "gtest/gtest-printers.h"
+#include <stdio.h>
+#include <cctype>
+#include <cwchar>
+#include <ostream> // NOLINT
+#include <string>
+#include "gtest/internal/gtest-port.h"
+#include "src/gtest-internal-inl.h"
+
+namespace testing {
+
+namespace {
+
+using ::std::ostream;
+
+// Prints a segment of bytes in the given object.
+GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
+GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
+GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
+GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
+void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
+ size_t count, ostream* os) {
+ char text[5] = "";
+ for (size_t i = 0; i != count; i++) {
+ const size_t j = start + i;
+ if (i != 0) {
+ // Organizes the bytes into groups of 2 for easy parsing by
+ // human.
+ if ((j % 2) == 0)
+ *os << ' ';
+ else
+ *os << '-';
+ }
+ GTEST_SNPRINTF_(text, sizeof(text), "%02X", obj_bytes[j]);
+ *os << text;
+ }
+}
+
+// Prints the bytes in the given value to the given ostream.
+void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,
+ ostream* os) {
+ // Tells the user how big the object is.
+ *os << count << "-byte object <";
+
+ const size_t kThreshold = 132;
+ const size_t kChunkSize = 64;
+ // If the object size is bigger than kThreshold, we'll have to omit
+ // some details by printing only the first and the last kChunkSize
+ // bytes.
+ if (count < kThreshold) {
+ PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
+ } else {
+ PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);
+ *os << " ... ";
+ // Rounds up to 2-byte boundary.
+ const size_t resume_pos = (count - kChunkSize + 1)/2*2;
+ PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os);
+ }
+ *os << ">";
+}
+
+} // namespace
+
+namespace internal2 {
+
+// Delegates to PrintBytesInObjectToImpl() to print the bytes in the
+// given object. The delegation simplifies the implementation, which
+// uses the << operator and thus is easier done outside of the
+// ::testing::internal namespace, which contains a << operator that
+// sometimes conflicts with the one in STL.
+void PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count,
+ ostream* os) {
+ PrintBytesInObjectToImpl(obj_bytes, count, os);
+}
+
+} // namespace internal2
+
+namespace internal {
+
+// Depending on the value of a char (or wchar_t), we print it in one
+// of three formats:
+// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
+// - as a hexadecimal escape sequence (e.g. '\x7F'), or
+// - as a special escape sequence (e.g. '\r', '\n').
+enum CharFormat {
+ kAsIs,
+ kHexEscape,
+ kSpecialEscape
+};
+
+// Returns true if c is a printable ASCII character. We test the
+// value of c directly instead of calling isprint(), which is buggy on
+// Windows Mobile.
+inline bool IsPrintableAscii(wchar_t c) {
+ return 0x20 <= c && c <= 0x7E;
+}
+
+// Prints a wide or narrow char c as a character literal without the
+// quotes, escaping it when necessary; returns how c was formatted.
+// The template argument UnsignedChar is the unsigned version of Char,
+// which is the type of c.
+template <typename UnsignedChar, typename Char>
+static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {
+ wchar_t w_c = static_cast<wchar_t>(c);
+ switch (w_c) {
+ case L'\0':
+ *os << "\\0";
+ break;
+ case L'\'':
+ *os << "\\'";
+ break;
+ case L'\\':
+ *os << "\\\\";
+ break;
+ case L'\a':
+ *os << "\\a";
+ break;
+ case L'\b':
+ *os << "\\b";
+ break;
+ case L'\f':
+ *os << "\\f";
+ break;
+ case L'\n':
+ *os << "\\n";
+ break;
+ case L'\r':
+ *os << "\\r";
+ break;
+ case L'\t':
+ *os << "\\t";
+ break;
+ case L'\v':
+ *os << "\\v";
+ break;
+ default:
+ if (IsPrintableAscii(w_c)) {
+ *os << static_cast<char>(c);
+ return kAsIs;
+ } else {
+ ostream::fmtflags flags = os->flags();
+ *os << "\\x" << std::hex << std::uppercase
+ << static_cast<int>(static_cast<UnsignedChar>(c));
+ os->flags(flags);
+ return kHexEscape;
+ }
+ }
+ return kSpecialEscape;
+}
+
+// Prints a wchar_t c as if it's part of a string literal, escaping it when
+// necessary; returns how c was formatted.
+static CharFormat PrintAsStringLiteralTo(wchar_t c, ostream* os) {
+ switch (c) {
+ case L'\'':
+ *os << "'";
+ return kAsIs;
+ case L'"':
+ *os << "\\\"";
+ return kSpecialEscape;
+ default:
+ return PrintAsCharLiteralTo<wchar_t>(c, os);
+ }
+}
+
+// Prints a char c as if it's part of a string literal, escaping it when
+// necessary; returns how c was formatted.
+static CharFormat PrintAsStringLiteralTo(char c, ostream* os) {
+ return PrintAsStringLiteralTo(
+ static_cast<wchar_t>(static_cast<unsigned char>(c)), os);
+}
+
+// Prints a wide or narrow character c and its code. '\0' is printed
+// as "'\\0'", other unprintable characters are also properly escaped
+// using the standard C++ escape sequence. The template argument
+// UnsignedChar is the unsigned version of Char, which is the type of c.
+template <typename UnsignedChar, typename Char>
+void PrintCharAndCodeTo(Char c, ostream* os) {
+ // First, print c as a literal in the most readable form we can find.
+ *os << ((sizeof(c) > 1) ? "L'" : "'");
+ const CharFormat format = PrintAsCharLiteralTo<UnsignedChar>(c, os);
+ *os << "'";
+
+ // To aid user debugging, we also print c's code in decimal, unless
+ // it's 0 (in which case c was printed as '\\0', making the code
+ // obvious).
+ if (c == 0)
+ return;
+ *os << " (" << static_cast<int>(c);
+
+ // For more convenience, we print c's code again in hexadecimal,
+ // unless c was already printed in the form '\x##' or the code is in
+ // [1, 9].
+ if (format == kHexEscape || (1 <= c && c <= 9)) {
+ // Do nothing.
+ } else {
+ *os << ", 0x" << String::FormatHexInt(static_cast<int>(c));
+ }
+ *os << ")";
+}
+
+void PrintTo(unsigned char c, ::std::ostream* os) {
+ PrintCharAndCodeTo<unsigned char>(c, os);
+}
+void PrintTo(signed char c, ::std::ostream* os) {
+ PrintCharAndCodeTo<unsigned char>(c, os);
+}
+
+// Prints a wchar_t as a symbol if it is printable or as its internal
+// code otherwise and also as its code. L'\0' is printed as "L'\\0'".
+void PrintTo(wchar_t wc, ostream* os) {
+ PrintCharAndCodeTo<wchar_t>(wc, os);
+}
+
+// Prints the given array of characters to the ostream. CharType must be either
+// char or wchar_t.
+// The array starts at begin, the length is len, it may include '\0' characters
+// and may not be NUL-terminated.
+template <typename CharType>
+GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
+GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
+GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
+GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
+static CharFormat PrintCharsAsStringTo(
+ const CharType* begin, size_t len, ostream* os) {
+ const char* const kQuoteBegin = sizeof(CharType) == 1 ? "\"" : "L\"";
+ *os << kQuoteBegin;
+ bool is_previous_hex = false;
+ CharFormat print_format = kAsIs;
+ for (size_t index = 0; index < len; ++index) {
+ const CharType cur = begin[index];
+ if (is_previous_hex && IsXDigit(cur)) {
+ // Previous character is of '\x..' form and this character can be
+ // interpreted as another hexadecimal digit in its number. Break string to
+ // disambiguate.
+ *os << "\" " << kQuoteBegin;
+ }
+ is_previous_hex = PrintAsStringLiteralTo(cur, os) == kHexEscape;
+ // Remember if any characters required hex escaping.
+ if (is_previous_hex) {
+ print_format = kHexEscape;
+ }
+ }
+ *os << "\"";
+ return print_format;
+}
+
+// Prints a (const) char/wchar_t array of 'len' elements, starting at address
+// 'begin'. CharType must be either char or wchar_t.
+template <typename CharType>
+GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
+GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
+GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
+GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
+static void UniversalPrintCharArray(
+ const CharType* begin, size_t len, ostream* os) {
+ // The code
+ // const char kFoo[] = "foo";
+ // generates an array of 4, not 3, elements, with the last one being '\0'.
+ //
+ // Therefore when printing a char array, we don't print the last element if
+ // it's '\0', such that the output matches the string literal as it's
+ // written in the source code.
+ if (len > 0 && begin[len - 1] == '\0') {
+ PrintCharsAsStringTo(begin, len - 1, os);
+ return;
+ }
+
+ // If, however, the last element in the array is not '\0', e.g.
+ // const char kFoo[] = { 'f', 'o', 'o' };
+ // we must print the entire array. We also print a message to indicate
+ // that the array is not NUL-terminated.
+ PrintCharsAsStringTo(begin, len, os);
+ *os << " (no terminating NUL)";
+}
+
+// Prints a (const) char array of 'len' elements, starting at address 'begin'.
+void UniversalPrintArray(const char* begin, size_t len, ostream* os) {
+ UniversalPrintCharArray(begin, len, os);
+}
+
+// Prints a (const) wchar_t array of 'len' elements, starting at address
+// 'begin'.
+void UniversalPrintArray(const wchar_t* begin, size_t len, ostream* os) {
+ UniversalPrintCharArray(begin, len, os);
+}
+
+// Prints the given C string to the ostream.
+void PrintTo(const char* s, ostream* os) {
+ if (s == nullptr) {
+ *os << "NULL";
+ } else {
+ *os << ImplicitCast_<const void*>(s) << " pointing to ";
+ PrintCharsAsStringTo(s, strlen(s), os);
+ }
+}
+
+// MSVC compiler can be configured to define whar_t as a typedef
+// of unsigned short. Defining an overload for const wchar_t* in that case
+// would cause pointers to unsigned shorts be printed as wide strings,
+// possibly accessing more memory than intended and causing invalid
+// memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
+// wchar_t is implemented as a native type.
+#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
+// Prints the given wide C string to the ostream.
+void PrintTo(const wchar_t* s, ostream* os) {
+ if (s == nullptr) {
+ *os << "NULL";
+ } else {
+ *os << ImplicitCast_<const void*>(s) << " pointing to ";
+ PrintCharsAsStringTo(s, wcslen(s), os);
+ }
+}
+#endif // wchar_t is native
+
+namespace {
+
+bool ContainsUnprintableControlCodes(const char* str, size_t length) {
+ const unsigned char *s = reinterpret_cast<const unsigned char *>(str);
+
+ for (size_t i = 0; i < length; i++) {
+ unsigned char ch = *s++;
+ if (std::iscntrl(ch)) {
+ switch (ch) {
+ case '\t':
+ case '\n':
+ case '\r':
+ break;
+ default:
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+bool IsUTF8TrailByte(unsigned char t) { return 0x80 <= t && t<= 0xbf; }
+
+bool IsValidUTF8(const char* str, size_t length) {
+ const unsigned char *s = reinterpret_cast<const unsigned char *>(str);
+
+ for (size_t i = 0; i < length;) {
+ unsigned char lead = s[i++];
+
+ if (lead <= 0x7f) {
+ continue; // single-byte character (ASCII) 0..7F
+ }
+ if (lead < 0xc2) {
+ return false; // trail byte or non-shortest form
+ } else if (lead <= 0xdf && (i + 1) <= length && IsUTF8TrailByte(s[i])) {
+ ++i; // 2-byte character
+ } else if (0xe0 <= lead && lead <= 0xef && (i + 2) <= length &&
+ IsUTF8TrailByte(s[i]) &&
+ IsUTF8TrailByte(s[i + 1]) &&
+ // check for non-shortest form and surrogate
+ (lead != 0xe0 || s[i] >= 0xa0) &&
+ (lead != 0xed || s[i] < 0xa0)) {
+ i += 2; // 3-byte character
+ } else if (0xf0 <= lead && lead <= 0xf4 && (i + 3) <= length &&
+ IsUTF8TrailByte(s[i]) &&
+ IsUTF8TrailByte(s[i + 1]) &&
+ IsUTF8TrailByte(s[i + 2]) &&
+ // check for non-shortest form
+ (lead != 0xf0 || s[i] >= 0x90) &&
+ (lead != 0xf4 || s[i] < 0x90)) {
+ i += 3; // 4-byte character
+ } else {
+ return false;
+ }
+ }
+ return true;
+}
+
+void ConditionalPrintAsText(const char* str, size_t length, ostream* os) {
+ if (!ContainsUnprintableControlCodes(str, length) &&
+ IsValidUTF8(str, length)) {
+ *os << "\n As Text: \"" << str << "\"";
+ }
+}
+
+} // anonymous namespace
+
+void PrintStringTo(const ::std::string& s, ostream* os) {
+ if (PrintCharsAsStringTo(s.data(), s.size(), os) == kHexEscape) {
+ if (GTEST_FLAG(print_utf8)) {
+ ConditionalPrintAsText(s.data(), s.size(), os);
+ }
+ }
+}
+
+#if GTEST_HAS_STD_WSTRING
+void PrintWideStringTo(const ::std::wstring& s, ostream* os) {
+ PrintCharsAsStringTo(s.data(), s.size(), os);
+}
+#endif // GTEST_HAS_STD_WSTRING
+
+} // namespace internal
+
+} // namespace testing
--- /dev/null
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// The Google C++ Testing and Mocking Framework (Google Test)
+
+#include "gtest/gtest-test-part.h"
+#include "src/gtest-internal-inl.h"
+
+namespace testing {
+
+using internal::GetUnitTestImpl;
+
+// Gets the summary of the failure message by omitting the stack trace
+// in it.
+std::string TestPartResult::ExtractSummary(const char* message) {
+ const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
+ return stack_trace == nullptr ? message : std::string(message, stack_trace);
+}
+
+// Prints a TestPartResult object.
+std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
+ return os << result.file_name() << ":" << result.line_number() << ": "
+ << (result.type() == TestPartResult::kSuccess
+ ? "Success"
+ : result.type() == TestPartResult::kSkip
+ ? "Skipped"
+ : result.type() == TestPartResult::kFatalFailure
+ ? "Fatal failure"
+ : "Non-fatal failure")
+ << ":\n"
+ << result.message() << std::endl;
+}
+
+// Appends a TestPartResult to the array.
+void TestPartResultArray::Append(const TestPartResult& result) {
+ array_.push_back(result);
+}
+
+// Returns the TestPartResult at the given index (0-based).
+const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {
+ if (index < 0 || index >= size()) {
+ printf("\nInvalid index (%d) into TestPartResultArray.\n", index);
+ internal::posix::Abort();
+ }
+
+ return array_[static_cast<size_t>(index)];
+}
+
+// Returns the number of TestPartResult objects in the array.
+int TestPartResultArray::size() const {
+ return static_cast<int>(array_.size());
+}
+
+namespace internal {
+
+HasNewFatalFailureHelper::HasNewFatalFailureHelper()
+ : has_new_fatal_failure_(false),
+ original_reporter_(GetUnitTestImpl()->
+ GetTestPartResultReporterForCurrentThread()) {
+ GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this);
+}
+
+HasNewFatalFailureHelper::~HasNewFatalFailureHelper() {
+ GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(
+ original_reporter_);
+}
+
+void HasNewFatalFailureHelper::ReportTestPartResult(
+ const TestPartResult& result) {
+ if (result.fatally_failed())
+ has_new_fatal_failure_ = true;
+ original_reporter_->ReportTestPartResult(result);
+}
+
+} // namespace internal
+
+} // namespace testing
--- /dev/null
+// Copyright 2008 Google Inc.
+// All Rights Reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+#include "gtest/gtest-typed-test.h"
+
+#include "gtest/gtest.h"
+
+namespace testing {
+namespace internal {
+
+#if GTEST_HAS_TYPED_TEST_P
+
+// Skips to the first non-space char in str. Returns an empty string if str
+// contains only whitespace characters.
+static const char* SkipSpaces(const char* str) {
+ while (IsSpace(*str))
+ str++;
+ return str;
+}
+
+static std::vector<std::string> SplitIntoTestNames(const char* src) {
+ std::vector<std::string> name_vec;
+ src = SkipSpaces(src);
+ for (; src != nullptr; src = SkipComma(src)) {
+ name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src)));
+ }
+ return name_vec;
+}
+
+// Verifies that registered_tests match the test names in
+// registered_tests_; returns registered_tests if successful, or
+// aborts the program otherwise.
+const char* TypedTestSuitePState::VerifyRegisteredTestNames(
+ const char* file, int line, const char* registered_tests) {
+ typedef RegisteredTestsMap::const_iterator RegisteredTestIter;
+ registered_ = true;
+
+ std::vector<std::string> name_vec = SplitIntoTestNames(registered_tests);
+
+ Message errors;
+
+ std::set<std::string> tests;
+ for (std::vector<std::string>::const_iterator name_it = name_vec.begin();
+ name_it != name_vec.end(); ++name_it) {
+ const std::string& name = *name_it;
+ if (tests.count(name) != 0) {
+ errors << "Test " << name << " is listed more than once.\n";
+ continue;
+ }
+
+ bool found = false;
+ for (RegisteredTestIter it = registered_tests_.begin();
+ it != registered_tests_.end();
+ ++it) {
+ if (name == it->first) {
+ found = true;
+ break;
+ }
+ }
+
+ if (found) {
+ tests.insert(name);
+ } else {
+ errors << "No test named " << name
+ << " can be found in this test suite.\n";
+ }
+ }
+
+ for (RegisteredTestIter it = registered_tests_.begin();
+ it != registered_tests_.end();
+ ++it) {
+ if (tests.count(it->first) == 0) {
+ errors << "You forgot to list test " << it->first << ".\n";
+ }
+ }
+
+ const std::string& errors_str = errors.GetString();
+ if (errors_str != "") {
+ fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
+ errors_str.c_str());
+ fflush(stderr);
+ posix::Abort();
+ }
+
+ return registered_tests;
+}
+
+#endif // GTEST_HAS_TYPED_TEST_P
+
+} // namespace internal
+} // namespace testing
--- /dev/null
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//
+// The Google C++ Testing and Mocking Framework (Google Test)
+
+#include "gtest/gtest.h"
+#include "gtest/internal/custom/gtest.h"
+#include "gtest/gtest-spi.h"
+
+#include <ctype.h>
+#include <math.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include <algorithm>
+#include <iomanip>
+#include <limits>
+#include <list>
+#include <map>
+#include <ostream> // NOLINT
+#include <sstream>
+#include <vector>
+
+#if GTEST_OS_LINUX
+
+# define GTEST_HAS_GETTIMEOFDAY_ 1
+
+# include <fcntl.h> // NOLINT
+# include <limits.h> // NOLINT
+# include <sched.h> // NOLINT
+// Declares vsnprintf(). This header is not available on Windows.
+# include <strings.h> // NOLINT
+# include <sys/mman.h> // NOLINT
+# include <sys/time.h> // NOLINT
+# include <unistd.h> // NOLINT
+# include <string>
+
+#elif GTEST_OS_ZOS
+# define GTEST_HAS_GETTIMEOFDAY_ 1
+# include <sys/time.h> // NOLINT
+
+// On z/OS we additionally need strings.h for strcasecmp.
+# include <strings.h> // NOLINT
+
+#elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE.
+
+# include <windows.h> // NOLINT
+# undef min
+
+#elif GTEST_OS_WINDOWS // We are on Windows proper.
+
+# include <io.h> // NOLINT
+# include <sys/timeb.h> // NOLINT
+# include <sys/types.h> // NOLINT
+# include <sys/stat.h> // NOLINT
+
+# if GTEST_OS_WINDOWS_MINGW
+// MinGW has gettimeofday() but not _ftime64().
+# define GTEST_HAS_GETTIMEOFDAY_ 1
+# include <sys/time.h> // NOLINT
+# endif // GTEST_OS_WINDOWS_MINGW
+
+// cpplint thinks that the header is already included, so we want to
+// silence it.
+# include <windows.h> // NOLINT
+# undef min
+
+#else
+
+// Assume other platforms have gettimeofday().
+# define GTEST_HAS_GETTIMEOFDAY_ 1
+
+// cpplint thinks that the header is already included, so we want to
+// silence it.
+# include <sys/time.h> // NOLINT
+# include <unistd.h> // NOLINT
+
+#endif // GTEST_OS_LINUX
+
+#if GTEST_HAS_EXCEPTIONS
+# include <stdexcept>
+#endif
+
+#if GTEST_CAN_STREAM_RESULTS_
+# include <arpa/inet.h> // NOLINT
+# include <netdb.h> // NOLINT
+# include <sys/socket.h> // NOLINT
+# include <sys/types.h> // NOLINT
+#endif
+
+#include "src/gtest-internal-inl.h"
+
+#if GTEST_OS_WINDOWS
+# define vsnprintf _vsnprintf
+#endif // GTEST_OS_WINDOWS
+
+#if GTEST_OS_MAC
+#ifndef GTEST_OS_IOS
+#include <crt_externs.h>
+#endif
+#endif
+
+#if GTEST_HAS_ABSL
+#include "absl/debugging/failure_signal_handler.h"
+#include "absl/debugging/stacktrace.h"
+#include "absl/debugging/symbolize.h"
+#include "absl/strings/str_cat.h"
+#endif // GTEST_HAS_ABSL
+
+namespace testing {
+
+using internal::CountIf;
+using internal::ForEach;
+using internal::GetElementOr;
+using internal::Shuffle;
+
+// Constants.
+
+// A test whose test suite name or test name matches this filter is
+// disabled and not run.
+static const char kDisableTestFilter[] = "DISABLED_*:*/DISABLED_*";
+
+// A test suite whose name matches this filter is considered a death
+// test suite and will be run before test suites whose name doesn't
+// match this filter.
+static const char kDeathTestSuiteFilter[] = "*DeathTest:*DeathTest/*";
+
+// A test filter that matches everything.
+static const char kUniversalFilter[] = "*";
+
+// The default output format.
+static const char kDefaultOutputFormat[] = "xml";
+// The default output file.
+static const char kDefaultOutputFile[] = "test_detail";
+
+// The environment variable name for the test shard index.
+static const char kTestShardIndex[] = "GTEST_SHARD_INDEX";
+// The environment variable name for the total number of test shards.
+static const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS";
+// The environment variable name for the test shard status file.
+static const char kTestShardStatusFile[] = "GTEST_SHARD_STATUS_FILE";
+
+namespace internal {
+
+// The text used in failure messages to indicate the start of the
+// stack trace.
+const char kStackTraceMarker[] = "\nStack trace:\n";
+
+// g_help_flag is true iff the --help flag or an equivalent form is
+// specified on the command line.
+bool g_help_flag = false;
+
+// Utilty function to Open File for Writing
+static FILE* OpenFileForWriting(const std::string& output_file) {
+ FILE* fileout = nullptr;
+ FilePath output_file_path(output_file);
+ FilePath output_dir(output_file_path.RemoveFileName());
+
+ if (output_dir.CreateDirectoriesRecursively()) {
+ fileout = posix::FOpen(output_file.c_str(), "w");
+ }
+ if (fileout == nullptr) {
+ GTEST_LOG_(FATAL) << "Unable to open file \"" << output_file << "\"";
+ }
+ return fileout;
+}
+
+} // namespace internal
+
+// Bazel passes in the argument to '--test_filter' via the TESTBRIDGE_TEST_ONLY
+// environment variable.
+static const char* GetDefaultFilter() {
+ const char* const testbridge_test_only =
+ internal::posix::GetEnv("TESTBRIDGE_TEST_ONLY");
+ if (testbridge_test_only != nullptr) {
+ return testbridge_test_only;
+ }
+ return kUniversalFilter;
+}
+
+GTEST_DEFINE_bool_(
+ also_run_disabled_tests,
+ internal::BoolFromGTestEnv("also_run_disabled_tests", false),
+ "Run disabled tests too, in addition to the tests normally being run.");
+
+GTEST_DEFINE_bool_(
+ break_on_failure,
+ internal::BoolFromGTestEnv("break_on_failure", false),
+ "True iff a failed assertion should be a debugger break-point.");
+
+GTEST_DEFINE_bool_(
+ catch_exceptions,
+ internal::BoolFromGTestEnv("catch_exceptions", true),
+ "True iff " GTEST_NAME_
+ " should catch exceptions and treat them as test failures.");
+
+GTEST_DEFINE_string_(
+ color,
+ internal::StringFromGTestEnv("color", "auto"),
+ "Whether to use colors in the output. Valid values: yes, no, "
+ "and auto. 'auto' means to use colors if the output is "
+ "being sent to a terminal and the TERM environment variable "
+ "is set to a terminal type that supports colors.");
+
+GTEST_DEFINE_string_(
+ filter,
+ internal::StringFromGTestEnv("filter", GetDefaultFilter()),
+ "A colon-separated list of glob (not regex) patterns "
+ "for filtering the tests to run, optionally followed by a "
+ "'-' and a : separated list of negative patterns (tests to "
+ "exclude). A test is run if it matches one of the positive "
+ "patterns and does not match any of the negative patterns.");
+
+GTEST_DEFINE_bool_(
+ install_failure_signal_handler,
+ internal::BoolFromGTestEnv("install_failure_signal_handler", false),
+ "If true and supported on the current platform, " GTEST_NAME_ " should "
+ "install a signal handler that dumps debugging information when fatal "
+ "signals are raised.");
+
+GTEST_DEFINE_bool_(list_tests, false,
+ "List all tests without running them.");
+
+// The net priority order after flag processing is thus:
+// --gtest_output command line flag
+// GTEST_OUTPUT environment variable
+// XML_OUTPUT_FILE environment variable
+// ''
+GTEST_DEFINE_string_(
+ output,
+ internal::StringFromGTestEnv("output",
+ internal::OutputFlagAlsoCheckEnvVar().c_str()),
+ "A format (defaults to \"xml\" but can be specified to be \"json\"), "
+ "optionally followed by a colon and an output file name or directory. "
+ "A directory is indicated by a trailing pathname separator. "
+ "Examples: \"xml:filename.xml\", \"xml::directoryname/\". "
+ "If a directory is specified, output files will be created "
+ "within that directory, with file-names based on the test "
+ "executable's name and, if necessary, made unique by adding "
+ "digits.");
+
+GTEST_DEFINE_bool_(
+ print_time,
+ internal::BoolFromGTestEnv("print_time", true),
+ "True iff " GTEST_NAME_
+ " should display elapsed time in text output.");
+
+GTEST_DEFINE_bool_(
+ print_utf8,
+ internal::BoolFromGTestEnv("print_utf8", true),
+ "True iff " GTEST_NAME_
+ " prints UTF8 characters as text.");
+
+GTEST_DEFINE_int32_(
+ random_seed,
+ internal::Int32FromGTestEnv("random_seed", 0),
+ "Random number seed to use when shuffling test orders. Must be in range "
+ "[1, 99999], or 0 to use a seed based on the current time.");
+
+GTEST_DEFINE_int32_(
+ repeat,
+ internal::Int32FromGTestEnv("repeat", 1),
+ "How many times to repeat each test. Specify a negative number "
+ "for repeating forever. Useful for shaking out flaky tests.");
+
+GTEST_DEFINE_bool_(
+ show_internal_stack_frames, false,
+ "True iff " GTEST_NAME_ " should include internal stack frames when "
+ "printing test failure stack traces.");
+
+GTEST_DEFINE_bool_(
+ shuffle,
+ internal::BoolFromGTestEnv("shuffle", false),
+ "True iff " GTEST_NAME_
+ " should randomize tests' order on every run.");
+
+GTEST_DEFINE_int32_(
+ stack_trace_depth,
+ internal::Int32FromGTestEnv("stack_trace_depth", kMaxStackTraceDepth),
+ "The maximum number of stack frames to print when an "
+ "assertion fails. The valid range is 0 through 100, inclusive.");
+
+GTEST_DEFINE_string_(
+ stream_result_to,
+ internal::StringFromGTestEnv("stream_result_to", ""),
+ "This flag specifies the host name and the port number on which to stream "
+ "test results. Example: \"localhost:555\". The flag is effective only on "
+ "Linux.");
+
+GTEST_DEFINE_bool_(
+ throw_on_failure,
+ internal::BoolFromGTestEnv("throw_on_failure", false),
+ "When this flag is specified, a failed assertion will throw an exception "
+ "if exceptions are enabled or exit the program with a non-zero code "
+ "otherwise. For use with an external test framework.");
+
+#if GTEST_USE_OWN_FLAGFILE_FLAG_
+GTEST_DEFINE_string_(
+ flagfile,
+ internal::StringFromGTestEnv("flagfile", ""),
+ "This flag specifies the flagfile to read command-line flags from.");
+#endif // GTEST_USE_OWN_FLAGFILE_FLAG_
+
+namespace internal {
+
+// Generates a random number from [0, range), using a Linear
+// Congruential Generator (LCG). Crashes if 'range' is 0 or greater
+// than kMaxRange.
+UInt32 Random::Generate(UInt32 range) {
+ // These constants are the same as are used in glibc's rand(3).
+ // Use wider types than necessary to prevent unsigned overflow diagnostics.
+ state_ = static_cast<UInt32>(1103515245ULL*state_ + 12345U) % kMaxRange;
+
+ GTEST_CHECK_(range > 0)
+ << "Cannot generate a number in the range [0, 0).";
+ GTEST_CHECK_(range <= kMaxRange)
+ << "Generation of a number in [0, " << range << ") was requested, "
+ << "but this can only generate numbers in [0, " << kMaxRange << ").";
+
+ // Converting via modulus introduces a bit of downward bias, but
+ // it's simple, and a linear congruential generator isn't too good
+ // to begin with.
+ return state_ % range;
+}
+
+// GTestIsInitialized() returns true iff the user has initialized
+// Google Test. Useful for catching the user mistake of not initializing
+// Google Test before calling RUN_ALL_TESTS().
+static bool GTestIsInitialized() { return GetArgvs().size() > 0; }
+
+// Iterates over a vector of TestSuites, keeping a running sum of the
+// results of calling a given int-returning method on each.
+// Returns the sum.
+static int SumOverTestSuiteList(const std::vector<TestSuite*>& case_list,
+ int (TestSuite::*method)() const) {
+ int sum = 0;
+ for (size_t i = 0; i < case_list.size(); i++) {
+ sum += (case_list[i]->*method)();
+ }
+ return sum;
+}
+
+// Returns true iff the test suite passed.
+static bool TestSuitePassed(const TestSuite* test_suite) {
+ return test_suite->should_run() && test_suite->Passed();
+}
+
+// Returns true iff the test suite failed.
+static bool TestSuiteFailed(const TestSuite* test_suite) {
+ return test_suite->should_run() && test_suite->Failed();
+}
+
+// Returns true iff test_suite contains at least one test that should
+// run.
+static bool ShouldRunTestSuite(const TestSuite* test_suite) {
+ return test_suite->should_run();
+}
+
+// AssertHelper constructor.
+AssertHelper::AssertHelper(TestPartResult::Type type,
+ const char* file,
+ int line,
+ const char* message)
+ : data_(new AssertHelperData(type, file, line, message)) {
+}
+
+AssertHelper::~AssertHelper() {
+ delete data_;
+}
+
+// Message assignment, for assertion streaming support.
+void AssertHelper::operator=(const Message& message) const {
+ UnitTest::GetInstance()->
+ AddTestPartResult(data_->type, data_->file, data_->line,
+ AppendUserMessage(data_->message, message),
+ UnitTest::GetInstance()->impl()
+ ->CurrentOsStackTraceExceptTop(1)
+ // Skips the stack frame for this function itself.
+ ); // NOLINT
+}
+
+// A copy of all command line arguments. Set by InitGoogleTest().
+static ::std::vector<std::string> g_argvs;
+
+::std::vector<std::string> GetArgvs() {
+#if defined(GTEST_CUSTOM_GET_ARGVS_)
+ // GTEST_CUSTOM_GET_ARGVS_() may return a container of std::string or
+ // ::string. This code converts it to the appropriate type.
+ const auto& custom = GTEST_CUSTOM_GET_ARGVS_();
+ return ::std::vector<std::string>(custom.begin(), custom.end());
+#else // defined(GTEST_CUSTOM_GET_ARGVS_)
+ return g_argvs;
+#endif // defined(GTEST_CUSTOM_GET_ARGVS_)
+}
+
+// Returns the current application's name, removing directory path if that
+// is present.
+FilePath GetCurrentExecutableName() {
+ FilePath result;
+
+#if GTEST_OS_WINDOWS || GTEST_OS_OS2
+ result.Set(FilePath(GetArgvs()[0]).RemoveExtension("exe"));
+#else
+ result.Set(FilePath(GetArgvs()[0]));
+#endif // GTEST_OS_WINDOWS
+
+ return result.RemoveDirectoryName();
+}
+
+// Functions for processing the gtest_output flag.
+
+// Returns the output format, or "" for normal printed output.
+std::string UnitTestOptions::GetOutputFormat() {
+ const char* const gtest_output_flag = GTEST_FLAG(output).c_str();
+ const char* const colon = strchr(gtest_output_flag, ':');
+ return (colon == nullptr)
+ ? std::string(gtest_output_flag)
+ : std::string(gtest_output_flag,
+ static_cast<size_t>(colon - gtest_output_flag));
+}
+
+// Returns the name of the requested output file, or the default if none
+// was explicitly specified.
+std::string UnitTestOptions::GetAbsolutePathToOutputFile() {
+ const char* const gtest_output_flag = GTEST_FLAG(output).c_str();
+
+ std::string format = GetOutputFormat();
+ if (format.empty())
+ format = std::string(kDefaultOutputFormat);
+
+ const char* const colon = strchr(gtest_output_flag, ':');
+ if (colon == nullptr)
+ return internal::FilePath::MakeFileName(
+ internal::FilePath(
+ UnitTest::GetInstance()->original_working_dir()),
+ internal::FilePath(kDefaultOutputFile), 0,
+ format.c_str()).string();
+
+ internal::FilePath output_name(colon + 1);
+ if (!output_name.IsAbsolutePath())
+ output_name = internal::FilePath::ConcatPaths(
+ internal::FilePath(UnitTest::GetInstance()->original_working_dir()),
+ internal::FilePath(colon + 1));
+
+ if (!output_name.IsDirectory())
+ return output_name.string();
+
+ internal::FilePath result(internal::FilePath::GenerateUniqueFileName(
+ output_name, internal::GetCurrentExecutableName(),
+ GetOutputFormat().c_str()));
+ return result.string();
+}
+
+// Returns true iff the wildcard pattern matches the string. The
+// first ':' or '\0' character in pattern marks the end of it.
+//
+// This recursive algorithm isn't very efficient, but is clear and
+// works well enough for matching test names, which are short.
+bool UnitTestOptions::PatternMatchesString(const char *pattern,
+ const char *str) {
+ switch (*pattern) {
+ case '\0':
+ case ':': // Either ':' or '\0' marks the end of the pattern.
+ return *str == '\0';
+ case '?': // Matches any single character.
+ return *str != '\0' && PatternMatchesString(pattern + 1, str + 1);
+ case '*': // Matches any string (possibly empty) of characters.
+ return (*str != '\0' && PatternMatchesString(pattern, str + 1)) ||
+ PatternMatchesString(pattern + 1, str);
+ default: // Non-special character. Matches itself.
+ return *pattern == *str &&
+ PatternMatchesString(pattern + 1, str + 1);
+ }
+}
+
+bool UnitTestOptions::MatchesFilter(
+ const std::string& name, const char* filter) {
+ const char *cur_pattern = filter;
+ for (;;) {
+ if (PatternMatchesString(cur_pattern, name.c_str())) {
+ return true;
+ }
+
+ // Finds the next pattern in the filter.
+ cur_pattern = strchr(cur_pattern, ':');
+
+ // Returns if no more pattern can be found.
+ if (cur_pattern == nullptr) {
+ return false;
+ }
+
+ // Skips the pattern separater (the ':' character).
+ cur_pattern++;
+ }
+}
+
+// Returns true iff the user-specified filter matches the test suite
+// name and the test name.
+bool UnitTestOptions::FilterMatchesTest(const std::string& test_suite_name,
+ const std::string& test_name) {
+ const std::string& full_name = test_suite_name + "." + test_name.c_str();
+
+ // Split --gtest_filter at '-', if there is one, to separate into
+ // positive filter and negative filter portions
+ const char* const p = GTEST_FLAG(filter).c_str();
+ const char* const dash = strchr(p, '-');
+ std::string positive;
+ std::string negative;
+ if (dash == nullptr) {
+ positive = GTEST_FLAG(filter).c_str(); // Whole string is a positive filter
+ negative = "";
+ } else {
+ positive = std::string(p, dash); // Everything up to the dash
+ negative = std::string(dash + 1); // Everything after the dash
+ if (positive.empty()) {
+ // Treat '-test1' as the same as '*-test1'
+ positive = kUniversalFilter;
+ }
+ }
+
+ // A filter is a colon-separated list of patterns. It matches a
+ // test if any pattern in it matches the test.
+ return (MatchesFilter(full_name, positive.c_str()) &&
+ !MatchesFilter(full_name, negative.c_str()));
+}
+
+#if GTEST_HAS_SEH
+// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
+// given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
+// This function is useful as an __except condition.
+int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
+ // Google Test should handle a SEH exception if:
+ // 1. the user wants it to, AND
+ // 2. this is not a breakpoint exception, AND
+ // 3. this is not a C++ exception (VC++ implements them via SEH,
+ // apparently).
+ //
+ // SEH exception code for C++ exceptions.
+ // (see http://support.microsoft.com/kb/185294 for more information).
+ const DWORD kCxxExceptionCode = 0xe06d7363;
+
+ bool should_handle = true;
+
+ if (!GTEST_FLAG(catch_exceptions))
+ should_handle = false;
+ else if (exception_code == EXCEPTION_BREAKPOINT)
+ should_handle = false;
+ else if (exception_code == kCxxExceptionCode)
+ should_handle = false;
+
+ return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
+}
+#endif // GTEST_HAS_SEH
+
+} // namespace internal
+
+// The c'tor sets this object as the test part result reporter used by
+// Google Test. The 'result' parameter specifies where to report the
+// results. Intercepts only failures from the current thread.
+ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
+ TestPartResultArray* result)
+ : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
+ result_(result) {
+ Init();
+}
+
+// The c'tor sets this object as the test part result reporter used by
+// Google Test. The 'result' parameter specifies where to report the
+// results.
+ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
+ InterceptMode intercept_mode, TestPartResultArray* result)
+ : intercept_mode_(intercept_mode),
+ result_(result) {
+ Init();
+}
+
+void ScopedFakeTestPartResultReporter::Init() {
+ internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
+ if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
+ old_reporter_ = impl->GetGlobalTestPartResultReporter();
+ impl->SetGlobalTestPartResultReporter(this);
+ } else {
+ old_reporter_ = impl->GetTestPartResultReporterForCurrentThread();
+ impl->SetTestPartResultReporterForCurrentThread(this);
+ }
+}
+
+// The d'tor restores the test part result reporter used by Google Test
+// before.
+ScopedFakeTestPartResultReporter::~ScopedFakeTestPartResultReporter() {
+ internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
+ if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
+ impl->SetGlobalTestPartResultReporter(old_reporter_);
+ } else {
+ impl->SetTestPartResultReporterForCurrentThread(old_reporter_);
+ }
+}
+
+// Increments the test part result count and remembers the result.
+// This method is from the TestPartResultReporterInterface interface.
+void ScopedFakeTestPartResultReporter::ReportTestPartResult(
+ const TestPartResult& result) {
+ result_->Append(result);
+}
+
+namespace internal {
+
+// Returns the type ID of ::testing::Test. We should always call this
+// instead of GetTypeId< ::testing::Test>() to get the type ID of
+// testing::Test. This is to work around a suspected linker bug when
+// using Google Test as a framework on Mac OS X. The bug causes
+// GetTypeId< ::testing::Test>() to return different values depending
+// on whether the call is from the Google Test framework itself or
+// from user test code. GetTestTypeId() is guaranteed to always
+// return the same value, as it always calls GetTypeId<>() from the
+// gtest.cc, which is within the Google Test framework.
+TypeId GetTestTypeId() {
+ return GetTypeId<Test>();
+}
+
+// The value of GetTestTypeId() as seen from within the Google Test
+// library. This is solely for testing GetTestTypeId().
+extern const TypeId kTestTypeIdInGoogleTest = GetTestTypeId();
+
+// This predicate-formatter checks that 'results' contains a test part
+// failure of the given type and that the failure message contains the
+// given substring.
+static AssertionResult HasOneFailure(const char* /* results_expr */,
+ const char* /* type_expr */,
+ const char* /* substr_expr */,
+ const TestPartResultArray& results,
+ TestPartResult::Type type,
+ const std::string& substr) {
+ const std::string expected(type == TestPartResult::kFatalFailure ?
+ "1 fatal failure" :
+ "1 non-fatal failure");
+ Message msg;
+ if (results.size() != 1) {
+ msg << "Expected: " << expected << "\n"
+ << " Actual: " << results.size() << " failures";
+ for (int i = 0; i < results.size(); i++) {
+ msg << "\n" << results.GetTestPartResult(i);
+ }
+ return AssertionFailure() << msg;
+ }
+
+ const TestPartResult& r = results.GetTestPartResult(0);
+ if (r.type() != type) {
+ return AssertionFailure() << "Expected: " << expected << "\n"
+ << " Actual:\n"
+ << r;
+ }
+
+ if (strstr(r.message(), substr.c_str()) == nullptr) {
+ return AssertionFailure() << "Expected: " << expected << " containing \""
+ << substr << "\"\n"
+ << " Actual:\n"
+ << r;
+ }
+
+ return AssertionSuccess();
+}
+
+// The constructor of SingleFailureChecker remembers where to look up
+// test part results, what type of failure we expect, and what
+// substring the failure message should contain.
+SingleFailureChecker::SingleFailureChecker(const TestPartResultArray* results,
+ TestPartResult::Type type,
+ const std::string& substr)
+ : results_(results), type_(type), substr_(substr) {}
+
+// The destructor of SingleFailureChecker verifies that the given
+// TestPartResultArray contains exactly one failure that has the given
+// type and contains the given substring. If that's not the case, a
+// non-fatal failure will be generated.
+SingleFailureChecker::~SingleFailureChecker() {
+ EXPECT_PRED_FORMAT3(HasOneFailure, *results_, type_, substr_);
+}
+
+DefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter(
+ UnitTestImpl* unit_test) : unit_test_(unit_test) {}
+
+void DefaultGlobalTestPartResultReporter::ReportTestPartResult(
+ const TestPartResult& result) {
+ unit_test_->current_test_result()->AddTestPartResult(result);
+ unit_test_->listeners()->repeater()->OnTestPartResult(result);
+}
+
+DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter(
+ UnitTestImpl* unit_test) : unit_test_(unit_test) {}
+
+void DefaultPerThreadTestPartResultReporter::ReportTestPartResult(
+ const TestPartResult& result) {
+ unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(result);
+}
+
+// Returns the global test part result reporter.
+TestPartResultReporterInterface*
+UnitTestImpl::GetGlobalTestPartResultReporter() {
+ internal::MutexLock lock(&global_test_part_result_reporter_mutex_);
+ return global_test_part_result_repoter_;
+}
+
+// Sets the global test part result reporter.
+void UnitTestImpl::SetGlobalTestPartResultReporter(
+ TestPartResultReporterInterface* reporter) {
+ internal::MutexLock lock(&global_test_part_result_reporter_mutex_);
+ global_test_part_result_repoter_ = reporter;
+}
+
+// Returns the test part result reporter for the current thread.
+TestPartResultReporterInterface*
+UnitTestImpl::GetTestPartResultReporterForCurrentThread() {
+ return per_thread_test_part_result_reporter_.get();
+}
+
+// Sets the test part result reporter for the current thread.
+void UnitTestImpl::SetTestPartResultReporterForCurrentThread(
+ TestPartResultReporterInterface* reporter) {
+ per_thread_test_part_result_reporter_.set(reporter);
+}
+
+// Gets the number of successful test suites.
+int UnitTestImpl::successful_test_suite_count() const {
+ return CountIf(test_suites_, TestSuitePassed);
+}
+
+// Gets the number of failed test suites.
+int UnitTestImpl::failed_test_suite_count() const {
+ return CountIf(test_suites_, TestSuiteFailed);
+}
+
+// Gets the number of all test suites.
+int UnitTestImpl::total_test_suite_count() const {
+ return static_cast<int>(test_suites_.size());
+}
+
+// Gets the number of all test suites that contain at least one test
+// that should run.
+int UnitTestImpl::test_suite_to_run_count() const {
+ return CountIf(test_suites_, ShouldRunTestSuite);
+}
+
+// Gets the number of successful tests.
+int UnitTestImpl::successful_test_count() const {
+ return SumOverTestSuiteList(test_suites_, &TestSuite::successful_test_count);
+}
+
+// Gets the number of skipped tests.
+int UnitTestImpl::skipped_test_count() const {
+ return SumOverTestSuiteList(test_suites_, &TestSuite::skipped_test_count);
+}
+
+// Gets the number of failed tests.
+int UnitTestImpl::failed_test_count() const {
+ return SumOverTestSuiteList(test_suites_, &TestSuite::failed_test_count);
+}
+
+// Gets the number of disabled tests that will be reported in the XML report.
+int UnitTestImpl::reportable_disabled_test_count() const {
+ return SumOverTestSuiteList(test_suites_,
+ &TestSuite::reportable_disabled_test_count);
+}
+
+// Gets the number of disabled tests.
+int UnitTestImpl::disabled_test_count() const {
+ return SumOverTestSuiteList(test_suites_, &TestSuite::disabled_test_count);
+}
+
+// Gets the number of tests to be printed in the XML report.
+int UnitTestImpl::reportable_test_count() const {
+ return SumOverTestSuiteList(test_suites_, &TestSuite::reportable_test_count);
+}
+
+// Gets the number of all tests.
+int UnitTestImpl::total_test_count() const {
+ return SumOverTestSuiteList(test_suites_, &TestSuite::total_test_count);
+}
+
+// Gets the number of tests that should run.
+int UnitTestImpl::test_to_run_count() const {
+ return SumOverTestSuiteList(test_suites_, &TestSuite::test_to_run_count);
+}
+
+// Returns the current OS stack trace as an std::string.
+//
+// The maximum number of stack frames to be included is specified by
+// the gtest_stack_trace_depth flag. The skip_count parameter
+// specifies the number of top frames to be skipped, which doesn't
+// count against the number of frames to be included.
+//
+// For example, if Foo() calls Bar(), which in turn calls
+// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
+// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
+std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
+ return os_stack_trace_getter()->CurrentStackTrace(
+ static_cast<int>(GTEST_FLAG(stack_trace_depth)),
+ skip_count + 1
+ // Skips the user-specified number of frames plus this function
+ // itself.
+ ); // NOLINT
+}
+
+// Returns the current time in milliseconds.
+TimeInMillis GetTimeInMillis() {
+#if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__)
+ // Difference between 1970-01-01 and 1601-01-01 in milliseconds.
+ // http://analogous.blogspot.com/2005/04/epoch.html
+ const TimeInMillis kJavaEpochToWinFileTimeDelta =
+ static_cast<TimeInMillis>(116444736UL) * 100000UL;
+ const DWORD kTenthMicrosInMilliSecond = 10000;
+
+ SYSTEMTIME now_systime;
+ FILETIME now_filetime;
+ ULARGE_INTEGER now_int64;
+ GetSystemTime(&now_systime);
+ if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
+ now_int64.LowPart = now_filetime.dwLowDateTime;
+ now_int64.HighPart = now_filetime.dwHighDateTime;
+ now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -
+ kJavaEpochToWinFileTimeDelta;
+ return now_int64.QuadPart;
+ }
+ return 0;
+#elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_
+ __timeb64 now;
+
+ // MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996
+ // (deprecated function) there.
+ GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
+ _ftime64(&now);
+ GTEST_DISABLE_MSC_DEPRECATED_POP_()
+
+ return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;
+#elif GTEST_HAS_GETTIMEOFDAY_
+ struct timeval now;
+ gettimeofday(&now, nullptr);
+ return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000;
+#else
+# error "Don't know how to get the current time on your system."
+#endif
+}
+
+// Utilities
+
+// class String.
+
+#if GTEST_OS_WINDOWS_MOBILE
+// Creates a UTF-16 wide string from the given ANSI string, allocating
+// memory using new. The caller is responsible for deleting the return
+// value using delete[]. Returns the wide string, or NULL if the
+// input is NULL.
+LPCWSTR String::AnsiToUtf16(const char* ansi) {
+ if (!ansi) return nullptr;
+ const int length = strlen(ansi);
+ const int unicode_length =
+ MultiByteToWideChar(CP_ACP, 0, ansi, length, nullptr, 0);
+ WCHAR* unicode = new WCHAR[unicode_length + 1];
+ MultiByteToWideChar(CP_ACP, 0, ansi, length,
+ unicode, unicode_length);
+ unicode[unicode_length] = 0;
+ return unicode;
+}
+
+// Creates an ANSI string from the given wide string, allocating
+// memory using new. The caller is responsible for deleting the return
+// value using delete[]. Returns the ANSI string, or NULL if the
+// input is NULL.
+const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
+ if (!utf16_str) return nullptr;
+ const int ansi_length = WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, nullptr,
+ 0, nullptr, nullptr);
+ char* ansi = new char[ansi_length + 1];
+ WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, ansi, ansi_length, nullptr,
+ nullptr);
+ ansi[ansi_length] = 0;
+ return ansi;
+}
+
+#endif // GTEST_OS_WINDOWS_MOBILE
+
+// Compares two C strings. Returns true iff they have the same content.
+//
+// Unlike strcmp(), this function can handle NULL argument(s). A NULL
+// C string is considered different to any non-NULL C string,
+// including the empty string.
+bool String::CStringEquals(const char * lhs, const char * rhs) {
+ if (lhs == nullptr) return rhs == nullptr;
+
+ if (rhs == nullptr) return false;
+
+ return strcmp(lhs, rhs) == 0;
+}
+
+#if GTEST_HAS_STD_WSTRING
+
+// Converts an array of wide chars to a narrow string using the UTF-8
+// encoding, and streams the result to the given Message object.
+static void StreamWideCharsToMessage(const wchar_t* wstr, size_t length,
+ Message* msg) {
+ for (size_t i = 0; i != length; ) { // NOLINT
+ if (wstr[i] != L'\0') {
+ *msg << WideStringToUtf8(wstr + i, static_cast<int>(length - i));
+ while (i != length && wstr[i] != L'\0')
+ i++;
+ } else {
+ *msg << '\0';
+ i++;
+ }
+ }
+}
+
+#endif // GTEST_HAS_STD_WSTRING
+
+void SplitString(const ::std::string& str, char delimiter,
+ ::std::vector< ::std::string>* dest) {
+ ::std::vector< ::std::string> parsed;
+ ::std::string::size_type pos = 0;
+ while (::testing::internal::AlwaysTrue()) {
+ const ::std::string::size_type colon = str.find(delimiter, pos);
+ if (colon == ::std::string::npos) {
+ parsed.push_back(str.substr(pos));
+ break;
+ } else {
+ parsed.push_back(str.substr(pos, colon - pos));
+ pos = colon + 1;
+ }
+ }
+ dest->swap(parsed);
+}
+
+} // namespace internal
+
+// Constructs an empty Message.
+// We allocate the stringstream separately because otherwise each use of
+// ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's
+// stack frame leading to huge stack frames in some cases; gcc does not reuse
+// the stack space.
+Message::Message() : ss_(new ::std::stringstream) {
+ // By default, we want there to be enough precision when printing
+ // a double to a Message.
+ *ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
+}
+
+// These two overloads allow streaming a wide C string to a Message
+// using the UTF-8 encoding.
+Message& Message::operator <<(const wchar_t* wide_c_str) {
+ return *this << internal::String::ShowWideCString(wide_c_str);
+}
+Message& Message::operator <<(wchar_t* wide_c_str) {
+ return *this << internal::String::ShowWideCString(wide_c_str);
+}
+
+#if GTEST_HAS_STD_WSTRING
+// Converts the given wide string to a narrow string using the UTF-8
+// encoding, and streams the result to this Message object.
+Message& Message::operator <<(const ::std::wstring& wstr) {
+ internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(), this);
+ return *this;
+}
+#endif // GTEST_HAS_STD_WSTRING
+
+// Gets the text streamed to this object so far as an std::string.
+// Each '\0' character in the buffer is replaced with "\\0".
+std::string Message::GetString() const {
+ return internal::StringStreamToString(ss_.get());
+}
+
+// AssertionResult constructors.
+// Used in EXPECT_TRUE/FALSE(assertion_result).
+AssertionResult::AssertionResult(const AssertionResult& other)
+ : success_(other.success_),
+ message_(other.message_.get() != nullptr
+ ? new ::std::string(*other.message_)
+ : static_cast< ::std::string*>(nullptr)) {}
+
+// Swaps two AssertionResults.
+void AssertionResult::swap(AssertionResult& other) {
+ using std::swap;
+ swap(success_, other.success_);
+ swap(message_, other.message_);
+}
+
+// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
+AssertionResult AssertionResult::operator!() const {
+ AssertionResult negation(!success_);
+ if (message_.get() != nullptr) negation << *message_;
+ return negation;
+}
+
+// Makes a successful assertion result.
+AssertionResult AssertionSuccess() {
+ return AssertionResult(true);
+}
+
+// Makes a failed assertion result.
+AssertionResult AssertionFailure() {
+ return AssertionResult(false);
+}
+
+// Makes a failed assertion result with the given failure message.
+// Deprecated; use AssertionFailure() << message.
+AssertionResult AssertionFailure(const Message& message) {
+ return AssertionFailure() << message;
+}
+
+namespace internal {
+
+namespace edit_distance {
+std::vector<EditType> CalculateOptimalEdits(const std::vector<size_t>& left,
+ const std::vector<size_t>& right) {
+ std::vector<std::vector<double> > costs(
+ left.size() + 1, std::vector<double>(right.size() + 1));
+ std::vector<std::vector<EditType> > best_move(
+ left.size() + 1, std::vector<EditType>(right.size() + 1));
+
+ // Populate for empty right.
+ for (size_t l_i = 0; l_i < costs.size(); ++l_i) {
+ costs[l_i][0] = static_cast<double>(l_i);
+ best_move[l_i][0] = kRemove;
+ }
+ // Populate for empty left.
+ for (size_t r_i = 1; r_i < costs[0].size(); ++r_i) {
+ costs[0][r_i] = static_cast<double>(r_i);
+ best_move[0][r_i] = kAdd;
+ }
+
+ for (size_t l_i = 0; l_i < left.size(); ++l_i) {
+ for (size_t r_i = 0; r_i < right.size(); ++r_i) {
+ if (left[l_i] == right[r_i]) {
+ // Found a match. Consume it.
+ costs[l_i + 1][r_i + 1] = costs[l_i][r_i];
+ best_move[l_i + 1][r_i + 1] = kMatch;
+ continue;
+ }
+
+ const double add = costs[l_i + 1][r_i];
+ const double remove = costs[l_i][r_i + 1];
+ const double replace = costs[l_i][r_i];
+ if (add < remove && add < replace) {
+ costs[l_i + 1][r_i + 1] = add + 1;
+ best_move[l_i + 1][r_i + 1] = kAdd;
+ } else if (remove < add && remove < replace) {
+ costs[l_i + 1][r_i + 1] = remove + 1;
+ best_move[l_i + 1][r_i + 1] = kRemove;
+ } else {
+ // We make replace a little more expensive than add/remove to lower
+ // their priority.
+ costs[l_i + 1][r_i + 1] = replace + 1.00001;
+ best_move[l_i + 1][r_i + 1] = kReplace;
+ }
+ }
+ }
+
+ // Reconstruct the best path. We do it in reverse order.
+ std::vector<EditType> best_path;
+ for (size_t l_i = left.size(), r_i = right.size(); l_i > 0 || r_i > 0;) {
+ EditType move = best_move[l_i][r_i];
+ best_path.push_back(move);
+ l_i -= move != kAdd;
+ r_i -= move != kRemove;
+ }
+ std::reverse(best_path.begin(), best_path.end());
+ return best_path;
+}
+
+namespace {
+
+// Helper class to convert string into ids with deduplication.
+class InternalStrings {
+ public:
+ size_t GetId(const std::string& str) {
+ IdMap::iterator it = ids_.find(str);
+ if (it != ids_.end()) return it->second;
+ size_t id = ids_.size();
+ return ids_[str] = id;
+ }
+
+ private:
+ typedef std::map<std::string, size_t> IdMap;
+ IdMap ids_;
+};
+
+} // namespace
+
+std::vector<EditType> CalculateOptimalEdits(
+ const std::vector<std::string>& left,
+ const std::vector<std::string>& right) {
+ std::vector<size_t> left_ids, right_ids;
+ {
+ InternalStrings intern_table;
+ for (size_t i = 0; i < left.size(); ++i) {
+ left_ids.push_back(intern_table.GetId(left[i]));
+ }
+ for (size_t i = 0; i < right.size(); ++i) {
+ right_ids.push_back(intern_table.GetId(right[i]));
+ }
+ }
+ return CalculateOptimalEdits(left_ids, right_ids);
+}
+
+namespace {
+
+// Helper class that holds the state for one hunk and prints it out to the
+// stream.
+// It reorders adds/removes when possible to group all removes before all
+// adds. It also adds the hunk header before printint into the stream.
+class Hunk {
+ public:
+ Hunk(size_t left_start, size_t right_start)
+ : left_start_(left_start),
+ right_start_(right_start),
+ adds_(),
+ removes_(),
+ common_() {}
+
+ void PushLine(char edit, const char* line) {
+ switch (edit) {
+ case ' ':
+ ++common_;
+ FlushEdits();
+ hunk_.push_back(std::make_pair(' ', line));
+ break;
+ case '-':
+ ++removes_;
+ hunk_removes_.push_back(std::make_pair('-', line));
+ break;
+ case '+':
+ ++adds_;
+ hunk_adds_.push_back(std::make_pair('+', line));
+ break;
+ }
+ }
+
+ void PrintTo(std::ostream* os) {
+ PrintHeader(os);
+ FlushEdits();
+ for (std::list<std::pair<char, const char*> >::const_iterator it =
+ hunk_.begin();
+ it != hunk_.end(); ++it) {
+ *os << it->first << it->second << "\n";
+ }
+ }
+
+ bool has_edits() const { return adds_ || removes_; }
+
+ private:
+ void FlushEdits() {
+ hunk_.splice(hunk_.end(), hunk_removes_);
+ hunk_.splice(hunk_.end(), hunk_adds_);
+ }
+
+ // Print a unified diff header for one hunk.
+ // The format is
+ // "@@ -<left_start>,<left_length> +<right_start>,<right_length> @@"
+ // where the left/right parts are omitted if unnecessary.
+ void PrintHeader(std::ostream* ss) const {
+ *ss << "@@ ";
+ if (removes_) {
+ *ss << "-" << left_start_ << "," << (removes_ + common_);
+ }
+ if (removes_ && adds_) {
+ *ss << " ";
+ }
+ if (adds_) {
+ *ss << "+" << right_start_ << "," << (adds_ + common_);
+ }
+ *ss << " @@\n";
+ }
+
+ size_t left_start_, right_start_;
+ size_t adds_, removes_, common_;
+ std::list<std::pair<char, const char*> > hunk_, hunk_adds_, hunk_removes_;
+};
+
+} // namespace
+
+// Create a list of diff hunks in Unified diff format.
+// Each hunk has a header generated by PrintHeader above plus a body with
+// lines prefixed with ' ' for no change, '-' for deletion and '+' for
+// addition.
+// 'context' represents the desired unchanged prefix/suffix around the diff.
+// If two hunks are close enough that their contexts overlap, then they are
+// joined into one hunk.
+std::string CreateUnifiedDiff(const std::vector<std::string>& left,
+ const std::vector<std::string>& right,
+ size_t context) {
+ const std::vector<EditType> edits = CalculateOptimalEdits(left, right);
+
+ size_t l_i = 0, r_i = 0, edit_i = 0;
+ std::stringstream ss;
+ while (edit_i < edits.size()) {
+ // Find first edit.
+ while (edit_i < edits.size() && edits[edit_i] == kMatch) {
+ ++l_i;
+ ++r_i;
+ ++edit_i;
+ }
+
+ // Find the first line to include in the hunk.
+ const size_t prefix_context = std::min(l_i, context);
+ Hunk hunk(l_i - prefix_context + 1, r_i - prefix_context + 1);
+ for (size_t i = prefix_context; i > 0; --i) {
+ hunk.PushLine(' ', left[l_i - i].c_str());
+ }
+
+ // Iterate the edits until we found enough suffix for the hunk or the input
+ // is over.
+ size_t n_suffix = 0;
+ for (; edit_i < edits.size(); ++edit_i) {
+ if (n_suffix >= context) {
+ // Continue only if the next hunk is very close.
+ auto it = edits.begin() + static_cast<int>(edit_i);
+ while (it != edits.end() && *it == kMatch) ++it;
+ if (it == edits.end() ||
+ static_cast<size_t>(it - edits.begin()) - edit_i >= context) {
+ // There is no next edit or it is too far away.
+ break;
+ }
+ }
+
+ EditType edit = edits[edit_i];
+ // Reset count when a non match is found.
+ n_suffix = edit == kMatch ? n_suffix + 1 : 0;
+
+ if (edit == kMatch || edit == kRemove || edit == kReplace) {
+ hunk.PushLine(edit == kMatch ? ' ' : '-', left[l_i].c_str());
+ }
+ if (edit == kAdd || edit == kReplace) {
+ hunk.PushLine('+', right[r_i].c_str());
+ }
+
+ // Advance indices, depending on edit type.
+ l_i += edit != kAdd;
+ r_i += edit != kRemove;
+ }
+
+ if (!hunk.has_edits()) {
+ // We are done. We don't want this hunk.
+ break;
+ }
+
+ hunk.PrintTo(&ss);
+ }
+ return ss.str();
+}
+
+} // namespace edit_distance
+
+namespace {
+
+// The string representation of the values received in EqFailure() are already
+// escaped. Split them on escaped '\n' boundaries. Leave all other escaped
+// characters the same.
+std::vector<std::string> SplitEscapedString(const std::string& str) {
+ std::vector<std::string> lines;
+ size_t start = 0, end = str.size();
+ if (end > 2 && str[0] == '"' && str[end - 1] == '"') {
+ ++start;
+ --end;
+ }
+ bool escaped = false;
+ for (size_t i = start; i + 1 < end; ++i) {
+ if (escaped) {
+ escaped = false;
+ if (str[i] == 'n') {
+ lines.push_back(str.substr(start, i - start - 1));
+ start = i + 1;
+ }
+ } else {
+ escaped = str[i] == '\\';
+ }
+ }
+ lines.push_back(str.substr(start, end - start));
+ return lines;
+}
+
+} // namespace
+
+// Constructs and returns the message for an equality assertion
+// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
+//
+// The first four parameters are the expressions used in the assertion
+// and their values, as strings. For example, for ASSERT_EQ(foo, bar)
+// where foo is 5 and bar is 6, we have:
+//
+// lhs_expression: "foo"
+// rhs_expression: "bar"
+// lhs_value: "5"
+// rhs_value: "6"
+//
+// The ignoring_case parameter is true iff the assertion is a
+// *_STRCASEEQ*. When it's true, the string "Ignoring case" will
+// be inserted into the message.
+AssertionResult EqFailure(const char* lhs_expression,
+ const char* rhs_expression,
+ const std::string& lhs_value,
+ const std::string& rhs_value,
+ bool ignoring_case) {
+ Message msg;
+ msg << "Expected equality of these values:";
+ msg << "\n " << lhs_expression;
+ if (lhs_value != lhs_expression) {
+ msg << "\n Which is: " << lhs_value;
+ }
+ msg << "\n " << rhs_expression;
+ if (rhs_value != rhs_expression) {
+ msg << "\n Which is: " << rhs_value;
+ }
+
+ if (ignoring_case) {
+ msg << "\nIgnoring case";
+ }
+
+ if (!lhs_value.empty() && !rhs_value.empty()) {
+ const std::vector<std::string> lhs_lines =
+ SplitEscapedString(lhs_value);
+ const std::vector<std::string> rhs_lines =
+ SplitEscapedString(rhs_value);
+ if (lhs_lines.size() > 1 || rhs_lines.size() > 1) {
+ msg << "\nWith diff:\n"
+ << edit_distance::CreateUnifiedDiff(lhs_lines, rhs_lines);
+ }
+ }
+
+ return AssertionFailure() << msg;
+}
+
+// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
+std::string GetBoolAssertionFailureMessage(
+ const AssertionResult& assertion_result,
+ const char* expression_text,
+ const char* actual_predicate_value,
+ const char* expected_predicate_value) {
+ const char* actual_message = assertion_result.message();
+ Message msg;
+ msg << "Value of: " << expression_text
+ << "\n Actual: " << actual_predicate_value;
+ if (actual_message[0] != '\0')
+ msg << " (" << actual_message << ")";
+ msg << "\nExpected: " << expected_predicate_value;
+ return msg.GetString();
+}
+
+// Helper function for implementing ASSERT_NEAR.
+AssertionResult DoubleNearPredFormat(const char* expr1,
+ const char* expr2,
+ const char* abs_error_expr,
+ double val1,
+ double val2,
+ double abs_error) {
+ const double diff = fabs(val1 - val2);
+ if (diff <= abs_error) return AssertionSuccess();
+
+ return AssertionFailure()
+ << "The difference between " << expr1 << " and " << expr2
+ << " is " << diff << ", which exceeds " << abs_error_expr << ", where\n"
+ << expr1 << " evaluates to " << val1 << ",\n"
+ << expr2 << " evaluates to " << val2 << ", and\n"
+ << abs_error_expr << " evaluates to " << abs_error << ".";
+}
+
+
+// Helper template for implementing FloatLE() and DoubleLE().
+template <typename RawType>
+AssertionResult FloatingPointLE(const char* expr1,
+ const char* expr2,
+ RawType val1,
+ RawType val2) {
+ // Returns success if val1 is less than val2,
+ if (val1 < val2) {
+ return AssertionSuccess();
+ }
+
+ // or if val1 is almost equal to val2.
+ const FloatingPoint<RawType> lhs(val1), rhs(val2);
+ if (lhs.AlmostEquals(rhs)) {
+ return AssertionSuccess();
+ }
+
+ // Note that the above two checks will both fail if either val1 or
+ // val2 is NaN, as the IEEE floating-point standard requires that
+ // any predicate involving a NaN must return false.
+
+ ::std::stringstream val1_ss;
+ val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
+ << val1;
+
+ ::std::stringstream val2_ss;
+ val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
+ << val2;
+
+ return AssertionFailure()
+ << "Expected: (" << expr1 << ") <= (" << expr2 << ")\n"
+ << " Actual: " << StringStreamToString(&val1_ss) << " vs "
+ << StringStreamToString(&val2_ss);
+}
+
+} // namespace internal
+
+// Asserts that val1 is less than, or almost equal to, val2. Fails
+// otherwise. In particular, it fails if either val1 or val2 is NaN.
+AssertionResult FloatLE(const char* expr1, const char* expr2,
+ float val1, float val2) {
+ return internal::FloatingPointLE<float>(expr1, expr2, val1, val2);
+}
+
+// Asserts that val1 is less than, or almost equal to, val2. Fails
+// otherwise. In particular, it fails if either val1 or val2 is NaN.
+AssertionResult DoubleLE(const char* expr1, const char* expr2,
+ double val1, double val2) {
+ return internal::FloatingPointLE<double>(expr1, expr2, val1, val2);
+}
+
+namespace internal {
+
+// The helper function for {ASSERT|EXPECT}_EQ with int or enum
+// arguments.
+AssertionResult CmpHelperEQ(const char* lhs_expression,
+ const char* rhs_expression,
+ BiggestInt lhs,
+ BiggestInt rhs) {
+ if (lhs == rhs) {
+ return AssertionSuccess();
+ }
+
+ return EqFailure(lhs_expression,
+ rhs_expression,
+ FormatForComparisonFailureMessage(lhs, rhs),
+ FormatForComparisonFailureMessage(rhs, lhs),
+ false);
+}
+
+// A macro for implementing the helper functions needed to implement
+// ASSERT_?? and EXPECT_?? with integer or enum arguments. It is here
+// just to avoid copy-and-paste of similar code.
+#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
+AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
+ BiggestInt val1, BiggestInt val2) {\
+ if (val1 op val2) {\
+ return AssertionSuccess();\
+ } else {\
+ return AssertionFailure() \
+ << "Expected: (" << expr1 << ") " #op " (" << expr2\
+ << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
+ << " vs " << FormatForComparisonFailureMessage(val2, val1);\
+ }\
+}
+
+// Implements the helper function for {ASSERT|EXPECT}_NE with int or
+// enum arguments.
+GTEST_IMPL_CMP_HELPER_(NE, !=)
+// Implements the helper function for {ASSERT|EXPECT}_LE with int or
+// enum arguments.
+GTEST_IMPL_CMP_HELPER_(LE, <=)
+// Implements the helper function for {ASSERT|EXPECT}_LT with int or
+// enum arguments.
+GTEST_IMPL_CMP_HELPER_(LT, < )
+// Implements the helper function for {ASSERT|EXPECT}_GE with int or
+// enum arguments.
+GTEST_IMPL_CMP_HELPER_(GE, >=)
+// Implements the helper function for {ASSERT|EXPECT}_GT with int or
+// enum arguments.
+GTEST_IMPL_CMP_HELPER_(GT, > )
+
+#undef GTEST_IMPL_CMP_HELPER_
+
+// The helper function for {ASSERT|EXPECT}_STREQ.
+AssertionResult CmpHelperSTREQ(const char* lhs_expression,
+ const char* rhs_expression,
+ const char* lhs,
+ const char* rhs) {
+ if (String::CStringEquals(lhs, rhs)) {
+ return AssertionSuccess();
+ }
+
+ return EqFailure(lhs_expression,
+ rhs_expression,
+ PrintToString(lhs),
+ PrintToString(rhs),
+ false);
+}
+
+// The helper function for {ASSERT|EXPECT}_STRCASEEQ.
+AssertionResult CmpHelperSTRCASEEQ(const char* lhs_expression,
+ const char* rhs_expression,
+ const char* lhs,
+ const char* rhs) {
+ if (String::CaseInsensitiveCStringEquals(lhs, rhs)) {
+ return AssertionSuccess();
+ }
+
+ return EqFailure(lhs_expression,
+ rhs_expression,
+ PrintToString(lhs),
+ PrintToString(rhs),
+ true);
+}
+
+// The helper function for {ASSERT|EXPECT}_STRNE.
+AssertionResult CmpHelperSTRNE(const char* s1_expression,
+ const char* s2_expression,
+ const char* s1,
+ const char* s2) {
+ if (!String::CStringEquals(s1, s2)) {
+ return AssertionSuccess();
+ } else {
+ return AssertionFailure() << "Expected: (" << s1_expression << ") != ("
+ << s2_expression << "), actual: \""
+ << s1 << "\" vs \"" << s2 << "\"";
+ }
+}
+
+// The helper function for {ASSERT|EXPECT}_STRCASENE.
+AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
+ const char* s2_expression,
+ const char* s1,
+ const char* s2) {
+ if (!String::CaseInsensitiveCStringEquals(s1, s2)) {
+ return AssertionSuccess();
+ } else {
+ return AssertionFailure()
+ << "Expected: (" << s1_expression << ") != ("
+ << s2_expression << ") (ignoring case), actual: \""
+ << s1 << "\" vs \"" << s2 << "\"";
+ }
+}
+
+} // namespace internal
+
+namespace {
+
+// Helper functions for implementing IsSubString() and IsNotSubstring().
+
+// This group of overloaded functions return true iff needle is a
+// substring of haystack. NULL is considered a substring of itself
+// only.
+
+bool IsSubstringPred(const char* needle, const char* haystack) {
+ if (needle == nullptr || haystack == nullptr) return needle == haystack;
+
+ return strstr(haystack, needle) != nullptr;
+}
+
+bool IsSubstringPred(const wchar_t* needle, const wchar_t* haystack) {
+ if (needle == nullptr || haystack == nullptr) return needle == haystack;
+
+ return wcsstr(haystack, needle) != nullptr;
+}
+
+// StringType here can be either ::std::string or ::std::wstring.
+template <typename StringType>
+bool IsSubstringPred(const StringType& needle,
+ const StringType& haystack) {
+ return haystack.find(needle) != StringType::npos;
+}
+
+// This function implements either IsSubstring() or IsNotSubstring(),
+// depending on the value of the expected_to_be_substring parameter.
+// StringType here can be const char*, const wchar_t*, ::std::string,
+// or ::std::wstring.
+template <typename StringType>
+AssertionResult IsSubstringImpl(
+ bool expected_to_be_substring,
+ const char* needle_expr, const char* haystack_expr,
+ const StringType& needle, const StringType& haystack) {
+ if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
+ return AssertionSuccess();
+
+ const bool is_wide_string = sizeof(needle[0]) > 1;
+ const char* const begin_string_quote = is_wide_string ? "L\"" : "\"";
+ return AssertionFailure()
+ << "Value of: " << needle_expr << "\n"
+ << " Actual: " << begin_string_quote << needle << "\"\n"
+ << "Expected: " << (expected_to_be_substring ? "" : "not ")
+ << "a substring of " << haystack_expr << "\n"
+ << "Which is: " << begin_string_quote << haystack << "\"";
+}
+
+} // namespace
+
+// IsSubstring() and IsNotSubstring() check whether needle is a
+// substring of haystack (NULL is considered a substring of itself
+// only), and return an appropriate error message when they fail.
+
+AssertionResult IsSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const char* needle, const char* haystack) {
+ return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
+}
+
+AssertionResult IsSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const wchar_t* needle, const wchar_t* haystack) {
+ return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
+}
+
+AssertionResult IsNotSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const char* needle, const char* haystack) {
+ return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
+}
+
+AssertionResult IsNotSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const wchar_t* needle, const wchar_t* haystack) {
+ return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
+}
+
+AssertionResult IsSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const ::std::string& needle, const ::std::string& haystack) {
+ return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
+}
+
+AssertionResult IsNotSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const ::std::string& needle, const ::std::string& haystack) {
+ return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
+}
+
+#if GTEST_HAS_STD_WSTRING
+AssertionResult IsSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const ::std::wstring& needle, const ::std::wstring& haystack) {
+ return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
+}
+
+AssertionResult IsNotSubstring(
+ const char* needle_expr, const char* haystack_expr,
+ const ::std::wstring& needle, const ::std::wstring& haystack) {
+ return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
+}
+#endif // GTEST_HAS_STD_WSTRING
+
+namespace internal {
+
+#if GTEST_OS_WINDOWS
+
+namespace {
+
+// Helper function for IsHRESULT{SuccessFailure} predicates
+AssertionResult HRESULTFailureHelper(const char* expr,
+ const char* expected,
+ long hr) { // NOLINT
+# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE
+
+ // Windows CE doesn't support FormatMessage.
+ const char error_text[] = "";
+
+# else
+
+ // Looks up the human-readable system message for the HRESULT code
+ // and since we're not passing any params to FormatMessage, we don't
+ // want inserts expanded.
+ const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS;
+ const DWORD kBufSize = 4096;
+ // Gets the system's human readable message string for this HRESULT.
+ char error_text[kBufSize] = { '\0' };
+ DWORD message_length = ::FormatMessageA(kFlags,
+ 0, // no source, we're asking system
+ hr, // the error
+ 0, // no line width restrictions
+ error_text, // output buffer
+ kBufSize, // buf size
+ nullptr); // no arguments for inserts
+ // Trims tailing white space (FormatMessage leaves a trailing CR-LF)
+ for (; message_length && IsSpace(error_text[message_length - 1]);
+ --message_length) {
+ error_text[message_length - 1] = '\0';
+ }
+
+# endif // GTEST_OS_WINDOWS_MOBILE
+
+ const std::string error_hex("0x" + String::FormatHexInt(hr));
+ return ::testing::AssertionFailure()
+ << "Expected: " << expr << " " << expected << ".\n"
+ << " Actual: " << error_hex << " " << error_text << "\n";
+}
+
+} // namespace
+
+AssertionResult IsHRESULTSuccess(const char* expr, long hr) { // NOLINT
+ if (SUCCEEDED(hr)) {
+ return AssertionSuccess();
+ }
+ return HRESULTFailureHelper(expr, "succeeds", hr);
+}
+
+AssertionResult IsHRESULTFailure(const char* expr, long hr) { // NOLINT
+ if (FAILED(hr)) {
+ return AssertionSuccess();
+ }
+ return HRESULTFailureHelper(expr, "fails", hr);
+}
+
+#endif // GTEST_OS_WINDOWS
+
+// Utility functions for encoding Unicode text (wide strings) in
+// UTF-8.
+
+// A Unicode code-point can have up to 21 bits, and is encoded in UTF-8
+// like this:
+//
+// Code-point length Encoding
+// 0 - 7 bits 0xxxxxxx
+// 8 - 11 bits 110xxxxx 10xxxxxx
+// 12 - 16 bits 1110xxxx 10xxxxxx 10xxxxxx
+// 17 - 21 bits 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+
+// The maximum code-point a one-byte UTF-8 sequence can represent.
+const UInt32 kMaxCodePoint1 = (static_cast<UInt32>(1) << 7) - 1;
+
+// The maximum code-point a two-byte UTF-8 sequence can represent.
+const UInt32 kMaxCodePoint2 = (static_cast<UInt32>(1) << (5 + 6)) - 1;
+
+// The maximum code-point a three-byte UTF-8 sequence can represent.
+const UInt32 kMaxCodePoint3 = (static_cast<UInt32>(1) << (4 + 2*6)) - 1;
+
+// The maximum code-point a four-byte UTF-8 sequence can represent.
+const UInt32 kMaxCodePoint4 = (static_cast<UInt32>(1) << (3 + 3*6)) - 1;
+
+// Chops off the n lowest bits from a bit pattern. Returns the n
+// lowest bits. As a side effect, the original bit pattern will be
+// shifted to the right by n bits.
+inline UInt32 ChopLowBits(UInt32* bits, int n) {
+ const UInt32 low_bits = *bits & ((static_cast<UInt32>(1) << n) - 1);
+ *bits >>= n;
+ return low_bits;
+}
+
+// Converts a Unicode code point to a narrow string in UTF-8 encoding.
+// code_point parameter is of type UInt32 because wchar_t may not be
+// wide enough to contain a code point.
+// If the code_point is not a valid Unicode code point
+// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted
+// to "(Invalid Unicode 0xXXXXXXXX)".
+std::string CodePointToUtf8(UInt32 code_point) {
+ if (code_point > kMaxCodePoint4) {
+ return "(Invalid Unicode 0x" + String::FormatHexUInt32(code_point) + ")";
+ }
+
+ char str[5]; // Big enough for the largest valid code point.
+ if (code_point <= kMaxCodePoint1) {
+ str[1] = '\0';
+ str[0] = static_cast<char>(code_point); // 0xxxxxxx
+ } else if (code_point <= kMaxCodePoint2) {
+ str[2] = '\0';
+ str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
+ str[0] = static_cast<char>(0xC0 | code_point); // 110xxxxx
+ } else if (code_point <= kMaxCodePoint3) {
+ str[3] = '\0';
+ str[2] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
+ str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
+ str[0] = static_cast<char>(0xE0 | code_point); // 1110xxxx
+ } else { // code_point <= kMaxCodePoint4
+ str[4] = '\0';
+ str[3] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
+ str[2] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
+ str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
+ str[0] = static_cast<char>(0xF0 | code_point); // 11110xxx
+ }
+ return str;
+}
+
+// The following two functions only make sense if the system
+// uses UTF-16 for wide string encoding. All supported systems
+// with 16 bit wchar_t (Windows, Cygwin) do use UTF-16.
+
+// Determines if the arguments constitute UTF-16 surrogate pair
+// and thus should be combined into a single Unicode code point
+// using CreateCodePointFromUtf16SurrogatePair.
+inline bool IsUtf16SurrogatePair(wchar_t first, wchar_t second) {
+ return sizeof(wchar_t) == 2 &&
+ (first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00;
+}
+
+// Creates a Unicode code point from UTF16 surrogate pair.
+inline UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first,
+ wchar_t second) {
+ const auto first_u = static_cast<UInt32>(first);
+ const auto second_u = static_cast<UInt32>(second);
+ const UInt32 mask = (1 << 10) - 1;
+ return (sizeof(wchar_t) == 2)
+ ? (((first_u & mask) << 10) | (second_u & mask)) + 0x10000
+ :
+ // This function should not be called when the condition is
+ // false, but we provide a sensible default in case it is.
+ first_u;
+}
+
+// Converts a wide string to a narrow string in UTF-8 encoding.
+// The wide string is assumed to have the following encoding:
+// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin)
+// UTF-32 if sizeof(wchar_t) == 4 (on Linux)
+// Parameter str points to a null-terminated wide string.
+// Parameter num_chars may additionally limit the number
+// of wchar_t characters processed. -1 is used when the entire string
+// should be processed.
+// If the string contains code points that are not valid Unicode code points
+// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
+// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
+// and contains invalid UTF-16 surrogate pairs, values in those pairs
+// will be encoded as individual Unicode characters from Basic Normal Plane.
+std::string WideStringToUtf8(const wchar_t* str, int num_chars) {
+ if (num_chars == -1)
+ num_chars = static_cast<int>(wcslen(str));
+
+ ::std::stringstream stream;
+ for (int i = 0; i < num_chars; ++i) {
+ UInt32 unicode_code_point;
+
+ if (str[i] == L'\0') {
+ break;
+ } else if (i + 1 < num_chars && IsUtf16SurrogatePair(str[i], str[i + 1])) {
+ unicode_code_point = CreateCodePointFromUtf16SurrogatePair(str[i],
+ str[i + 1]);
+ i++;
+ } else {
+ unicode_code_point = static_cast<UInt32>(str[i]);
+ }
+
+ stream << CodePointToUtf8(unicode_code_point);
+ }
+ return StringStreamToString(&stream);
+}
+
+// Converts a wide C string to an std::string using the UTF-8 encoding.
+// NULL will be converted to "(null)".
+std::string String::ShowWideCString(const wchar_t * wide_c_str) {
+ if (wide_c_str == nullptr) return "(null)";
+
+ return internal::WideStringToUtf8(wide_c_str, -1);
+}
+
+// Compares two wide C strings. Returns true iff they have the same
+// content.
+//
+// Unlike wcscmp(), this function can handle NULL argument(s). A NULL
+// C string is considered different to any non-NULL C string,
+// including the empty string.
+bool String::WideCStringEquals(const wchar_t * lhs, const wchar_t * rhs) {
+ if (lhs == nullptr) return rhs == nullptr;
+
+ if (rhs == nullptr) return false;
+
+ return wcscmp(lhs, rhs) == 0;
+}
+
+// Helper function for *_STREQ on wide strings.
+AssertionResult CmpHelperSTREQ(const char* lhs_expression,
+ const char* rhs_expression,
+ const wchar_t* lhs,
+ const wchar_t* rhs) {
+ if (String::WideCStringEquals(lhs, rhs)) {
+ return AssertionSuccess();
+ }
+
+ return EqFailure(lhs_expression,
+ rhs_expression,
+ PrintToString(lhs),
+ PrintToString(rhs),
+ false);
+}
+
+// Helper function for *_STRNE on wide strings.
+AssertionResult CmpHelperSTRNE(const char* s1_expression,
+ const char* s2_expression,
+ const wchar_t* s1,
+ const wchar_t* s2) {
+ if (!String::WideCStringEquals(s1, s2)) {
+ return AssertionSuccess();
+ }
+
+ return AssertionFailure() << "Expected: (" << s1_expression << ") != ("
+ << s2_expression << "), actual: "
+ << PrintToString(s1)
+ << " vs " << PrintToString(s2);
+}
+
+// Compares two C strings, ignoring case. Returns true iff they have
+// the same content.
+//
+// Unlike strcasecmp(), this function can handle NULL argument(s). A
+// NULL C string is considered different to any non-NULL C string,
+// including the empty string.
+bool String::CaseInsensitiveCStringEquals(const char * lhs, const char * rhs) {
+ if (lhs == nullptr) return rhs == nullptr;
+ if (rhs == nullptr) return false;
+ return posix::StrCaseCmp(lhs, rhs) == 0;
+}
+
+ // Compares two wide C strings, ignoring case. Returns true iff they
+ // have the same content.
+ //
+ // Unlike wcscasecmp(), this function can handle NULL argument(s).
+ // A NULL C string is considered different to any non-NULL wide C string,
+ // including the empty string.
+ // NB: The implementations on different platforms slightly differ.
+ // On windows, this method uses _wcsicmp which compares according to LC_CTYPE
+ // environment variable. On GNU platform this method uses wcscasecmp
+ // which compares according to LC_CTYPE category of the current locale.
+ // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the
+ // current locale.
+bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
+ const wchar_t* rhs) {
+ if (lhs == nullptr) return rhs == nullptr;
+
+ if (rhs == nullptr) return false;
+
+#if GTEST_OS_WINDOWS
+ return _wcsicmp(lhs, rhs) == 0;
+#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID
+ return wcscasecmp(lhs, rhs) == 0;
+#else
+ // Android, Mac OS X and Cygwin don't define wcscasecmp.
+ // Other unknown OSes may not define it either.
+ wint_t left, right;
+ do {
+ left = towlower(*lhs++);
+ right = towlower(*rhs++);
+ } while (left && left == right);
+ return left == right;
+#endif // OS selector
+}
+
+// Returns true iff str ends with the given suffix, ignoring case.
+// Any string is considered to end with an empty suffix.
+bool String::EndsWithCaseInsensitive(
+ const std::string& str, const std::string& suffix) {
+ const size_t str_len = str.length();
+ const size_t suffix_len = suffix.length();
+ return (str_len >= suffix_len) &&
+ CaseInsensitiveCStringEquals(str.c_str() + str_len - suffix_len,
+ suffix.c_str());
+}
+
+// Formats an int value as "%02d".
+std::string String::FormatIntWidth2(int value) {
+ std::stringstream ss;
+ ss << std::setfill('0') << std::setw(2) << value;
+ return ss.str();
+}
+
+// Formats an int value as "%X".
+std::string String::FormatHexUInt32(UInt32 value) {
+ std::stringstream ss;
+ ss << std::hex << std::uppercase << value;
+ return ss.str();
+}
+
+// Formats an int value as "%X".
+std::string String::FormatHexInt(int value) {
+ return FormatHexUInt32(static_cast<UInt32>(value));
+}
+
+// Formats a byte as "%02X".
+std::string String::FormatByte(unsigned char value) {
+ std::stringstream ss;
+ ss << std::setfill('0') << std::setw(2) << std::hex << std::uppercase
+ << static_cast<unsigned int>(value);
+ return ss.str();
+}
+
+// Converts the buffer in a stringstream to an std::string, converting NUL
+// bytes to "\\0" along the way.
+std::string StringStreamToString(::std::stringstream* ss) {
+ const ::std::string& str = ss->str();
+ const char* const start = str.c_str();
+ const char* const end = start + str.length();
+
+ std::string result;
+ result.reserve(static_cast<size_t>(2 * (end - start)));
+ for (const char* ch = start; ch != end; ++ch) {
+ if (*ch == '\0') {
+ result += "\\0"; // Replaces NUL with "\\0";
+ } else {
+ result += *ch;
+ }
+ }
+
+ return result;
+}
+
+// Appends the user-supplied message to the Google-Test-generated message.
+std::string AppendUserMessage(const std::string& gtest_msg,
+ const Message& user_msg) {
+ // Appends the user message if it's non-empty.
+ const std::string user_msg_string = user_msg.GetString();
+ if (user_msg_string.empty()) {
+ return gtest_msg;
+ }
+
+ return gtest_msg + "\n" + user_msg_string;
+}
+
+} // namespace internal
+
+// class TestResult
+
+// Creates an empty TestResult.
+TestResult::TestResult()
+ : death_test_count_(0),
+ elapsed_time_(0) {
+}
+
+// D'tor.
+TestResult::~TestResult() {
+}
+
+// Returns the i-th test part result among all the results. i can
+// range from 0 to total_part_count() - 1. If i is not in that range,
+// aborts the program.
+const TestPartResult& TestResult::GetTestPartResult(int i) const {
+ if (i < 0 || i >= total_part_count())
+ internal::posix::Abort();
+ return test_part_results_.at(static_cast<size_t>(i));
+}
+
+// Returns the i-th test property. i can range from 0 to
+// test_property_count() - 1. If i is not in that range, aborts the
+// program.
+const TestProperty& TestResult::GetTestProperty(int i) const {
+ if (i < 0 || i >= test_property_count())
+ internal::posix::Abort();
+ return test_properties_.at(static_cast<size_t>(i));
+}
+
+// Clears the test part results.
+void TestResult::ClearTestPartResults() {
+ test_part_results_.clear();
+}
+
+// Adds a test part result to the list.
+void TestResult::AddTestPartResult(const TestPartResult& test_part_result) {
+ test_part_results_.push_back(test_part_result);
+}
+
+// Adds a test property to the list. If a property with the same key as the
+// supplied property is already represented, the value of this test_property
+// replaces the old value for that key.
+void TestResult::RecordProperty(const std::string& xml_element,
+ const TestProperty& test_property) {
+ if (!ValidateTestProperty(xml_element, test_property)) {
+ return;
+ }
+ internal::MutexLock lock(&test_properites_mutex_);
+ const std::vector<TestProperty>::iterator property_with_matching_key =
+ std::find_if(test_properties_.begin(), test_properties_.end(),
+ internal::TestPropertyKeyIs(test_property.key()));
+ if (property_with_matching_key == test_properties_.end()) {
+ test_properties_.push_back(test_property);
+ return;
+ }
+ property_with_matching_key->SetValue(test_property.value());
+}
+
+// The list of reserved attributes used in the <testsuites> element of XML
+// output.
+static const char* const kReservedTestSuitesAttributes[] = {
+ "disabled",
+ "errors",
+ "failures",
+ "name",
+ "random_seed",
+ "tests",
+ "time",
+ "timestamp"
+};
+
+// The list of reserved attributes used in the <testsuite> element of XML
+// output.
+static const char* const kReservedTestSuiteAttributes[] = {
+ "disabled",
+ "errors",
+ "failures",
+ "name",
+ "tests",
+ "time"
+};
+
+// The list of reserved attributes used in the <testcase> element of XML output.
+static const char* const kReservedTestCaseAttributes[] = {
+ "classname", "name", "status", "time", "type_param",
+ "value_param", "file", "line"};
+
+// Use a slightly different set for allowed output to ensure existing tests can
+// still RecordProperty("result")
+static const char* const kReservedOutputTestCaseAttributes[] = {
+ "classname", "name", "status", "time", "type_param",
+ "value_param", "file", "line", "result"};
+
+template <int kSize>
+std::vector<std::string> ArrayAsVector(const char* const (&array)[kSize]) {
+ return std::vector<std::string>(array, array + kSize);
+}
+
+static std::vector<std::string> GetReservedAttributesForElement(
+ const std::string& xml_element) {
+ if (xml_element == "testsuites") {
+ return ArrayAsVector(kReservedTestSuitesAttributes);
+ } else if (xml_element == "testsuite") {
+ return ArrayAsVector(kReservedTestSuiteAttributes);
+ } else if (xml_element == "testcase") {
+ return ArrayAsVector(kReservedTestCaseAttributes);
+ } else {
+ GTEST_CHECK_(false) << "Unrecognized xml_element provided: " << xml_element;
+ }
+ // This code is unreachable but some compilers may not realizes that.
+ return std::vector<std::string>();
+}
+
+// TODO(jdesprez): Merge the two getReserved attributes once skip is improved
+static std::vector<std::string> GetReservedOutputAttributesForElement(
+ const std::string& xml_element) {
+ if (xml_element == "testsuites") {
+ return ArrayAsVector(kReservedTestSuitesAttributes);
+ } else if (xml_element == "testsuite") {
+ return ArrayAsVector(kReservedTestSuiteAttributes);
+ } else if (xml_element == "testcase") {
+ return ArrayAsVector(kReservedOutputTestCaseAttributes);
+ } else {
+ GTEST_CHECK_(false) << "Unrecognized xml_element provided: " << xml_element;
+ }
+ // This code is unreachable but some compilers may not realizes that.
+ return std::vector<std::string>();
+}
+
+static std::string FormatWordList(const std::vector<std::string>& words) {
+ Message word_list;
+ for (size_t i = 0; i < words.size(); ++i) {
+ if (i > 0 && words.size() > 2) {
+ word_list << ", ";
+ }
+ if (i == words.size() - 1) {
+ word_list << "and ";
+ }
+ word_list << "'" << words[i] << "'";
+ }
+ return word_list.GetString();
+}
+
+static bool ValidateTestPropertyName(
+ const std::string& property_name,
+ const std::vector<std::string>& reserved_names) {
+ if (std::find(reserved_names.begin(), reserved_names.end(), property_name) !=
+ reserved_names.end()) {
+ ADD_FAILURE() << "Reserved key used in RecordProperty(): " << property_name
+ << " (" << FormatWordList(reserved_names)
+ << " are reserved by " << GTEST_NAME_ << ")";
+ return false;
+ }
+ return true;
+}
+
+// Adds a failure if the key is a reserved attribute of the element named
+// xml_element. Returns true if the property is valid.
+bool TestResult::ValidateTestProperty(const std::string& xml_element,
+ const TestProperty& test_property) {
+ return ValidateTestPropertyName(test_property.key(),
+ GetReservedAttributesForElement(xml_element));
+}
+
+// Clears the object.
+void TestResult::Clear() {
+ test_part_results_.clear();
+ test_properties_.clear();
+ death_test_count_ = 0;
+ elapsed_time_ = 0;
+}
+
+// Returns true off the test part was skipped.
+static bool TestPartSkipped(const TestPartResult& result) {
+ return result.skipped();
+}
+
+// Returns true iff the test was skipped.
+bool TestResult::Skipped() const {
+ return !Failed() && CountIf(test_part_results_, TestPartSkipped) > 0;
+}
+
+// Returns true iff the test failed.
+bool TestResult::Failed() const {
+ for (int i = 0; i < total_part_count(); ++i) {
+ if (GetTestPartResult(i).failed())
+ return true;
+ }
+ return false;
+}
+
+// Returns true iff the test part fatally failed.
+static bool TestPartFatallyFailed(const TestPartResult& result) {
+ return result.fatally_failed();
+}
+
+// Returns true iff the test fatally failed.
+bool TestResult::HasFatalFailure() const {
+ return CountIf(test_part_results_, TestPartFatallyFailed) > 0;
+}
+
+// Returns true iff the test part non-fatally failed.
+static bool TestPartNonfatallyFailed(const TestPartResult& result) {
+ return result.nonfatally_failed();
+}
+
+// Returns true iff the test has a non-fatal failure.
+bool TestResult::HasNonfatalFailure() const {
+ return CountIf(test_part_results_, TestPartNonfatallyFailed) > 0;
+}
+
+// Gets the number of all test parts. This is the sum of the number
+// of successful test parts and the number of failed test parts.
+int TestResult::total_part_count() const {
+ return static_cast<int>(test_part_results_.size());
+}
+
+// Returns the number of the test properties.
+int TestResult::test_property_count() const {
+ return static_cast<int>(test_properties_.size());
+}
+
+// class Test
+
+// Creates a Test object.
+
+// The c'tor saves the states of all flags.
+Test::Test()
+ : gtest_flag_saver_(new GTEST_FLAG_SAVER_) {
+}
+
+// The d'tor restores the states of all flags. The actual work is
+// done by the d'tor of the gtest_flag_saver_ field, and thus not
+// visible here.
+Test::~Test() {
+}
+
+// Sets up the test fixture.
+//
+// A sub-class may override this.
+void Test::SetUp() {
+}
+
+// Tears down the test fixture.
+//
+// A sub-class may override this.
+void Test::TearDown() {
+}
+
+// Allows user supplied key value pairs to be recorded for later output.
+void Test::RecordProperty(const std::string& key, const std::string& value) {
+ UnitTest::GetInstance()->RecordProperty(key, value);
+}
+
+// Allows user supplied key value pairs to be recorded for later output.
+void Test::RecordProperty(const std::string& key, int value) {
+ Message value_message;
+ value_message << value;
+ RecordProperty(key, value_message.GetString().c_str());
+}
+
+namespace internal {
+
+void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
+ const std::string& message) {
+ // This function is a friend of UnitTest and as such has access to
+ // AddTestPartResult.
+ UnitTest::GetInstance()->AddTestPartResult(
+ result_type,
+ nullptr, // No info about the source file where the exception occurred.
+ -1, // We have no info on which line caused the exception.
+ message,
+ ""); // No stack trace, either.
+}
+
+} // namespace internal
+
+// Google Test requires all tests in the same test suite to use the same test
+// fixture class. This function checks if the current test has the
+// same fixture class as the first test in the current test suite. If
+// yes, it returns true; otherwise it generates a Google Test failure and
+// returns false.
+bool Test::HasSameFixtureClass() {
+ internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
+ const TestSuite* const test_suite = impl->current_test_suite();
+
+ // Info about the first test in the current test suite.
+ const TestInfo* const first_test_info = test_suite->test_info_list()[0];
+ const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;
+ const char* const first_test_name = first_test_info->name();
+
+ // Info about the current test.
+ const TestInfo* const this_test_info = impl->current_test_info();
+ const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_;
+ const char* const this_test_name = this_test_info->name();
+
+ if (this_fixture_id != first_fixture_id) {
+ // Is the first test defined using TEST?
+ const bool first_is_TEST = first_fixture_id == internal::GetTestTypeId();
+ // Is this test defined using TEST?
+ const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId();
+
+ if (first_is_TEST || this_is_TEST) {
+ // Both TEST and TEST_F appear in same test suite, which is incorrect.
+ // Tell the user how to fix this.
+
+ // Gets the name of the TEST and the name of the TEST_F. Note
+ // that first_is_TEST and this_is_TEST cannot both be true, as
+ // the fixture IDs are different for the two tests.
+ const char* const TEST_name =
+ first_is_TEST ? first_test_name : this_test_name;
+ const char* const TEST_F_name =
+ first_is_TEST ? this_test_name : first_test_name;
+
+ ADD_FAILURE()
+ << "All tests in the same test suite must use the same test fixture\n"
+ << "class, so mixing TEST_F and TEST in the same test suite is\n"
+ << "illegal. In test suite " << this_test_info->test_suite_name()
+ << ",\n"
+ << "test " << TEST_F_name << " is defined using TEST_F but\n"
+ << "test " << TEST_name << " is defined using TEST. You probably\n"
+ << "want to change the TEST to TEST_F or move it to another test\n"
+ << "case.";
+ } else {
+ // Two fixture classes with the same name appear in two different
+ // namespaces, which is not allowed. Tell the user how to fix this.
+ ADD_FAILURE()
+ << "All tests in the same test suite must use the same test fixture\n"
+ << "class. However, in test suite "
+ << this_test_info->test_suite_name() << ",\n"
+ << "you defined test " << first_test_name << " and test "
+ << this_test_name << "\n"
+ << "using two different test fixture classes. This can happen if\n"
+ << "the two classes are from different namespaces or translation\n"
+ << "units and have the same name. You should probably rename one\n"
+ << "of the classes to put the tests into different test suites.";
+ }
+ return false;
+ }
+
+ return true;
+}
+
+#if GTEST_HAS_SEH
+
+// Adds an "exception thrown" fatal failure to the current test. This
+// function returns its result via an output parameter pointer because VC++
+// prohibits creation of objects with destructors on stack in functions
+// using __try (see error C2712).
+static std::string* FormatSehExceptionMessage(DWORD exception_code,
+ const char* location) {
+ Message message;
+ message << "SEH exception with code 0x" << std::setbase(16) <<
+ exception_code << std::setbase(10) << " thrown in " << location << ".";
+
+ return new std::string(message.GetString());
+}
+
+#endif // GTEST_HAS_SEH
+
+namespace internal {
+
+#if GTEST_HAS_EXCEPTIONS
+
+// Adds an "exception thrown" fatal failure to the current test.
+static std::string FormatCxxExceptionMessage(const char* description,
+ const char* location) {
+ Message message;
+ if (description != nullptr) {
+ message << "C++ exception with description \"" << description << "\"";
+ } else {
+ message << "Unknown C++ exception";
+ }
+ message << " thrown in " << location << ".";
+
+ return message.GetString();
+}
+
+static std::string PrintTestPartResultToString(
+ const TestPartResult& test_part_result);
+
+GoogleTestFailureException::GoogleTestFailureException(
+ const TestPartResult& failure)
+ : ::std::runtime_error(PrintTestPartResultToString(failure).c_str()) {}
+
+#endif // GTEST_HAS_EXCEPTIONS
+
+// We put these helper functions in the internal namespace as IBM's xlC
+// compiler rejects the code if they were declared static.
+
+// Runs the given method and handles SEH exceptions it throws, when
+// SEH is supported; returns the 0-value for type Result in case of an
+// SEH exception. (Microsoft compilers cannot handle SEH and C++
+// exceptions in the same function. Therefore, we provide a separate
+// wrapper function for handling SEH exceptions.)
+template <class T, typename Result>
+Result HandleSehExceptionsInMethodIfSupported(
+ T* object, Result (T::*method)(), const char* location) {
+#if GTEST_HAS_SEH
+ __try {
+ return (object->*method)();
+ } __except (internal::UnitTestOptions::GTestShouldProcessSEH( // NOLINT
+ GetExceptionCode())) {
+ // We create the exception message on the heap because VC++ prohibits
+ // creation of objects with destructors on stack in functions using __try
+ // (see error C2712).
+ std::string* exception_message = FormatSehExceptionMessage(
+ GetExceptionCode(), location);
+ internal::ReportFailureInUnknownLocation(TestPartResult::kFatalFailure,
+ *exception_message);
+ delete exception_message;
+ return static_cast<Result>(0);
+ }
+#else
+ (void)location;
+ return (object->*method)();
+#endif // GTEST_HAS_SEH
+}
+
+// Runs the given method and catches and reports C++ and/or SEH-style
+// exceptions, if they are supported; returns the 0-value for type
+// Result in case of an SEH exception.
+template <class T, typename Result>
+Result HandleExceptionsInMethodIfSupported(
+ T* object, Result (T::*method)(), const char* location) {
+ // NOTE: The user code can affect the way in which Google Test handles
+ // exceptions by setting GTEST_FLAG(catch_exceptions), but only before
+ // RUN_ALL_TESTS() starts. It is technically possible to check the flag
+ // after the exception is caught and either report or re-throw the
+ // exception based on the flag's value:
+ //
+ // try {
+ // // Perform the test method.
+ // } catch (...) {
+ // if (GTEST_FLAG(catch_exceptions))
+ // // Report the exception as failure.
+ // else
+ // throw; // Re-throws the original exception.
+ // }
+ //
+ // However, the purpose of this flag is to allow the program to drop into
+ // the debugger when the exception is thrown. On most platforms, once the
+ // control enters the catch block, the exception origin information is
+ // lost and the debugger will stop the program at the point of the
+ // re-throw in this function -- instead of at the point of the original
+ // throw statement in the code under test. For this reason, we perform
+ // the check early, sacrificing the ability to affect Google Test's
+ // exception handling in the method where the exception is thrown.
+ if (internal::GetUnitTestImpl()->catch_exceptions()) {
+#if GTEST_HAS_EXCEPTIONS
+ try {
+ return HandleSehExceptionsInMethodIfSupported(object, method, location);
+ } catch (const AssertionException&) { // NOLINT
+ // This failure was reported already.
+ } catch (const internal::GoogleTestFailureException&) { // NOLINT
+ // This exception type can only be thrown by a failed Google
+ // Test assertion with the intention of letting another testing
+ // framework catch it. Therefore we just re-throw it.
+ throw;
+ } catch (const std::exception& e) { // NOLINT
+ internal::ReportFailureInUnknownLocation(
+ TestPartResult::kFatalFailure,
+ FormatCxxExceptionMessage(e.what(), location));
+ } catch (...) { // NOLINT
+ internal::ReportFailureInUnknownLocation(
+ TestPartResult::kFatalFailure,
+ FormatCxxExceptionMessage(nullptr, location));
+ }
+ return static_cast<Result>(0);
+#else
+ return HandleSehExceptionsInMethodIfSupported(object, method, location);
+#endif // GTEST_HAS_EXCEPTIONS
+ } else {
+ return (object->*method)();
+ }
+}
+
+} // namespace internal
+
+// Runs the test and updates the test result.
+void Test::Run() {
+ if (!HasSameFixtureClass()) return;
+
+ internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
+ impl->os_stack_trace_getter()->UponLeavingGTest();
+ internal::HandleExceptionsInMethodIfSupported(this, &Test::SetUp, "SetUp()");
+ // We will run the test only if SetUp() was successful and didn't call
+ // GTEST_SKIP().
+ if (!HasFatalFailure() && !IsSkipped()) {
+ impl->os_stack_trace_getter()->UponLeavingGTest();
+ internal::HandleExceptionsInMethodIfSupported(
+ this, &Test::TestBody, "the test body");
+ }
+
+ // However, we want to clean up as much as possible. Hence we will
+ // always call TearDown(), even if SetUp() or the test body has
+ // failed.
+ impl->os_stack_trace_getter()->UponLeavingGTest();
+ internal::HandleExceptionsInMethodIfSupported(
+ this, &Test::TearDown, "TearDown()");
+}
+
+// Returns true iff the current test has a fatal failure.
+bool Test::HasFatalFailure() {
+ return internal::GetUnitTestImpl()->current_test_result()->HasFatalFailure();
+}
+
+// Returns true iff the current test has a non-fatal failure.
+bool Test::HasNonfatalFailure() {
+ return internal::GetUnitTestImpl()->current_test_result()->
+ HasNonfatalFailure();
+}
+
+// Returns true iff the current test was skipped.
+bool Test::IsSkipped() {
+ return internal::GetUnitTestImpl()->current_test_result()->Skipped();
+}
+
+// class TestInfo
+
+// Constructs a TestInfo object. It assumes ownership of the test factory
+// object.
+TestInfo::TestInfo(const std::string& a_test_suite_name,
+ const std::string& a_name, const char* a_type_param,
+ const char* a_value_param,
+ internal::CodeLocation a_code_location,
+ internal::TypeId fixture_class_id,
+ internal::TestFactoryBase* factory)
+ : test_suite_name_(a_test_suite_name),
+ name_(a_name),
+ type_param_(a_type_param ? new std::string(a_type_param) : nullptr),
+ value_param_(a_value_param ? new std::string(a_value_param) : nullptr),
+ location_(a_code_location),
+ fixture_class_id_(fixture_class_id),
+ should_run_(false),
+ is_disabled_(false),
+ matches_filter_(false),
+ factory_(factory),
+ result_() {}
+
+// Destructs a TestInfo object.
+TestInfo::~TestInfo() { delete factory_; }
+
+namespace internal {
+
+// Creates a new TestInfo object and registers it with Google Test;
+// returns the created object.
+//
+// Arguments:
+//
+// test_suite_name: name of the test suite
+// name: name of the test
+// type_param: the name of the test's type parameter, or NULL if
+// this is not a typed or a type-parameterized test.
+// value_param: text representation of the test's value parameter,
+// or NULL if this is not a value-parameterized test.
+// code_location: code location where the test is defined
+// fixture_class_id: ID of the test fixture class
+// set_up_tc: pointer to the function that sets up the test suite
+// tear_down_tc: pointer to the function that tears down the test suite
+// factory: pointer to the factory that creates a test object.
+// The newly created TestInfo instance will assume
+// ownership of the factory object.
+TestInfo* MakeAndRegisterTestInfo(
+ const char* test_suite_name, const char* name, const char* type_param,
+ const char* value_param, CodeLocation code_location,
+ TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc,
+ TearDownTestSuiteFunc tear_down_tc, TestFactoryBase* factory) {
+ TestInfo* const test_info =
+ new TestInfo(test_suite_name, name, type_param, value_param,
+ code_location, fixture_class_id, factory);
+ GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info);
+ return test_info;
+}
+
+void ReportInvalidTestSuiteType(const char* test_suite_name,
+ CodeLocation code_location) {
+ Message errors;
+ errors
+ << "Attempted redefinition of test suite " << test_suite_name << ".\n"
+ << "All tests in the same test suite must use the same test fixture\n"
+ << "class. However, in test suite " << test_suite_name << ", you tried\n"
+ << "to define a test using a fixture class different from the one\n"
+ << "used earlier. This can happen if the two fixture classes are\n"
+ << "from different namespaces and have the same name. You should\n"
+ << "probably rename one of the classes to put the tests into different\n"
+ << "test suites.";
+
+ GTEST_LOG_(ERROR) << FormatFileLocation(code_location.file.c_str(),
+ code_location.line)
+ << " " << errors.GetString();
+}
+} // namespace internal
+
+namespace {
+
+// A predicate that checks the test name of a TestInfo against a known
+// value.
+//
+// This is used for implementation of the TestSuite class only. We put
+// it in the anonymous namespace to prevent polluting the outer
+// namespace.
+//
+// TestNameIs is copyable.
+class TestNameIs {
+ public:
+ // Constructor.
+ //
+ // TestNameIs has NO default constructor.
+ explicit TestNameIs(const char* name)
+ : name_(name) {}
+
+ // Returns true iff the test name of test_info matches name_.
+ bool operator()(const TestInfo * test_info) const {
+ return test_info && test_info->name() == name_;
+ }
+
+ private:
+ std::string name_;
+};
+
+} // namespace
+
+namespace internal {
+
+// This method expands all parameterized tests registered with macros TEST_P
+// and INSTANTIATE_TEST_SUITE_P into regular tests and registers those.
+// This will be done just once during the program runtime.
+void UnitTestImpl::RegisterParameterizedTests() {
+ if (!parameterized_tests_registered_) {
+ parameterized_test_registry_.RegisterTests();
+ parameterized_tests_registered_ = true;
+ }
+}
+
+} // namespace internal
+
+// Creates the test object, runs it, records its result, and then
+// deletes it.
+void TestInfo::Run() {
+ if (!should_run_) return;
+
+ // Tells UnitTest where to store test result.
+ internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
+ impl->set_current_test_info(this);
+
+ TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
+
+ // Notifies the unit test event listeners that a test is about to start.
+ repeater->OnTestStart(*this);
+
+ const TimeInMillis start = internal::GetTimeInMillis();
+
+ impl->os_stack_trace_getter()->UponLeavingGTest();
+
+ // Creates the test object.
+ Test* const test = internal::HandleExceptionsInMethodIfSupported(
+ factory_, &internal::TestFactoryBase::CreateTest,
+ "the test fixture's constructor");
+
+ // Runs the test if the constructor didn't generate a fatal failure or invoke
+ // GTEST_SKIP().
+ // Note that the object will not be null
+ if (!Test::HasFatalFailure() && !Test::IsSkipped()) {
+ // This doesn't throw as all user code that can throw are wrapped into
+ // exception handling code.
+ test->Run();
+ }
+
+ if (test != nullptr) {
+ // Deletes the test object.
+ impl->os_stack_trace_getter()->UponLeavingGTest();
+ internal::HandleExceptionsInMethodIfSupported(
+ test, &Test::DeleteSelf_, "the test fixture's destructor");
+ }
+
+ result_.set_elapsed_time(internal::GetTimeInMillis() - start);
+
+ // Notifies the unit test event listener that a test has just finished.
+ repeater->OnTestEnd(*this);
+
+ // Tells UnitTest to stop associating assertion results to this
+ // test.
+ impl->set_current_test_info(nullptr);
+}
+
+// class TestSuite
+
+// Gets the number of successful tests in this test suite.
+int TestSuite::successful_test_count() const {
+ return CountIf(test_info_list_, TestPassed);
+}
+
+// Gets the number of successful tests in this test suite.
+int TestSuite::skipped_test_count() const {
+ return CountIf(test_info_list_, TestSkipped);
+}
+
+// Gets the number of failed tests in this test suite.
+int TestSuite::failed_test_count() const {
+ return CountIf(test_info_list_, TestFailed);
+}
+
+// Gets the number of disabled tests that will be reported in the XML report.
+int TestSuite::reportable_disabled_test_count() const {
+ return CountIf(test_info_list_, TestReportableDisabled);
+}
+
+// Gets the number of disabled tests in this test suite.
+int TestSuite::disabled_test_count() const {
+ return CountIf(test_info_list_, TestDisabled);
+}
+
+// Gets the number of tests to be printed in the XML report.
+int TestSuite::reportable_test_count() const {
+ return CountIf(test_info_list_, TestReportable);
+}
+
+// Get the number of tests in this test suite that should run.
+int TestSuite::test_to_run_count() const {
+ return CountIf(test_info_list_, ShouldRunTest);
+}
+
+// Gets the number of all tests.
+int TestSuite::total_test_count() const {
+ return static_cast<int>(test_info_list_.size());
+}
+
+// Creates a TestSuite with the given name.
+//
+// Arguments:
+//
+// name: name of the test suite
+// a_type_param: the name of the test suite's type parameter, or NULL if
+// this is not a typed or a type-parameterized test suite.
+// set_up_tc: pointer to the function that sets up the test suite
+// tear_down_tc: pointer to the function that tears down the test suite
+TestSuite::TestSuite(const char* a_name, const char* a_type_param,
+ internal::SetUpTestSuiteFunc set_up_tc,
+ internal::TearDownTestSuiteFunc tear_down_tc)
+ : name_(a_name),
+ type_param_(a_type_param ? new std::string(a_type_param) : nullptr),
+ set_up_tc_(set_up_tc),
+ tear_down_tc_(tear_down_tc),
+ should_run_(false),
+ elapsed_time_(0) {}
+
+// Destructor of TestSuite.
+TestSuite::~TestSuite() {
+ // Deletes every Test in the collection.
+ ForEach(test_info_list_, internal::Delete<TestInfo>);
+}
+
+// Returns the i-th test among all the tests. i can range from 0 to
+// total_test_count() - 1. If i is not in that range, returns NULL.
+const TestInfo* TestSuite::GetTestInfo(int i) const {
+ const int index = GetElementOr(test_indices_, i, -1);
+ return index < 0 ? nullptr : test_info_list_[static_cast<size_t>(index)];
+}
+
+// Returns the i-th test among all the tests. i can range from 0 to
+// total_test_count() - 1. If i is not in that range, returns NULL.
+TestInfo* TestSuite::GetMutableTestInfo(int i) {
+ const int index = GetElementOr(test_indices_, i, -1);
+ return index < 0 ? nullptr : test_info_list_[static_cast<size_t>(index)];
+}
+
+// Adds a test to this test suite. Will delete the test upon
+// destruction of the TestSuite object.
+void TestSuite::AddTestInfo(TestInfo* test_info) {
+ test_info_list_.push_back(test_info);
+ test_indices_.push_back(static_cast<int>(test_indices_.size()));
+}
+
+// Runs every test in this TestSuite.
+void TestSuite::Run() {
+ if (!should_run_) return;
+
+ internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
+ impl->set_current_test_suite(this);
+
+ TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
+
+ // Call both legacy and the new API
+ repeater->OnTestSuiteStart(*this);
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
+ repeater->OnTestCaseStart(*this);
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
+
+ impl->os_stack_trace_getter()->UponLeavingGTest();
+ internal::HandleExceptionsInMethodIfSupported(
+ this, &TestSuite::RunSetUpTestSuite, "SetUpTestSuite()");
+
+ const internal::TimeInMillis start = internal::GetTimeInMillis();
+ for (int i = 0; i < total_test_count(); i++) {
+ GetMutableTestInfo(i)->Run();
+ }
+ elapsed_time_ = internal::GetTimeInMillis() - start;
+
+ impl->os_stack_trace_getter()->UponLeavingGTest();
+ internal::HandleExceptionsInMethodIfSupported(
+ this, &TestSuite::RunTearDownTestSuite, "TearDownTestSuite()");
+
+ // Call both legacy and the new API
+ repeater->OnTestSuiteEnd(*this);
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
+ repeater->OnTestCaseEnd(*this);
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
+
+ impl->set_current_test_suite(nullptr);
+}
+
+// Clears the results of all tests in this test suite.
+void TestSuite::ClearResult() {
+ ad_hoc_test_result_.Clear();
+ ForEach(test_info_list_, TestInfo::ClearTestResult);
+}
+
+// Shuffles the tests in this test suite.
+void TestSuite::ShuffleTests(internal::Random* random) {
+ Shuffle(random, &test_indices_);
+}
+
+// Restores the test order to before the first shuffle.
+void TestSuite::UnshuffleTests() {
+ for (size_t i = 0; i < test_indices_.size(); i++) {
+ test_indices_[i] = static_cast<int>(i);
+ }
+}
+
+// Formats a countable noun. Depending on its quantity, either the
+// singular form or the plural form is used. e.g.
+//
+// FormatCountableNoun(1, "formula", "formuli") returns "1 formula".
+// FormatCountableNoun(5, "book", "books") returns "5 books".
+static std::string FormatCountableNoun(int count,
+ const char * singular_form,
+ const char * plural_form) {
+ return internal::StreamableToString(count) + " " +
+ (count == 1 ? singular_form : plural_form);
+}
+
+// Formats the count of tests.
+static std::string FormatTestCount(int test_count) {
+ return FormatCountableNoun(test_count, "test", "tests");
+}
+
+// Formats the count of test suites.
+static std::string FormatTestSuiteCount(int test_suite_count) {
+ return FormatCountableNoun(test_suite_count, "test suite", "test suites");
+}
+
+// Converts a TestPartResult::Type enum to human-friendly string
+// representation. Both kNonFatalFailure and kFatalFailure are translated
+// to "Failure", as the user usually doesn't care about the difference
+// between the two when viewing the test result.
+static const char * TestPartResultTypeToString(TestPartResult::Type type) {
+ switch (type) {
+ case TestPartResult::kSkip:
+ return "Skipped";
+ case TestPartResult::kSuccess:
+ return "Success";
+
+ case TestPartResult::kNonFatalFailure:
+ case TestPartResult::kFatalFailure:
+#ifdef _MSC_VER
+ return "error: ";
+#else
+ return "Failure\n";
+#endif
+ default:
+ return "Unknown result type";
+ }
+}
+
+namespace internal {
+
+// Prints a TestPartResult to an std::string.
+static std::string PrintTestPartResultToString(
+ const TestPartResult& test_part_result) {
+ return (Message()
+ << internal::FormatFileLocation(test_part_result.file_name(),
+ test_part_result.line_number())
+ << " " << TestPartResultTypeToString(test_part_result.type())
+ << test_part_result.message()).GetString();
+}
+
+// Prints a TestPartResult.
+static void PrintTestPartResult(const TestPartResult& test_part_result) {
+ const std::string& result =
+ PrintTestPartResultToString(test_part_result);
+ printf("%s\n", result.c_str());
+ fflush(stdout);
+ // If the test program runs in Visual Studio or a debugger, the
+ // following statements add the test part result message to the Output
+ // window such that the user can double-click on it to jump to the
+ // corresponding source code location; otherwise they do nothing.
+#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
+ // We don't call OutputDebugString*() on Windows Mobile, as printing
+ // to stdout is done by OutputDebugString() there already - we don't
+ // want the same message printed twice.
+ ::OutputDebugStringA(result.c_str());
+ ::OutputDebugStringA("\n");
+#endif
+}
+
+// class PrettyUnitTestResultPrinter
+#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
+ !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
+
+// Returns the character attribute for the given color.
+static WORD GetColorAttribute(GTestColor color) {
+ switch (color) {
+ case COLOR_RED: return FOREGROUND_RED;
+ case COLOR_GREEN: return FOREGROUND_GREEN;
+ case COLOR_YELLOW: return FOREGROUND_RED | FOREGROUND_GREEN;
+ default: return 0;
+ }
+}
+
+static int GetBitOffset(WORD color_mask) {
+ if (color_mask == 0) return 0;
+
+ int bitOffset = 0;
+ while ((color_mask & 1) == 0) {
+ color_mask >>= 1;
+ ++bitOffset;
+ }
+ return bitOffset;
+}
+
+static WORD GetNewColor(GTestColor color, WORD old_color_attrs) {
+ // Let's reuse the BG
+ static const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
+ BACKGROUND_RED | BACKGROUND_INTENSITY;
+ static const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
+ FOREGROUND_RED | FOREGROUND_INTENSITY;
+ const WORD existing_bg = old_color_attrs & background_mask;
+
+ WORD new_color =
+ GetColorAttribute(color) | existing_bg | FOREGROUND_INTENSITY;
+ static const int bg_bitOffset = GetBitOffset(background_mask);
+ static const int fg_bitOffset = GetBitOffset(foreground_mask);
+
+ if (((new_color & background_mask) >> bg_bitOffset) ==
+ ((new_color & foreground_mask) >> fg_bitOffset)) {
+ new_color ^= FOREGROUND_INTENSITY; // invert intensity
+ }
+ return new_color;
+}
+
+#else
+
+// Returns the ANSI color code for the given color. COLOR_DEFAULT is
+// an invalid input.
+static const char* GetAnsiColorCode(GTestColor color) {
+ switch (color) {
+ case COLOR_RED: return "1";
+ case COLOR_GREEN: return "2";
+ case COLOR_YELLOW: return "3";
+ default:
+ return nullptr;
+ }
+}
+
+#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
+
+// Returns true iff Google Test should use colors in the output.
+bool ShouldUseColor(bool stdout_is_tty) {
+ const char* const gtest_color = GTEST_FLAG(color).c_str();
+
+ if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) {
+#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
+ // On Windows the TERM variable is usually not set, but the
+ // console there does support colors.
+ return stdout_is_tty;
+#else
+ // On non-Windows platforms, we rely on the TERM variable.
+ const char* const term = posix::GetEnv("TERM");
+ const bool term_supports_color =
+ String::CStringEquals(term, "xterm") ||
+ String::CStringEquals(term, "xterm-color") ||
+ String::CStringEquals(term, "xterm-256color") ||
+ String::CStringEquals(term, "screen") ||
+ String::CStringEquals(term, "screen-256color") ||
+ String::CStringEquals(term, "tmux") ||
+ String::CStringEquals(term, "tmux-256color") ||
+ String::CStringEquals(term, "rxvt-unicode") ||
+ String::CStringEquals(term, "rxvt-unicode-256color") ||
+ String::CStringEquals(term, "linux") ||
+ String::CStringEquals(term, "cygwin");
+ return stdout_is_tty && term_supports_color;
+#endif // GTEST_OS_WINDOWS
+ }
+
+ return String::CaseInsensitiveCStringEquals(gtest_color, "yes") ||
+ String::CaseInsensitiveCStringEquals(gtest_color, "true") ||
+ String::CaseInsensitiveCStringEquals(gtest_color, "t") ||
+ String::CStringEquals(gtest_color, "1");
+ // We take "yes", "true", "t", and "1" as meaning "yes". If the
+ // value is neither one of these nor "auto", we treat it as "no" to
+ // be conservative.
+}
+
+// Helpers for printing colored strings to stdout. Note that on Windows, we
+// cannot simply emit special characters and have the terminal change colors.
+// This routine must actually emit the characters rather than return a string
+// that would be colored when printed, as can be done on Linux.
+void ColoredPrintf(GTestColor color, const char* fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+
+#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \
+ GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
+ const bool use_color = AlwaysFalse();
+#else
+ static const bool in_color_mode =
+ ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0);
+ const bool use_color = in_color_mode && (color != COLOR_DEFAULT);
+#endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS
+
+ if (!use_color) {
+ vprintf(fmt, args);
+ va_end(args);
+ return;
+ }
+
+#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
+ !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
+ const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
+
+ // Gets the current text color.
+ CONSOLE_SCREEN_BUFFER_INFO buffer_info;
+ GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
+ const WORD old_color_attrs = buffer_info.wAttributes;
+ const WORD new_color = GetNewColor(color, old_color_attrs);
+
+ // We need to flush the stream buffers into the console before each
+ // SetConsoleTextAttribute call lest it affect the text that is already
+ // printed but has not yet reached the console.
+ fflush(stdout);
+ SetConsoleTextAttribute(stdout_handle, new_color);
+
+ vprintf(fmt, args);
+
+ fflush(stdout);
+ // Restores the text color.
+ SetConsoleTextAttribute(stdout_handle, old_color_attrs);
+#else
+ printf("\033[0;3%sm", GetAnsiColorCode(color));
+ vprintf(fmt, args);
+ printf("\033[m"); // Resets the terminal to default.
+#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
+ va_end(args);
+}
+
+// Text printed in Google Test's text output and --gtest_list_tests
+// output to label the type parameter and value parameter for a test.
+static const char kTypeParamLabel[] = "TypeParam";
+static const char kValueParamLabel[] = "GetParam()";
+
+static void PrintFullTestCommentIfPresent(const TestInfo& test_info) {
+ const char* const type_param = test_info.type_param();
+ const char* const value_param = test_info.value_param();
+
+ if (type_param != nullptr || value_param != nullptr) {
+ printf(", where ");
+ if (type_param != nullptr) {
+ printf("%s = %s", kTypeParamLabel, type_param);
+ if (value_param != nullptr) printf(" and ");
+ }
+ if (value_param != nullptr) {
+ printf("%s = %s", kValueParamLabel, value_param);
+ }
+ }
+}
+
+// This class implements the TestEventListener interface.
+//
+// Class PrettyUnitTestResultPrinter is copyable.
+class PrettyUnitTestResultPrinter : public TestEventListener {
+ public:
+ PrettyUnitTestResultPrinter() {}
+ static void PrintTestName(const char* test_suite, const char* test) {
+ printf("%s.%s", test_suite, test);
+ }
+
+ // The following methods override what's in the TestEventListener class.
+ void OnTestProgramStart(const UnitTest& /*unit_test*/) override {}
+ void OnTestIterationStart(const UnitTest& unit_test, int iteration) override;
+ void OnEnvironmentsSetUpStart(const UnitTest& unit_test) override;
+ void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {}
+ void OnTestCaseStart(const TestSuite& test_suite) override;
+ void OnTestStart(const TestInfo& test_info) override;
+ void OnTestPartResult(const TestPartResult& result) override;
+ void OnTestEnd(const TestInfo& test_info) override;
+ void OnTestCaseEnd(const TestSuite& test_suite) override;
+ void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override;
+ void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {}
+ void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
+ void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {}
+
+ private:
+ static void PrintFailedTests(const UnitTest& unit_test);
+ static void PrintSkippedTests(const UnitTest& unit_test);
+};
+
+ // Fired before each iteration of tests starts.
+void PrettyUnitTestResultPrinter::OnTestIterationStart(
+ const UnitTest& unit_test, int iteration) {
+ if (GTEST_FLAG(repeat) != 1)
+ printf("\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
+
+ const char* const filter = GTEST_FLAG(filter).c_str();
+
+ // Prints the filter if it's not *. This reminds the user that some
+ // tests may be skipped.
+ if (!String::CStringEquals(filter, kUniversalFilter)) {
+ ColoredPrintf(COLOR_YELLOW,
+ "Note: %s filter = %s\n", GTEST_NAME_, filter);
+ }
+
+ if (internal::ShouldShard(kTestTotalShards, kTestShardIndex, false)) {
+ const Int32 shard_index = Int32FromEnvOrDie(kTestShardIndex, -1);
+ ColoredPrintf(COLOR_YELLOW,
+ "Note: This is test shard %d of %s.\n",
+ static_cast<int>(shard_index) + 1,
+ internal::posix::GetEnv(kTestTotalShards));
+ }
+
+ if (GTEST_FLAG(shuffle)) {
+ ColoredPrintf(COLOR_YELLOW,
+ "Note: Randomizing tests' orders with a seed of %d .\n",
+ unit_test.random_seed());
+ }
+
+ ColoredPrintf(COLOR_GREEN, "[==========] ");
+ printf("Running %s from %s.\n",
+ FormatTestCount(unit_test.test_to_run_count()).c_str(),
+ FormatTestSuiteCount(unit_test.test_suite_to_run_count()).c_str());
+ fflush(stdout);
+}
+
+void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart(
+ const UnitTest& /*unit_test*/) {
+ ColoredPrintf(COLOR_GREEN, "[----------] ");
+ printf("Global test environment set-up.\n");
+ fflush(stdout);
+}
+
+void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestSuite& test_suite) {
+ const std::string counts =
+ FormatCountableNoun(test_suite.test_to_run_count(), "test", "tests");
+ ColoredPrintf(COLOR_GREEN, "[----------] ");
+ printf("%s from %s", counts.c_str(), test_suite.name());
+ if (test_suite.type_param() == nullptr) {
+ printf("\n");
+ } else {
+ printf(", where %s = %s\n", kTypeParamLabel, test_suite.type_param());
+ }
+ fflush(stdout);
+}
+
+void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {
+ ColoredPrintf(COLOR_GREEN, "[ RUN ] ");
+ PrintTestName(test_info.test_suite_name(), test_info.name());
+ printf("\n");
+ fflush(stdout);
+}
+
+// Called after an assertion failure.
+void PrettyUnitTestResultPrinter::OnTestPartResult(
+ const TestPartResult& result) {
+ switch (result.type()) {
+ // If the test part succeeded, or was skipped,
+ // we don't need to do anything.
+ case TestPartResult::kSkip:
+ case TestPartResult::kSuccess:
+ return;
+ default:
+ // Print failure message from the assertion
+ // (e.g. expected this and got that).
+ PrintTestPartResult(result);
+ fflush(stdout);
+ }
+}
+
+void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
+ if (test_info.result()->Passed()) {
+ ColoredPrintf(COLOR_GREEN, "[ OK ] ");
+ } else if (test_info.result()->Skipped()) {
+ ColoredPrintf(COLOR_GREEN, "[ SKIPPED ] ");
+ } else {
+ ColoredPrintf(COLOR_RED, "[ FAILED ] ");
+ }
+ PrintTestName(test_info.test_suite_name(), test_info.name());
+ if (test_info.result()->Failed())
+ PrintFullTestCommentIfPresent(test_info);
+
+ if (GTEST_FLAG(print_time)) {
+ printf(" (%s ms)\n", internal::StreamableToString(
+ test_info.result()->elapsed_time()).c_str());
+ } else {
+ printf("\n");
+ }
+ fflush(stdout);
+}
+
+void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestSuite& test_suite) {
+ if (!GTEST_FLAG(print_time)) return;
+
+ const std::string counts =
+ FormatCountableNoun(test_suite.test_to_run_count(), "test", "tests");
+ ColoredPrintf(COLOR_GREEN, "[----------] ");
+ printf("%s from %s (%s ms total)\n\n", counts.c_str(), test_suite.name(),
+ internal::StreamableToString(test_suite.elapsed_time()).c_str());
+ fflush(stdout);
+}
+
+void PrettyUnitTestResultPrinter::OnEnvironmentsTearDownStart(
+ const UnitTest& /*unit_test*/) {
+ ColoredPrintf(COLOR_GREEN, "[----------] ");
+ printf("Global test environment tear-down\n");
+ fflush(stdout);
+}
+
+// Internal helper for printing the list of failed tests.
+void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) {
+ const int failed_test_count = unit_test.failed_test_count();
+ if (failed_test_count == 0) {
+ return;
+ }
+
+ for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
+ const TestSuite& test_suite = *unit_test.GetTestSuite(i);
+ if (!test_suite.should_run() || (test_suite.failed_test_count() == 0)) {
+ continue;
+ }
+ for (int j = 0; j < test_suite.total_test_count(); ++j) {
+ const TestInfo& test_info = *test_suite.GetTestInfo(j);
+ if (!test_info.should_run() || !test_info.result()->Failed()) {
+ continue;
+ }
+ ColoredPrintf(COLOR_RED, "[ FAILED ] ");
+ printf("%s.%s", test_suite.name(), test_info.name());
+ PrintFullTestCommentIfPresent(test_info);
+ printf("\n");
+ }
+ }
+}
+
+// Internal helper for printing the list of skipped tests.
+void PrettyUnitTestResultPrinter::PrintSkippedTests(const UnitTest& unit_test) {
+ const int skipped_test_count = unit_test.skipped_test_count();
+ if (skipped_test_count == 0) {
+ return;
+ }
+
+ for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
+ const TestSuite& test_suite = *unit_test.GetTestSuite(i);
+ if (!test_suite.should_run() || (test_suite.skipped_test_count() == 0)) {
+ continue;
+ }
+ for (int j = 0; j < test_suite.total_test_count(); ++j) {
+ const TestInfo& test_info = *test_suite.GetTestInfo(j);
+ if (!test_info.should_run() || !test_info.result()->Skipped()) {
+ continue;
+ }
+ ColoredPrintf(COLOR_GREEN, "[ SKIPPED ] ");
+ printf("%s.%s", test_suite.name(), test_info.name());
+ printf("\n");
+ }
+ }
+}
+
+void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
+ int /*iteration*/) {
+ ColoredPrintf(COLOR_GREEN, "[==========] ");
+ printf("%s from %s ran.",
+ FormatTestCount(unit_test.test_to_run_count()).c_str(),
+ FormatTestSuiteCount(unit_test.test_suite_to_run_count()).c_str());
+ if (GTEST_FLAG(print_time)) {
+ printf(" (%s ms total)",
+ internal::StreamableToString(unit_test.elapsed_time()).c_str());
+ }
+ printf("\n");
+ ColoredPrintf(COLOR_GREEN, "[ PASSED ] ");
+ printf("%s.\n", FormatTestCount(unit_test.successful_test_count()).c_str());
+
+ const int skipped_test_count = unit_test.skipped_test_count();
+ if (skipped_test_count > 0) {
+ ColoredPrintf(COLOR_GREEN, "[ SKIPPED ] ");
+ printf("%s, listed below:\n", FormatTestCount(skipped_test_count).c_str());
+ PrintSkippedTests(unit_test);
+ }
+
+ int num_failures = unit_test.failed_test_count();
+ if (!unit_test.Passed()) {
+ const int failed_test_count = unit_test.failed_test_count();
+ ColoredPrintf(COLOR_RED, "[ FAILED ] ");
+ printf("%s, listed below:\n", FormatTestCount(failed_test_count).c_str());
+ PrintFailedTests(unit_test);
+ printf("\n%2d FAILED %s\n", num_failures,
+ num_failures == 1 ? "TEST" : "TESTS");
+ }
+
+ int num_disabled = unit_test.reportable_disabled_test_count();
+ if (num_disabled && !GTEST_FLAG(also_run_disabled_tests)) {
+ if (!num_failures) {
+ printf("\n"); // Add a spacer if no FAILURE banner is displayed.
+ }
+ ColoredPrintf(COLOR_YELLOW,
+ " YOU HAVE %d DISABLED %s\n\n",
+ num_disabled,
+ num_disabled == 1 ? "TEST" : "TESTS");
+ }
+ // Ensure that Google Test output is printed before, e.g., heapchecker output.
+ fflush(stdout);
+}
+
+// End PrettyUnitTestResultPrinter
+
+// class TestEventRepeater
+//
+// This class forwards events to other event listeners.
+class TestEventRepeater : public TestEventListener {
+ public:
+ TestEventRepeater() : forwarding_enabled_(true) {}
+ ~TestEventRepeater() override;
+ void Append(TestEventListener *listener);
+ TestEventListener* Release(TestEventListener* listener);
+
+ // Controls whether events will be forwarded to listeners_. Set to false
+ // in death test child processes.
+ bool forwarding_enabled() const { return forwarding_enabled_; }
+ void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; }
+
+ void OnTestProgramStart(const UnitTest& unit_test) override;
+ void OnTestIterationStart(const UnitTest& unit_test, int iteration) override;
+ void OnEnvironmentsSetUpStart(const UnitTest& unit_test) override;
+ void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) override;
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
+ void OnTestCaseStart(const TestSuite& parameter) override;
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
+ void OnTestSuiteStart(const TestSuite& parameter) override;
+ void OnTestStart(const TestInfo& test_info) override;
+ void OnTestPartResult(const TestPartResult& result) override;
+ void OnTestEnd(const TestInfo& test_info) override;
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
+ void OnTestCaseEnd(const TestSuite& parameter) override;
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
+ void OnTestSuiteEnd(const TestSuite& parameter) override;
+ void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override;
+ void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) override;
+ void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
+ void OnTestProgramEnd(const UnitTest& unit_test) override;
+
+ private:
+ // Controls whether events will be forwarded to listeners_. Set to false
+ // in death test child processes.
+ bool forwarding_enabled_;
+ // The list of listeners that receive events.
+ std::vector<TestEventListener*> listeners_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventRepeater);
+};
+
+TestEventRepeater::~TestEventRepeater() {
+ ForEach(listeners_, Delete<TestEventListener>);
+}
+
+void TestEventRepeater::Append(TestEventListener *listener) {
+ listeners_.push_back(listener);
+}
+
+TestEventListener* TestEventRepeater::Release(TestEventListener *listener) {
+ for (size_t i = 0; i < listeners_.size(); ++i) {
+ if (listeners_[i] == listener) {
+ listeners_.erase(listeners_.begin() + static_cast<int>(i));
+ return listener;
+ }
+ }
+
+ return nullptr;
+}
+
+// Since most methods are very similar, use macros to reduce boilerplate.
+// This defines a member that forwards the call to all listeners.
+#define GTEST_REPEATER_METHOD_(Name, Type) \
+void TestEventRepeater::Name(const Type& parameter) { \
+ if (forwarding_enabled_) { \
+ for (size_t i = 0; i < listeners_.size(); i++) { \
+ listeners_[i]->Name(parameter); \
+ } \
+ } \
+}
+// This defines a member that forwards the call to all listeners in reverse
+// order.
+#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \
+ void TestEventRepeater::Name(const Type& parameter) { \
+ if (forwarding_enabled_) { \
+ for (size_t i = listeners_.size(); i != 0; i--) { \
+ listeners_[i - 1]->Name(parameter); \
+ } \
+ } \
+ }
+
+GTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest)
+GTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest)
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+GTEST_REPEATER_METHOD_(OnTestCaseStart, TestSuite)
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+GTEST_REPEATER_METHOD_(OnTestSuiteStart, TestSuite)
+GTEST_REPEATER_METHOD_(OnTestStart, TestInfo)
+GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult)
+GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest)
+GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest)
+GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsTearDownEnd, UnitTest)
+GTEST_REVERSE_REPEATER_METHOD_(OnTestEnd, TestInfo)
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+GTEST_REVERSE_REPEATER_METHOD_(OnTestCaseEnd, TestSuite)
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+GTEST_REVERSE_REPEATER_METHOD_(OnTestSuiteEnd, TestSuite)
+GTEST_REVERSE_REPEATER_METHOD_(OnTestProgramEnd, UnitTest)
+
+#undef GTEST_REPEATER_METHOD_
+#undef GTEST_REVERSE_REPEATER_METHOD_
+
+void TestEventRepeater::OnTestIterationStart(const UnitTest& unit_test,
+ int iteration) {
+ if (forwarding_enabled_) {
+ for (size_t i = 0; i < listeners_.size(); i++) {
+ listeners_[i]->OnTestIterationStart(unit_test, iteration);
+ }
+ }
+}
+
+void TestEventRepeater::OnTestIterationEnd(const UnitTest& unit_test,
+ int iteration) {
+ if (forwarding_enabled_) {
+ for (size_t i = listeners_.size(); i > 0; i--) {
+ listeners_[i - 1]->OnTestIterationEnd(unit_test, iteration);
+ }
+ }
+}
+
+// End TestEventRepeater
+
+// This class generates an XML output file.
+class XmlUnitTestResultPrinter : public EmptyTestEventListener {
+ public:
+ explicit XmlUnitTestResultPrinter(const char* output_file);
+
+ void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
+ void ListTestsMatchingFilter(const std::vector<TestSuite*>& test_suites);
+
+ // Prints an XML summary of all unit tests.
+ static void PrintXmlTestsList(std::ostream* stream,
+ const std::vector<TestSuite*>& test_suites);
+
+ private:
+ // Is c a whitespace character that is normalized to a space character
+ // when it appears in an XML attribute value?
+ static bool IsNormalizableWhitespace(char c) {
+ return c == 0x9 || c == 0xA || c == 0xD;
+ }
+
+ // May c appear in a well-formed XML document?
+ static bool IsValidXmlCharacter(char c) {
+ return IsNormalizableWhitespace(c) || c >= 0x20;
+ }
+
+ // Returns an XML-escaped copy of the input string str. If
+ // is_attribute is true, the text is meant to appear as an attribute
+ // value, and normalizable whitespace is preserved by replacing it
+ // with character references.
+ static std::string EscapeXml(const std::string& str, bool is_attribute);
+
+ // Returns the given string with all characters invalid in XML removed.
+ static std::string RemoveInvalidXmlCharacters(const std::string& str);
+
+ // Convenience wrapper around EscapeXml when str is an attribute value.
+ static std::string EscapeXmlAttribute(const std::string& str) {
+ return EscapeXml(str, true);
+ }
+
+ // Convenience wrapper around EscapeXml when str is not an attribute value.
+ static std::string EscapeXmlText(const char* str) {
+ return EscapeXml(str, false);
+ }
+
+ // Verifies that the given attribute belongs to the given element and
+ // streams the attribute as XML.
+ static void OutputXmlAttribute(std::ostream* stream,
+ const std::string& element_name,
+ const std::string& name,
+ const std::string& value);
+
+ // Streams an XML CDATA section, escaping invalid CDATA sequences as needed.
+ static void OutputXmlCDataSection(::std::ostream* stream, const char* data);
+
+ // Streams an XML representation of a TestInfo object.
+ static void OutputXmlTestInfo(::std::ostream* stream,
+ const char* test_suite_name,
+ const TestInfo& test_info);
+
+ // Prints an XML representation of a TestSuite object
+ static void PrintXmlTestSuite(::std::ostream* stream,
+ const TestSuite& test_suite);
+
+ // Prints an XML summary of unit_test to output stream out.
+ static void PrintXmlUnitTest(::std::ostream* stream,
+ const UnitTest& unit_test);
+
+ // Produces a string representing the test properties in a result as space
+ // delimited XML attributes based on the property key="value" pairs.
+ // When the std::string is not empty, it includes a space at the beginning,
+ // to delimit this attribute from prior attributes.
+ static std::string TestPropertiesAsXmlAttributes(const TestResult& result);
+
+ // Streams an XML representation of the test properties of a TestResult
+ // object.
+ static void OutputXmlTestProperties(std::ostream* stream,
+ const TestResult& result);
+
+ // The output file.
+ const std::string output_file_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(XmlUnitTestResultPrinter);
+};
+
+// Creates a new XmlUnitTestResultPrinter.
+XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file)
+ : output_file_(output_file) {
+ if (output_file_.empty()) {
+ GTEST_LOG_(FATAL) << "XML output file may not be null";
+ }
+}
+
+// Called after the unit test ends.
+void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
+ int /*iteration*/) {
+ FILE* xmlout = OpenFileForWriting(output_file_);
+ std::stringstream stream;
+ PrintXmlUnitTest(&stream, unit_test);
+ fprintf(xmlout, "%s", StringStreamToString(&stream).c_str());
+ fclose(xmlout);
+}
+
+void XmlUnitTestResultPrinter::ListTestsMatchingFilter(
+ const std::vector<TestSuite*>& test_suites) {
+ FILE* xmlout = OpenFileForWriting(output_file_);
+ std::stringstream stream;
+ PrintXmlTestsList(&stream, test_suites);
+ fprintf(xmlout, "%s", StringStreamToString(&stream).c_str());
+ fclose(xmlout);
+}
+
+// Returns an XML-escaped copy of the input string str. If is_attribute
+// is true, the text is meant to appear as an attribute value, and
+// normalizable whitespace is preserved by replacing it with character
+// references.
+//
+// Invalid XML characters in str, if any, are stripped from the output.
+// It is expected that most, if not all, of the text processed by this
+// module will consist of ordinary English text.
+// If this module is ever modified to produce version 1.1 XML output,
+// most invalid characters can be retained using character references.
+std::string XmlUnitTestResultPrinter::EscapeXml(
+ const std::string& str, bool is_attribute) {
+ Message m;
+
+ for (size_t i = 0; i < str.size(); ++i) {
+ const char ch = str[i];
+ switch (ch) {
+ case '<':
+ m << "<";
+ break;
+ case '>':
+ m << ">";
+ break;
+ case '&':
+ m << "&";
+ break;
+ case '\'':
+ if (is_attribute)
+ m << "'";
+ else
+ m << '\'';
+ break;
+ case '"':
+ if (is_attribute)
+ m << """;
+ else
+ m << '"';
+ break;
+ default:
+ if (IsValidXmlCharacter(ch)) {
+ if (is_attribute && IsNormalizableWhitespace(ch))
+ m << "&#x" << String::FormatByte(static_cast<unsigned char>(ch))
+ << ";";
+ else
+ m << ch;
+ }
+ break;
+ }
+ }
+
+ return m.GetString();
+}
+
+// Returns the given string with all characters invalid in XML removed.
+// Currently invalid characters are dropped from the string. An
+// alternative is to replace them with certain characters such as . or ?.
+std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(
+ const std::string& str) {
+ std::string output;
+ output.reserve(str.size());
+ for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
+ if (IsValidXmlCharacter(*it))
+ output.push_back(*it);
+
+ return output;
+}
+
+// The following routines generate an XML representation of a UnitTest
+// object.
+// GOOGLETEST_CM0009 DO NOT DELETE
+//
+// This is how Google Test concepts map to the DTD:
+//
+// <testsuites name="AllTests"> <-- corresponds to a UnitTest object
+// <testsuite name="testcase-name"> <-- corresponds to a TestSuite object
+// <testcase name="test-name"> <-- corresponds to a TestInfo object
+// <failure message="...">...</failure>
+// <failure message="...">...</failure>
+// <failure message="...">...</failure>
+// <-- individual assertion failures
+// </testcase>
+// </testsuite>
+// </testsuites>
+
+// Formats the given time in milliseconds as seconds.
+std::string FormatTimeInMillisAsSeconds(TimeInMillis ms) {
+ ::std::stringstream ss;
+ ss << (static_cast<double>(ms) * 1e-3);
+ return ss.str();
+}
+
+static bool PortableLocaltime(time_t seconds, struct tm* out) {
+#if defined(_MSC_VER)
+ return localtime_s(out, &seconds) == 0;
+#elif defined(__MINGW32__) || defined(__MINGW64__)
+ // MINGW <time.h> provides neither localtime_r nor localtime_s, but uses
+ // Windows' localtime(), which has a thread-local tm buffer.
+ struct tm* tm_ptr = localtime(&seconds); // NOLINT
+ if (tm_ptr == nullptr) return false;
+ *out = *tm_ptr;
+ return true;
+#else
+ return localtime_r(&seconds, out) != nullptr;
+#endif
+}
+
+// Converts the given epoch time in milliseconds to a date string in the ISO
+// 8601 format, without the timezone information.
+std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms) {
+ struct tm time_struct;
+ if (!PortableLocaltime(static_cast<time_t>(ms / 1000), &time_struct))
+ return "";
+ // YYYY-MM-DDThh:mm:ss
+ return StreamableToString(time_struct.tm_year + 1900) + "-" +
+ String::FormatIntWidth2(time_struct.tm_mon + 1) + "-" +
+ String::FormatIntWidth2(time_struct.tm_mday) + "T" +
+ String::FormatIntWidth2(time_struct.tm_hour) + ":" +
+ String::FormatIntWidth2(time_struct.tm_min) + ":" +
+ String::FormatIntWidth2(time_struct.tm_sec);
+}
+
+// Streams an XML CDATA section, escaping invalid CDATA sequences as needed.
+void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream,
+ const char* data) {
+ const char* segment = data;
+ *stream << "<![CDATA[";
+ for (;;) {
+ const char* const next_segment = strstr(segment, "]]>");
+ if (next_segment != nullptr) {
+ stream->write(
+ segment, static_cast<std::streamsize>(next_segment - segment));
+ *stream << "]]>]]><![CDATA[";
+ segment = next_segment + strlen("]]>");
+ } else {
+ *stream << segment;
+ break;
+ }
+ }
+ *stream << "]]>";
+}
+
+void XmlUnitTestResultPrinter::OutputXmlAttribute(
+ std::ostream* stream,
+ const std::string& element_name,
+ const std::string& name,
+ const std::string& value) {
+ const std::vector<std::string>& allowed_names =
+ GetReservedOutputAttributesForElement(element_name);
+
+ GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
+ allowed_names.end())
+ << "Attribute " << name << " is not allowed for element <" << element_name
+ << ">.";
+
+ *stream << " " << name << "=\"" << EscapeXmlAttribute(value) << "\"";
+}
+
+// Prints an XML representation of a TestInfo object.
+void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
+ const char* test_suite_name,
+ const TestInfo& test_info) {
+ const TestResult& result = *test_info.result();
+ const std::string kTestsuite = "testcase";
+
+ if (test_info.is_in_another_shard()) {
+ return;
+ }
+
+ *stream << " <testcase";
+ OutputXmlAttribute(stream, kTestsuite, "name", test_info.name());
+
+ if (test_info.value_param() != nullptr) {
+ OutputXmlAttribute(stream, kTestsuite, "value_param",
+ test_info.value_param());
+ }
+ if (test_info.type_param() != nullptr) {
+ OutputXmlAttribute(stream, kTestsuite, "type_param",
+ test_info.type_param());
+ }
+ if (GTEST_FLAG(list_tests)) {
+ OutputXmlAttribute(stream, kTestsuite, "file", test_info.file());
+ OutputXmlAttribute(stream, kTestsuite, "line",
+ StreamableToString(test_info.line()));
+ *stream << " />\n";
+ return;
+ }
+
+ OutputXmlAttribute(stream, kTestsuite, "status",
+ test_info.should_run() ? "run" : "notrun");
+ OutputXmlAttribute(stream, kTestsuite, "result",
+ test_info.should_run()
+ ? (result.Skipped() ? "skipped" : "completed")
+ : "suppressed");
+ OutputXmlAttribute(stream, kTestsuite, "time",
+ FormatTimeInMillisAsSeconds(result.elapsed_time()));
+ OutputXmlAttribute(stream, kTestsuite, "classname", test_suite_name);
+
+ int failures = 0;
+ for (int i = 0; i < result.total_part_count(); ++i) {
+ const TestPartResult& part = result.GetTestPartResult(i);
+ if (part.failed()) {
+ if (++failures == 1) {
+ *stream << ">\n";
+ }
+ const std::string location =
+ internal::FormatCompilerIndependentFileLocation(part.file_name(),
+ part.line_number());
+ const std::string summary = location + "\n" + part.summary();
+ *stream << " <failure message=\""
+ << EscapeXmlAttribute(summary.c_str())
+ << "\" type=\"\">";
+ const std::string detail = location + "\n" + part.message();
+ OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str());
+ *stream << "</failure>\n";
+ }
+ }
+
+ if (failures == 0 && result.test_property_count() == 0) {
+ *stream << " />\n";
+ } else {
+ if (failures == 0) {
+ *stream << ">\n";
+ }
+ OutputXmlTestProperties(stream, result);
+ *stream << " </testcase>\n";
+ }
+}
+
+// Prints an XML representation of a TestSuite object
+void XmlUnitTestResultPrinter::PrintXmlTestSuite(std::ostream* stream,
+ const TestSuite& test_suite) {
+ const std::string kTestsuite = "testsuite";
+ *stream << " <" << kTestsuite;
+ OutputXmlAttribute(stream, kTestsuite, "name", test_suite.name());
+ OutputXmlAttribute(stream, kTestsuite, "tests",
+ StreamableToString(test_suite.reportable_test_count()));
+ if (!GTEST_FLAG(list_tests)) {
+ OutputXmlAttribute(stream, kTestsuite, "failures",
+ StreamableToString(test_suite.failed_test_count()));
+ OutputXmlAttribute(
+ stream, kTestsuite, "disabled",
+ StreamableToString(test_suite.reportable_disabled_test_count()));
+ OutputXmlAttribute(stream, kTestsuite, "errors", "0");
+ OutputXmlAttribute(stream, kTestsuite, "time",
+ FormatTimeInMillisAsSeconds(test_suite.elapsed_time()));
+ *stream << TestPropertiesAsXmlAttributes(test_suite.ad_hoc_test_result());
+ }
+ *stream << ">\n";
+ for (int i = 0; i < test_suite.total_test_count(); ++i) {
+ if (test_suite.GetTestInfo(i)->is_reportable())
+ OutputXmlTestInfo(stream, test_suite.name(), *test_suite.GetTestInfo(i));
+ }
+ *stream << " </" << kTestsuite << ">\n";
+}
+
+// Prints an XML summary of unit_test to output stream out.
+void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream,
+ const UnitTest& unit_test) {
+ const std::string kTestsuites = "testsuites";
+
+ *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ *stream << "<" << kTestsuites;
+
+ OutputXmlAttribute(stream, kTestsuites, "tests",
+ StreamableToString(unit_test.reportable_test_count()));
+ OutputXmlAttribute(stream, kTestsuites, "failures",
+ StreamableToString(unit_test.failed_test_count()));
+ OutputXmlAttribute(
+ stream, kTestsuites, "disabled",
+ StreamableToString(unit_test.reportable_disabled_test_count()));
+ OutputXmlAttribute(stream, kTestsuites, "errors", "0");
+ OutputXmlAttribute(
+ stream, kTestsuites, "timestamp",
+ FormatEpochTimeInMillisAsIso8601(unit_test.start_timestamp()));
+ OutputXmlAttribute(stream, kTestsuites, "time",
+ FormatTimeInMillisAsSeconds(unit_test.elapsed_time()));
+
+ if (GTEST_FLAG(shuffle)) {
+ OutputXmlAttribute(stream, kTestsuites, "random_seed",
+ StreamableToString(unit_test.random_seed()));
+ }
+ *stream << TestPropertiesAsXmlAttributes(unit_test.ad_hoc_test_result());
+
+ OutputXmlAttribute(stream, kTestsuites, "name", "AllTests");
+ *stream << ">\n";
+
+ for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
+ if (unit_test.GetTestSuite(i)->reportable_test_count() > 0)
+ PrintXmlTestSuite(stream, *unit_test.GetTestSuite(i));
+ }
+ *stream << "</" << kTestsuites << ">\n";
+}
+
+void XmlUnitTestResultPrinter::PrintXmlTestsList(
+ std::ostream* stream, const std::vector<TestSuite*>& test_suites) {
+ const std::string kTestsuites = "testsuites";
+
+ *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ *stream << "<" << kTestsuites;
+
+ int total_tests = 0;
+ for (auto test_suite : test_suites) {
+ total_tests += test_suite->total_test_count();
+ }
+ OutputXmlAttribute(stream, kTestsuites, "tests",
+ StreamableToString(total_tests));
+ OutputXmlAttribute(stream, kTestsuites, "name", "AllTests");
+ *stream << ">\n";
+
+ for (auto test_suite : test_suites) {
+ PrintXmlTestSuite(stream, *test_suite);
+ }
+ *stream << "</" << kTestsuites << ">\n";
+}
+
+// Produces a string representing the test properties in a result as space
+// delimited XML attributes based on the property key="value" pairs.
+std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
+ const TestResult& result) {
+ Message attributes;
+ for (int i = 0; i < result.test_property_count(); ++i) {
+ const TestProperty& property = result.GetTestProperty(i);
+ attributes << " " << property.key() << "="
+ << "\"" << EscapeXmlAttribute(property.value()) << "\"";
+ }
+ return attributes.GetString();
+}
+
+void XmlUnitTestResultPrinter::OutputXmlTestProperties(
+ std::ostream* stream, const TestResult& result) {
+ const std::string kProperties = "properties";
+ const std::string kProperty = "property";
+
+ if (result.test_property_count() <= 0) {
+ return;
+ }
+
+ *stream << "<" << kProperties << ">\n";
+ for (int i = 0; i < result.test_property_count(); ++i) {
+ const TestProperty& property = result.GetTestProperty(i);
+ *stream << "<" << kProperty;
+ *stream << " name=\"" << EscapeXmlAttribute(property.key()) << "\"";
+ *stream << " value=\"" << EscapeXmlAttribute(property.value()) << "\"";
+ *stream << "/>\n";
+ }
+ *stream << "</" << kProperties << ">\n";
+}
+
+// End XmlUnitTestResultPrinter
+
+// This class generates an JSON output file.
+class JsonUnitTestResultPrinter : public EmptyTestEventListener {
+ public:
+ explicit JsonUnitTestResultPrinter(const char* output_file);
+
+ void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
+
+ // Prints an JSON summary of all unit tests.
+ static void PrintJsonTestList(::std::ostream* stream,
+ const std::vector<TestSuite*>& test_suites);
+
+ private:
+ // Returns an JSON-escaped copy of the input string str.
+ static std::string EscapeJson(const std::string& str);
+
+ //// Verifies that the given attribute belongs to the given element and
+ //// streams the attribute as JSON.
+ static void OutputJsonKey(std::ostream* stream,
+ const std::string& element_name,
+ const std::string& name,
+ const std::string& value,
+ const std::string& indent,
+ bool comma = true);
+ static void OutputJsonKey(std::ostream* stream,
+ const std::string& element_name,
+ const std::string& name,
+ int value,
+ const std::string& indent,
+ bool comma = true);
+
+ // Streams a JSON representation of a TestInfo object.
+ static void OutputJsonTestInfo(::std::ostream* stream,
+ const char* test_suite_name,
+ const TestInfo& test_info);
+
+ // Prints a JSON representation of a TestSuite object
+ static void PrintJsonTestSuite(::std::ostream* stream,
+ const TestSuite& test_suite);
+
+ // Prints a JSON summary of unit_test to output stream out.
+ static void PrintJsonUnitTest(::std::ostream* stream,
+ const UnitTest& unit_test);
+
+ // Produces a string representing the test properties in a result as
+ // a JSON dictionary.
+ static std::string TestPropertiesAsJson(const TestResult& result,
+ const std::string& indent);
+
+ // The output file.
+ const std::string output_file_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(JsonUnitTestResultPrinter);
+};
+
+// Creates a new JsonUnitTestResultPrinter.
+JsonUnitTestResultPrinter::JsonUnitTestResultPrinter(const char* output_file)
+ : output_file_(output_file) {
+ if (output_file_.empty()) {
+ GTEST_LOG_(FATAL) << "JSON output file may not be null";
+ }
+}
+
+void JsonUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
+ int /*iteration*/) {
+ FILE* jsonout = OpenFileForWriting(output_file_);
+ std::stringstream stream;
+ PrintJsonUnitTest(&stream, unit_test);
+ fprintf(jsonout, "%s", StringStreamToString(&stream).c_str());
+ fclose(jsonout);
+}
+
+// Returns an JSON-escaped copy of the input string str.
+std::string JsonUnitTestResultPrinter::EscapeJson(const std::string& str) {
+ Message m;
+
+ for (size_t i = 0; i < str.size(); ++i) {
+ const char ch = str[i];
+ switch (ch) {
+ case '\\':
+ case '"':
+ case '/':
+ m << '\\' << ch;
+ break;
+ case '\b':
+ m << "\\b";
+ break;
+ case '\t':
+ m << "\\t";
+ break;
+ case '\n':
+ m << "\\n";
+ break;
+ case '\f':
+ m << "\\f";
+ break;
+ case '\r':
+ m << "\\r";
+ break;
+ default:
+ if (ch < ' ') {
+ m << "\\u00" << String::FormatByte(static_cast<unsigned char>(ch));
+ } else {
+ m << ch;
+ }
+ break;
+ }
+ }
+
+ return m.GetString();
+}
+
+// The following routines generate an JSON representation of a UnitTest
+// object.
+
+// Formats the given time in milliseconds as seconds.
+static std::string FormatTimeInMillisAsDuration(TimeInMillis ms) {
+ ::std::stringstream ss;
+ ss << (static_cast<double>(ms) * 1e-3) << "s";
+ return ss.str();
+}
+
+// Converts the given epoch time in milliseconds to a date string in the
+// RFC3339 format, without the timezone information.
+static std::string FormatEpochTimeInMillisAsRFC3339(TimeInMillis ms) {
+ struct tm time_struct;
+ if (!PortableLocaltime(static_cast<time_t>(ms / 1000), &time_struct))
+ return "";
+ // YYYY-MM-DDThh:mm:ss
+ return StreamableToString(time_struct.tm_year + 1900) + "-" +
+ String::FormatIntWidth2(time_struct.tm_mon + 1) + "-" +
+ String::FormatIntWidth2(time_struct.tm_mday) + "T" +
+ String::FormatIntWidth2(time_struct.tm_hour) + ":" +
+ String::FormatIntWidth2(time_struct.tm_min) + ":" +
+ String::FormatIntWidth2(time_struct.tm_sec) + "Z";
+}
+
+static inline std::string Indent(size_t width) {
+ return std::string(width, ' ');
+}
+
+void JsonUnitTestResultPrinter::OutputJsonKey(
+ std::ostream* stream,
+ const std::string& element_name,
+ const std::string& name,
+ const std::string& value,
+ const std::string& indent,
+ bool comma) {
+ const std::vector<std::string>& allowed_names =
+ GetReservedOutputAttributesForElement(element_name);
+
+ GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
+ allowed_names.end())
+ << "Key \"" << name << "\" is not allowed for value \"" << element_name
+ << "\".";
+
+ *stream << indent << "\"" << name << "\": \"" << EscapeJson(value) << "\"";
+ if (comma)
+ *stream << ",\n";
+}
+
+void JsonUnitTestResultPrinter::OutputJsonKey(
+ std::ostream* stream,
+ const std::string& element_name,
+ const std::string& name,
+ int value,
+ const std::string& indent,
+ bool comma) {
+ const std::vector<std::string>& allowed_names =
+ GetReservedOutputAttributesForElement(element_name);
+
+ GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
+ allowed_names.end())
+ << "Key \"" << name << "\" is not allowed for value \"" << element_name
+ << "\".";
+
+ *stream << indent << "\"" << name << "\": " << StreamableToString(value);
+ if (comma)
+ *stream << ",\n";
+}
+
+// Prints a JSON representation of a TestInfo object.
+void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream,
+ const char* test_suite_name,
+ const TestInfo& test_info) {
+ const TestResult& result = *test_info.result();
+ const std::string kTestsuite = "testcase";
+ const std::string kIndent = Indent(10);
+
+ *stream << Indent(8) << "{\n";
+ OutputJsonKey(stream, kTestsuite, "name", test_info.name(), kIndent);
+
+ if (test_info.value_param() != nullptr) {
+ OutputJsonKey(stream, kTestsuite, "value_param", test_info.value_param(),
+ kIndent);
+ }
+ if (test_info.type_param() != nullptr) {
+ OutputJsonKey(stream, kTestsuite, "type_param", test_info.type_param(),
+ kIndent);
+ }
+ if (GTEST_FLAG(list_tests)) {
+ OutputJsonKey(stream, kTestsuite, "file", test_info.file(), kIndent);
+ OutputJsonKey(stream, kTestsuite, "line", test_info.line(), kIndent, false);
+ *stream << "\n" << Indent(8) << "}";
+ return;
+ }
+
+ OutputJsonKey(stream, kTestsuite, "status",
+ test_info.should_run() ? "RUN" : "NOTRUN", kIndent);
+ OutputJsonKey(stream, kTestsuite, "result",
+ test_info.should_run()
+ ? (result.Skipped() ? "SKIPPED" : "COMPLETED")
+ : "SUPPRESSED",
+ kIndent);
+ OutputJsonKey(stream, kTestsuite, "time",
+ FormatTimeInMillisAsDuration(result.elapsed_time()), kIndent);
+ OutputJsonKey(stream, kTestsuite, "classname", test_suite_name, kIndent,
+ false);
+ *stream << TestPropertiesAsJson(result, kIndent);
+
+ int failures = 0;
+ for (int i = 0; i < result.total_part_count(); ++i) {
+ const TestPartResult& part = result.GetTestPartResult(i);
+ if (part.failed()) {
+ *stream << ",\n";
+ if (++failures == 1) {
+ *stream << kIndent << "\"" << "failures" << "\": [\n";
+ }
+ const std::string location =
+ internal::FormatCompilerIndependentFileLocation(part.file_name(),
+ part.line_number());
+ const std::string message = EscapeJson(location + "\n" + part.message());
+ *stream << kIndent << " {\n"
+ << kIndent << " \"failure\": \"" << message << "\",\n"
+ << kIndent << " \"type\": \"\"\n"
+ << kIndent << " }";
+ }
+ }
+
+ if (failures > 0)
+ *stream << "\n" << kIndent << "]";
+ *stream << "\n" << Indent(8) << "}";
+}
+
+// Prints an JSON representation of a TestSuite object
+void JsonUnitTestResultPrinter::PrintJsonTestSuite(
+ std::ostream* stream, const TestSuite& test_suite) {
+ const std::string kTestsuite = "testsuite";
+ const std::string kIndent = Indent(6);
+
+ *stream << Indent(4) << "{\n";
+ OutputJsonKey(stream, kTestsuite, "name", test_suite.name(), kIndent);
+ OutputJsonKey(stream, kTestsuite, "tests", test_suite.reportable_test_count(),
+ kIndent);
+ if (!GTEST_FLAG(list_tests)) {
+ OutputJsonKey(stream, kTestsuite, "failures",
+ test_suite.failed_test_count(), kIndent);
+ OutputJsonKey(stream, kTestsuite, "disabled",
+ test_suite.reportable_disabled_test_count(), kIndent);
+ OutputJsonKey(stream, kTestsuite, "errors", 0, kIndent);
+ OutputJsonKey(stream, kTestsuite, "time",
+ FormatTimeInMillisAsDuration(test_suite.elapsed_time()),
+ kIndent, false);
+ *stream << TestPropertiesAsJson(test_suite.ad_hoc_test_result(), kIndent)
+ << ",\n";
+ }
+
+ *stream << kIndent << "\"" << kTestsuite << "\": [\n";
+
+ bool comma = false;
+ for (int i = 0; i < test_suite.total_test_count(); ++i) {
+ if (test_suite.GetTestInfo(i)->is_reportable()) {
+ if (comma) {
+ *stream << ",\n";
+ } else {
+ comma = true;
+ }
+ OutputJsonTestInfo(stream, test_suite.name(), *test_suite.GetTestInfo(i));
+ }
+ }
+ *stream << "\n" << kIndent << "]\n" << Indent(4) << "}";
+}
+
+// Prints a JSON summary of unit_test to output stream out.
+void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream,
+ const UnitTest& unit_test) {
+ const std::string kTestsuites = "testsuites";
+ const std::string kIndent = Indent(2);
+ *stream << "{\n";
+
+ OutputJsonKey(stream, kTestsuites, "tests", unit_test.reportable_test_count(),
+ kIndent);
+ OutputJsonKey(stream, kTestsuites, "failures", unit_test.failed_test_count(),
+ kIndent);
+ OutputJsonKey(stream, kTestsuites, "disabled",
+ unit_test.reportable_disabled_test_count(), kIndent);
+ OutputJsonKey(stream, kTestsuites, "errors", 0, kIndent);
+ if (GTEST_FLAG(shuffle)) {
+ OutputJsonKey(stream, kTestsuites, "random_seed", unit_test.random_seed(),
+ kIndent);
+ }
+ OutputJsonKey(stream, kTestsuites, "timestamp",
+ FormatEpochTimeInMillisAsRFC3339(unit_test.start_timestamp()),
+ kIndent);
+ OutputJsonKey(stream, kTestsuites, "time",
+ FormatTimeInMillisAsDuration(unit_test.elapsed_time()), kIndent,
+ false);
+
+ *stream << TestPropertiesAsJson(unit_test.ad_hoc_test_result(), kIndent)
+ << ",\n";
+
+ OutputJsonKey(stream, kTestsuites, "name", "AllTests", kIndent);
+ *stream << kIndent << "\"" << kTestsuites << "\": [\n";
+
+ bool comma = false;
+ for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
+ if (unit_test.GetTestSuite(i)->reportable_test_count() > 0) {
+ if (comma) {
+ *stream << ",\n";
+ } else {
+ comma = true;
+ }
+ PrintJsonTestSuite(stream, *unit_test.GetTestSuite(i));
+ }
+ }
+
+ *stream << "\n" << kIndent << "]\n" << "}\n";
+}
+
+void JsonUnitTestResultPrinter::PrintJsonTestList(
+ std::ostream* stream, const std::vector<TestSuite*>& test_suites) {
+ const std::string kTestsuites = "testsuites";
+ const std::string kIndent = Indent(2);
+ *stream << "{\n";
+ int total_tests = 0;
+ for (auto test_suite : test_suites) {
+ total_tests += test_suite->total_test_count();
+ }
+ OutputJsonKey(stream, kTestsuites, "tests", total_tests, kIndent);
+
+ OutputJsonKey(stream, kTestsuites, "name", "AllTests", kIndent);
+ *stream << kIndent << "\"" << kTestsuites << "\": [\n";
+
+ for (size_t i = 0; i < test_suites.size(); ++i) {
+ if (i != 0) {
+ *stream << ",\n";
+ }
+ PrintJsonTestSuite(stream, *test_suites[i]);
+ }
+
+ *stream << "\n"
+ << kIndent << "]\n"
+ << "}\n";
+}
+// Produces a string representing the test properties in a result as
+// a JSON dictionary.
+std::string JsonUnitTestResultPrinter::TestPropertiesAsJson(
+ const TestResult& result, const std::string& indent) {
+ Message attributes;
+ for (int i = 0; i < result.test_property_count(); ++i) {
+ const TestProperty& property = result.GetTestProperty(i);
+ attributes << ",\n" << indent << "\"" << property.key() << "\": "
+ << "\"" << EscapeJson(property.value()) << "\"";
+ }
+ return attributes.GetString();
+}
+
+// End JsonUnitTestResultPrinter
+
+#if GTEST_CAN_STREAM_RESULTS_
+
+// Checks if str contains '=', '&', '%' or '\n' characters. If yes,
+// replaces them by "%xx" where xx is their hexadecimal value. For
+// example, replaces "=" with "%3D". This algorithm is O(strlen(str))
+// in both time and space -- important as the input str may contain an
+// arbitrarily long test failure message and stack trace.
+std::string StreamingListener::UrlEncode(const char* str) {
+ std::string result;
+ result.reserve(strlen(str) + 1);
+ for (char ch = *str; ch != '\0'; ch = *++str) {
+ switch (ch) {
+ case '%':
+ case '=':
+ case '&':
+ case '\n':
+ result.append("%" + String::FormatByte(static_cast<unsigned char>(ch)));
+ break;
+ default:
+ result.push_back(ch);
+ break;
+ }
+ }
+ return result;
+}
+
+void StreamingListener::SocketWriter::MakeConnection() {
+ GTEST_CHECK_(sockfd_ == -1)
+ << "MakeConnection() can't be called when there is already a connection.";
+
+ addrinfo hints;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC; // To allow both IPv4 and IPv6 addresses.
+ hints.ai_socktype = SOCK_STREAM;
+ addrinfo* servinfo = nullptr;
+
+ // Use the getaddrinfo() to get a linked list of IP addresses for
+ // the given host name.
+ const int error_num = getaddrinfo(
+ host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
+ if (error_num != 0) {
+ GTEST_LOG_(WARNING) << "stream_result_to: getaddrinfo() failed: "
+ << gai_strerror(error_num);
+ }
+
+ // Loop through all the results and connect to the first we can.
+ for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != nullptr;
+ cur_addr = cur_addr->ai_next) {
+ sockfd_ = socket(
+ cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
+ if (sockfd_ != -1) {
+ // Connect the client socket to the server socket.
+ if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
+ close(sockfd_);
+ sockfd_ = -1;
+ }
+ }
+ }
+
+ freeaddrinfo(servinfo); // all done with this structure
+
+ if (sockfd_ == -1) {
+ GTEST_LOG_(WARNING) << "stream_result_to: failed to connect to "
+ << host_name_ << ":" << port_num_;
+ }
+}
+
+// End of class Streaming Listener
+#endif // GTEST_CAN_STREAM_RESULTS__
+
+// class OsStackTraceGetter
+
+const char* const OsStackTraceGetterInterface::kElidedFramesMarker =
+ "... " GTEST_NAME_ " internal frames ...";
+
+std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count)
+ GTEST_LOCK_EXCLUDED_(mutex_) {
+#if GTEST_HAS_ABSL
+ std::string result;
+
+ if (max_depth <= 0) {
+ return result;
+ }
+
+ max_depth = std::min(max_depth, kMaxStackTraceDepth);
+
+ std::vector<void*> raw_stack(max_depth);
+ // Skips the frames requested by the caller, plus this function.
+ const int raw_stack_size =
+ absl::GetStackTrace(&raw_stack[0], max_depth, skip_count + 1);
+
+ void* caller_frame = nullptr;
+ {
+ MutexLock lock(&mutex_);
+ caller_frame = caller_frame_;
+ }
+
+ for (int i = 0; i < raw_stack_size; ++i) {
+ if (raw_stack[i] == caller_frame &&
+ !GTEST_FLAG(show_internal_stack_frames)) {
+ // Add a marker to the trace and stop adding frames.
+ absl::StrAppend(&result, kElidedFramesMarker, "\n");
+ break;
+ }
+
+ char tmp[1024];
+ const char* symbol = "(unknown)";
+ if (absl::Symbolize(raw_stack[i], tmp, sizeof(tmp))) {
+ symbol = tmp;
+ }
+
+ char line[1024];
+ snprintf(line, sizeof(line), " %p: %s\n", raw_stack[i], symbol);
+ result += line;
+ }
+
+ return result;
+
+#else // !GTEST_HAS_ABSL
+ static_cast<void>(max_depth);
+ static_cast<void>(skip_count);
+ return "";
+#endif // GTEST_HAS_ABSL
+}
+
+void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) {
+#if GTEST_HAS_ABSL
+ void* caller_frame = nullptr;
+ if (absl::GetStackTrace(&caller_frame, 1, 3) <= 0) {
+ caller_frame = nullptr;
+ }
+
+ MutexLock lock(&mutex_);
+ caller_frame_ = caller_frame;
+#endif // GTEST_HAS_ABSL
+}
+
+// A helper class that creates the premature-exit file in its
+// constructor and deletes the file in its destructor.
+class ScopedPrematureExitFile {
+ public:
+ explicit ScopedPrematureExitFile(const char* premature_exit_filepath)
+ : premature_exit_filepath_(premature_exit_filepath ?
+ premature_exit_filepath : "") {
+ // If a path to the premature-exit file is specified...
+ if (!premature_exit_filepath_.empty()) {
+ // create the file with a single "0" character in it. I/O
+ // errors are ignored as there's nothing better we can do and we
+ // don't want to fail the test because of this.
+ FILE* pfile = posix::FOpen(premature_exit_filepath, "w");
+ fwrite("0", 1, 1, pfile);
+ fclose(pfile);
+ }
+ }
+
+ ~ScopedPrematureExitFile() {
+ if (!premature_exit_filepath_.empty()) {
+ int retval = remove(premature_exit_filepath_.c_str());
+ if (retval) {
+ GTEST_LOG_(ERROR) << "Failed to remove premature exit filepath \""
+ << premature_exit_filepath_ << "\" with error "
+ << retval;
+ }
+ }
+ }
+
+ private:
+ const std::string premature_exit_filepath_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedPrematureExitFile);
+};
+
+} // namespace internal
+
+// class TestEventListeners
+
+TestEventListeners::TestEventListeners()
+ : repeater_(new internal::TestEventRepeater()),
+ default_result_printer_(nullptr),
+ default_xml_generator_(nullptr) {}
+
+TestEventListeners::~TestEventListeners() { delete repeater_; }
+
+// Returns the standard listener responsible for the default console
+// output. Can be removed from the listeners list to shut down default
+// console output. Note that removing this object from the listener list
+// with Release transfers its ownership to the user.
+void TestEventListeners::Append(TestEventListener* listener) {
+ repeater_->Append(listener);
+}
+
+// Removes the given event listener from the list and returns it. It then
+// becomes the caller's responsibility to delete the listener. Returns
+// NULL if the listener is not found in the list.
+TestEventListener* TestEventListeners::Release(TestEventListener* listener) {
+ if (listener == default_result_printer_)
+ default_result_printer_ = nullptr;
+ else if (listener == default_xml_generator_)
+ default_xml_generator_ = nullptr;
+ return repeater_->Release(listener);
+}
+
+// Returns repeater that broadcasts the TestEventListener events to all
+// subscribers.
+TestEventListener* TestEventListeners::repeater() { return repeater_; }
+
+// Sets the default_result_printer attribute to the provided listener.
+// The listener is also added to the listener list and previous
+// default_result_printer is removed from it and deleted. The listener can
+// also be NULL in which case it will not be added to the list. Does
+// nothing if the previous and the current listener objects are the same.
+void TestEventListeners::SetDefaultResultPrinter(TestEventListener* listener) {
+ if (default_result_printer_ != listener) {
+ // It is an error to pass this method a listener that is already in the
+ // list.
+ delete Release(default_result_printer_);
+ default_result_printer_ = listener;
+ if (listener != nullptr) Append(listener);
+ }
+}
+
+// Sets the default_xml_generator attribute to the provided listener. The
+// listener is also added to the listener list and previous
+// default_xml_generator is removed from it and deleted. The listener can
+// also be NULL in which case it will not be added to the list. Does
+// nothing if the previous and the current listener objects are the same.
+void TestEventListeners::SetDefaultXmlGenerator(TestEventListener* listener) {
+ if (default_xml_generator_ != listener) {
+ // It is an error to pass this method a listener that is already in the
+ // list.
+ delete Release(default_xml_generator_);
+ default_xml_generator_ = listener;
+ if (listener != nullptr) Append(listener);
+ }
+}
+
+// Controls whether events will be forwarded by the repeater to the
+// listeners in the list.
+bool TestEventListeners::EventForwardingEnabled() const {
+ return repeater_->forwarding_enabled();
+}
+
+void TestEventListeners::SuppressEventForwarding() {
+ repeater_->set_forwarding_enabled(false);
+}
+
+// class UnitTest
+
+// Gets the singleton UnitTest object. The first time this method is
+// called, a UnitTest object is constructed and returned. Consecutive
+// calls will return the same object.
+//
+// We don't protect this under mutex_ as a user is not supposed to
+// call this before main() starts, from which point on the return
+// value will never change.
+UnitTest* UnitTest::GetInstance() {
+ // CodeGear C++Builder insists on a public destructor for the
+ // default implementation. Use this implementation to keep good OO
+ // design with private destructor.
+
+#if defined(__BORLANDC__)
+ static UnitTest* const instance = new UnitTest;
+ return instance;
+#else
+ static UnitTest instance;
+ return &instance;
+#endif // defined(__BORLANDC__)
+}
+
+// Gets the number of successful test suites.
+int UnitTest::successful_test_suite_count() const {
+ return impl()->successful_test_suite_count();
+}
+
+// Gets the number of failed test suites.
+int UnitTest::failed_test_suite_count() const {
+ return impl()->failed_test_suite_count();
+}
+
+// Gets the number of all test suites.
+int UnitTest::total_test_suite_count() const {
+ return impl()->total_test_suite_count();
+}
+
+// Gets the number of all test suites that contain at least one test
+// that should run.
+int UnitTest::test_suite_to_run_count() const {
+ return impl()->test_suite_to_run_count();
+}
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+int UnitTest::successful_test_case_count() const {
+ return impl()->successful_test_suite_count();
+}
+int UnitTest::failed_test_case_count() const {
+ return impl()->failed_test_suite_count();
+}
+int UnitTest::total_test_case_count() const {
+ return impl()->total_test_suite_count();
+}
+int UnitTest::test_case_to_run_count() const {
+ return impl()->test_suite_to_run_count();
+}
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+// Gets the number of successful tests.
+int UnitTest::successful_test_count() const {
+ return impl()->successful_test_count();
+}
+
+// Gets the number of skipped tests.
+int UnitTest::skipped_test_count() const {
+ return impl()->skipped_test_count();
+}
+
+// Gets the number of failed tests.
+int UnitTest::failed_test_count() const { return impl()->failed_test_count(); }
+
+// Gets the number of disabled tests that will be reported in the XML report.
+int UnitTest::reportable_disabled_test_count() const {
+ return impl()->reportable_disabled_test_count();
+}
+
+// Gets the number of disabled tests.
+int UnitTest::disabled_test_count() const {
+ return impl()->disabled_test_count();
+}
+
+// Gets the number of tests to be printed in the XML report.
+int UnitTest::reportable_test_count() const {
+ return impl()->reportable_test_count();
+}
+
+// Gets the number of all tests.
+int UnitTest::total_test_count() const { return impl()->total_test_count(); }
+
+// Gets the number of tests that should run.
+int UnitTest::test_to_run_count() const { return impl()->test_to_run_count(); }
+
+// Gets the time of the test program start, in ms from the start of the
+// UNIX epoch.
+internal::TimeInMillis UnitTest::start_timestamp() const {
+ return impl()->start_timestamp();
+}
+
+// Gets the elapsed time, in milliseconds.
+internal::TimeInMillis UnitTest::elapsed_time() const {
+ return impl()->elapsed_time();
+}
+
+// Returns true iff the unit test passed (i.e. all test suites passed).
+bool UnitTest::Passed() const { return impl()->Passed(); }
+
+// Returns true iff the unit test failed (i.e. some test suite failed
+// or something outside of all tests failed).
+bool UnitTest::Failed() const { return impl()->Failed(); }
+
+// Gets the i-th test suite among all the test suites. i can range from 0 to
+// total_test_suite_count() - 1. If i is not in that range, returns NULL.
+const TestSuite* UnitTest::GetTestSuite(int i) const {
+ return impl()->GetTestSuite(i);
+}
+
+// Legacy API is deprecated but still available
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+const TestCase* UnitTest::GetTestCase(int i) const {
+ return impl()->GetTestCase(i);
+}
+#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+
+// Returns the TestResult containing information on test failures and
+// properties logged outside of individual test suites.
+const TestResult& UnitTest::ad_hoc_test_result() const {
+ return *impl()->ad_hoc_test_result();
+}
+
+// Gets the i-th test suite among all the test suites. i can range from 0 to
+// total_test_suite_count() - 1. If i is not in that range, returns NULL.
+TestSuite* UnitTest::GetMutableTestSuite(int i) {
+ return impl()->GetMutableSuiteCase(i);
+}
+
+// Returns the list of event listeners that can be used to track events
+// inside Google Test.
+TestEventListeners& UnitTest::listeners() {
+ return *impl()->listeners();
+}
+
+// Registers and returns a global test environment. When a test
+// program is run, all global test environments will be set-up in the
+// order they were registered. After all tests in the program have
+// finished, all global test environments will be torn-down in the
+// *reverse* order they were registered.
+//
+// The UnitTest object takes ownership of the given environment.
+//
+// We don't protect this under mutex_, as we only support calling it
+// from the main thread.
+Environment* UnitTest::AddEnvironment(Environment* env) {
+ if (env == nullptr) {
+ return nullptr;
+ }
+
+ impl_->environments().push_back(env);
+ return env;
+}
+
+// Adds a TestPartResult to the current TestResult object. All Google Test
+// assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) eventually call
+// this to report their results. The user code should use the
+// assertion macros instead of calling this directly.
+void UnitTest::AddTestPartResult(
+ TestPartResult::Type result_type,
+ const char* file_name,
+ int line_number,
+ const std::string& message,
+ const std::string& os_stack_trace) GTEST_LOCK_EXCLUDED_(mutex_) {
+ Message msg;
+ msg << message;
+
+ internal::MutexLock lock(&mutex_);
+ if (impl_->gtest_trace_stack().size() > 0) {
+ msg << "\n" << GTEST_NAME_ << " trace:";
+
+ for (size_t i = impl_->gtest_trace_stack().size(); i > 0; --i) {
+ const internal::TraceInfo& trace = impl_->gtest_trace_stack()[i - 1];
+ msg << "\n" << internal::FormatFileLocation(trace.file, trace.line)
+ << " " << trace.message;
+ }
+ }
+
+ if (os_stack_trace.c_str() != nullptr && !os_stack_trace.empty()) {
+ msg << internal::kStackTraceMarker << os_stack_trace;
+ }
+
+ const TestPartResult result = TestPartResult(
+ result_type, file_name, line_number, msg.GetString().c_str());
+ impl_->GetTestPartResultReporterForCurrentThread()->
+ ReportTestPartResult(result);
+
+ if (result_type != TestPartResult::kSuccess &&
+ result_type != TestPartResult::kSkip) {
+ // gtest_break_on_failure takes precedence over
+ // gtest_throw_on_failure. This allows a user to set the latter
+ // in the code (perhaps in order to use Google Test assertions
+ // with another testing framework) and specify the former on the
+ // command line for debugging.
+ if (GTEST_FLAG(break_on_failure)) {
+#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
+ // Using DebugBreak on Windows allows gtest to still break into a debugger
+ // when a failure happens and both the --gtest_break_on_failure and
+ // the --gtest_catch_exceptions flags are specified.
+ DebugBreak();
+#elif (!defined(__native_client__)) && \
+ ((defined(__clang__) || defined(__GNUC__)) && \
+ (defined(__x86_64__) || defined(__i386__)))
+ // with clang/gcc we can achieve the same effect on x86 by invoking int3
+ asm("int3");
+#else
+ // Dereference nullptr through a volatile pointer to prevent the compiler
+ // from removing. We use this rather than abort() or __builtin_trap() for
+ // portability: some debuggers don't correctly trap abort().
+ *static_cast<volatile int*>(nullptr) = 1;
+#endif // GTEST_OS_WINDOWS
+ } else if (GTEST_FLAG(throw_on_failure)) {
+#if GTEST_HAS_EXCEPTIONS
+ throw internal::GoogleTestFailureException(result);
+#else
+ // We cannot call abort() as it generates a pop-up in debug mode
+ // that cannot be suppressed in VC 7.1 or below.
+ exit(1);
+#endif
+ }
+ }
+}
+
+// Adds a TestProperty to the current TestResult object when invoked from
+// inside a test, to current TestSuite's ad_hoc_test_result_ when invoked
+// from SetUpTestSuite or TearDownTestSuite, or to the global property set
+// when invoked elsewhere. If the result already contains a property with
+// the same key, the value will be updated.
+void UnitTest::RecordProperty(const std::string& key,
+ const std::string& value) {
+ impl_->RecordProperty(TestProperty(key, value));
+}
+
+// Runs all tests in this UnitTest object and prints the result.
+// Returns 0 if successful, or 1 otherwise.
+//
+// We don't protect this under mutex_, as we only support calling it
+// from the main thread.
+int UnitTest::Run() {
+ const bool in_death_test_child_process =
+ internal::GTEST_FLAG(internal_run_death_test).length() > 0;
+
+ // Google Test implements this protocol for catching that a test
+ // program exits before returning control to Google Test:
+ //
+ // 1. Upon start, Google Test creates a file whose absolute path
+ // is specified by the environment variable
+ // TEST_PREMATURE_EXIT_FILE.
+ // 2. When Google Test has finished its work, it deletes the file.
+ //
+ // This allows a test runner to set TEST_PREMATURE_EXIT_FILE before
+ // running a Google-Test-based test program and check the existence
+ // of the file at the end of the test execution to see if it has
+ // exited prematurely.
+
+ // If we are in the child process of a death test, don't
+ // create/delete the premature exit file, as doing so is unnecessary
+ // and will confuse the parent process. Otherwise, create/delete
+ // the file upon entering/leaving this function. If the program
+ // somehow exits before this function has a chance to return, the
+ // premature-exit file will be left undeleted, causing a test runner
+ // that understands the premature-exit-file protocol to report the
+ // test as having failed.
+ const internal::ScopedPrematureExitFile premature_exit_file(
+ in_death_test_child_process
+ ? nullptr
+ : internal::posix::GetEnv("TEST_PREMATURE_EXIT_FILE"));
+
+ // Captures the value of GTEST_FLAG(catch_exceptions). This value will be
+ // used for the duration of the program.
+ impl()->set_catch_exceptions(GTEST_FLAG(catch_exceptions));
+
+#if GTEST_OS_WINDOWS
+ // Either the user wants Google Test to catch exceptions thrown by the
+ // tests or this is executing in the context of death test child
+ // process. In either case the user does not want to see pop-up dialogs
+ // about crashes - they are expected.
+ if (impl()->catch_exceptions() || in_death_test_child_process) {
+# if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
+ // SetErrorMode doesn't exist on CE.
+ SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
+ SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
+# endif // !GTEST_OS_WINDOWS_MOBILE
+
+# if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
+ // Death test children can be terminated with _abort(). On Windows,
+ // _abort() can show a dialog with a warning message. This forces the
+ // abort message to go to stderr instead.
+ _set_error_mode(_OUT_TO_STDERR);
+# endif
+
+# if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE
+ // In the debug version, Visual Studio pops up a separate dialog
+ // offering a choice to debug the aborted program. We need to suppress
+ // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
+ // executed. Google Test will notify the user of any unexpected
+ // failure via stderr.
+ if (!GTEST_FLAG(break_on_failure))
+ _set_abort_behavior(
+ 0x0, // Clear the following flags:
+ _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump.
+# endif
+ }
+#endif // GTEST_OS_WINDOWS
+
+ return internal::HandleExceptionsInMethodIfSupported(
+ impl(),
+ &internal::UnitTestImpl::RunAllTests,
+ "auxiliary test code (environments or event listeners)") ? 0 : 1;
+}
+
+// Returns the working directory when the first TEST() or TEST_F() was
+// executed.
+const char* UnitTest::original_working_dir() const {
+ return impl_->original_working_dir_.c_str();
+}
+
+// Returns the TestSuite object for the test that's currently running,
+// or NULL if no test is running.
+const TestSuite* UnitTest::current_test_suite() const
+ GTEST_LOCK_EXCLUDED_(mutex_) {
+ internal::MutexLock lock(&mutex_);
+ return impl_->current_test_suite();
+}
+
+// Legacy API is still available but deprecated
+#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
+const TestCase* UnitTest::current_test_case() const
+ GTEST_LOCK_EXCLUDED_(mutex_) {
+ internal::MutexLock lock(&mutex_);
+ return impl_->current_test_suite();
+}
+#endif
+
+// Returns the TestInfo object for the test that's currently running,
+// or NULL if no test is running.
+const TestInfo* UnitTest::current_test_info() const
+ GTEST_LOCK_EXCLUDED_(mutex_) {
+ internal::MutexLock lock(&mutex_);
+ return impl_->current_test_info();
+}
+
+// Returns the random seed used at the start of the current test run.
+int UnitTest::random_seed() const { return impl_->random_seed(); }
+
+// Returns ParameterizedTestSuiteRegistry object used to keep track of
+// value-parameterized tests and instantiate and register them.
+internal::ParameterizedTestSuiteRegistry&
+UnitTest::parameterized_test_registry() GTEST_LOCK_EXCLUDED_(mutex_) {
+ return impl_->parameterized_test_registry();
+}
+
+// Creates an empty UnitTest.
+UnitTest::UnitTest() {
+ impl_ = new internal::UnitTestImpl(this);
+}
+
+// Destructor of UnitTest.
+UnitTest::~UnitTest() {
+ delete impl_;
+}
+
+// Pushes a trace defined by SCOPED_TRACE() on to the per-thread
+// Google Test trace stack.
+void UnitTest::PushGTestTrace(const internal::TraceInfo& trace)
+ GTEST_LOCK_EXCLUDED_(mutex_) {
+ internal::MutexLock lock(&mutex_);
+ impl_->gtest_trace_stack().push_back(trace);
+}
+
+// Pops a trace from the per-thread Google Test trace stack.
+void UnitTest::PopGTestTrace()
+ GTEST_LOCK_EXCLUDED_(mutex_) {
+ internal::MutexLock lock(&mutex_);
+ impl_->gtest_trace_stack().pop_back();
+}
+
+namespace internal {
+
+UnitTestImpl::UnitTestImpl(UnitTest* parent)
+ : parent_(parent),
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355 /* using this in initializer */)
+ default_global_test_part_result_reporter_(this),
+ default_per_thread_test_part_result_reporter_(this),
+ GTEST_DISABLE_MSC_WARNINGS_POP_() global_test_part_result_repoter_(
+ &default_global_test_part_result_reporter_),
+ per_thread_test_part_result_reporter_(
+ &default_per_thread_test_part_result_reporter_),
+ parameterized_test_registry_(),
+ parameterized_tests_registered_(false),
+ last_death_test_suite_(-1),
+ current_test_suite_(nullptr),
+ current_test_info_(nullptr),
+ ad_hoc_test_result_(),
+ os_stack_trace_getter_(nullptr),
+ post_flag_parse_init_performed_(false),
+ random_seed_(0), // Will be overridden by the flag before first use.
+ random_(0), // Will be reseeded before first use.
+ start_timestamp_(0),
+ elapsed_time_(0),
+#if GTEST_HAS_DEATH_TEST
+ death_test_factory_(new DefaultDeathTestFactory),
+#endif
+ // Will be overridden by the flag before first use.
+ catch_exceptions_(false) {
+ listeners()->SetDefaultResultPrinter(new PrettyUnitTestResultPrinter);
+}
+
+UnitTestImpl::~UnitTestImpl() {
+ // Deletes every TestSuite.
+ ForEach(test_suites_, internal::Delete<TestSuite>);
+
+ // Deletes every Environment.
+ ForEach(environments_, internal::Delete<Environment>);
+
+ delete os_stack_trace_getter_;
+}
+
+// Adds a TestProperty to the current TestResult object when invoked in a
+// context of a test, to current test suite's ad_hoc_test_result when invoke
+// from SetUpTestSuite/TearDownTestSuite, or to the global property set
+// otherwise. If the result already contains a property with the same key,
+// the value will be updated.
+void UnitTestImpl::RecordProperty(const TestProperty& test_property) {
+ std::string xml_element;
+ TestResult* test_result; // TestResult appropriate for property recording.
+
+ if (current_test_info_ != nullptr) {
+ xml_element = "testcase";
+ test_result = &(current_test_info_->result_);
+ } else if (current_test_suite_ != nullptr) {
+ xml_element = "testsuite";
+ test_result = &(current_test_suite_->ad_hoc_test_result_);
+ } else {
+ xml_element = "testsuites";
+ test_result = &ad_hoc_test_result_;
+ }
+ test_result->RecordProperty(xml_element, test_property);
+}
+
+#if GTEST_HAS_DEATH_TEST
+// Disables event forwarding if the control is currently in a death test
+// subprocess. Must not be called before InitGoogleTest.
+void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
+ if (internal_run_death_test_flag_.get() != nullptr)
+ listeners()->SuppressEventForwarding();
+}
+#endif // GTEST_HAS_DEATH_TEST
+
+// Initializes event listeners performing XML output as specified by
+// UnitTestOptions. Must not be called before InitGoogleTest.
+void UnitTestImpl::ConfigureXmlOutput() {
+ const std::string& output_format = UnitTestOptions::GetOutputFormat();
+ if (output_format == "xml") {
+ listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter(
+ UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
+ } else if (output_format == "json") {
+ listeners()->SetDefaultXmlGenerator(new JsonUnitTestResultPrinter(
+ UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
+ } else if (output_format != "") {
+ GTEST_LOG_(WARNING) << "WARNING: unrecognized output format \""
+ << output_format << "\" ignored.";
+ }
+}
+
+#if GTEST_CAN_STREAM_RESULTS_
+// Initializes event listeners for streaming test results in string form.
+// Must not be called before InitGoogleTest.
+void UnitTestImpl::ConfigureStreamingOutput() {
+ const std::string& target = GTEST_FLAG(stream_result_to);
+ if (!target.empty()) {
+ const size_t pos = target.find(':');
+ if (pos != std::string::npos) {
+ listeners()->Append(new StreamingListener(target.substr(0, pos),
+ target.substr(pos+1)));
+ } else {
+ GTEST_LOG_(WARNING) << "unrecognized streaming target \"" << target
+ << "\" ignored.";
+ }
+ }
+}
+#endif // GTEST_CAN_STREAM_RESULTS_
+
+// Performs initialization dependent upon flag values obtained in
+// ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
+// ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
+// this function is also called from RunAllTests. Since this function can be
+// called more than once, it has to be idempotent.
+void UnitTestImpl::PostFlagParsingInit() {
+ // Ensures that this function does not execute more than once.
+ if (!post_flag_parse_init_performed_) {
+ post_flag_parse_init_performed_ = true;
+
+#if defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
+ // Register to send notifications about key process state changes.
+ listeners()->Append(new GTEST_CUSTOM_TEST_EVENT_LISTENER_());
+#endif // defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
+
+#if GTEST_HAS_DEATH_TEST
+ InitDeathTestSubprocessControlInfo();
+ SuppressTestEventsIfInSubprocess();
+#endif // GTEST_HAS_DEATH_TEST
+
+ // Registers parameterized tests. This makes parameterized tests
+ // available to the UnitTest reflection API without running
+ // RUN_ALL_TESTS.
+ RegisterParameterizedTests();
+
+ // Configures listeners for XML output. This makes it possible for users
+ // to shut down the default XML output before invoking RUN_ALL_TESTS.
+ ConfigureXmlOutput();
+
+#if GTEST_CAN_STREAM_RESULTS_
+ // Configures listeners for streaming test results to the specified server.
+ ConfigureStreamingOutput();
+#endif // GTEST_CAN_STREAM_RESULTS_
+
+#if GTEST_HAS_ABSL
+ if (GTEST_FLAG(install_failure_signal_handler)) {
+ absl::FailureSignalHandlerOptions options;
+ absl::InstallFailureSignalHandler(options);
+ }
+#endif // GTEST_HAS_ABSL
+ }
+}
+
+// A predicate that checks the name of a TestSuite against a known
+// value.
+//
+// This is used for implementation of the UnitTest class only. We put
+// it in the anonymous namespace to prevent polluting the outer
+// namespace.
+//
+// TestSuiteNameIs is copyable.
+class TestSuiteNameIs {
+ public:
+ // Constructor.
+ explicit TestSuiteNameIs(const std::string& name) : name_(name) {}
+
+ // Returns true iff the name of test_suite matches name_.
+ bool operator()(const TestSuite* test_suite) const {
+ return test_suite != nullptr &&
+ strcmp(test_suite->name(), name_.c_str()) == 0;
+ }
+
+ private:
+ std::string name_;
+};
+
+// Finds and returns a TestSuite with the given name. If one doesn't
+// exist, creates one and returns it. It's the CALLER'S
+// RESPONSIBILITY to ensure that this function is only called WHEN THE
+// TESTS ARE NOT SHUFFLED.
+//
+// Arguments:
+//
+// test_suite_name: name of the test suite
+// type_param: the name of the test suite's type parameter, or NULL if
+// this is not a typed or a type-parameterized test suite.
+// set_up_tc: pointer to the function that sets up the test suite
+// tear_down_tc: pointer to the function that tears down the test suite
+TestSuite* UnitTestImpl::GetTestSuite(
+ const char* test_suite_name, const char* type_param,
+ internal::SetUpTestSuiteFunc set_up_tc,
+ internal::TearDownTestSuiteFunc tear_down_tc) {
+ // Can we find a TestSuite with the given name?
+ const auto test_suite =
+ std::find_if(test_suites_.rbegin(), test_suites_.rend(),
+ TestSuiteNameIs(test_suite_name));
+
+ if (test_suite != test_suites_.rend()) return *test_suite;
+
+ // No. Let's create one.
+ auto* const new_test_suite =
+ new TestSuite(test_suite_name, type_param, set_up_tc, tear_down_tc);
+
+ // Is this a death test suite?
+ if (internal::UnitTestOptions::MatchesFilter(test_suite_name,
+ kDeathTestSuiteFilter)) {
+ // Yes. Inserts the test suite after the last death test suite
+ // defined so far. This only works when the test suites haven't
+ // been shuffled. Otherwise we may end up running a death test
+ // after a non-death test.
+ ++last_death_test_suite_;
+ test_suites_.insert(test_suites_.begin() + last_death_test_suite_,
+ new_test_suite);
+ } else {
+ // No. Appends to the end of the list.
+ test_suites_.push_back(new_test_suite);
+ }
+
+ test_suite_indices_.push_back(static_cast<int>(test_suite_indices_.size()));
+ return new_test_suite;
+}
+
+// Helpers for setting up / tearing down the given environment. They
+// are for use in the ForEach() function.
+static void SetUpEnvironment(Environment* env) { env->SetUp(); }
+static void TearDownEnvironment(Environment* env) { env->TearDown(); }
+
+// Runs all tests in this UnitTest object, prints the result, and
+// returns true if all tests are successful. If any exception is
+// thrown during a test, the test is considered to be failed, but the
+// rest of the tests will still be run.
+//
+// When parameterized tests are enabled, it expands and registers
+// parameterized tests first in RegisterParameterizedTests().
+// All other functions called from RunAllTests() may safely assume that
+// parameterized tests are ready to be counted and run.
+bool UnitTestImpl::RunAllTests() {
+ // True iff Google Test is initialized before RUN_ALL_TESTS() is called.
+ const bool gtest_is_initialized_before_run_all_tests = GTestIsInitialized();
+
+ // Do not run any test if the --help flag was specified.
+ if (g_help_flag)
+ return true;
+
+ // Repeats the call to the post-flag parsing initialization in case the
+ // user didn't call InitGoogleTest.
+ PostFlagParsingInit();
+
+ // Even if sharding is not on, test runners may want to use the
+ // GTEST_SHARD_STATUS_FILE to query whether the test supports the sharding
+ // protocol.
+ internal::WriteToShardStatusFileIfNeeded();
+
+ // True iff we are in a subprocess for running a thread-safe-style
+ // death test.
+ bool in_subprocess_for_death_test = false;
+
+#if GTEST_HAS_DEATH_TEST
+ in_subprocess_for_death_test =
+ (internal_run_death_test_flag_.get() != nullptr);
+# if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
+ if (in_subprocess_for_death_test) {
+ GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_();
+ }
+# endif // defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
+#endif // GTEST_HAS_DEATH_TEST
+
+ const bool should_shard = ShouldShard(kTestTotalShards, kTestShardIndex,
+ in_subprocess_for_death_test);
+
+ // Compares the full test names with the filter to decide which
+ // tests to run.
+ const bool has_tests_to_run = FilterTests(should_shard
+ ? HONOR_SHARDING_PROTOCOL
+ : IGNORE_SHARDING_PROTOCOL) > 0;
+
+ // Lists the tests and exits if the --gtest_list_tests flag was specified.
+ if (GTEST_FLAG(list_tests)) {
+ // This must be called *after* FilterTests() has been called.
+ ListTestsMatchingFilter();
+ return true;
+ }
+
+ random_seed_ = GTEST_FLAG(shuffle) ?
+ GetRandomSeedFromFlag(GTEST_FLAG(random_seed)) : 0;
+
+ // True iff at least one test has failed.
+ bool failed = false;
+
+ TestEventListener* repeater = listeners()->repeater();
+
+ start_timestamp_ = GetTimeInMillis();
+ repeater->OnTestProgramStart(*parent_);
+
+ // How many times to repeat the tests? We don't want to repeat them
+ // when we are inside the subprocess of a death test.
+ const int repeat = in_subprocess_for_death_test ? 1 : GTEST_FLAG(repeat);
+ // Repeats forever if the repeat count is negative.
+ const bool gtest_repeat_forever = repeat < 0;
+ for (int i = 0; gtest_repeat_forever || i != repeat; i++) {
+ // We want to preserve failures generated by ad-hoc test
+ // assertions executed before RUN_ALL_TESTS().
+ ClearNonAdHocTestResult();
+
+ const TimeInMillis start = GetTimeInMillis();
+
+ // Shuffles test suites and tests if requested.
+ if (has_tests_to_run && GTEST_FLAG(shuffle)) {
+ random()->Reseed(static_cast<UInt32>(random_seed_));
+ // This should be done before calling OnTestIterationStart(),
+ // such that a test event listener can see the actual test order
+ // in the event.
+ ShuffleTests();
+ }
+
+ // Tells the unit test event listeners that the tests are about to start.
+ repeater->OnTestIterationStart(*parent_, i);
+
+ // Runs each test suite if there is at least one test to run.
+ if (has_tests_to_run) {
+ // Sets up all environments beforehand.
+ repeater->OnEnvironmentsSetUpStart(*parent_);
+ ForEach(environments_, SetUpEnvironment);
+ repeater->OnEnvironmentsSetUpEnd(*parent_);
+
+ // Runs the tests only if there was no fatal failure or skip triggered
+ // during global set-up.
+ if (Test::IsSkipped()) {
+ // Emit diagnostics when global set-up calls skip, as it will not be
+ // emitted by default.
+ TestResult& test_result =
+ *internal::GetUnitTestImpl()->current_test_result();
+ for (int j = 0; j < test_result.total_part_count(); ++j) {
+ const TestPartResult& test_part_result =
+ test_result.GetTestPartResult(j);
+ if (test_part_result.type() == TestPartResult::kSkip) {
+ const std::string& result = test_part_result.message();
+ printf("%s\n", result.c_str());
+ }
+ }
+ fflush(stdout);
+ } else if (!Test::HasFatalFailure()) {
+ for (int test_index = 0; test_index < total_test_suite_count();
+ test_index++) {
+ GetMutableSuiteCase(test_index)->Run();
+ }
+ }
+
+ // Tears down all environments in reverse order afterwards.
+ repeater->OnEnvironmentsTearDownStart(*parent_);
+ std::for_each(environments_.rbegin(), environments_.rend(),
+ TearDownEnvironment);
+ repeater->OnEnvironmentsTearDownEnd(*parent_);
+ }
+
+ elapsed_time_ = GetTimeInMillis() - start;
+
+ // Tells the unit test event listener that the tests have just finished.
+ repeater->OnTestIterationEnd(*parent_, i);
+
+ // Gets the result and clears it.
+ if (!Passed()) {
+ failed = true;
+ }
+
+ // Restores the original test order after the iteration. This
+ // allows the user to quickly repro a failure that happens in the
+ // N-th iteration without repeating the first (N - 1) iterations.
+ // This is not enclosed in "if (GTEST_FLAG(shuffle)) { ... }", in
+ // case the user somehow changes the value of the flag somewhere
+ // (it's always safe to unshuffle the tests).
+ UnshuffleTests();
+
+ if (GTEST_FLAG(shuffle)) {
+ // Picks a new random seed for each iteration.
+ random_seed_ = GetNextRandomSeed(random_seed_);
+ }
+ }
+
+ repeater->OnTestProgramEnd(*parent_);
+
+ if (!gtest_is_initialized_before_run_all_tests) {
+ ColoredPrintf(
+ COLOR_RED,
+ "\nIMPORTANT NOTICE - DO NOT IGNORE:\n"
+ "This test program did NOT call " GTEST_INIT_GOOGLE_TEST_NAME_
+ "() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_
+ " will start to enforce the valid usage. "
+ "Please fix it ASAP, or IT WILL START TO FAIL.\n"); // NOLINT
+#if GTEST_FOR_GOOGLE_
+ ColoredPrintf(COLOR_RED,
+ "For more details, see http://wiki/Main/ValidGUnitMain.\n");
+#endif // GTEST_FOR_GOOGLE_
+ }
+
+ return !failed;
+}
+
+// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
+// if the variable is present. If a file already exists at this location, this
+// function will write over it. If the variable is present, but the file cannot
+// be created, prints an error and exits.
+void WriteToShardStatusFileIfNeeded() {
+ const char* const test_shard_file = posix::GetEnv(kTestShardStatusFile);
+ if (test_shard_file != nullptr) {
+ FILE* const file = posix::FOpen(test_shard_file, "w");
+ if (file == nullptr) {
+ ColoredPrintf(COLOR_RED,
+ "Could not write to the test shard status file \"%s\" "
+ "specified by the %s environment variable.\n",
+ test_shard_file, kTestShardStatusFile);
+ fflush(stdout);
+ exit(EXIT_FAILURE);
+ }
+ fclose(file);
+ }
+}
+
+// Checks whether sharding is enabled by examining the relevant
+// environment variable values. If the variables are present,
+// but inconsistent (i.e., shard_index >= total_shards), prints
+// an error and exits. If in_subprocess_for_death_test, sharding is
+// disabled because it must only be applied to the original test
+// process. Otherwise, we could filter out death tests we intended to execute.
+bool ShouldShard(const char* total_shards_env,
+ const char* shard_index_env,
+ bool in_subprocess_for_death_test) {
+ if (in_subprocess_for_death_test) {
+ return false;
+ }
+
+ const Int32 total_shards = Int32FromEnvOrDie(total_shards_env, -1);
+ const Int32 shard_index = Int32FromEnvOrDie(shard_index_env, -1);
+
+ if (total_shards == -1 && shard_index == -1) {
+ return false;
+ } else if (total_shards == -1 && shard_index != -1) {
+ const Message msg = Message()
+ << "Invalid environment variables: you have "
+ << kTestShardIndex << " = " << shard_index
+ << ", but have left " << kTestTotalShards << " unset.\n";
+ ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str());
+ fflush(stdout);
+ exit(EXIT_FAILURE);
+ } else if (total_shards != -1 && shard_index == -1) {
+ const Message msg = Message()
+ << "Invalid environment variables: you have "
+ << kTestTotalShards << " = " << total_shards
+ << ", but have left " << kTestShardIndex << " unset.\n";
+ ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str());
+ fflush(stdout);
+ exit(EXIT_FAILURE);
+ } else if (shard_index < 0 || shard_index >= total_shards) {
+ const Message msg = Message()
+ << "Invalid environment variables: we require 0 <= "
+ << kTestShardIndex << " < " << kTestTotalShards
+ << ", but you have " << kTestShardIndex << "=" << shard_index
+ << ", " << kTestTotalShards << "=" << total_shards << ".\n";
+ ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str());
+ fflush(stdout);
+ exit(EXIT_FAILURE);
+ }
+
+ return total_shards > 1;
+}
+
+// Parses the environment variable var as an Int32. If it is unset,
+// returns default_val. If it is not an Int32, prints an error
+// and aborts.
+Int32 Int32FromEnvOrDie(const char* var, Int32 default_val) {
+ const char* str_val = posix::GetEnv(var);
+ if (str_val == nullptr) {
+ return default_val;
+ }
+
+ Int32 result;
+ if (!ParseInt32(Message() << "The value of environment variable " << var,
+ str_val, &result)) {
+ exit(EXIT_FAILURE);
+ }
+ return result;
+}
+
+// Given the total number of shards, the shard index, and the test id,
+// returns true iff the test should be run on this shard. The test id is
+// some arbitrary but unique non-negative integer assigned to each test
+// method. Assumes that 0 <= shard_index < total_shards.
+bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) {
+ return (test_id % total_shards) == shard_index;
+}
+
+// Compares the name of each test with the user-specified filter to
+// decide whether the test should be run, then records the result in
+// each TestSuite and TestInfo object.
+// If shard_tests == true, further filters tests based on sharding
+// variables in the environment - see
+// https://github.com/google/googletest/blob/master/googletest/docs/advanced.md
+// . Returns the number of tests that should run.
+int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
+ const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ?
+ Int32FromEnvOrDie(kTestTotalShards, -1) : -1;
+ const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
+ Int32FromEnvOrDie(kTestShardIndex, -1) : -1;
+
+ // num_runnable_tests are the number of tests that will
+ // run across all shards (i.e., match filter and are not disabled).
+ // num_selected_tests are the number of tests to be run on
+ // this shard.
+ int num_runnable_tests = 0;
+ int num_selected_tests = 0;
+ for (auto* test_suite : test_suites_) {
+ const std::string& test_suite_name = test_suite->name();
+ test_suite->set_should_run(false);
+
+ for (size_t j = 0; j < test_suite->test_info_list().size(); j++) {
+ TestInfo* const test_info = test_suite->test_info_list()[j];
+ const std::string test_name(test_info->name());
+ // A test is disabled if test suite name or test name matches
+ // kDisableTestFilter.
+ const bool is_disabled = internal::UnitTestOptions::MatchesFilter(
+ test_suite_name, kDisableTestFilter) ||
+ internal::UnitTestOptions::MatchesFilter(
+ test_name, kDisableTestFilter);
+ test_info->is_disabled_ = is_disabled;
+
+ const bool matches_filter = internal::UnitTestOptions::FilterMatchesTest(
+ test_suite_name, test_name);
+ test_info->matches_filter_ = matches_filter;
+
+ const bool is_runnable =
+ (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
+ matches_filter;
+
+ const bool is_in_another_shard =
+ shard_tests != IGNORE_SHARDING_PROTOCOL &&
+ !ShouldRunTestOnShard(total_shards, shard_index, num_runnable_tests);
+ test_info->is_in_another_shard_ = is_in_another_shard;
+ const bool is_selected = is_runnable && !is_in_another_shard;
+
+ num_runnable_tests += is_runnable;
+ num_selected_tests += is_selected;
+
+ test_info->should_run_ = is_selected;
+ test_suite->set_should_run(test_suite->should_run() || is_selected);
+ }
+ }
+ return num_selected_tests;
+}
+
+// Prints the given C-string on a single line by replacing all '\n'
+// characters with string "\\n". If the output takes more than
+// max_length characters, only prints the first max_length characters
+// and "...".
+static void PrintOnOneLine(const char* str, int max_length) {
+ if (str != nullptr) {
+ for (int i = 0; *str != '\0'; ++str) {
+ if (i >= max_length) {
+ printf("...");
+ break;
+ }
+ if (*str == '\n') {
+ printf("\\n");
+ i += 2;
+ } else {
+ printf("%c", *str);
+ ++i;
+ }
+ }
+ }
+}
+
+// Prints the names of the tests matching the user-specified filter flag.
+void UnitTestImpl::ListTestsMatchingFilter() {
+ // Print at most this many characters for each type/value parameter.
+ const int kMaxParamLength = 250;
+
+ for (auto* test_suite : test_suites_) {
+ bool printed_test_suite_name = false;
+
+ for (size_t j = 0; j < test_suite->test_info_list().size(); j++) {
+ const TestInfo* const test_info = test_suite->test_info_list()[j];
+ if (test_info->matches_filter_) {
+ if (!printed_test_suite_name) {
+ printed_test_suite_name = true;
+ printf("%s.", test_suite->name());
+ if (test_suite->type_param() != nullptr) {
+ printf(" # %s = ", kTypeParamLabel);
+ // We print the type parameter on a single line to make
+ // the output easy to parse by a program.
+ PrintOnOneLine(test_suite->type_param(), kMaxParamLength);
+ }
+ printf("\n");
+ }
+ printf(" %s", test_info->name());
+ if (test_info->value_param() != nullptr) {
+ printf(" # %s = ", kValueParamLabel);
+ // We print the value parameter on a single line to make the
+ // output easy to parse by a program.
+ PrintOnOneLine(test_info->value_param(), kMaxParamLength);
+ }
+ printf("\n");
+ }
+ }
+ }
+ fflush(stdout);
+ const std::string& output_format = UnitTestOptions::GetOutputFormat();
+ if (output_format == "xml" || output_format == "json") {
+ FILE* fileout = OpenFileForWriting(
+ UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
+ std::stringstream stream;
+ if (output_format == "xml") {
+ XmlUnitTestResultPrinter(
+ UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
+ .PrintXmlTestsList(&stream, test_suites_);
+ } else if (output_format == "json") {
+ JsonUnitTestResultPrinter(
+ UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
+ .PrintJsonTestList(&stream, test_suites_);
+ }
+ fprintf(fileout, "%s", StringStreamToString(&stream).c_str());
+ fclose(fileout);
+ }
+}
+
+// Sets the OS stack trace getter.
+//
+// Does nothing if the input and the current OS stack trace getter are
+// the same; otherwise, deletes the old getter and makes the input the
+// current getter.
+void UnitTestImpl::set_os_stack_trace_getter(
+ OsStackTraceGetterInterface* getter) {
+ if (os_stack_trace_getter_ != getter) {
+ delete os_stack_trace_getter_;
+ os_stack_trace_getter_ = getter;
+ }
+}
+
+// Returns the current OS stack trace getter if it is not NULL;
+// otherwise, creates an OsStackTraceGetter, makes it the current
+// getter, and returns it.
+OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() {
+ if (os_stack_trace_getter_ == nullptr) {
+#ifdef GTEST_OS_STACK_TRACE_GETTER_
+ os_stack_trace_getter_ = new GTEST_OS_STACK_TRACE_GETTER_;
+#else
+ os_stack_trace_getter_ = new OsStackTraceGetter;
+#endif // GTEST_OS_STACK_TRACE_GETTER_
+ }
+
+ return os_stack_trace_getter_;
+}
+
+// Returns the most specific TestResult currently running.
+TestResult* UnitTestImpl::current_test_result() {
+ if (current_test_info_ != nullptr) {
+ return ¤t_test_info_->result_;
+ }
+ if (current_test_suite_ != nullptr) {
+ return ¤t_test_suite_->ad_hoc_test_result_;
+ }
+ return &ad_hoc_test_result_;
+}
+
+// Shuffles all test suites, and the tests within each test suite,
+// making sure that death tests are still run first.
+void UnitTestImpl::ShuffleTests() {
+ // Shuffles the death test suites.
+ ShuffleRange(random(), 0, last_death_test_suite_ + 1, &test_suite_indices_);
+
+ // Shuffles the non-death test suites.
+ ShuffleRange(random(), last_death_test_suite_ + 1,
+ static_cast<int>(test_suites_.size()), &test_suite_indices_);
+
+ // Shuffles the tests inside each test suite.
+ for (auto& test_suite : test_suites_) {
+ test_suite->ShuffleTests(random());
+ }
+}
+
+// Restores the test suites and tests to their order before the first shuffle.
+void UnitTestImpl::UnshuffleTests() {
+ for (size_t i = 0; i < test_suites_.size(); i++) {
+ // Unshuffles the tests in each test suite.
+ test_suites_[i]->UnshuffleTests();
+ // Resets the index of each test suite.
+ test_suite_indices_[i] = static_cast<int>(i);
+ }
+}
+
+// Returns the current OS stack trace as an std::string.
+//
+// The maximum number of stack frames to be included is specified by
+// the gtest_stack_trace_depth flag. The skip_count parameter
+// specifies the number of top frames to be skipped, which doesn't
+// count against the number of frames to be included.
+//
+// For example, if Foo() calls Bar(), which in turn calls
+// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
+// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
+std::string GetCurrentOsStackTraceExceptTop(UnitTest* /*unit_test*/,
+ int skip_count) {
+ // We pass skip_count + 1 to skip this wrapper function in addition
+ // to what the user really wants to skip.
+ return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1);
+}
+
+// Used by the GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_ macro to
+// suppress unreachable code warnings.
+namespace {
+class ClassUniqueToAlwaysTrue {};
+}
+
+bool IsTrue(bool condition) { return condition; }
+
+bool AlwaysTrue() {
+#if GTEST_HAS_EXCEPTIONS
+ // This condition is always false so AlwaysTrue() never actually throws,
+ // but it makes the compiler think that it may throw.
+ if (IsTrue(false))
+ throw ClassUniqueToAlwaysTrue();
+#endif // GTEST_HAS_EXCEPTIONS
+ return true;
+}
+
+// If *pstr starts with the given prefix, modifies *pstr to be right
+// past the prefix and returns true; otherwise leaves *pstr unchanged
+// and returns false. None of pstr, *pstr, and prefix can be NULL.
+bool SkipPrefix(const char* prefix, const char** pstr) {
+ const size_t prefix_len = strlen(prefix);
+ if (strncmp(*pstr, prefix, prefix_len) == 0) {
+ *pstr += prefix_len;
+ return true;
+ }
+ return false;
+}
+
+// Parses a string as a command line flag. The string should have
+// the format "--flag=value". When def_optional is true, the "=value"
+// part can be omitted.
+//
+// Returns the value of the flag, or NULL if the parsing failed.
+static const char* ParseFlagValue(const char* str, const char* flag,
+ bool def_optional) {
+ // str and flag must not be NULL.
+ if (str == nullptr || flag == nullptr) return nullptr;
+
+ // The flag must start with "--" followed by GTEST_FLAG_PREFIX_.
+ const std::string flag_str = std::string("--") + GTEST_FLAG_PREFIX_ + flag;
+ const size_t flag_len = flag_str.length();
+ if (strncmp(str, flag_str.c_str(), flag_len) != 0) return nullptr;
+
+ // Skips the flag name.
+ const char* flag_end = str + flag_len;
+
+ // When def_optional is true, it's OK to not have a "=value" part.
+ if (def_optional && (flag_end[0] == '\0')) {
+ return flag_end;
+ }
+
+ // If def_optional is true and there are more characters after the
+ // flag name, or if def_optional is false, there must be a '=' after
+ // the flag name.
+ if (flag_end[0] != '=') return nullptr;
+
+ // Returns the string after "=".
+ return flag_end + 1;
+}
+
+// Parses a string for a bool flag, in the form of either
+// "--flag=value" or "--flag".
+//
+// In the former case, the value is taken as true as long as it does
+// not start with '0', 'f', or 'F'.
+//
+// In the latter case, the value is taken as true.
+//
+// On success, stores the value of the flag in *value, and returns
+// true. On failure, returns false without changing *value.
+static bool ParseBoolFlag(const char* str, const char* flag, bool* value) {
+ // Gets the value of the flag as a string.
+ const char* const value_str = ParseFlagValue(str, flag, true);
+
+ // Aborts if the parsing failed.
+ if (value_str == nullptr) return false;
+
+ // Converts the string value to a bool.
+ *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F');
+ return true;
+}
+
+// Parses a string for an Int32 flag, in the form of
+// "--flag=value".
+//
+// On success, stores the value of the flag in *value, and returns
+// true. On failure, returns false without changing *value.
+bool ParseInt32Flag(const char* str, const char* flag, Int32* value) {
+ // Gets the value of the flag as a string.
+ const char* const value_str = ParseFlagValue(str, flag, false);
+
+ // Aborts if the parsing failed.
+ if (value_str == nullptr) return false;
+
+ // Sets *value to the value of the flag.
+ return ParseInt32(Message() << "The value of flag --" << flag,
+ value_str, value);
+}
+
+// Parses a string for a string flag, in the form of
+// "--flag=value".
+//
+// On success, stores the value of the flag in *value, and returns
+// true. On failure, returns false without changing *value.
+template <typename String>
+static bool ParseStringFlag(const char* str, const char* flag, String* value) {
+ // Gets the value of the flag as a string.
+ const char* const value_str = ParseFlagValue(str, flag, false);
+
+ // Aborts if the parsing failed.
+ if (value_str == nullptr) return false;
+
+ // Sets *value to the value of the flag.
+ *value = value_str;
+ return true;
+}
+
+// Determines whether a string has a prefix that Google Test uses for its
+// flags, i.e., starts with GTEST_FLAG_PREFIX_ or GTEST_FLAG_PREFIX_DASH_.
+// If Google Test detects that a command line flag has its prefix but is not
+// recognized, it will print its help message. Flags starting with
+// GTEST_INTERNAL_PREFIX_ followed by "internal_" are considered Google Test
+// internal flags and do not trigger the help message.
+static bool HasGoogleTestFlagPrefix(const char* str) {
+ return (SkipPrefix("--", &str) ||
+ SkipPrefix("-", &str) ||
+ SkipPrefix("/", &str)) &&
+ !SkipPrefix(GTEST_FLAG_PREFIX_ "internal_", &str) &&
+ (SkipPrefix(GTEST_FLAG_PREFIX_, &str) ||
+ SkipPrefix(GTEST_FLAG_PREFIX_DASH_, &str));
+}
+
+// Prints a string containing code-encoded text. The following escape
+// sequences can be used in the string to control the text color:
+//
+// @@ prints a single '@' character.
+// @R changes the color to red.
+// @G changes the color to green.
+// @Y changes the color to yellow.
+// @D changes to the default terminal text color.
+//
+static void PrintColorEncoded(const char* str) {
+ GTestColor color = COLOR_DEFAULT; // The current color.
+
+ // Conceptually, we split the string into segments divided by escape
+ // sequences. Then we print one segment at a time. At the end of
+ // each iteration, the str pointer advances to the beginning of the
+ // next segment.
+ for (;;) {
+ const char* p = strchr(str, '@');
+ if (p == nullptr) {
+ ColoredPrintf(color, "%s", str);
+ return;
+ }
+
+ ColoredPrintf(color, "%s", std::string(str, p).c_str());
+
+ const char ch = p[1];
+ str = p + 2;
+ if (ch == '@') {
+ ColoredPrintf(color, "@");
+ } else if (ch == 'D') {
+ color = COLOR_DEFAULT;
+ } else if (ch == 'R') {
+ color = COLOR_RED;
+ } else if (ch == 'G') {
+ color = COLOR_GREEN;
+ } else if (ch == 'Y') {
+ color = COLOR_YELLOW;
+ } else {
+ --str;
+ }
+ }
+}
+
+static const char kColorEncodedHelpMessage[] =
+"This program contains tests written using " GTEST_NAME_ ". You can use the\n"
+"following command line flags to control its behavior:\n"
+"\n"
+"Test Selection:\n"
+" @G--" GTEST_FLAG_PREFIX_ "list_tests@D\n"
+" List the names of all tests instead of running them. The name of\n"
+" TEST(Foo, Bar) is \"Foo.Bar\".\n"
+" @G--" GTEST_FLAG_PREFIX_ "filter=@YPOSTIVE_PATTERNS"
+ "[@G-@YNEGATIVE_PATTERNS]@D\n"
+" Run only the tests whose name matches one of the positive patterns but\n"
+" none of the negative patterns. '?' matches any single character; '*'\n"
+" matches any substring; ':' separates two patterns.\n"
+" @G--" GTEST_FLAG_PREFIX_ "also_run_disabled_tests@D\n"
+" Run all disabled tests too.\n"
+"\n"
+"Test Execution:\n"
+" @G--" GTEST_FLAG_PREFIX_ "repeat=@Y[COUNT]@D\n"
+" Run the tests repeatedly; use a negative count to repeat forever.\n"
+" @G--" GTEST_FLAG_PREFIX_ "shuffle@D\n"
+" Randomize tests' orders on every iteration.\n"
+" @G--" GTEST_FLAG_PREFIX_ "random_seed=@Y[NUMBER]@D\n"
+" Random number seed to use for shuffling test orders (between 1 and\n"
+" 99999, or 0 to use a seed based on the current time).\n"
+"\n"
+"Test Output:\n"
+" @G--" GTEST_FLAG_PREFIX_ "color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\n"
+" Enable/disable colored output. The default is @Gauto@D.\n"
+" -@G-" GTEST_FLAG_PREFIX_ "print_time=0@D\n"
+" Don't print the elapsed time of each test.\n"
+" @G--" GTEST_FLAG_PREFIX_ "output=@Y(@Gjson@Y|@Gxml@Y)[@G:@YDIRECTORY_PATH@G"
+ GTEST_PATH_SEP_ "@Y|@G:@YFILE_PATH]@D\n"
+" Generate a JSON or XML report in the given directory or with the given\n"
+" file name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.\n"
+# if GTEST_CAN_STREAM_RESULTS_
+" @G--" GTEST_FLAG_PREFIX_ "stream_result_to=@YHOST@G:@YPORT@D\n"
+" Stream test results to the given server.\n"
+# endif // GTEST_CAN_STREAM_RESULTS_
+"\n"
+"Assertion Behavior:\n"
+# if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
+" @G--" GTEST_FLAG_PREFIX_ "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n"
+" Set the default death test style.\n"
+# endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
+" @G--" GTEST_FLAG_PREFIX_ "break_on_failure@D\n"
+" Turn assertion failures into debugger break-points.\n"
+" @G--" GTEST_FLAG_PREFIX_ "throw_on_failure@D\n"
+" Turn assertion failures into C++ exceptions for use by an external\n"
+" test framework.\n"
+" @G--" GTEST_FLAG_PREFIX_ "catch_exceptions=0@D\n"
+" Do not report exceptions as test failures. Instead, allow them\n"
+" to crash the program or throw a pop-up (on Windows).\n"
+"\n"
+"Except for @G--" GTEST_FLAG_PREFIX_ "list_tests@D, you can alternatively set "
+ "the corresponding\n"
+"environment variable of a flag (all letters in upper-case). For example, to\n"
+"disable colored text output, you can either specify @G--" GTEST_FLAG_PREFIX_
+ "color=no@D or set\n"
+"the @G" GTEST_FLAG_PREFIX_UPPER_ "COLOR@D environment variable to @Gno@D.\n"
+"\n"
+"For more information, please read the " GTEST_NAME_ " documentation at\n"
+"@G" GTEST_PROJECT_URL_ "@D. If you find a bug in " GTEST_NAME_ "\n"
+"(not one in your own code or tests), please report it to\n"
+"@G<" GTEST_DEV_EMAIL_ ">@D.\n";
+
+static bool ParseGoogleTestFlag(const char* const arg) {
+ return ParseBoolFlag(arg, kAlsoRunDisabledTestsFlag,
+ >EST_FLAG(also_run_disabled_tests)) ||
+ ParseBoolFlag(arg, kBreakOnFailureFlag,
+ >EST_FLAG(break_on_failure)) ||
+ ParseBoolFlag(arg, kCatchExceptionsFlag,
+ >EST_FLAG(catch_exceptions)) ||
+ ParseStringFlag(arg, kColorFlag, >EST_FLAG(color)) ||
+ ParseStringFlag(arg, kDeathTestStyleFlag,
+ >EST_FLAG(death_test_style)) ||
+ ParseBoolFlag(arg, kDeathTestUseFork,
+ >EST_FLAG(death_test_use_fork)) ||
+ ParseStringFlag(arg, kFilterFlag, >EST_FLAG(filter)) ||
+ ParseStringFlag(arg, kInternalRunDeathTestFlag,
+ >EST_FLAG(internal_run_death_test)) ||
+ ParseBoolFlag(arg, kListTestsFlag, >EST_FLAG(list_tests)) ||
+ ParseStringFlag(arg, kOutputFlag, >EST_FLAG(output)) ||
+ ParseBoolFlag(arg, kPrintTimeFlag, >EST_FLAG(print_time)) ||
+ ParseBoolFlag(arg, kPrintUTF8Flag, >EST_FLAG(print_utf8)) ||
+ ParseInt32Flag(arg, kRandomSeedFlag, >EST_FLAG(random_seed)) ||
+ ParseInt32Flag(arg, kRepeatFlag, >EST_FLAG(repeat)) ||
+ ParseBoolFlag(arg, kShuffleFlag, >EST_FLAG(shuffle)) ||
+ ParseInt32Flag(arg, kStackTraceDepthFlag,
+ >EST_FLAG(stack_trace_depth)) ||
+ ParseStringFlag(arg, kStreamResultToFlag,
+ >EST_FLAG(stream_result_to)) ||
+ ParseBoolFlag(arg, kThrowOnFailureFlag,
+ >EST_FLAG(throw_on_failure));
+}
+
+#if GTEST_USE_OWN_FLAGFILE_FLAG_
+static void LoadFlagsFromFile(const std::string& path) {
+ FILE* flagfile = posix::FOpen(path.c_str(), "r");
+ if (!flagfile) {
+ GTEST_LOG_(FATAL) << "Unable to open file \"" << GTEST_FLAG(flagfile)
+ << "\"";
+ }
+ std::string contents(ReadEntireFile(flagfile));
+ posix::FClose(flagfile);
+ std::vector<std::string> lines;
+ SplitString(contents, '\n', &lines);
+ for (size_t i = 0; i < lines.size(); ++i) {
+ if (lines[i].empty())
+ continue;
+ if (!ParseGoogleTestFlag(lines[i].c_str()))
+ g_help_flag = true;
+ }
+}
+#endif // GTEST_USE_OWN_FLAGFILE_FLAG_
+
+// Parses the command line for Google Test flags, without initializing
+// other parts of Google Test. The type parameter CharType can be
+// instantiated to either char or wchar_t.
+template <typename CharType>
+void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
+ for (int i = 1; i < *argc; i++) {
+ const std::string arg_string = StreamableToString(argv[i]);
+ const char* const arg = arg_string.c_str();
+
+ using internal::ParseBoolFlag;
+ using internal::ParseInt32Flag;
+ using internal::ParseStringFlag;
+
+ bool remove_flag = false;
+ if (ParseGoogleTestFlag(arg)) {
+ remove_flag = true;
+#if GTEST_USE_OWN_FLAGFILE_FLAG_
+ } else if (ParseStringFlag(arg, kFlagfileFlag, >EST_FLAG(flagfile))) {
+ LoadFlagsFromFile(GTEST_FLAG(flagfile));
+ remove_flag = true;
+#endif // GTEST_USE_OWN_FLAGFILE_FLAG_
+ } else if (arg_string == "--help" || arg_string == "-h" ||
+ arg_string == "-?" || arg_string == "/?" ||
+ HasGoogleTestFlagPrefix(arg)) {
+ // Both help flag and unrecognized Google Test flags (excluding
+ // internal ones) trigger help display.
+ g_help_flag = true;
+ }
+
+ if (remove_flag) {
+ // Shift the remainder of the argv list left by one. Note
+ // that argv has (*argc + 1) elements, the last one always being
+ // NULL. The following loop moves the trailing NULL element as
+ // well.
+ for (int j = i; j != *argc; j++) {
+ argv[j] = argv[j + 1];
+ }
+
+ // Decrements the argument count.
+ (*argc)--;
+
+ // We also need to decrement the iterator as we just removed
+ // an element.
+ i--;
+ }
+ }
+
+ if (g_help_flag) {
+ // We print the help here instead of in RUN_ALL_TESTS(), as the
+ // latter may not be called at all if the user is using Google
+ // Test with another testing framework.
+ PrintColorEncoded(kColorEncodedHelpMessage);
+ }
+}
+
+// Parses the command line for Google Test flags, without initializing
+// other parts of Google Test.
+void ParseGoogleTestFlagsOnly(int* argc, char** argv) {
+ ParseGoogleTestFlagsOnlyImpl(argc, argv);
+
+ // Fix the value of *_NSGetArgc() on macOS, but iff
+ // *_NSGetArgv() == argv
+ // Only applicable to char** version of argv
+#if GTEST_OS_MAC
+#ifndef GTEST_OS_IOS
+ if (*_NSGetArgv() == argv) {
+ *_NSGetArgc() = *argc;
+ }
+#endif
+#endif
+}
+void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv) {
+ ParseGoogleTestFlagsOnlyImpl(argc, argv);
+}
+
+// The internal implementation of InitGoogleTest().
+//
+// The type parameter CharType can be instantiated to either char or
+// wchar_t.
+template <typename CharType>
+void InitGoogleTestImpl(int* argc, CharType** argv) {
+ // We don't want to run the initialization code twice.
+ if (GTestIsInitialized()) return;
+
+ if (*argc <= 0) return;
+
+ g_argvs.clear();
+ for (int i = 0; i != *argc; i++) {
+ g_argvs.push_back(StreamableToString(argv[i]));
+ }
+
+#if GTEST_HAS_ABSL
+ absl::InitializeSymbolizer(g_argvs[0].c_str());
+#endif // GTEST_HAS_ABSL
+
+ ParseGoogleTestFlagsOnly(argc, argv);
+ GetUnitTestImpl()->PostFlagParsingInit();
+}
+
+} // namespace internal
+
+// Initializes Google Test. This must be called before calling
+// RUN_ALL_TESTS(). In particular, it parses a command line for the
+// flags that Google Test recognizes. Whenever a Google Test flag is
+// seen, it is removed from argv, and *argc is decremented.
+//
+// No value is returned. Instead, the Google Test flag variables are
+// updated.
+//
+// Calling the function for the second time has no user-visible effect.
+void InitGoogleTest(int* argc, char** argv) {
+#if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
+ GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
+#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
+ internal::InitGoogleTestImpl(argc, argv);
+#endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
+}
+
+// This overloaded version can be used in Windows programs compiled in
+// UNICODE mode.
+void InitGoogleTest(int* argc, wchar_t** argv) {
+#if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
+ GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
+#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
+ internal::InitGoogleTestImpl(argc, argv);
+#endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
+}
+
+// This overloaded version can be used on Arduino/embedded platforms where
+// there is no argc/argv.
+void InitGoogleTest() {
+ // Since Arduino doesn't have a command line, fake out the argc/argv arguments
+ int argc = 1;
+ const auto arg0 = "dummy";
+ char* argv0 = const_cast<char*>(arg0);
+ char** argv = &argv0;
+
+#if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
+ GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(&argc, argv);
+#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
+ internal::InitGoogleTestImpl(&argc, argv);
+#endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
+}
+
+std::string TempDir() {
+#if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_)
+ return GTEST_CUSTOM_TEMPDIR_FUNCTION_();
+#endif
+
+#if GTEST_OS_WINDOWS_MOBILE
+ return "\\temp\\";
+#elif GTEST_OS_WINDOWS
+ const char* temp_dir = internal::posix::GetEnv("TEMP");
+ if (temp_dir == nullptr || temp_dir[0] == '\0')
+ return "\\temp\\";
+ else if (temp_dir[strlen(temp_dir) - 1] == '\\')
+ return temp_dir;
+ else
+ return std::string(temp_dir) + "\\";
+#elif GTEST_OS_LINUX_ANDROID
+ return "/sdcard/";
+#else
+ return "/tmp/";
+#endif // GTEST_OS_WINDOWS_MOBILE
+}
+
+// Class ScopedTrace
+
+// Pushes the given source file location and message onto a per-thread
+// trace stack maintained by Google Test.
+void ScopedTrace::PushTrace(const char* file, int line, std::string message) {
+ internal::TraceInfo trace;
+ trace.file = file;
+ trace.line = line;
+ trace.message.swap(message);
+
+ UnitTest::GetInstance()->PushGTestTrace(trace);
+}
+
+// Pops the info pushed by the c'tor.
+ScopedTrace::~ScopedTrace()
+ GTEST_LOCK_EXCLUDED_(&UnitTest::mutex_) {
+ UnitTest::GetInstance()->PopGTestTrace();
+}
+
+} // namespace testing
--- /dev/null
+// Copyright 2006, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <cstdio>
+#include "gtest/gtest.h"
+
+#ifdef ARDUINO
+void setup() {
+ testing::InitGoogleTest();
+}
+
+void loop() { RUN_ALL_TESTS(); }
+
+#else
+
+GTEST_API_ int main(int argc, char **argv) {
+ printf("Running main() from %s\n", __FILE__);
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+#endif
}
function StressMonitorDataRange(label, min, max) {
+ utils_.printDeprecationWarningFor(HumanActivityType.STRESS_MONITOR);
validator_.validateConstructorCall(this, tizen.StressMonitorDataRange);
var args = validator_.validateArgs(arguments, [
throw new WebAPIException(WebAPIException.NOT_SUPPORTED_ERR);
}
+ if (HumanActivityType.STRESS_MONITOR == args.type) {
+ utils_.printDeprecationWarningFor(HumanActivityType.STRESS_MONITOR);
+ }
+
var data = {
type: args.type
};
};
var result = native_.call(
- 'HumanActivityMonitorManager_getHumanActivityData',
+ 'HumanActivityMonitorManagerGetHumanActivityData',
data,
callback
);
}
}
- // always set the listener
- // if it's another call to startListener() overwrite the old one
+ // always set the listener, if it's another call to startListener()
+ // overwrite the old one
native_.addListener(listenerId, listener);
}
function checkPrivilegesForMethod(method, type) {
utils_.checkPrivilegeAccess(utils_.privilege.HEALTHINFO);
- if ('HumanActivityMonitorManager_stop' === method && 'GPS' === type) {
+ if ('HumanActivityMonitorManagerStop' === method && 'GPS' === type) {
utils_.checkPrivilegeAccess(utils_.privilege.LOCATION);
}
}
);
}
+ if (HumanActivityType.STRESS_MONITOR == args.type) {
+ utils_.printDeprecationWarningFor(HumanActivityType.STRESS_MONITOR);
+ }
+
var listenerId = 'HumanActivityMonitor_' + args.type;
var optionsAttributes = ['callbackInterval', 'sampleInterval'],
options = args.options || {};
utils_.log(
'callbackInterval = ' + callbackInterval + ', sampleInterval = ' + sampleInterval
);
- startListener(listenerId, listener, 'HumanActivityMonitorManager_start', {
+ startListener(listenerId, listener, 'HumanActivityMonitorManagerStart', {
type: args.type,
listenerId: listenerId,
callbackInterval: callbackInterval,
);
}
+ if (HumanActivityType.STRESS_MONITOR == args.type) {
+ utils_.printDeprecationWarningFor(HumanActivityType.STRESS_MONITOR);
+ }
+
if (HumanActivityType.PEDOMETER === args.type) {
stopListener(
'HumanActivityMonitor_PEDOMETER',
- 'HumanActivityMonitorManager_stop',
+ 'HumanActivityMonitorManagerStop',
{ type: HumanActivityType.PEDOMETER },
pedometerListener && !accumulativePedometerListener
);
} else {
stopListener(
'HumanActivityMonitor_' + args.type,
- 'HumanActivityMonitorManager_stop',
+ 'HumanActivityMonitorManagerStop',
{ type: args.type },
true
);
HumanActivityMonitorManager.prototype.unsetAccumulativePedometerListener = function() {
stopListener(
'HumanActivityMonitor_PEDOMETER',
- 'HumanActivityMonitorManager_stop',
+ 'HumanActivityMonitorManagerStop',
{ type: HumanActivityType.PEDOMETER },
accumulativePedometerListener && !pedometerListener
);
]);
var result = native_.call(
- 'HumanActivityMonitorManager_addActivityRecognitionListener',
+ 'HumanActivityMonitorManagerAddActivityRecognitionListener',
{ type: args.type, listenerId: activityRecognitionListener.listenerName }
);
if (native_.isFailure(result)) {
]);
var result = native_.call(
- 'HumanActivityMonitorManager_removeActivityRecognitionListener',
+ 'HumanActivityMonitorManagerRemoveActivityRecognitionListener',
{ watchId: args.watchId }
);
if (native_.isFailure(result)) {
callArgs.type = args.type;
- var result = native_.callSync('HumanActivityMonitorManager_startRecorder', callArgs);
+ var result = native_.callSync('HumanActivityMonitorManagerStartRecorder', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
var callArgs = {};
callArgs.type = args.type;
- var result = native_.callSync('HumanActivityMonitorManager_stopRecorder', callArgs);
+ var result = native_.callSync('HumanActivityMonitorManagerStopRecorder', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
};
var result = native_.call(
- 'HumanActivityMonitorManager_readRecorderData',
+ 'HumanActivityMonitorManagerReadRecorderData',
callArgs,
callback
);
var callArgs = {};
callArgs.type = args.type;
- var result = native_.callSync('GestureManager_isGestureSupported', callArgs);
+ var result = native_.callSync('GestureManagerIsGestureSupported', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
var typeCountMap = alwaysOn ? this.typeCountMapAlwaysOn : this.typeCountMapDefault;
if (typeCountMap[type] === 0) {
var result = this.native.callSync(
- 'GestureManager_addGestureRecognitionListener',
+ 'GestureManagerAddGestureRecognitionListener',
listener
);
if (this.native.isFailure(result)) {
if (typeCountMap[listener.type] === 1) {
var result = this.native.callSync(
- 'GestureManager_removeGestureRecognitionListener',
+ 'GestureManagerRemoveGestureRecognitionListener',
listener
);
if (this.native.isFailure(result)) {
}
StressMonitorListenerManager.prototype.onListener = function(data) {
+ utils_.printDeprecationWarningFor(HumanActivityType.STRESS_MONITOR);
if (stressListener) {
stressListener(data);
}
var stressMonitorListener = new StressMonitorListenerManager();
HumanActivityMonitorManager.prototype.addStressMonitorChangeListener = function() {
+ utils_.printDeprecationWarningFor(HumanActivityType.STRESS_MONITOR);
utils_.checkPrivilegeAccess(privilege_.HEALTHINFO);
var args = validator_.validateMethod(arguments, [
{
};
HumanActivityMonitorManager.prototype.removeStressMonitorChangeListener = function() {
+ utils_.printDeprecationWarningFor(HumanActivityType.STRESS_MONITOR);
var args = validator_.validateMethod(arguments, [
{
name: 'watchId',
HumanActivityAccumulativePedometerData.prototype = new HumanActivityData();
// prettier-ignore
HumanActivityAccumulativePedometerData.prototype.constructor =
- HumanActivityAccumulativePedometerData;
+HumanActivityAccumulativePedometerData;
function HumanActivityHRMData(data) {
SetReadOnlyProperty(this, 'heartRate', data.heartRate);
HumanActivitySleepDetectorData.prototype.constructor = HumanActivitySleepMonitorData;
function HumanActivityStressMonitorData(data) {
+ utils_.printDeprecationWarningFor(HumanActivityType.STRESS_MONITOR);
SetReadOnlyProperty(this, 'stressScore', data.stressScore);
}
HumanActivityRecorderPedometerData.prototype = new HumanActivityRecorderData();
// prettier-ignore
HumanActivityRecorderPedometerData.prototype.constructor =
- HumanActivityRecorderPedometerData;
+HumanActivityRecorderPedometerData;
function HumanActivityRecorderHRMData(data) {
HumanActivityRecorderData.call(this, data);
HumanActivityRecorderSleepMonitorData.prototype = new HumanActivityRecorderData();
// prettier-ignore
HumanActivityRecorderSleepMonitorData.prototype.constructor =
- HumanActivityRecorderSleepMonitorData;
+HumanActivityRecorderSleepMonitorData;
function HumanActivityRecorderPressureData(data) {
HumanActivityRecorderData.call(this, data);
HumanActivityRecorderPressureData.prototype = new HumanActivityRecorderData();
// prettier-ignore
HumanActivityRecorderPressureData.prototype.constructor =
- HumanActivityRecorderPressureData;
+HumanActivityRecorderPressureData;
tizen.StressMonitorDataRange = StressMonitorDataRange;
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&HumanActivityMonitorInstance::x, this, _1, _2));
- REGISTER_SYNC("HumanActivityMonitorManager_getHumanActivityData",
- HumanActivityMonitorManagerGetHumanActivityData);
- REGISTER_SYNC("HumanActivityMonitorManager_start", HumanActivityMonitorManagerStart);
- REGISTER_SYNC("HumanActivityMonitorManager_stop", HumanActivityMonitorManagerStop);
- REGISTER_SYNC("HumanActivityMonitorManager_addActivityRecognitionListener",
- HumanActivityMonitorManagerAddActivityRecognitionListener);
- REGISTER_SYNC("HumanActivityMonitorManager_removeActivityRecognitionListener",
- HumanActivityMonitorManagerRemoveActivityRecognitionListener);
- REGISTER_SYNC("HumanActivityMonitorManager_startRecorder",
- HumanActivityMonitorManagerStartRecorder);
- REGISTER_SYNC("HumanActivityMonitorManager_stopRecorder",
- HumanActivityMonitorManagerStopRecorder);
- REGISTER_SYNC("HumanActivityMonitorManager_readRecorderData",
- HumanActivityMonitorManagerReadRecorderData);
- REGISTER_SYNC("GestureManager_isGestureSupported", GestureManagerIsGestureSupported);
- REGISTER_SYNC("GestureManager_addGestureRecognitionListener",
- GestureManagerAddGestureRecognitionListener);
- REGISTER_SYNC("GestureManager_removeGestureRecognitionListener",
- GestureManagerRemoveGestureRecognitionListener);
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) \
+ RegisterSyncHandler(#M, std::bind(&HumanActivityMonitorInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(HumanActivityMonitorManagerGetHumanActivityData);
+ REGISTER_METHOD(HumanActivityMonitorManagerStart);
+ REGISTER_METHOD(HumanActivityMonitorManagerStop);
+ REGISTER_METHOD(HumanActivityMonitorManagerAddActivityRecognitionListener);
+ REGISTER_METHOD(HumanActivityMonitorManagerRemoveActivityRecognitionListener);
+ REGISTER_METHOD(HumanActivityMonitorManagerStartRecorder);
+ REGISTER_METHOD(HumanActivityMonitorManagerStopRecorder);
+ REGISTER_METHOD(HumanActivityMonitorManagerReadRecorderData);
+ REGISTER_METHOD(GestureManagerIsGestureSupported);
+ REGISTER_METHOD(GestureManagerAddGestureRecognitionListener);
+ REGISTER_METHOD(GestureManagerRemoveGestureRecognitionListener);
+
+#undef REGISTER_METHOD
}
HumanActivityMonitorInstance::~HumanActivityMonitorInstance() {
}
/**
- * This class provides access to the API functionalities through the
- * tizen.tvinputdevice interface.
+ * This class provides access to the API functionalities through
+ * the tizen.tvinputdevice interface.
* @constructor
*/
function InputDeviceManager() {
};
/**
- * Registers an input device key to receive DOM keyboard event when it is pressed or
- * released.
+ * Registers an input device key to receive DOM keyboard event when
+ * it is pressed or released.
* @param {!string} keyName The key name
*/
InputDeviceManager.prototype.registerKey = function(keyName) {
get: function() {
var callArgs = {};
callArgs.id = this[kIdKey];
- var result = native.callSync('IotconResource_getObserverIds', callArgs);
+ var result = native.callSync('IotconResourceGetObserverIds', callArgs);
return native.getResultObject(result);
}.bind(this),
set: function() {},
callArgs.observerIds = args.observerIds;
callArgs.attributes = attributes;
- var result = native.callSync('IotconResource_notify', callArgs);
+ var result = native.callSync('IotconResourceNotify', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.id = this[kIdKey];
callArgs.types = args.types;
- var result = native.callSync('IotconResource_addResourceTypes', callArgs);
+ var result = native.callSync('IotconResourceAddResourceTypes', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.id = this[kIdKey];
callArgs.iface = args.iface;
- var result = native.callSync('IotconResource_addResourceInterface', callArgs);
+ var result = native.callSync('IotconResourceAddResourceInterface', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.id = this[kIdKey];
callArgs.childId = args.resource[kIdKey];
- var result = native.callSync('IotconResource_addChildResource', callArgs);
+ var result = native.callSync('IotconResourceAddChildResource', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.id = this[kIdKey];
callArgs.childId = args.resource[kIdKey];
- var result = native.callSync('IotconResource_removeChildResource', callArgs);
+ var result = native.callSync('IotconResourceRemoveChildResource', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
- var result = native.callSync('IotconResource_setRequestListener', callArgs);
+ var result = native.callSync('IotconResourceSetRequestListener', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
var callArgs = {};
callArgs.id = this[kIdKey];
- var result = native.callSync('IotconResource_unsetRequestListener', callArgs);
+ var result = native.callSync('IotconResourceUnsetRequestListener', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.representation = this.representation;
callArgs.options = this.options;
- var result = native.callSync('IotconResponse_send', callArgs);
+ var result = native.callSync('IotconResponseSend', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
get: function() {
var callArgs = prepareResourceInfo(this);
var result = native.callSync(
- 'IotconRemoteResource_getCachedRepresentation',
+ 'IotconRemoteResourceGetCachedRepresentation',
callArgs
);
if (native.isSuccess(result)) {
get: function() {
var options_ = null;
var callArgs = prepareResourceInfo(this, true);
- var result = native.callSync('IotconRemoteResource_getOptions', callArgs);
+ var result = native.callSync('IotconRemoteResourceGetOptions', callArgs);
if (native.isSuccess(result)) {
var data = native.getResultObject(result);
options_ = [];
var callArgs = prepareResourceInfo(this, true);
callArgs['options'] = val;
- var result = native.callSync('IotconRemoteResource_setOptions', callArgs);
+ var result = native.callSync('IotconRemoteResourceSetOptions', callArgs);
if (native.isSuccess(result)) {
manageId(this, native.getResultObject(result));
}
var callArgs = prepareResourceInfo(this, true);
var result = native.callSync(
- 'IotconRemoteResource_getTimeInterval',
+ 'IotconRemoteResourceGetTimeInterval',
callArgs
);
if (native.isSuccess(result)) {
var callArgs = prepareResourceInfo(this, true);
callArgs[timeInterval] = converter.toLong(val);
- native.callSync('IotconRemoteResource_setTimeInterval', callArgs);
+ native.callSync('IotconRemoteResourceSetTimeInterval', callArgs);
}.bind(this),
enumerable: true
}
}
}.bind(this);
- var result = native.call('IotconRemoteResource_methodGet', callArgs, callback);
+ var result = native.call('IotconRemoteResourceMethodGet', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
}.bind(this);
- var result = native.call('IotconRemoteResource_methodPut', callArgs, callback);
+ var result = native.call('IotconRemoteResourceMethodPut', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
}.bind(this);
- var result = native.call('IotconRemoteResource_methodPost', callArgs, callback);
+ var result = native.call('IotconRemoteResourceMethodPost', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
}.bind(this);
- var result = native.call('IotconRemoteResource_methodDelete', callArgs, callback);
+ var result = native.call('IotconRemoteResourceMethodDelete', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
args.successCallback(new RemoteResponse(result.data));
};
- var result = native.callSync('IotconRemoteResource_startObserving', callArgs);
+ var result = native.callSync('IotconRemoteResourceStartObserving', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
RemoteResource.prototype.stopObserving = function() {
var callArgs = prepareResourceInfo(this);
- var result = native.callSync('IotconRemoteResource_stopObserving', callArgs);
+ var result = native.callSync('IotconRemoteResourceStopObserving', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
native.callIfPossible(args.successCallback(createRepresentation(result.data)));
};
- var result = native.callSync('IotconRemoteResource_startCaching', callArgs);
+ var result = native.callSync('IotconRemoteResourceStartCaching', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
RemoteResource.prototype.stopCaching = function() {
var callArgs = prepareResourceInfo(this);
- var result = native.callSync('IotconRemoteResource_stopCaching', callArgs);
+ var result = native.callSync('IotconRemoteResourceStopCaching', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
};
var result = native.callSync(
- 'IotconRemoteResource_setResourceStateChangeListener',
+ 'IotconRemoteResourceSetResourceStateChangeListener',
callArgs
);
var callArgs = prepareResourceInfo(this);
var result = native.callSync(
- 'IotconRemoteResource_unsetResourceStateChangeListener',
+ 'IotconRemoteResourceUnsetResourceStateChangeListener',
callArgs
);
}
};
- var result = native.callSync('IotconClient_findResource', callArgs);
+ var result = native.callSync('IotconClientFindResource', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
} else {
callArgs.resourceType = args.resourceType;
callArgs.connectivityType = args.connectivityType;
- var result = native.callSync('IotconClient_addPresenceEventListener', callArgs);
+ var result = native.callSync('IotconClientAddPresenceEventListener', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
var callArgs = {};
callArgs.id = args.watchId;
- var result = native.callSync('IotconClient_removePresenceEventListener', callArgs);
+ var result = native.callSync('IotconClientRemovePresenceEventListener', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
- var result = native.call('IotconClient_findDeviceInfo', callArgs);
+ var result = native.call('IotconClientFindDeviceInfo', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
- var result = native.call('IotconClient_findPlatformInfo', callArgs);
+ var result = native.call('IotconClientFindPlatformInfo', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
callArgs.resourceTypes = args.resourceTypes;
callArgs.resourceInterfaces = args.resourceInterfaces;
- var result = native.callSync('IotconServer_createResource', callArgs);
+ var result = native.callSync('IotconServerCreateResource', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
var callArgs = {};
callArgs.id = args.resource[kIdKey];
- var result = native.callSync('IotconServer_removeResource', callArgs);
+ var result = native.callSync('IotconServerRemoveResource', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
timeToLive: args.timeToLive
};
- var result = native.callSync('IotconServer_startPresence', callArgs);
+ var result = native.callSync('IotconServerStartPresence', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
Server.prototype.stopPresence = function() {
- var result = native.callSync('IotconServer_stopPresence', {});
+ var result = native.callSync('IotconServerStopPresence', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
deviceName: deviceName
};
- var result = native.callSync('Iotcon_setDeviceName', callArgs);
+ var result = native.callSync('IotconSetDeviceName', callArgs);
if (native.isSuccess(result)) {
_deviceName = deviceName;
}
filePath: args.filePath
};
- var result = native.callSync('Iotcon_initialize', data);
+ var result = native.callSync('IotconInitialize', data);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
};
Iotcon.prototype.getTimeout = function() {
- var result = native.callSync('Iotcon_getTimeout', {});
+ var result = native.callSync('IotconGetTimeout', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
var callArgs = {};
callArgs.timeout = args.timeout;
- var result = native.callSync('Iotcon_setTimeout', callArgs);
+ var result = native.callSync('IotconSetTimeout', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
]);
- var result = native.callSync('Iotcon_addGeneratedPinListener', {});
+ var result = native.callSync('IotconAddGeneratedPinListener', {});
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
]);
- var result = native.callSync('Iotcon_removeGeneratedPinListener', {
+ var result = native.callSync('IotconRemoveGeneratedPinListener', {
watchId: args.watchId
});
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&IotconInstance::x, this, _1))
-
- REGISTER_SYNC("IotconResource_getObserverIds", ResourceGetObserverIds);
- REGISTER_SYNC("IotconResource_notify", ResourceNotify);
- REGISTER_SYNC("IotconResource_addResourceTypes", ResourceAddResourceTypes);
- REGISTER_SYNC("IotconResource_addResourceInterface", ResourceAddResourceInterface);
- REGISTER_SYNC("IotconResource_addChildResource", ResourceAddChildResource);
- REGISTER_SYNC("IotconResource_removeChildResource", ResourceRemoveChildResource);
- REGISTER_SYNC("IotconResource_setRequestListener", ResourceSetRequestListener);
- REGISTER_SYNC("IotconResource_unsetRequestListener", ResourceUnsetRequestListener);
- REGISTER_SYNC("IotconResponse_send", ResponseSend);
- REGISTER_SYNC("IotconRemoteResource_getCachedRepresentation",
- RemoteResourceGetCachedRepresentation);
- REGISTER_SYNC("IotconRemoteResource_getOptions", RemoteResourceGetOptions);
- REGISTER_SYNC("IotconRemoteResource_setOptions", RemoteResourceSetOptions);
- REGISTER_SYNC("IotconRemoteResource_startObserving", RemoteResourceStartObserving);
- REGISTER_SYNC("IotconRemoteResource_stopObserving", RemoteResourceStopObserving);
- REGISTER_SYNC("IotconRemoteResource_startCaching", RemoteResourceStartCaching);
- REGISTER_SYNC("IotconRemoteResource_stopCaching", RemoteResourceStopCaching);
- REGISTER_SYNC("IotconRemoteResource_setResourceStateChangeListener",
- RemoteResourceSetResourceStateChangeListener);
- REGISTER_SYNC("IotconRemoteResource_unsetResourceStateChangeListener",
- RemoteResourceUnsetResourceStateChangeListener);
- REGISTER_SYNC("IotconRemoteResource_getTimeInterval", RemoteResourceGetTimeInterval);
- REGISTER_SYNC("IotconRemoteResource_setTimeInterval", RemoteResourceSetTimeInterval);
- REGISTER_SYNC("IotconClient_addPresenceEventListener", ClientAddPresenceEventListener);
- REGISTER_SYNC("IotconClient_removePresenceEventListener", ClientRemovePresenceEventListener);
- REGISTER_SYNC("Iotcon_initialize", Initialize);
- REGISTER_SYNC("Iotcon_getTimeout", GetTimeout);
- REGISTER_SYNC("Iotcon_setTimeout", SetTimeout);
- REGISTER_SYNC("Iotcon_addGeneratedPinListener", AddGeneratedPinListener);
- REGISTER_SYNC("Iotcon_removeGeneratedPinListener", RemoveGeneratedPinListener);
- REGISTER_SYNC("IotconServer_createResource", ServerCreateResource);
- REGISTER_SYNC("IotconServer_removeResource", ServerRemoveResource);
- REGISTER_SYNC("IotconServer_startPresence", ServerStartPresence);
- REGISTER_SYNC("IotconServer_stopPresence", ServerStopPresence);
- REGISTER_SYNC("Iotcon_setDeviceName", SetDeviceName);
- REGISTER_SYNC("IotconClient_findResource", ClientFindResource);
- REGISTER_SYNC("IotconClient_findDeviceInfo", ClientFindDeviceInfo);
- REGISTER_SYNC("IotconClient_findPlatformInfo", ClientFindPlatformInfo);
-#undef REGISTER_SYNC
-
-#define REGISTER_ASYNC(c, x) RegisterHandler(c, std::bind(&IotconInstance::x, this, _1, _2));
-
- REGISTER_ASYNC("IotconRemoteResource_methodGet", RemoteResourceMethodGet);
- REGISTER_ASYNC("IotconRemoteResource_methodPut", RemoteResourceMethodPut);
- REGISTER_ASYNC("IotconRemoteResource_methodPost", RemoteResourceMethodPost);
- REGISTER_ASYNC("IotconRemoteResource_methodDelete", RemoteResourceMethodDelete);
-
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&IotconInstance::M, this, _1))
+
+ REGISTER_METHOD(IotconResourceGetObserverIds);
+ REGISTER_METHOD(IotconResourceNotify);
+ REGISTER_METHOD(IotconResourceAddResourceTypes);
+ REGISTER_METHOD(IotconResourceAddResourceInterface);
+ REGISTER_METHOD(IotconResourceAddChildResource);
+ REGISTER_METHOD(IotconResourceRemoveChildResource);
+ REGISTER_METHOD(IotconResourceSetRequestListener);
+ REGISTER_METHOD(IotconResourceUnsetRequestListener);
+ REGISTER_METHOD(IotconResponseSend);
+ REGISTER_METHOD(IotconRemoteResourceGetCachedRepresentation);
+ REGISTER_METHOD(IotconRemoteResourceGetOptions);
+ REGISTER_METHOD(IotconRemoteResourceSetOptions);
+ REGISTER_METHOD(IotconRemoteResourceStartObserving);
+ REGISTER_METHOD(IotconRemoteResourceStopObserving);
+ REGISTER_METHOD(IotconRemoteResourceStartCaching);
+ REGISTER_METHOD(IotconRemoteResourceStopCaching);
+ REGISTER_METHOD(IotconRemoteResourceSetResourceStateChangeListener);
+ REGISTER_METHOD(IotconRemoteResourceUnsetResourceStateChangeListener);
+ REGISTER_METHOD(IotconRemoteResourceGetTimeInterval);
+ REGISTER_METHOD(IotconRemoteResourceSetTimeInterval);
+ REGISTER_METHOD(IotconClientAddPresenceEventListener);
+ REGISTER_METHOD(IotconClientRemovePresenceEventListener);
+ REGISTER_METHOD(IotconInitialize);
+ REGISTER_METHOD(IotconGetTimeout);
+ REGISTER_METHOD(IotconSetTimeout);
+ REGISTER_METHOD(IotconAddGeneratedPinListener);
+ REGISTER_METHOD(IotconRemoveGeneratedPinListener);
+ REGISTER_METHOD(IotconServerCreateResource);
+ REGISTER_METHOD(IotconServerRemoveResource);
+ REGISTER_METHOD(IotconServerStartPresence);
+ REGISTER_METHOD(IotconServerStopPresence);
+ REGISTER_METHOD(IotconSetDeviceName);
+ REGISTER_METHOD(IotconClientFindResource);
+ REGISTER_METHOD(IotconClientFindDeviceInfo);
+ REGISTER_METHOD(IotconClientFindPlatformInfo);
+#undef REGISTER_METHOD
+
+#define REGISTER_METHOD(M) RegisterHandler(#M, std::bind(&IotconInstance::M, this, _1, _2))
+
+ REGISTER_METHOD(IotconRemoteResourceMethodGet);
+ REGISTER_METHOD(IotconRemoteResourceMethodPut);
+ REGISTER_METHOD(IotconRemoteResourceMethodPost);
+ REGISTER_METHOD(IotconRemoteResourceMethodDelete);
+
+#undef REGISTER_METHOD
}
IotconInstance::~IotconInstance() {
}
}
-common::TizenResult IotconInstance::ResourceGetObserverIds(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconResourceGetObserverIds(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kId);
return common::TizenSuccess(value);
}
-common::TizenResult IotconInstance::ResourceNotify(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconResourceNotify(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::ResourceAddResourceTypes(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconResourceAddResourceTypes(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::ResourceAddResourceInterface(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconResourceAddResourceInterface(
+ const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::ResourceAddChildResource(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconResourceAddChildResource(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::ResourceRemoveChildResource(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconResourceRemoveChildResource(
+ const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::ResourceSetRequestListener(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconResourceSetRequestListener(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kId);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::ResourceUnsetRequestListener(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconResourceUnsetRequestListener(
+ const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kId);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::ResponseSend(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconResponseSend(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kId);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::RemoteResourceGetCachedRepresentation(
+common::TizenResult IotconInstance::IotconRemoteResourceGetCachedRepresentation(
const picojson::object& args) {
ScopeLogger();
return common::AbortError("Failed to gather cached representation");
}
-common::TizenResult IotconInstance::RemoteResourceGetOptions(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconRemoteResourceGetOptions(const picojson::object& args) {
ScopeLogger();
FoundRemoteInfoPtr ptr;
return common::AbortError("Failed to gather options");
}
-common::TizenResult IotconInstance::RemoteResourceSetOptions(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconRemoteResourceSetOptions(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kOptions);
return common::TizenSuccess{IotconClientManager::GetInstance().StoreRemoteResource(ptr)};
}
-common::TizenResult IotconInstance::RemoteResourceMethodGet(const picojson::object& args,
- const common::AsyncToken& token) {
+common::TizenResult IotconInstance::IotconRemoteResourceMethodGet(const picojson::object& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess{IotconClientManager::GetInstance().StoreRemoteResource(resource)};
}
-common::TizenResult IotconInstance::RemoteResourceMethodPut(const picojson::object& args,
- const common::AsyncToken& token) {
+common::TizenResult IotconInstance::IotconRemoteResourceMethodPut(const picojson::object& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess{IotconClientManager::GetInstance().StoreRemoteResource(resource)};
}
-common::TizenResult IotconInstance::RemoteResourceMethodPost(const picojson::object& args,
- const common::AsyncToken& token) {
+common::TizenResult IotconInstance::IotconRemoteResourceMethodPost(
+ const picojson::object& args, const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess{IotconClientManager::GetInstance().StoreRemoteResource(resource)};
}
-common::TizenResult IotconInstance::RemoteResourceMethodDelete(const picojson::object& args,
- const common::AsyncToken& token) {
+common::TizenResult IotconInstance::IotconRemoteResourceMethodDelete(
+ const picojson::object& args, const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
}
}
-common::TizenResult IotconInstance::RemoteResourceStartObserving(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconRemoteResourceStartObserving(
+ const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess{ret};
}
-common::TizenResult IotconInstance::RemoteResourceStopObserving(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconRemoteResourceStopObserving(
+ const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
}
}
-common::TizenResult IotconInstance::RemoteResourceStartCaching(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconRemoteResourceStartCaching(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess{ret};
}
-common::TizenResult IotconInstance::RemoteResourceStopCaching(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconRemoteResourceStopCaching(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
}
}
-common::TizenResult IotconInstance::RemoteResourceSetResourceStateChangeListener(
+common::TizenResult IotconInstance::IotconRemoteResourceSetResourceStateChangeListener(
const picojson::object& args) {
ScopeLogger();
return common::TizenSuccess{ret};
}
-common::TizenResult IotconInstance::RemoteResourceUnsetResourceStateChangeListener(
+common::TizenResult IotconInstance::IotconRemoteResourceUnsetResourceStateChangeListener(
const picojson::object& args) {
ScopeLogger();
return common::TizenSuccess{IotconClientManager::GetInstance().RemoveRemoteResource(ptr)};
}
-common::TizenResult IotconInstance::RemoteResourceGetTimeInterval(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconRemoteResourceGetTimeInterval(
+ const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess{picojson::value(static_cast<double>(time_interval))};
}
-common::TizenResult IotconInstance::RemoteResourceSetTimeInterval(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconRemoteResourceSetTimeInterval(
+ const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
if (data->was_called) {
return IOTCON_FUNC_STOP;
}
+ ret = IotconUtils::ConvertIotconError(result);
+ break;
default:
ret = IotconUtils::ConvertIotconError(result);
+ break;
}
data->fun(ret, v);
return IOTCON_FUNC_CONTINUE;
}
-common::TizenResult IotconInstance::ClientFindResource(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconClientFindResource(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::ClientAddPresenceEventListener(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconClientAddPresenceEventListener(
+ const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess(picojson::value{static_cast<double>(id)});
}
-common::TizenResult IotconInstance::ClientRemovePresenceEventListener(
+common::TizenResult IotconInstance::IotconClientRemovePresenceEventListener(
const picojson::object& args) {
ScopeLogger();
return IOTCON_FUNC_CONTINUE;
}
-common::TizenResult IotconInstance::ClientFindDeviceInfo(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconClientFindDeviceInfo(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return IOTCON_FUNC_CONTINUE;
}
-common::TizenResult IotconInstance::ClientFindPlatformInfo(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconClientFindPlatformInfo(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::ServerCreateResource(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconServerCreateResource(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return common::TizenSuccess{result};
}
-common::TizenResult IotconInstance::ServerRemoveResource(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconServerRemoveResource(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return IotconServerManager::GetInstance().DestroyResource(GetId(args));
}
-common::TizenResult IotconInstance::ServerStartPresence(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconServerStartPresence(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return result;
}
-common::TizenResult IotconInstance::ServerStopPresence(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconServerStopPresence(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return result;
}
-common::TizenResult IotconInstance::SetDeviceName(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconSetDeviceName(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return result;
}
-common::TizenResult IotconInstance::Initialize(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconInitialize(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeIotcon);
return result;
}
-common::TizenResult IotconInstance::GetTimeout(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconGetTimeout(const picojson::object& args) {
ScopeLogger();
int timeout = 0;
return common::TizenSuccess{picojson::value{static_cast<double>(timeout)}};
}
-common::TizenResult IotconInstance::SetTimeout(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconSetTimeout(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kTimeout);
return common::TizenSuccess();
}
-common::TizenResult IotconInstance::AddGeneratedPinListener(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconAddGeneratedPinListener(const picojson::object& args) {
ScopeLogger();
auto listener = [this](const char* pin, long watchId) {
return IotconManager::GetInstance().addGeneratedPinListener(listener);
}
-common::TizenResult IotconInstance::RemoveGeneratedPinListener(const picojson::object& args) {
+common::TizenResult IotconInstance::IotconRemoveGeneratedPinListener(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, "watchId");
static bool ResourceFoundCallback(iotcon_remote_resource_h resource, iotcon_error_e result,
void* user_data);
- common::TizenResult ResourceGetObserverIds(const picojson::object& args);
- common::TizenResult ResourceNotify(const picojson::object& args);
- common::TizenResult ResourceAddResourceTypes(const picojson::object& args);
- common::TizenResult ResourceAddResourceInterface(const picojson::object& args);
- common::TizenResult ResourceAddChildResource(const picojson::object& args);
- common::TizenResult ResourceRemoveChildResource(const picojson::object& args);
- common::TizenResult ResourceSetRequestListener(const picojson::object& args);
- common::TizenResult ResourceUnsetRequestListener(const picojson::object& args);
- common::TizenResult ResponseSend(const picojson::object& args);
- common::TizenResult RemoteResourceGetCachedRepresentation(const picojson::object& args);
- common::TizenResult RemoteResourceGetOptions(const picojson::object& args);
- common::TizenResult RemoteResourceSetOptions(const picojson::object& args);
- common::TizenResult RemoteResourceMethodGet(const picojson::object& args,
- const common::AsyncToken& token);
- common::TizenResult RemoteResourceMethodPut(const picojson::object& args,
- const common::AsyncToken& token);
- common::TizenResult RemoteResourceMethodPost(const picojson::object& args,
- const common::AsyncToken& token);
- common::TizenResult RemoteResourceMethodDelete(const picojson::object& args,
- const common::AsyncToken& token);
- common::TizenResult RemoteResourceStartObserving(const picojson::object& args);
- common::TizenResult RemoteResourceStopObserving(const picojson::object& args);
- common::TizenResult RemoteResourceStartCaching(const picojson::object& args);
- common::TizenResult RemoteResourceStopCaching(const picojson::object& args);
- common::TizenResult RemoteResourceSetResourceStateChangeListener(const picojson::object& args);
- common::TizenResult RemoteResourceUnsetResourceStateChangeListener(const picojson::object& args);
- common::TizenResult RemoteResourceGetTimeInterval(const picojson::object& args);
- common::TizenResult RemoteResourceSetTimeInterval(const picojson::object& args);
- common::TizenResult ClientFindResource(const picojson::object& args);
- common::TizenResult ClientAddPresenceEventListener(const picojson::object& args);
- common::TizenResult ClientRemovePresenceEventListener(const picojson::object& args);
- common::TizenResult ClientFindDeviceInfo(const picojson::object& args);
- common::TizenResult ClientFindPlatformInfo(const picojson::object& args);
- common::TizenResult ServerCreateResource(const picojson::object& args);
- common::TizenResult ServerRemoveResource(const picojson::object& args);
- common::TizenResult ServerStartPresence(const picojson::object& args);
- common::TizenResult ServerStopPresence(const picojson::object& args);
- common::TizenResult SetDeviceName(const picojson::object& args);
- common::TizenResult Initialize(const picojson::object& args);
- common::TizenResult GetTimeout(const picojson::object& args);
- common::TizenResult SetTimeout(const picojson::object& args);
- common::TizenResult AddGeneratedPinListener(const picojson::object& args);
- common::TizenResult RemoveGeneratedPinListener(const picojson::object& args);
+ common::TizenResult IotconResourceGetObserverIds(const picojson::object& args);
+ common::TizenResult IotconResourceNotify(const picojson::object& args);
+ common::TizenResult IotconResourceAddResourceTypes(const picojson::object& args);
+ common::TizenResult IotconResourceAddResourceInterface(const picojson::object& args);
+ common::TizenResult IotconResourceAddChildResource(const picojson::object& args);
+ common::TizenResult IotconResourceRemoveChildResource(const picojson::object& args);
+ common::TizenResult IotconResourceSetRequestListener(const picojson::object& args);
+ common::TizenResult IotconResourceUnsetRequestListener(const picojson::object& args);
+ common::TizenResult IotconResponseSend(const picojson::object& args);
+ common::TizenResult IotconRemoteResourceGetCachedRepresentation(const picojson::object& args);
+ common::TizenResult IotconRemoteResourceGetOptions(const picojson::object& args);
+ common::TizenResult IotconRemoteResourceSetOptions(const picojson::object& args);
+ common::TizenResult IotconRemoteResourceMethodGet(const picojson::object& args,
+ const common::AsyncToken& token);
+ common::TizenResult IotconRemoteResourceMethodPut(const picojson::object& args,
+ const common::AsyncToken& token);
+ common::TizenResult IotconRemoteResourceMethodPost(const picojson::object& args,
+ const common::AsyncToken& token);
+ common::TizenResult IotconRemoteResourceMethodDelete(const picojson::object& args,
+ const common::AsyncToken& token);
+ common::TizenResult IotconRemoteResourceStartObserving(const picojson::object& args);
+ common::TizenResult IotconRemoteResourceStopObserving(const picojson::object& args);
+ common::TizenResult IotconRemoteResourceStartCaching(const picojson::object& args);
+ common::TizenResult IotconRemoteResourceStopCaching(const picojson::object& args);
+ common::TizenResult IotconRemoteResourceSetResourceStateChangeListener(
+ const picojson::object& args);
+ common::TizenResult IotconRemoteResourceUnsetResourceStateChangeListener(
+ const picojson::object& args);
+ common::TizenResult IotconRemoteResourceGetTimeInterval(const picojson::object& args);
+ common::TizenResult IotconRemoteResourceSetTimeInterval(const picojson::object& args);
+ common::TizenResult IotconClientFindResource(const picojson::object& args);
+ common::TizenResult IotconClientAddPresenceEventListener(const picojson::object& args);
+ common::TizenResult IotconClientRemovePresenceEventListener(const picojson::object& args);
+ common::TizenResult IotconClientFindDeviceInfo(const picojson::object& args);
+ common::TizenResult IotconClientFindPlatformInfo(const picojson::object& args);
+ common::TizenResult IotconServerCreateResource(const picojson::object& args);
+ common::TizenResult IotconServerRemoveResource(const picojson::object& args);
+ common::TizenResult IotconServerStartPresence(const picojson::object& args);
+ common::TizenResult IotconServerStopPresence(const picojson::object& args);
+ common::TizenResult IotconSetDeviceName(const picojson::object& args);
+ common::TizenResult IotconInitialize(const picojson::object& args);
+ common::TizenResult IotconGetTimeout(const picojson::object& args);
+ common::TizenResult IotconSetTimeout(const picojson::object& args);
+ common::TizenResult IotconAddGeneratedPinListener(const picojson::object& args);
+ common::TizenResult IotconRemoveGeneratedPinListener(const picojson::object& args);
common::PostCallback PostForMethodCall(const common::AsyncToken& token,
const FoundRemoteInfoPtr& resource);
]);
var result = native.call(
- 'KeyManager_saveData',
+ 'KeyManagerSaveData',
{
aliasName: _trim(args.aliasName),
rawData: args.rawData,
data_alias = args.dataAlias.packageId + ' ' + data_alias;
}
- var ret = native.callSync('KeyManager_removeAlias', {
+ var ret = native.callSync('KeyManagerRemoveAlias', {
aliasName: data_alias
});
if (native.isFailure(ret)) {
data_alias = args.dataAlias.packageId + ' ' + data_alias;
}
- var ret = native.callSync('KeyManager_getData', {
+ var ret = native.callSync('KeyManagerGetData', {
name: data_alias,
password: args.password
});
};
KeyManager.prototype.getDataAliasList = function() {
- var ret = native.callSync('KeyManager_getDataAliasList', {});
+ var ret = native.callSync('KeyManagerGetDataAliasList', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
}
}
var result = native.call(
- 'KeyManager_setPermissions',
+ 'KeyManagerSetPermissions',
{
aliasName: data_alias,
packageId: args.packageId,
typedef std::vector<unsigned char> RawBuffer;
-typedef int (*AliasListFunction)(ckmc_alias_list_s**);
+const std::string kSpace = ckmc_owner_id_separator;
-const std::string kSpace = " ";
+} // namespace
-void GetGenericAliasList(AliasListFunction func, picojson::object* out) {
+KeyManagerInstance::KeyManagerInstance() {
ScopeLogger();
+ using std::placeholders::_1;
+ using std::placeholders::_2;
- ckmc_alias_list_s* alias_list = nullptr;
- int ret = func(&alias_list);
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&KeyManagerInstance::M, this, _1, _2))
- picojson::value result{picojson::array{}};
+ REGISTER_METHOD(KeyManagerGetDataAliasList);
+ REGISTER_METHOD(KeyManagerSaveData);
+ REGISTER_METHOD(KeyManagerGetData);
+ REGISTER_METHOD(KeyManagerRemoveAlias);
+ REGISTER_METHOD(KeyManagerSetPermissions);
- if (CKMC_ERROR_NONE == ret) {
- auto& aliases = result.get<picojson::array>();
-
- picojson::value resultElem = picojson::value(picojson::object());
- picojson::object& obj = resultElem.get<picojson::object>();
- ckmc_alias_list_s* head = alias_list;
-
- while (head) {
- // aliases.push_back(picojson::value(head->alias ? head->alias : ""));
- if (head->alias) {
- char* saveptr = nullptr;
- char* tokenized = strtok_r(head->alias, kSpace.c_str(), &saveptr);
- if (nullptr != tokenized) {
- obj["packageId"] = picojson::value(tokenized);
- }
- tokenized = strtok_r(nullptr, kSpace.c_str(), &saveptr);
- if (nullptr != tokenized) {
- obj["name"] = picojson::value(tokenized);
- }
-
- aliases.push_back(resultElem);
- }
+#undef REGISTER_METHOD
+}
- head = head->next;
- }
+void KeyManagerInstance::KeyManagerGetDataAliasList(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
- if (alias_list) {
- ckmc_alias_list_all_free(alias_list);
- }
+ picojson::value result = picojson::value(picojson::array());
+ auto& aliases = result.get<picojson::array>();
+
+ ckmc_alias_info_list_s* alias_info_list = nullptr;
+ SCOPE_EXIT {
+ ckmc_alias_info_list_all_free(alias_info_list);
+ };
+
+ int ret = ckmc_get_data_alias_info_list(&alias_info_list);
+
+ // It is stated in key-manager documantation that this error means empty list
+ // I have also checked native implementation. It does not look good, but it was
+ // reported to native team and they decided not to change it.
+ if (CKMC_ERROR_DB_ALIAS_UNKNOWN == ret) {
+ LoggerD("Alias list is empty");
+ ReportSuccess(result, out);
+ return;
}
- common::tools::ReportSuccess(result, *out);
-}
-} // namespace
+ if (CKMC_ERROR_NONE != ret) {
+ LoggerD("Failed to get alias list: %d", ret);
+ PlatformResult error = GetError(ret);
+ ReportError(error, &out);
+ return;
+ }
-KeyManagerInstance::KeyManagerInstance() {
- ScopeLogger();
- using std::placeholders::_1;
- using std::placeholders::_2;
+ picojson::value result_element = picojson::value(picojson::object());
+ picojson::object& obj = result_element.get<picojson::object>();
+ ckmc_alias_info_list_s* current_item = alias_info_list;
+
+ while (current_item) {
+ if (current_item->info) {
+ char* name = nullptr;
- RegisterSyncHandler("KeyManager_getDataAliasList",
- std::bind(&KeyManagerInstance::GetDataAliasList, this, _1, _2));
+ ret = ckmc_alias_info_get_alias(current_item->info, &name);
- RegisterSyncHandler("KeyManager_saveData",
- std::bind(&KeyManagerInstance::SaveData, this, _1, _2));
+ if (CKMC_ERROR_NONE != ret) {
+ LoggerD("Failed to get alias name information: %d", ret);
+ PlatformResult error = GetError(ret);
+ ReportError(error, &out);
+ return;
+ }
+ LoggerD("Alias name: %s", name);
+ char* saveptr = nullptr;
+ char* tokenized = strtok_r(name, kSpace.c_str(), &saveptr);
- RegisterSyncHandler("KeyManager_getData", std::bind(&KeyManagerInstance::GetData, this, _1, _2));
+ if (nullptr != tokenized) {
+ obj["packageId"] = picojson::value(tokenized);
+ }
- RegisterSyncHandler("KeyManager_removeAlias",
- std::bind(&KeyManagerInstance::RemoveAlias, this, _1, _2));
+ tokenized = strtok_r(nullptr, kSpace.c_str(), &saveptr);
+ if (nullptr != tokenized) {
+ obj["name"] = picojson::value(tokenized);
+ }
- RegisterSyncHandler("KeyManager_setPermissions",
- std::bind(&KeyManagerInstance::SetPermission, this, _1, _2));
-}
+ bool is_password_protected = false;
+ ret = ckmc_alias_info_is_password_protected(current_item->info, &is_password_protected);
-void KeyManagerInstance::GetDataAliasList(const picojson::value& args, picojson::object& out) {
- ScopeLogger();
+ if (CKMC_ERROR_NONE != ret) {
+ LoggerE("Failed to get alias password information: %d", ret);
+ PlatformResult error = GetError(ret);
+ ReportError(error, &out);
+ return;
+ }
+ obj["isProtected"] = picojson::value(is_password_protected);
+ aliases.push_back(result_element);
+ }
+ current_item = current_item->next;
+ }
- GetGenericAliasList(ckmc_get_data_alias_list, &out);
+ ReportSuccess(result, out);
}
PlatformResult KeyManagerInstance::GetError(int ret) {
}
}
-void KeyManagerInstance::SaveData(const picojson::value& args, picojson::object& out) {
+void KeyManagerInstance::KeyManagerSaveData(const picojson::value& args, picojson::object& out) {
ScopeLogger();
std::string data_raw = args.get("rawData").get<std::string>();
if (password_value.is<std::string>()) {
password = password_value.get<std::string>();
- LoggerE("password %s ", password.c_str());
}
auto save_data = [data_raw, password, alias](const std::shared_ptr<picojson::value>& result) {
ReportSuccess(out);
}
-void KeyManagerInstance::GetData(const picojson::value& args, picojson::object& out) {
+void KeyManagerInstance::KeyManagerGetData(const picojson::value& args, picojson::object& out) {
ScopeLogger();
const auto& data_alias = args.get("name").get<std::string>();
ScopeLogger();
}
-void KeyManagerInstance::RemoveAlias(const picojson::value& args, picojson::object& out) {
+void KeyManagerInstance::KeyManagerRemoveAlias(const picojson::value& args, picojson::object& out) {
ScopeLogger();
const std::string& alias = args.get("aliasName").get<std::string>();
}
}
-void KeyManagerInstance::SetPermission(const picojson::value& args, picojson::object& out) {
+void KeyManagerInstance::KeyManagerSetPermissions(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
const std::string& data_name = args.get("aliasName").get<std::string>();
virtual ~KeyManagerInstance();
private:
- void GetDataAliasList(picojson::value const& args, picojson::object& out);
+ void KeyManagerGetDataAliasList(picojson::value const& args, picojson::object& out);
- void SaveData(const picojson::value& args, picojson::object& out);
- void GetData(const picojson::value& args, picojson::object& out);
- void RemoveAlias(const picojson::value& args, picojson::object& out);
+ void KeyManagerSaveData(const picojson::value& args, picojson::object& out);
+ void KeyManagerGetData(const picojson::value& args, picojson::object& out);
+ void KeyManagerRemoveAlias(const picojson::value& args, picojson::object& out);
- void SetPermission(const picojson::value& args, picojson::object& out);
+ void KeyManagerSetPermissions(const picojson::value& args, picojson::object& out);
static common::PlatformResult GetError(int ret);
};
--- /dev/null
+mocha.setup('bdd');
+
+describe('sendCommand', function() {
+ var client = null,
+ server = null,
+ sinfo = null,
+ commandListenerId = null;
+
+ before(function() {
+ server = tizen.mediacontroller.createServer();
+ client = tizen.mediacontroller.getClient();
+ server.updatePlaybackState('PLAY');
+ sinfo = client.getLatestServerInfo();
+ });
+
+ afterEach(function() {
+ server.removeCommandListener(commandListenerId);
+ });
+
+ it('should trigger command listener and success callback', function(done) {
+ commandListenerId = server.addCommandListener(function(client, command, data) {
+ chai.expect(command).to.equal('myCommand');
+ chai.expect(Object.keys(data).length).to.equal(1);
+ chai.expect(data.key).to.equal('value');
+ return { key: 'response data' };
+ });
+
+ sinfo.sendCommand(
+ 'myCommand',
+ { key: 'value' },
+ function(response) {
+ chai.expect(Object.keys(response).length).to.equal(1);
+ chai.expect(response.key).to.equal('response data');
+ done();
+ },
+ function(error) {
+ done(new Error(error));
+ }
+ );
+ });
+
+ it('should accept tizen.Bundle data argument', function(done) {
+ commandListenerId = server.addCommandListener(function(client, command, data) {
+ chai.expect(command).to.equal('myCommand');
+ chai.expect(Object.keys(data).length).to.equal(1);
+ chai.expect(data.key).to.equal('value');
+ return { key: 'response data' };
+ });
+
+ sinfo.sendCommand(
+ 'myCommand',
+ new tizen.Bundle({ key: 'value' }),
+ function(response) {
+ chai.expect(Object.keys(response).length).to.equal(1);
+ chai.expect(response.key).to.equal('response data');
+ done();
+ },
+ function(error) {
+ done(new Error(error));
+ }
+ );
+ });
+
+ it('should accept null data argument', function(done) {
+ commandListenerId = server.addCommandListener(function(client, command, data) {
+ chai.expect(command).to.equal('myCommand');
+ chai.expect(data).to.equal(null);
+ return { key: 'response data' };
+ });
+
+ sinfo.sendCommand(
+ 'myCommand',
+ null,
+ function(response) {
+ chai.expect(Object.keys(response).length).to.equal(1);
+ chai.expect(response.key).to.equal('response data');
+ done();
+ },
+ function(error) {
+ done(new Error(error));
+ }
+ );
+ });
+
+ it('should accept RequestReply as a response', function(done) {
+ commandListenerId = server.addCommandListener(function(client, command, data) {
+ chai.expect(command).to.equal('myCommand');
+ chai.expect(data).to.equal(null);
+ return new tizen.mediacontroller.RequestReply({ key: 'response data' }, 10);
+ });
+
+ sinfo.sendCommand(
+ 'myCommand',
+ null,
+ function(data, code) {
+ chai.expect(code).to.equal(10);
+ chai.expect(Object.keys(data).length).to.equal(1);
+ chai.expect(data.key).to.equal('response data');
+ done();
+ },
+ function(error) {
+ done(new Error(error));
+ }
+ );
+ });
+
+ it('should accept RequestReply with null data as a response', function(done) {
+ commandListenerId = server.addCommandListener(function(client, command, data) {
+ chai.expect(command).to.equal('myCommand');
+ chai.expect(data).to.equal(null);
+ return new tizen.mediacontroller.RequestReply(null, 10);
+ });
+
+ sinfo.sendCommand(
+ 'myCommand',
+ null,
+ function(data, code) {
+ chai.expect(code).to.equal(10);
+ chai.expect(data).to.equal(null);
+ done();
+ },
+ function(error) {
+ done(new Error(error));
+ }
+ );
+ });
+
+ it('should be okey to return nothing from command listener', function(done) {
+ commandListenerId = server.addCommandListener(function(client, command, data) {
+ chai.expect(command).to.equal('myCommand');
+ chai.expect(data).to.equal(null);
+ });
+
+ sinfo.sendCommand(
+ 'myCommand',
+ null,
+ function(data, code) {
+ chai.expect(data).to.equal(null);
+ chai.expect(code).to.equal(0);
+ done();
+ },
+ function(error) {
+ done(new Error(error));
+ }
+ );
+ });
+});
+
+mocha.checkLeaks();
+mocha
+ .run()
+ .on('pass', function(test) {
+ console.log(test.title + ' OK');
+ })
+ .on('fail', function(test, err) {
+ console.error(test.title + ' FAILED');
+ console.error(err);
+ })
+ .on('end', function() {
+ console.log('All done');
+ });
--- /dev/null
+mocha.setup('bdd');
+
+var server = tizen.mediacontroller.createServer();
+var client = tizen.mediacontroller.getClient();
+server.updatePlaybackState('PLAY');
+
+describe('MediaControllerServer::getAllClientsInfo', function() {
+ it('should return client info for this application', function(done) {
+ var clientsInfo = server.getAllClientsInfo();
+ chai.expect(clientsInfo.length).to.equal(1);
+ var appId = tizen.application.getCurrentApplication().appInfo.id;
+ chai.expect(clientsInfo[0].name).to.equal(appId);
+ done();
+ });
+});
+
+describe('MediaControllerClientInfo::name', function() {
+ it('should be readonly attribute', function(done) {
+ var clientsInfo = server.getAllClientsInfo();
+ var old = clientsInfo[0].name;
+ clientsInfo[0].name = 'other';
+ chai.expect(clientsInfo[0].name).to.equal(old);
+ done();
+ });
+});
+
+describe('MediaControllerClient::setCustomEventListener', function() {
+ after(function() {
+ client.unsetCustomEventListener();
+ });
+
+ it('should throw TypeMismatchError if argument is not a function', function(done) {
+ try {
+ client.setCustomEventListener('not-a-function');
+ done(new Error('Expected TypeMismatchError.'));
+ } catch (error) {
+ chai.expect(error.name).to.equal('TypeMismatchError');
+ done();
+ }
+ });
+
+ it('should override previously set listener if called multiple times', function(done) {
+ function firstListener(serverName, event, data) {
+ done(new Error('first listener should have been overriden'));
+ }
+ function secondListener(serverName, event, data) {
+ done();
+ }
+ function callback(data, code) {
+ /* ignore */
+ }
+
+ client.setCustomEventListener(firstListener);
+ client.setCustomEventListener(secondListener);
+ server.getAllClientsInfo()[0].sendEvent('test', {}, callback);
+ });
+});
+
+describe('MediaControllerClient::unsetCustomEventListener', function() {
+ it('should have no effect if the listener is not set', function(done) {
+ function listener(server, event, data) {
+ /* ignore */
+ }
+ client.unsetCustomEventListener();
+ client.setCustomEventListener(listener);
+ client.unsetCustomEventListener();
+ client.unsetCustomEventListener();
+ done();
+ });
+});
+
+describe('MediaControllerClientInfo::sendEvent', function() {
+ var cinfo = null;
+ before(function() {
+ cinfo = server.getAllClientsInfo()[0];
+ });
+
+ it('should throw TypeMismatchError if any argument has invalid type', function(done) {
+ try {
+ cinfo.sendEvent('TestEvent', null, 'not-a-function');
+ done(new Error('Expected TypeMismatchError'));
+ } catch (error) {
+ chai.expect(error.name).to.equal('TypeMismatchError');
+ }
+ try {
+ cinfo.sendEvent('TestEvent', 'not-an-object-or-null', function(
+ data,
+ code
+ ) {});
+ done(new Error('Expected TypeMismatchError'));
+ } catch (error) {
+ chai.expect(error.name).to.equal('TypeMismatchError');
+ }
+ done();
+ });
+
+ it('should trigger client listener', function(done) {
+ function listener(serverName, event, data) {
+ var currentAppId = tizen.application.getCurrentApplication().appInfo.id;
+ chai.expect(serverName).to.equal(currentAppId);
+ chai.expect(event).to.equal('TestEvent');
+ chai.expect(data).to.be.null;
+ done();
+ }
+ function callback(data, code) {
+ /* ignore */
+ }
+ client.setCustomEventListener(listener);
+ cinfo.sendEvent('TestEvent', null, callback);
+ });
+
+ it('should receive reply via callback', function(done) {
+ function listener(server, event, data) {
+ return new tizen.mediacontroller.RequestReply(null, 123);
+ }
+
+ function callback(data, code) {
+ chai.expect(code).to.equal(123);
+ chai.expect(data).to.equal(null);
+ done();
+ }
+
+ client.setCustomEventListener(listener);
+ cinfo.sendEvent('TestEvent', null, callback);
+ });
+
+ it('should pass data bundle', function(done) {
+ function listener(server, event, data) {
+ chai.expect(event).to.equal('TestEvent');
+ chai.expect(data.test).to.equal('data');
+ return new tizen.mediacontroller.RequestReply(
+ { TestReply: 'ReplyData' },
+ 123
+ );
+ }
+
+ function callback(data, code) {
+ chai.expect(data.TestReply).to.equal('ReplyData');
+ done();
+ }
+
+ client.setCustomEventListener(listener);
+ cinfo.sendEvent('TestEvent', new tizen.Bundle({ test: 'data' }), callback);
+ });
+});
+
+mocha.checkLeaks();
+mocha
+ .run()
+ .on('pass', function(test) {
+ console.log(test.title + ' OK');
+ })
+ .on('fail', function(test, err) {
+ console.error(test.title + ' FAILED');
+ console.error(err);
+ })
+ .on('end', function() {
+ console.log('All done');
+ });
--- /dev/null
+mocha.setup('bdd');
+
+describe('sendSearchRequest', function() {
+ var client = null,
+ server = null,
+ sinfo = null,
+ listenerId = null;
+
+ before(function() {
+ server = tizen.mediacontroller.createServer();
+ client = tizen.mediacontroller.getClient();
+ server.updatePlaybackState('PLAY');
+ sinfo = client.getLatestServerInfo();
+ });
+
+ afterEach(function() {
+ server.unsetSearchRequestListener(listenerId);
+ });
+
+ it('should trigger search request listener and reply callback', function(done) {
+ function requestCallback(client, request) {
+ chai.expect(request.length).to.equal(2);
+ var keywords = [request[0].keyword, request[1].keyword];
+ chai.expect(keywords).to.have.members(['rock', 'pop']);
+ return new tizen.mediacontroller.RequestReply(
+ { key: ['tizen1', 'tizen2'] },
+ 123
+ );
+ }
+ server.setSearchRequestListener(requestCallback);
+
+ var request = [
+ new tizen.mediacontroller.SearchFilter('MUSIC', 'GENRE', 'rock', null),
+ new tizen.mediacontroller.SearchFilter('MUSIC', 'GENRE', 'pop', null)
+ ];
+
+ sinfo.sendSearchRequest(request, function(reply) {
+ chai.expect(reply.code).to.equal(123);
+ chai.expect(reply.data.get('key')).to.deep.equal(['tizen1', 'tizen2']);
+ done();
+ });
+ });
+
+ it('should raise InvalidValuesErr if too many filters in the request', function(done) {
+ var request = [];
+ for (var i = 0; i < 20 + 1; ++i) {
+ request.push(
+ new tizen.mediacontroller.SearchFilter('MUSIC', 'GENRE', 'genre' + i)
+ );
+ }
+
+ try {
+ sinfo.sendSearchRequest(request, function(reply) {
+ done(new Error('search request reply received unexpectedly'));
+ });
+ done(new Error('sendSearchRequest should fail but did not'));
+ } catch (error) {
+ chai.expect(error.name).to.equal('InvalidValuesError');
+ done();
+ }
+ });
+
+ it('should throw type mismatch error for invalid request type', function(done) {
+ try {
+ sinfo.sendSearchRequest('not-array', function(reply) {
+ done(new Error('search request reply received unexpectedly'));
+ });
+ done(new Error('sendSearchRequest should fail but did not'));
+ } catch (error) {
+ chai.expect(error.name).to.equal('TypeMismatchError');
+ done();
+ }
+ });
+
+ it('set/unsetSearchRequestListener() methods should not throw an error', function(done) {
+ try {
+ server.unsetSearchRequestListener();
+ server.setSearchRequestListener(function(client, request) {});
+ server.unsetSearchRequestListener();
+ server.setSearchRequestListener(function(client, request) {});
+ server.unsetSearchRequestListener();
+ done();
+ } catch (error) {
+ done(new Error(error));
+ }
+ });
+
+ it('search filter objects should be properly constructed', function(done) {
+ var f1 = new tizen.mediacontroller.SearchFilter('MUSIC');
+ chai.expect(f1.contentType).to.equal('MUSIC');
+ chai.expect(f1.category).to.equal('NO_CATEGORY');
+ chai.expect(f1.keyword).to.equal(null);
+ chai.expect(f1.extraData).to.equal(null);
+
+ var f3 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen');
+ chai.expect(f3.contentType).to.equal('MUSIC');
+ chai.expect(f3.category).to.equal('TITLE');
+ chai.expect(f3.keyword).to.equal('tizen');
+ chai.expect(f3.extraData).to.equal(null);
+
+ var f4 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen', {});
+ chai.expect(f4.contentType).to.equal('MUSIC');
+ chai.expect(f4.category).to.equal('TITLE');
+ chai.expect(f4.keyword).to.equal('tizen');
+ chai.expect(f4.extraData).to.satisfy(x => x instanceof tizen.Bundle);
+
+ var f5 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen', {
+ key: 'value'
+ });
+ chai.expect(f5.contentType).to.equal('MUSIC');
+ chai.expect(f5.category).to.equal('TITLE');
+ chai.expect(f5.keyword).to.equal('tizen');
+ chai.expect(f5.extraData).to.satisfy(x => x instanceof tizen.Bundle);
+ chai.expect(f5.extraData.get('key')).to.equal('value');
+
+ done();
+ });
+
+ it('search filter object setters should work properly', function(done) {
+ var f1 = new tizen.mediacontroller.SearchFilter('MUSIC');
+ chai.expect(f1.contentType).to.equal('MUSIC');
+
+ f1.contentType = 'VIDEO';
+ chai.expect(f1.contentType).to.equal('VIDEO');
+
+ try {
+ f1.contentType = 'INVALID VALUE';
+ done(new Error('invalid content type value should cause error but did not'));
+ } catch (error) {
+ chai.expect(error.name).to.equal('TypeMismatchError');
+ }
+
+ try {
+ f1.contentType = 10;
+ done(new Error('invalid content type value should cause error but did not'));
+ } catch (error) {
+ chai.expect(error.name).to.equal('TypeMismatchError');
+ }
+
+ var f2 = new tizen.mediacontroller.SearchFilter('MUSIC');
+ chai.expect(f2.category).to.equal('NO_CATEGORY');
+ try {
+ f2.category = null;
+ done(new Error('search category is not nullable'));
+ } catch (error) {
+ chai.expect(error.name).to.equal('TypeMismatchError');
+ }
+
+ try {
+ f2.category = 'INVALID VALUE';
+ done(new Error('invalid category value should cause an error but did not'));
+ } catch (error) {
+ chai.expect(error.name).to.equal('TypeMismatchError');
+ }
+
+ var f3 = new tizen.mediacontroller.SearchFilter('MUSIC');
+ chai.expect(f3.keyword).to.be.null;
+
+ f3.keyword = 'hello';
+ chai.expect(f3.keyword).to.equal('hello');
+
+ f3.keyword = null;
+ chai.expect(f3.keyword).to.be.null;
+
+ f3.keyword = '';
+ chai.expect(f3.keyword).to.equal('');
+
+ var f4 = new tizen.mediacontroller.SearchFilter('MUSIC');
+ chai.expect(f4.extraData).to.be.null;
+
+ f4.extraData = new tizen.Bundle({ key: 'value' });
+ chai.expect(f4.extraData.get('key')).to.equal('value');
+
+ f4.extraData = null;
+ chai.expect(f4.extraData).to.be.null;
+
+ f4.extraData = { key: 'value' };
+ chai.expect(f4.extraData.get('key')).to.equal('value');
+
+ f4.extraData = 'invalid value';
+ chai.expect(f4.extraData.data).to.be.empty;
+
+ var f5 = new tizen.mediacontroller.SearchFilter('MUSIC', 'NO_CATEGORY', null);
+ chai.expect(f5.keyword).to.be.null;
+
+ try {
+ f5.category = 'TITLE';
+ done(
+ new Error(
+ 'exception should be thrown if keyword == null and category != null'
+ )
+ );
+ } catch (error) {
+ chai.expect(error.name).to.equal('InvalidValuesError');
+ }
+
+ try {
+ var f6 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', null);
+ done(
+ new Error(
+ 'exception should be thrown if keyword == null and category != null'
+ )
+ );
+ } catch (error) {
+ chai.expect(error.name).to.equal('InvalidValuesError');
+ }
+
+ var f6 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen');
+ try {
+ f6.keyword = null;
+ done(
+ new Error(
+ 'exception should be thrown if keyword == null and category != null'
+ )
+ );
+ } catch (error) {
+ chai.expect(error.name).to.equal('InvalidValuesError');
+ }
+
+ done();
+ });
+});
+
+mocha.checkLeaks();
+mocha
+ .run()
+ .on('pass', function(test) {
+ console.log(test.title + ' OK');
+ })
+ .on('fail', function(test, err) {
+ console.error(test.title + ' FAILED');
+ console.error(err);
+ })
+ .on('end', function() {
+ console.log('All done');
+ });
'mediacontroller_instance.h',
'mediacontroller_server.cc',
'mediacontroller_server.h',
- 'mediacontroller_types.cc',
- 'mediacontroller_types.h',
+ 'mediacontroller_utils.cc',
+ 'mediacontroller_utils.h',
],
'conditions': [
['tizen == 1', {
}
};
+var EventReplyListenerManager = new utils_.CommonListenerManager(
+ native_,
+ '_EventReplyListener'
+);
+EventReplyListenerManager.listenerIdToRequestId = {};
+
var ServerCommandListener = new ListenerManager(
native_,
'_ServerCommandListener',
function(msg, listener) {
- var data = undefined;
- data = listener(msg.clientName, msg.command, msg.data);
-
- if (type_.isUndefined(data)) {
- data = null;
+ // passing raw msg.data object instead of tizen.Bundle
+ // due to backward compatibility issue.
+ var reply = listener(msg.clientName, msg.command, msg.data);
+
+ if (!(reply instanceof RequestReply)) {
+ reply = new RequestReply(
+ xwalk.utils.type.isNullOrUndefined(reply) ? null : reply,
+ 0
+ );
}
var nativeData = {
clientName: msg.clientName,
requestId: msg.requestId,
- data: data
+ reply: reply
};
- var result = native_.callSync('MediaControllerServer_replyCommand', nativeData);
+ var result = native_.callSync('MediaControllerServerReplyCommand', nativeData);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
watchId
) {
if (this.requestIdToListenerId[watchId] === msg.requestId) {
+ // this listener is a wrapper around user callback which is neccessary
+ // due to difference between sendCommand() and new API methods.
listener(msg);
+
this.removeListener(watchId);
delete this.requestIdToListenerId[watchId];
+
return true;
}
return false;
'_ServerPlaybackInfoListener',
function(msg, listener) {
if (msg.action === 'onplaybackstaterequest') {
- native_.callIfPossible(listener[msg.action], msg.state);
+ native_.callIfPossible(listener[msg.action], msg.state, msg.clientName);
}
if (msg.action === 'onplaybackpositionrequest') {
- native_.callIfPossible(listener[msg.action], msg.position);
+ native_.callIfPossible(listener[msg.action], msg.position, msg.clientName);
}
- if (
- msg.action === 'onshufflemoderequest' ||
- msg.action === 'onrepeatmoderequest'
- ) {
- native_.callIfPossible(listener[msg.action], msg.mode);
+ if (msg.action === 'onshufflemoderequest') {
+ native_.callIfPossible(listener[msg.action], msg.mode, msg.clientName);
+ }
+ if (msg.action === 'onrepeatmoderequest') {
+ utils_.printDeprecationWarningFor(
+ 'onrepeatmoderequest',
+ 'onrepeatstaterequest'
+ );
+ native_.callIfPossible(listener[msg.action], msg.mode, msg.clientName);
+ }
+ if (msg.action === 'onrepeatstaterequest') {
+ native_.callIfPossible(listener[msg.action], msg.state, msg.clientName);
+ }
+ if (msg.action === 'onplaybackitemrequest') {
+ native_.callIfPossible(
+ listener[msg.action],
+ msg.playlistName,
+ msg.index,
+ msg.state,
+ msg.position,
+ msg.clientName
+ );
}
}
);
native_,
'_ServerInfoStatusListener',
function(msg, listener) {
- listener(msg.state);
+ native_.callIfPossible(listener, msg.state);
}
);
'_ServerInfoPlaybackInfoListener',
function(msg, listener) {
if (msg.action === 'onplaybackchanged') {
- listener[msg.action](msg.state, msg.position);
+ native_.callIfPossible(listener[msg.action], msg.state, msg.position);
}
- if (
- msg.action === 'onshufflemodechanged' ||
- msg.action === 'onrepeatmodechanged'
- ) {
- listener[msg.action](msg.mode);
+ if (msg.action === 'onshufflemodechanged') {
+ native_.callIfPossible(listener[msg.action], msg.mode);
+ }
+ if (msg.action === 'onrepeatmodechanged') {
+ utils_.printDeprecationWarningFor(
+ 'onrepeatmodechanged',
+ 'onrepeatstatechanged'
+ );
+ native_.callIfPossible(listener[msg.action], msg.mode);
+ }
+ if (msg.action === 'onrepeatstatechanged') {
+ native_.callIfPossible(listener[msg.action], msg.state);
}
if (msg.action === 'onmetadatachanged') {
- listener[msg.action](new MediaControllerMetadata(msg.metadata));
+ native_.callIfPossible(
+ listener[msg.action],
+ new MediaControllerMetadata(msg.metadata)
+ );
+ }
+ }
+);
+
+var ServerInfoPlaylistUpdatedListener = new ListenerManager(
+ native_,
+ '_ServerInfoPlaylistUpdatedListener',
+ function(msg, listener) {
+ if (msg.action === 'onplaylistupdated') {
+ native_.callIfPossible(
+ listener[msg.action],
+ msg.serverName,
+ new MediaControllerPlaylist(msg)
+ );
+ }
+ if (msg.action === 'onplaylistdeleted') {
+ native_.callIfPossible(listener[msg.action], msg.serverName, msg.name);
+ }
+ }
+);
+
+var ClientAbilityChangeListener = new ListenerManager(
+ native_,
+ '_ClientAbilityChangeListener',
+ function(msg, listener) {
+ if (msg.action === 'onplaybackabilitychanged') {
+ native_.callIfPossible(
+ listener[msg.action],
+ new MediaControllerServerInfo(msg),
+ new MediaControllerPlaybackAbilitiesInfo(msg.name)
+ );
+ }
+ if (msg.action === 'ondisplaymodeabilitychanged') {
+ native_.callIfPossible(
+ listener[msg.action],
+ new MediaControllerServerInfo(msg),
+ new MediaControllerDisplayModeAbilitiesInfo(msg.name)
+ );
+ }
+ if (msg.action === 'ondisplayrotationabilitychanged') {
+ native_.callIfPossible(
+ listener[msg.action],
+ new MediaControllerServerInfo(msg),
+ new MediaControllerDisplayRotationAbilitiesInfo(msg.name)
+ );
+ }
+ if (msg.action === 'onsimpleabilitychanged') {
+ native_.callIfPossible(
+ listener[msg.action],
+ new MediaControllerServerInfo(msg),
+ msg.type,
+ msg.ability
+ );
}
}
);
REWIND: 'REWIND'
};
+var MediaControllerRepeatState = {
+ REPEAT_OFF: 'REPEAT_OFF',
+ REPEAT_ONE: 'REPEAT_ONE',
+ REPEAT_ALL: 'REPEAT_ALL'
+};
+
+var MediaControllerContentAgeRating = {
+ ALL: 'ALL',
+ ONE: '1',
+ TWO: '2',
+ THREE: '3',
+ FOUR: '4',
+ FIVE: '5',
+ SIX: '6',
+ SEVEN: '7',
+ EIGHT: '8',
+ NINE: '9',
+ TEN: '10',
+ ELEVEN: '11',
+ TWELVE: '12',
+ THIRTEEN: '13',
+ FOURTEEN: '14',
+ FIFTEEN: '15',
+ SIXTEEN: '16',
+ SEVENTEEN: '17',
+ EIGHTEEN: '18',
+ NINETEEN: '19'
+};
+
+var MediaControllerSearchCategory = {
+ NO_CATEGORY: 'NO_CATEGORY',
+ TITLE: 'TITLE',
+ ARTIST: 'ARTIST',
+ ALBUM: 'ALBUM',
+ GENRE: 'GENRE',
+ TPO: 'TPO'
+};
+
var MediaControllerContentType = {
IMAGE: 'IMAGE',
MUSIC: 'MUSIC',
UNDECIDED: 'UNDECIDED'
};
+var MediaControllerAbilitySupport = {
+ YES: 'YES',
+ NO: 'NO',
+ UNDECIDED: 'UNDECIDED'
+};
+
+var MediaControllerSimpleAbility = {
+ PLAYBACK_POSITION: 'PLAYBACK_POSITION',
+ SHUFFLE: 'SHUFFLE',
+ REPEAT: 'REPEAT',
+ PLAYLIST: 'PLAYLIST',
+ CLIENT_CUSTOM: 'CLIENT_CUSTOM',
+ SEARCH: 'SEARCH',
+ SUBTITLES: 'SUBTITLES',
+ MODE_360: 'MODE_360'
+};
+
+var MediaControllerDisplayModeType = {
+ LETTER_BOX: 'LETTER_BOX',
+ ORIGIN_SIZE: 'ORIGIN_SIZE',
+ FULL_SCREEN: 'FULL_SCREEN',
+ CROPPED_FULL: 'CROPPED_FULL'
+};
+
+var MediaControllerDisplayRotationType = {
+ ROTATION_NONE: 'ROTATION_NONE',
+ ROTATION_90: 'ROTATION_90',
+ ROTATION_180: 'ROTATION_180',
+ ROTATION_270: 'ROTATION_270'
+};
+
function MediaControllerManager() {}
MediaControllerManager.prototype.getClient = function() {
- var result = native_.callSync('MediaControllerManager_getClient', {});
+ var result = native_.callSync('MediaControllerManagerGetClient', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
};
MediaControllerManager.prototype.createServer = function() {
- var result = native_.callSync('MediaControllerManager_createServer', {});
+ var result = native_.callSync('MediaControllerManagerCreateServer', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
var _description = '';
var _trackNum = '';
var _picture = '';
+ var _seasonNumber = 0;
+ var _seasonTitle = null;
+ var _episodeNumber = 0;
+ var _episodeTitle = null;
+ var _resolutionWidth = 0;
+ var _resolutionHeight = 0;
Object.defineProperties(this, {
title: {
get: function() {
_picture = converter_.toString(v);
},
enumerable: true
+ },
+ seasonNumber: {
+ get: function() {
+ return _seasonNumber;
+ },
+ set: function(v) {
+ _seasonNumber = converter_.toLong(v);
+ },
+ enumerable: true
+ },
+ seasonTitle: {
+ get: function() {
+ return _seasonTitle;
+ },
+ set: function(v) {
+ _seasonTitle = converter_.toString(v, true);
+ },
+ enumerable: true,
+ nullable: true
+ },
+ episodeNumber: {
+ get: function() {
+ return _episodeNumber;
+ },
+ set: function(v) {
+ _episodeNumber = converter_.toLong(v);
+ },
+ enumerable: true
+ },
+ episodeTitle: {
+ get: function() {
+ return _episodeTitle;
+ },
+ set: function(v) {
+ _episodeTitle = converter_.toString(v, true);
+ },
+ enumerable: true,
+ nullable: true
+ },
+ resolutionWidth: {
+ get: function() {
+ return _resolutionWidth;
+ },
+ set: function(v) {
+ _resolutionWidth = v < 0 ? _resolutionWidth : converter_.toLong(v);
+ },
+ enumerable: true
+ },
+ resolutionHeight: {
+ get: function() {
+ return _resolutionHeight;
+ },
+ set: function(v) {
+ _resolutionHeight = v < 0 ? _resolutionHeight : converter_.toLong(v);
+ },
+ enumerable: true
}
});
var _position = 0;
var _shuffleMode = false;
var _repeatMode = false;
+ var _contentType = MediaControllerContentType.UNDECIDED;
+ var _repeatState = MediaControllerRepeatState.REPEAT_ALL;
+ var _ageRating = MediaControllerContentAgeRating.ALL;
var _metadata = new MediaControllerMetadata();
+ var _index = null;
+ var _playlistName = null;
Object.defineProperties(this, {
state: {
get: function() {
},
enumerable: true
},
+ ageRating: {
+ get: function() {
+ return _ageRating;
+ },
+ set: function(v) {
+ _ageRating = edit_.isAllowed && v ? v : _ageRating;
+ },
+ enumerable: true
+ },
shuffleMode: {
get: function() {
return _shuffleMode;
},
repeatMode: {
get: function() {
+ utils_.printDeprecationWarningFor('repeatMode', 'repeatState');
return _repeatMode;
},
set: function(v) {
},
enumerable: true
},
+ repeatState: {
+ get: function() {
+ return _repeatState;
+ },
+ set: function(v) {
+ _repeatState = edit_.isAllowed && v ? v : _repeatState;
+ },
+ enumerable: true
+ },
+ contentType: {
+ get: function() {
+ return _contentType;
+ },
+ set: function(v) {
+ _contentType = edit_.isAllowed && v ? v : _contentType;
+ },
+ enumerable: true
+ },
metadata: {
get: function() {
return _metadata;
edit_.isAllowed && v ? new MediaControllerMetadata(v) : _metadata;
},
enumerable: true
+ },
+ index: {
+ get: function() {
+ return _index;
+ },
+ set: function(v) {
+ _index = edit_.isAllowed && v ? v : _index;
+ },
+ enumerable: true
+ },
+ playlistName: {
+ get: function() {
+ return _playlistName;
+ },
+ set: function(v) {
+ _playlistName = edit_.isAllowed && v ? v : _playlistName;
+ },
+ enumerable: true
}
});
}
};
-function MediaControllerServer(data) {
+var MediaControllerAbilities = function() {
+ var _playbackPosition = MediaControllerAbilitySupport.UNDECIDED,
+ _shuffle = MediaControllerAbilitySupport.UNDECIDED,
+ _repeat = MediaControllerAbilitySupport.UNDECIDED,
+ _playlist = MediaControllerAbilitySupport.UNDECIDED,
+ _clientCustom = MediaControllerAbilitySupport.UNDECIDED,
+ _search = MediaControllerAbilitySupport.UNDECIDED,
+ _subtitles = MediaControllerAbilitySupport.NO,
+ _mode360 = MediaControllerAbilitySupport.NO;
+
Object.defineProperties(this, {
- playbackInfo: {
- value: new MediaControllerPlaybackInfo(data),
- writable: false,
+ playback: {
+ value: new MediaControllerPlaybackAbilities(),
+ enumerable: true
+ },
+ displayMode: {
+ value: new MediaControllerDisplayModeAbilities(),
+ enumerable: true
+ },
+ displayRotation: {
+ value: new MediaControllerDisplayRotationAbilities(),
+ enumerable: true
+ },
+ playbackPosition: {
+ get: function() {
+ return _playbackPosition;
+ },
+ set: function(val) {
+ if (val !== _playbackPosition) {
+ setSimpleAbility(MediaControllerSimpleAbility.PLAYBACK_POSITION, val);
+ _playbackPosition = val;
+ }
+ },
+ enumerable: true
+ },
+ shuffle: {
+ get: function() {
+ return _shuffle;
+ },
+ set: function(val) {
+ if (val !== _shuffle) {
+ setSimpleAbility(MediaControllerSimpleAbility.SHUFFLE, val);
+ _shuffle = val;
+ }
+ },
+ enumerable: true
+ },
+ repeat: {
+ get: function() {
+ return _repeat;
+ },
+ set: function(val) {
+ if (val !== _repeat) {
+ setSimpleAbility(MediaControllerSimpleAbility.REPEAT, val);
+ _repeat = val;
+ }
+ },
+ enumerable: true
+ },
+ playlist: {
+ get: function() {
+ return _playlist;
+ },
+ set: function(val) {
+ if (val !== _playlist) {
+ setSimpleAbility(MediaControllerSimpleAbility.PLAYLIST, val);
+ _playlist = val;
+ }
+ },
+ enumerable: true
+ },
+ clientCustom: {
+ get: function() {
+ return _clientCustom;
+ },
+ set: function(val) {
+ if (val !== _clientCustom) {
+ setSimpleAbility(MediaControllerSimpleAbility.CLIENT_CUSTOM, val);
+ _clientCustom = val;
+ }
+ },
+ enumerable: true
+ },
+ search: {
+ get: function() {
+ return _search;
+ },
+ set: function(val) {
+ if (val !== _search) {
+ setSimpleAbility(MediaControllerSimpleAbility.SEARCH, val);
+ _search = val;
+ }
+ },
+ enumerable: true
+ },
+ subtitles: {
+ get: function() {
+ return _subtitles;
+ },
+ set: function(val) {
+ if (val !== _subtitles) {
+ setSimpleAbility(MediaControllerSimpleAbility.SUBTITLES, val);
+ _subtitles = val;
+ }
+ },
+ enumerable: true
+ },
+ mode360: {
+ get: function() {
+ return _mode360;
+ },
+ set: function(val) {
+ if (val !== _mode360) {
+ setSimpleAbility(MediaControllerSimpleAbility.MODE_360, val);
+ _mode360 = val;
+ }
+ },
enumerable: true
}
});
-}
-
-MediaControllerServer.prototype.updatePlaybackState = function(state) {
- var args = validator_.validateArgs(arguments, [
- {
- name: 'state',
- type: types_.ENUM,
- values: Object.keys(MediaControllerPlaybackState)
- }
- ]);
-
- var data = {
- state: args.state
- };
-
- var result = native_.callSync('MediaControllerServer_updatePlaybackState', data);
+};
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+var MediaControllerPlaybackAbilities = function() {
+ var _play = MediaControllerAbilitySupport.UNDECIDED,
+ _pause = MediaControllerAbilitySupport.UNDECIDED,
+ _stop = MediaControllerAbilitySupport.UNDECIDED,
+ _next = MediaControllerAbilitySupport.UNDECIDED,
+ _prev = MediaControllerAbilitySupport.UNDECIDED,
+ _forward = MediaControllerAbilitySupport.UNDECIDED,
+ _rewind = MediaControllerAbilitySupport.UNDECIDED,
+ _togglePlayPause = MediaControllerAbilitySupport.UNDECIDED;
- edit_.allow();
- this.playbackInfo.state = args.state;
- edit_.disallow();
-};
+ Object.defineProperties(this, {
+ play: {
+ get: function() {
+ return _play;
+ },
+ set: function(val) {
+ checkSupportValue(val);
+ _play = val;
+ },
+ enumerable: true
+ },
+ pause: {
+ get: function() {
+ return _pause;
+ },
+ set: function(val) {
+ checkSupportValue(val);
+ _pause = val;
+ },
+ enumerable: true
+ },
+ stop: {
+ get: function() {
+ return _stop;
+ },
+ set: function(val) {
+ checkSupportValue(val);
+ _stop = val;
+ },
+ enumerable: true
+ },
+ next: {
+ get: function() {
+ return _next;
+ },
+ set: function(val) {
+ checkSupportValue(val);
+ _next = val;
+ },
+ enumerable: true
+ },
+ prev: {
+ get: function() {
+ return _prev;
+ },
+ set: function(val) {
+ checkSupportValue(val);
+ _prev = val;
+ },
+ enumerable: true
+ },
+ forward: {
+ get: function() {
+ return _forward;
+ },
+ set: function(val) {
+ checkSupportValue(val);
+ _forward = val;
+ },
+ enumerable: true
+ },
+ rewind: {
+ get: function() {
+ return _rewind;
+ },
+ set: function(val) {
+ checkSupportValue(val);
+ _rewind = val;
+ },
+ enumerable: true
+ },
+ togglePlayPause: {
+ get: function() {
+ return _togglePlayPause;
+ },
+ set: function(val) {
+ checkSupportValue(val);
+ _togglePlayPause = val;
+ },
+ enumerable: true
+ }
+ });
-MediaControllerServer.prototype.updatePlaybackPosition = function(position) {
- var args = validator_.validateArgs(arguments, [
- { name: 'position', type: types_.UNSIGNED_LONG_LONG }
- ]);
+ this.saveAbilities = function() {
+ var data = {
+ PLAY: _play,
+ PAUSE: _pause,
+ STOP: _stop,
+ NEXT: _next,
+ PREV: _prev,
+ FORWARD: _forward,
+ REWIND: _rewind,
+ TOGGLE_PLAY_PAUSE: _togglePlayPause
+ };
- var data = {
- position: args.position
+ var result = native_.callSync(
+ 'MediaControllerServerSavePlaybackAbilities',
+ data
+ );
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
};
+};
- var result = native_.callSync('MediaControllerServer_updatePlaybackPosition', data);
-
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+var MediaControllerDisplayModeAbilities = function() {
+ var _letterBox = MediaControllerAbilitySupport.NO,
+ _originSize = MediaControllerAbilitySupport.NO,
+ _fullScreen = MediaControllerAbilitySupport.NO,
+ _croppedFull = MediaControllerAbilitySupport.NO;
+
+ Object.defineProperties(this, {
+ letterBox: {
+ get: function() {
+ return _letterBox;
+ },
+ set: function(val) {
+ if (val !== _letterBox) {
+ setDisplayModeAbility(MediaControllerDisplayModeType.LETTER_BOX, val);
+ _letterBox = val;
+ }
+ },
+ enumerable: true
+ },
+ originSize: {
+ get: function() {
+ return _originSize;
+ },
+ set: function(val) {
+ if (val !== _originSize) {
+ setDisplayModeAbility(
+ MediaControllerDisplayModeType.ORIGIN_SIZE,
+ val
+ );
+ _originSize = val;
+ }
+ },
+ enumerable: true
+ },
+ fullScreen: {
+ get: function() {
+ return _fullScreen;
+ },
+ set: function(val) {
+ if (val !== _fullScreen) {
+ setDisplayModeAbility(
+ MediaControllerDisplayModeType.FULL_SCREEN,
+ val
+ );
+ _fullScreen = val;
+ }
+ },
+ enumerable: true
+ },
+ croppedFull: {
+ get: function() {
+ return _croppedFull;
+ },
+ set: function(val) {
+ if (val !== _croppedFull) {
+ setDisplayModeAbility(
+ MediaControllerDisplayModeType.CROPPED_FULL,
+ val
+ );
+ _croppedFull = val;
+ }
+ },
+ enumerable: true
+ }
+ });
+};
+
+var MediaControllerDisplayRotationAbilities = function() {
+ var _rotationNone = MediaControllerAbilitySupport.NO,
+ _rotation90 = MediaControllerAbilitySupport.NO,
+ _rotation180 = MediaControllerAbilitySupport.NO,
+ _rotation270 = MediaControllerAbilitySupport.NO;
+
+ Object.defineProperties(this, {
+ rotationNone: {
+ get: function() {
+ return _rotationNone;
+ },
+ set: function(val) {
+ if (val !== _rotationNone) {
+ setDisplayRotationAbility(
+ MediaControllerDisplayRotationType.ROTATION_NONE,
+ val
+ );
+ _rotationNone = val;
+ }
+ },
+ enumerable: true
+ },
+ rotation90: {
+ get: function() {
+ return _rotation90;
+ },
+ set: function(val) {
+ if (val !== _rotation90) {
+ setDisplayRotationAbility(
+ MediaControllerDisplayRotationType.ROTATION_90,
+ val
+ );
+ _rotation90 = val;
+ }
+ },
+ enumerable: true
+ },
+ rotation180: {
+ get: function() {
+ return _rotation180;
+ },
+ set: function(val) {
+ if (val !== _rotation180) {
+ setDisplayRotationAbility(
+ MediaControllerDisplayRotationType.ROTATION_180,
+ val
+ );
+ _rotation180 = val;
+ }
+ },
+ enumerable: true
+ },
+ rotation270: {
+ get: function() {
+ return _rotation270;
+ },
+ set: function(val) {
+ if (val !== _rotation270) {
+ setDisplayRotationAbility(
+ MediaControllerDisplayRotationType.ROTATION_270,
+ val
+ );
+ _rotation270 = val;
+ }
+ },
+ enumerable: true
+ }
+ });
+};
+
+var MediaControllerAbilitiesInfo = function(serverName) {
+ Object.defineProperties(this, {
+ playback: {
+ value: new MediaControllerPlaybackAbilitiesInfo(serverName),
+ enumerable: true,
+ writable: false
+ },
+ displayMode: {
+ value: new MediaControllerDisplayModeAbilitiesInfo(serverName),
+ enumerable: true,
+ writable: false
+ },
+ displayRotation: {
+ value: new MediaControllerDisplayRotationAbilitiesInfo(serverName),
+ enumerable: true,
+ writable: false
+ },
+ playbackPosition: {
+ get: function() {
+ return getSimpleAbility(
+ serverName,
+ MediaControllerSimpleAbility.PLAYBACK_POSITION
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ shuffle: {
+ get: function() {
+ return getSimpleAbility(serverName, MediaControllerSimpleAbility.SHUFFLE);
+ },
+ set: function() {},
+ enumerable: true
+ },
+ repeat: {
+ get: function() {
+ return getSimpleAbility(serverName, MediaControllerSimpleAbility.REPEAT);
+ },
+ set: function() {},
+ enumerable: true
+ },
+ playlist: {
+ get: function() {
+ return getSimpleAbility(
+ serverName,
+ MediaControllerSimpleAbility.PLAYLIST
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ clientCustom: {
+ get: function() {
+ return getSimpleAbility(
+ serverName,
+ MediaControllerSimpleAbility.CLIENT_CUSTOM
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ search: {
+ get: function() {
+ return getSimpleAbility(serverName, MediaControllerSimpleAbility.SEARCH);
+ },
+ set: function() {},
+ enumerable: true
+ },
+ subtitles: {
+ get: function() {
+ return getSimpleAbility(
+ serverName,
+ MediaControllerSimpleAbility.SUBTITLES
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ mode360: {
+ get: function() {
+ return getSimpleAbility(
+ serverName,
+ MediaControllerSimpleAbility.MODE_360
+ );
+ },
+ set: function() {},
+ enumerable: true
+ }
+ });
+
+ this.subscribe = function() {
+ var data = {
+ serverName: serverName
+ };
+ var result = native_.callSync('MediaControllerAbilitiesInfoSubscribe', data);
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+ };
+
+ this.unsubscribe = function() {
+ var data = {
+ serverName: serverName
+ };
+ var result = native_.callSync('MediaControllerAbilitiesInfoUnsubscribe', data);
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+ };
+};
+
+var MediaControllerPlaybackAbilitiesInfo = function(serverName) {
+ Object.defineProperties(this, {
+ play: {
+ get: function() {
+ return getPlaybackAbility(serverName, MediaControllerPlaybackState.PLAY);
+ },
+ set: function() {},
+ enumerable: true
+ },
+ pause: {
+ get: function() {
+ return getPlaybackAbility(serverName, MediaControllerPlaybackState.PAUSE);
+ },
+ set: function() {},
+ enumerable: true
+ },
+ stop: {
+ get: function() {
+ return getPlaybackAbility(serverName, MediaControllerPlaybackState.STOP);
+ },
+ set: function() {},
+ enumerable: true
+ },
+ next: {
+ get: function() {
+ return getPlaybackAbility(serverName, MediaControllerPlaybackState.NEXT);
+ },
+ set: function() {},
+ enumerable: true
+ },
+ prev: {
+ get: function() {
+ return getPlaybackAbility(serverName, MediaControllerPlaybackState.PREV);
+ },
+ set: function() {},
+ enumerable: true
+ },
+ forward: {
+ get: function() {
+ return getPlaybackAbility(
+ serverName,
+ MediaControllerPlaybackState.FORWARD
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ rewind: {
+ get: function() {
+ return getPlaybackAbility(
+ serverName,
+ MediaControllerPlaybackState.REWIND
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ togglePlayPause: {
+ get: function() {
+ return getPlaybackAbility(serverName, 'TOGGLE_PLAY_PAUSE');
+ },
+ set: function() {},
+ enumerable: true
+ }
+ });
+};
+
+var MediaControllerDisplayModeAbilitiesInfo = function(serverName) {
+ Object.defineProperties(this, {
+ letterBox: {
+ get: function() {
+ return getDisplayModeAbility(
+ serverName,
+ MediaControllerDisplayModeType.LETTER_BOX
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ originSize: {
+ get: function() {
+ return getDisplayModeAbility(
+ serverName,
+ MediaControllerDisplayModeType.ORIGIN_SIZE
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ fullScreen: {
+ get: function() {
+ return getDisplayModeAbility(
+ serverName,
+ MediaControllerDisplayModeType.FULL_SCREEN
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ croppedFull: {
+ get: function() {
+ return getDisplayModeAbility(
+ serverName,
+ MediaControllerDisplayModeType.CROPPED_FULL
+ );
+ },
+ set: function() {},
+ enumerable: true
+ }
+ });
+};
+
+var MediaControllerDisplayRotationAbilitiesInfo = function(serverName) {
+ Object.defineProperties(this, {
+ rotationNone: {
+ get: function() {
+ return getDisplayRotationAbility(
+ serverName,
+ MediaControllerDisplayRotationType.ROTATION_NONE
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ rotation90: {
+ get: function() {
+ return getDisplayRotationAbility(
+ serverName,
+ MediaControllerDisplayRotationType.ROTATION_90
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ rotation180: {
+ get: function() {
+ return getDisplayRotationAbility(
+ serverName,
+ MediaControllerDisplayRotationType.ROTATION_180
+ );
+ },
+ set: function() {},
+ enumerable: true
+ },
+ rotation270: {
+ get: function() {
+ return getDisplayRotationAbility(
+ serverName,
+ MediaControllerDisplayRotationType.ROTATION_270
+ );
+ },
+ set: function() {},
+ enumerable: true
+ }
+ });
+};
+
+// subtitles
+var MediaControllerSubtitles = function() {
+ // the default value is false
+ var _enabled = false;
+ Object.defineProperties(this, {
+ enabled: {
+ get: function() {
+ return _enabled;
+ },
+ set: function(v) {
+ var data = {
+ enabled: converter_.toBoolean(v)
+ };
+ if (data.enabled !== _enabled) {
+ var result = native_.callSync(
+ 'MediaControllerSubtitlesUpdateEnabled',
+ data
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ _enabled = data.enabled;
+ }
+ },
+ enumerable: true
+ }
+ });
+};
+
+var MediaControllerSubtitlesListener = new ListenerManager(
+ native_,
+ '_MediaControllerSubtitlesListener',
+ function(msg, listener) {
+ var reply = listener(msg.clientName, msg.enabled);
+
+ if (!(reply instanceof RequestReply)) {
+ reply = new RequestReply(
+ xwalk.utils.type.isNullOrUndefined(reply) ? null : reply,
+ 0
+ );
+ }
+
+ var nativeData = {
+ clientName: msg.clientName,
+ requestId: msg.requestId,
+ reply: reply
+ };
+ var result = native_.callSync('MediaControllerServerReplyCommand', nativeData);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+);
+
+MediaControllerSubtitles.prototype.addChangeRequestListener = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'listener',
+ type: types_.FUNCTION,
+ optional: false,
+ nullable: false
+ }
+ ]);
+
+ if (type_.isEmptyObject(MediaControllerSubtitlesListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerSubtitlesAddChangeRequestListener',
+ {
+ listenerId: MediaControllerSubtitlesListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ return MediaControllerSubtitlesListener.addListener(args.listener);
+};
+
+MediaControllerSubtitles.prototype.removeChangeRequestListener = function(watchId) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ MediaControllerSubtitlesListener.removeListener(args.watchId);
+
+ if (type_.isEmptyObject(MediaControllerSubtitlesListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerSubtitlesRemoveChangeRequestListener'
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+};
+
+var SubtitlesChangeListener = new ListenerManager(
+ native_,
+ '_SubtitlesChangeListener',
+ function(msg, listener) {
+ listener(msg.enabled);
+ }
+);
+
+var MediaControllerSubtitlesInfo = function(name) {
+ var _serverName = name;
+ Object.defineProperties(this, {
+ enabled: {
+ get: function() {
+ var result = native_.callSync('MediaControllerSubtitlesInfoGetEnabled', {
+ name: _serverName
+ });
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+ return native_.getResultObject(result);
+ },
+ set: function(v) {},
+ enumerable: true
+ }
+ });
+
+ this.sendRequest = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'enabled',
+ type: types_.BOOLEAN
+ },
+ {
+ name: 'replyCallback',
+ type: types_.FUNCTION
+ }
+ ]);
+ var callback = function(result) {
+ native_.callIfPossible(
+ args.replyCallback,
+ native_.getResultObject(result).data,
+ native_.getResultObject(result).code
+ );
+ };
+
+ var nativeData = {
+ enabled: args.enabled,
+ name: _serverName,
+ listenerId: ReplyCommandListener.listenerName
+ };
+
+ var result = native_.callSync(
+ 'MediaControllerSubtitlesInfoSendRequest',
+ nativeData
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ var replyListenerId = ReplyCommandListener.addListener(callback);
+ ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
+ };
+
+ this.addModeChangeListener = function(listener) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'listener', type: types_.FUNCTION }
+ ]);
+
+ if (type_.isEmptyObject(SubtitlesChangeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerSubtitlesInfoAddModeChangeListener',
+ {
+ listenerId: SubtitlesChangeListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ return SubtitlesChangeListener.addServerInfoListener(args.listener, _serverName);
+ };
+
+ this.removeModeChangeListener = function(watchId) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ SubtitlesChangeListener.removeServerInfoListener(args.watchId);
+
+ if (type_.isEmptyObject(SubtitlesChangeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerSubtitlesInfoRemoveModeChangeListener'
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ };
+};
+
+// mode360
+var MediaControllerMode360 = function() {
+ // the default value is false
+ var _enabled = false;
+ Object.defineProperties(this, {
+ enabled: {
+ get: function() {
+ return _enabled;
+ },
+ set: function(v) {
+ var data = {
+ enabled: converter_.toBoolean(v)
+ };
+ if (data.enabled !== _enabled) {
+ var result = native_.callSync(
+ 'MediaControllerMode360UpdateEnabled',
+ data
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ _enabled = data.enabled;
+ }
+ },
+ enumerable: true
+ }
+ });
+};
+
+var MediaControllerMode360Listener = new ListenerManager(
+ native_,
+ '_MediaControllerMode360Listener',
+ function(msg, listener) {
+ var reply = listener(msg.clientName, msg.enabled);
+
+ if (!(reply instanceof RequestReply)) {
+ reply = new RequestReply(
+ xwalk.utils.type.isNullOrUndefined(reply) ? null : reply,
+ 0
+ );
+ }
+
+ var nativeData = {
+ clientName: msg.clientName,
+ requestId: msg.requestId,
+ reply: reply
+ };
+ var result = native_.callSync('MediaControllerServerReplyCommand', nativeData);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+);
+
+MediaControllerMode360.prototype.addChangeRequestListener = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'listener',
+ type: types_.FUNCTION,
+ optional: false,
+ nullable: false
+ }
+ ]);
+
+ if (type_.isEmptyObject(MediaControllerMode360Listener.listeners)) {
+ var result = native_.callSync('MediaControllerMode360AddChangeRequestListener', {
+ listenerId: MediaControllerMode360Listener.listenerName
+ });
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ return MediaControllerMode360Listener.addListener(args.listener);
+};
+
+MediaControllerMode360.prototype.removeChangeRequestListener = function(watchId) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ MediaControllerMode360Listener.removeListener(args.watchId);
+
+ if (type_.isEmptyObject(MediaControllerMode360Listener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerMode360RemoveChangeRequestListener'
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+};
+
+var Mode360ChangeListener = new ListenerManager(
+ native_,
+ '_Mode360ChangeListener',
+ function(msg, listener) {
+ listener(msg.enabled);
+ }
+);
+
+var MediaControllerMode360Info = function(name) {
+ var _serverName = name;
+ Object.defineProperties(this, {
+ enabled: {
+ get: function() {
+ var result = native_.callSync('MediaControllerMode360InfoGetEnabled', {
+ name: _serverName
+ });
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+ return native_.getResultObject(result);
+ },
+ set: function(v) {},
+ enumerable: true
+ }
+ });
+
+ this.sendRequest = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'enabled',
+ type: types_.BOOLEAN
+ },
+ {
+ name: 'replyCallback',
+ type: types_.FUNCTION
+ }
+ ]);
+ var callback = function(result) {
+ native_.callIfPossible(
+ args.replyCallback,
+ native_.getResultObject(result).data,
+ native_.getResultObject(result).code
+ );
+ };
+
+ var nativeData = {
+ enabled: args.enabled,
+ name: _serverName,
+ listenerId: ReplyCommandListener.listenerName
+ };
+
+ var result = native_.callSync(
+ 'MediaControllerMode360InfoSendRequest',
+ nativeData
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ var replyListenerId = ReplyCommandListener.addListener(callback);
+ ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
+ };
+
+ this.addModeChangeListener = function(listener) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'listener', type: types_.FUNCTION }
+ ]);
+
+ if (type_.isEmptyObject(Mode360ChangeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerMode360InfoAddModeChangeListener',
+ {
+ listenerId: Mode360ChangeListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ return Mode360ChangeListener.addServerInfoListener(args.listener, _serverName);
+ };
+
+ this.removeModeChangeListener = function(watchId) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ Mode360ChangeListener.removeServerInfoListener(args.watchId);
+
+ if (type_.isEmptyObject(Mode360ChangeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerMode360InfoRemoveModeChangeListener'
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ };
+};
+
+// displayMode
+var MediaControllerDisplayMode = function() {
+ // the default value is MediaControllerDisplayModeType.FULL_SCREEN
+ var _type = MediaControllerDisplayModeType.FULL_SCREEN;
+ Object.defineProperties(this, {
+ type: {
+ get: function() {
+ return _type;
+ },
+ set: function(v) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'type',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerDisplayModeType)
+ }
+ ]);
+ if (args.type !== _type) {
+ var result = native_.callSync(
+ 'MediaControllerDisplayModeUpdateType',
+ args
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ _type = args.type;
+ }
+ },
+ enumerable: true
+ }
+ });
+};
+
+var MediaControllerDisplayModeListener = new ListenerManager(
+ native_,
+ '_MediaControllerDisplayModeListener',
+ function(msg, listener) {
+ var reply = listener(msg.clientName, msg.type);
+
+ if (!(reply instanceof RequestReply)) {
+ reply = new RequestReply(
+ xwalk.utils.type.isNullOrUndefined(reply) ? null : reply,
+ 0
+ );
+ }
+
+ var nativeData = {
+ clientName: msg.clientName,
+ requestId: msg.requestId,
+ reply: reply
+ };
+ var result = native_.callSync('MediaControllerServerReplyCommand', nativeData);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+);
+
+MediaControllerDisplayMode.prototype.addChangeRequestListener = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'listener',
+ type: types_.FUNCTION,
+ optional: false,
+ nullable: false
+ }
+ ]);
+
+ if (type_.isEmptyObject(MediaControllerDisplayModeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerDisplayModeAddChangeRequestListener',
+ {
+ listenerId: MediaControllerDisplayModeListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ return MediaControllerDisplayModeListener.addListener(args.listener);
+};
+
+MediaControllerDisplayMode.prototype.removeChangeRequestListener = function(watchId) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ MediaControllerDisplayModeListener.removeListener(args.watchId);
+
+ if (type_.isEmptyObject(MediaControllerDisplayModeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerDisplayModeRemoveChangeRequestListener'
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+};
+
+var DisplayModeChangeListener = new ListenerManager(
+ native_,
+ '_DisplayModeChangeListener',
+ function(msg, listener) {
+ listener(msg.displayMode);
+ }
+);
+
+var MediaControllerDisplayModeInfo = function(name) {
+ var _serverName = name;
+ Object.defineProperties(this, {
+ type: {
+ get: function() {
+ var result = native_.callSync('MediaControllerDisplayModeInfoGetType', {
+ name: _serverName
+ });
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+ return native_.getResultObject(result);
+ },
+ set: function(v) {},
+ enumerable: true
+ }
+ });
+
+ this.sendRequest = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'type',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerDisplayModeType)
+ },
+ {
+ name: 'replyCallback',
+ type: types_.FUNCTION
+ }
+ ]);
+ var callback = function(result) {
+ native_.callIfPossible(
+ args.replyCallback,
+ native_.getResultObject(result).data,
+ native_.getResultObject(result).code
+ );
+ };
+
+ var nativeData = {
+ type: args.type,
+ name: _serverName,
+ listenerId: ReplyCommandListener.listenerName
+ };
+
+ var result = native_.callSync(
+ 'MediaControllerDisplayModeInfoSendType',
+ nativeData
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ var replyListenerId = ReplyCommandListener.addListener(callback);
+ ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
+ };
+
+ this.addModeChangeListener = function(listener) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'listener', type: types_.FUNCTION }
+ ]);
+
+ if (type_.isEmptyObject(DisplayModeChangeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerDisplayModeInfoAddModeChangeListener',
+ {
+ listenerId: DisplayModeChangeListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ return DisplayModeChangeListener.addServerInfoListener(
+ args.listener,
+ _serverName
+ );
+ };
+ this.removeModeChangeListener = function(watchId) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ DisplayModeChangeListener.removeServerInfoListener(args.watchId);
+
+ if (type_.isEmptyObject(DisplayModeChangeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerDisplayModeInfoRemoveModeChangeListener'
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ };
+};
+
+// displayRotation
+var MediaControllerDisplayRotation = function() {
+ // the default value is "ROTATION_NONE"
+ var _displayRotation = MediaControllerDisplayRotationType.ROTATION_NONE;
+ Object.defineProperties(this, {
+ displayRotation: {
+ get: function() {
+ return _displayRotation;
+ },
+ set: function(v) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'displayRotation',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerDisplayRotationType)
+ }
+ ]);
+ if (args.displayRotation == _displayRotation) {
+ return;
+ }
+ var result = native_.callSync(
+ 'MediaControllerDisplayRotationUpdate',
+ args
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ _displayRotation = args.displayRotation;
+ },
+ enumerable: true
+ }
+ });
+};
+
+var MediaControllerDisplayRotationListener = new ListenerManager(
+ native_,
+ '_MediaControllerDisplayRotationListener',
+ function(msg, listener) {
+ var reply = listener(msg.clientName, msg.displayRotation);
+
+ if (!(reply instanceof RequestReply)) {
+ reply = new RequestReply(type_.isNullOrUndefined(reply) ? null : reply, 0);
+ }
+
+ var nativeData = {
+ clientName: msg.clientName,
+ requestId: msg.requestId,
+ reply: reply
+ };
+ var result = native_.callSync('MediaControllerServerReplyCommand', nativeData);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+);
+
+MediaControllerDisplayRotation.prototype.addChangeRequestListener = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'listener',
+ type: types_.FUNCTION,
+ optional: false,
+ nullable: false
+ }
+ ]);
+
+ if (type_.isEmptyObject(MediaControllerDisplayRotationListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerDisplayRotationAddChangeRequestListener',
+ {
+ listenerId: MediaControllerDisplayRotationListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ return MediaControllerDisplayRotationListener.addListener(args.listener);
+};
+
+MediaControllerDisplayRotation.prototype.removeChangeRequestListener = function(watchId) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ MediaControllerDisplayRotationListener.removeListener(args.watchId);
+
+ if (type_.isEmptyObject(MediaControllerDisplayRotationListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerDisplayRotationRemoveChangeRequestListener'
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+};
+
+var MediaControllerDisplayRotationChangeListener = new ListenerManager(
+ native_,
+ '_MediaControllerDisplayRotationChangeListener',
+ function(msg, listener) {
+ listener(msg.displayRotation);
+ }
+);
+
+var MediaControllerDisplayRotationInfo = function(name) {
+ var _serverName = name;
+ Object.defineProperties(this, {
+ displayRotation: {
+ get: function() {
+ var result = native_.callSync(
+ 'MediaControllerDisplayRotationInfoGet',
+ {
+ name: _serverName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+ return native_.getResultObject(result);
+ },
+ set: function(v) {},
+ enumerable: true
+ }
+ });
+
+ this.sendRequest = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'displayRotation',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerDisplayRotationType)
+ },
+ {
+ name: 'replyCallback',
+ type: types_.FUNCTION,
+ optional: false,
+ nullable: false
+ }
+ ]);
+ var callback = function(result) {
+ native_.callIfPossible(
+ args.replyCallback,
+ native_.getResultObject(result).data,
+ native_.getResultObject(result).code
+ );
+ };
+
+ var nativeData = {
+ displayRotation: args.displayRotation,
+ name: _serverName,
+ listenerId: ReplyCommandListener.listenerName
+ };
+
+ var result = native_.callSync(
+ 'MediaControllerDisplayRotationInfoSend',
+ nativeData
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ var replyListenerId = ReplyCommandListener.addListener(callback);
+ ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
+ };
+
+ this.addDisplayRotationChangeListener = function(listener) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'listener', type: types_.FUNCTION }
+ ]);
+
+ if (type_.isEmptyObject(MediaControllerDisplayRotationChangeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerDisplayRotationInfoAddChangeListener',
+ {
+ listenerId: MediaControllerDisplayRotationChangeListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ return MediaControllerDisplayRotationChangeListener.addServerInfoListener(
+ args.listener,
+ _serverName
+ );
+ };
+
+ this.removeDisplayRotationChangeListener = function(watchId) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ MediaControllerDisplayRotationChangeListener.removeServerInfoListener(
+ args.watchId
+ );
+
+ if (type_.isEmptyObject(MediaControllerDisplayRotationChangeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerDisplayRotationInfoRemoveChangeListener'
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ };
+};
+
+function MediaControllerServer(data) {
+ var _iconURI = null;
+
+ Object.defineProperties(this, {
+ playbackInfo: {
+ value: new MediaControllerPlaybackInfo(data),
+ writable: false,
+ enumerable: true
+ },
+ iconURI: {
+ get: function() {
+ return _iconURI;
+ },
+ set: function(v) {
+ _iconURI = edit_.isAllowed ? (v ? v : null) : _iconURI;
+ },
+ enumerable: true
+ },
+ abilities: {
+ value: new MediaControllerAbilities(),
+ enumerable: true
+ },
+ subtitles: {
+ value: new MediaControllerSubtitles(),
+ enumerable: true
+ },
+ mode360: {
+ value: new MediaControllerMode360(),
+ enumerable: true
+ },
+ displayMode: {
+ value: new MediaControllerDisplayMode(),
+ enumerable: true
+ },
+ displayRotation: {
+ value: new MediaControllerDisplayRotation(),
+ enumerable: true
+ }
+ });
+}
+
+MediaControllerServer.prototype.updatePlaybackState = function(state) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'state',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerPlaybackState)
+ }
+ ]);
+
+ var data = {
+ state: args.state
+ };
+
+ var result = native_.callSync('MediaControllerServerUpdatePlaybackState', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ edit_.allow();
+ this.playbackInfo.state = args.state;
+ edit_.disallow();
+};
+
+MediaControllerServer.prototype.updateIconURI = function(iconURI) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'iconURI', type: types_.STRING, nullable: true }
+ ]);
+
+ var data = {
+ iconURI: args.iconURI
+ };
+
+ var result = native_.callSync('MediaControllerServerUpdateIconURI', data);
+ if (native_.isFailure(result)) {
+ throw new WebAPIException(
+ WebAPIException.UNKNOWN_ERR,
+ native_.getErrorObject(result).message
+ );
+ }
+
+ edit_.allow();
+ this.iconURI = args.iconURI;
+ edit_.disallow();
+};
+
+MediaControllerServer.prototype.updatePlaybackPosition = function(position) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'position', type: types_.UNSIGNED_LONG_LONG }
+ ]);
+
+ var data = {
+ position: args.position
+ };
+
+ var result = native_.callSync('MediaControllerServerUpdatePlaybackPosition', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ edit_.allow();
+ this.playbackInfo.position = args.position;
+ edit_.disallow();
+};
+
+MediaControllerServer.prototype.updatePlaybackAgeRating = function(rating) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'rating',
+ type: types_.ENUM,
+ values: Object.values(MediaControllerContentAgeRating)
+ }
+ ]);
+
+ var data = {
+ rating: args.rating
+ };
+
+ var result = native_.callSync('MediaControllerServerUpdatePlaybackAgeRating', data);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ edit_.allow();
+ this.playbackInfo.ageRating = args.rating;
+ edit_.disallow();
+};
+
+MediaControllerServer.prototype.updatePlaybackContentType = function(contentType) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'contentType',
+ type: types_.ENUM,
+ values: Object.values(MediaControllerContentType)
+ }
+ ]);
+
+ var data = {
+ contentType: args.contentType
+ };
+
+ var result = native_.callSync(
+ 'MediaControllerServerUpdatePlaybackContentType',
+ data
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ edit_.allow();
+ this.playbackInfo.contentType = args.contentType;
+ edit_.disallow();
+};
+
+MediaControllerServer.prototype.updateShuffleMode = function(mode) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'mode', type: types_.BOOLEAN }
+ ]);
+
+ var data = {
+ mode: args.mode
+ };
+
+ var result = native_.callSync('MediaControllerServerUpdateShuffleMode', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ edit_.allow();
+ this.playbackInfo.shuffleMode = args.mode;
+ edit_.disallow();
+};
+
+MediaControllerServer.prototype.updateRepeatMode = function(mode) {
+ utils_.printDeprecationWarningFor('updateRepeatMode()', 'updateRepeatState()');
+ var args = validator_.validateArgs(arguments, [
+ { name: 'mode', type: types_.BOOLEAN }
+ ]);
+
+ var data = {
+ mode: args.mode
+ };
+
+ var result = native_.callSync('MediaControllerServerUpdateRepeatMode', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ edit_.allow();
+ this.playbackInfo.repeatMode = args.mode;
+ this.playbackInfo.repeatState = args.mode
+ ? MediaControllerRepeatState.REPEAT_ALL
+ : MediaControllerRepeatState.REPEAT_OFF;
+ edit_.disallow();
+};
+
+MediaControllerServer.prototype.updateRepeatState = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'state',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerRepeatState)
+ }
+ ]);
+
+ var data = {
+ state: args.state
+ };
+
+ var result = native_.callSync('MediaControllerServerUpdateRepeatState', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ edit_.allow();
+ this.playbackInfo.repeatState = args.state;
+ if (MediaControllerRepeatState.REPEAT_ONE !== args.state) {
+ this.playbackInfo.repeatMode =
+ args.state === MediaControllerRepeatState.REPEAT_ALL;
+ }
+ edit_.disallow();
+};
+
+MediaControllerServer.prototype.updateMetadata = function(metadata) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'metadata',
+ type: types_.PLATFORM_OBJECT,
+ values: MediaControllerMetadata
+ }
+ ]);
+
+ var data = {
+ metadata: args.metadata
+ };
+
+ var result = native_.callSync('MediaControllerServerUpdateMetadata', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
edit_.allow();
- this.playbackInfo.position = args.position;
+ this.playbackInfo.metadata = args.metadata;
edit_.disallow();
};
-MediaControllerServer.prototype.updateShuffleMode = function(mode) {
+MediaControllerServer.prototype.addChangeRequestPlaybackInfoListener = function(
+ listener
+) {
var args = validator_.validateArgs(arguments, [
- { name: 'mode', type: types_.BOOLEAN }
+ {
+ name: 'listener',
+ type: types_.LISTENER,
+ values: [
+ 'onplaybackstaterequest',
+ 'onplaybackpositionrequest',
+ 'onshufflemoderequest',
+ 'onrepeatmoderequest',
+ 'onrepeatstaterequest',
+ 'onplaybackitemrequest'
+ ]
+ }
+ ]);
+
+ if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerServerAddChangeRequestPlaybackInfoListener',
+ {
+ listenerId: ServerPlaybackInfoListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+
+ return ServerPlaybackInfoListener.addListener(args.listener);
+};
+
+MediaControllerServer.prototype.removeChangeRequestPlaybackInfoListener = function(
+ watchId
+) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ ServerPlaybackInfoListener.removeListener(args.watchId);
+
+ if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) {
+ native_.callSync('MediaControllerServerRemoveChangeRequestPlaybackInfoListener');
+ }
+};
+
+MediaControllerServer.prototype.addCommandListener = function(listener) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'listener', type: types_.FUNCTION }
+ ]);
+
+ if (type_.isEmptyObject(ServerCommandListener.listeners)) {
+ var result = native_.callSync('MediaControllerServerAddCommandListener', {
+ listenerId: ServerCommandListener.listenerName
+ });
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+
+ return ServerCommandListener.addListener(args.listener);
+};
+
+MediaControllerServer.prototype.removeCommandListener = function(watchId) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ ServerCommandListener.removeListener(args.watchId);
+
+ if (type_.isEmptyObject(ServerCommandListener.listeners)) {
+ native_.callSync('MediaControllerServerRemoveCommandListener');
+ }
+};
+
+MediaControllerServer.prototype.createPlaylist = function(name) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'name', type: types_.STRING }
+ ]);
+
+ var data = {
+ name: args.name
+ };
+
+ var result = native_.callSync('MediaControllerServerCreatePlaylist', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ return new MediaControllerPlaylist(native_.getResultObject(result));
+};
+
+MediaControllerServer.prototype.savePlaylist = function(
+ playlist,
+ successCallback,
+ errorCallback
+) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'playlist',
+ type: types_.PLATFORM_OBJECT,
+ values: MediaControllerPlaylist
+ },
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ var data = {
+ name: args.playlist.name
+ };
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ native_.callIfPossible(args.successCallback);
+ };
+
+ var result = native_.call('MediaControllerServerSavePlaylist', data, callback);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+};
+
+MediaControllerServer.prototype.deletePlaylist = function(
+ name,
+ successCallback,
+ errorCallback
+) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'name', type: types_.STRING },
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ var data = {
+ name: args.name
+ };
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ native_.callIfPossible(args.successCallback);
+ };
+
+ var result = native_.call('MediaControllerServerDeletePlaylist', data, callback);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+};
+
+MediaControllerServer.prototype.updatePlaybackItem = function(playlistName, index) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'playlistName', type: types_.STRING },
+ { name: 'index', type: types_.STRING }
+ ]);
+
+ var data = {
+ playlistName: args.playlistName,
+ index: args.index
+ };
+
+ var result = native_.callSync('MediaControllerServerUpdatePlaybackItem', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ edit_.allow();
+ this.playbackInfo.index = args.index;
+ this.playbackInfo.playlistName = args.playlistName;
+ edit_.disallow();
+};
+
+MediaControllerServer.prototype.getAllPlaylists = function(
+ successCallback,
+ errorCallback
+) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION,
+ optional: false,
+ nullable: false
+ },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ var data = native_.getResultObject(result);
+ var playlists = [];
+
+ for (var i = 0; i < data.length; i++) {
+ playlists.push(new MediaControllerPlaylist(data[i]));
+ }
+
+ native_.callIfPossible(args.successCallback, playlists);
+ };
+ var result = native_.call('MediaControllerServerGetAllPlaylists', {}, callback);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+};
+
+function RequestReply(data, code) {
+ xwalk.utils.validator.isConstructorCall(this, RequestReply);
+ this.code = xwalk.utils.converter.toLong(code);
+ this.data = xwalk.utils.type.isNullOrUndefined(data) ? null : new tizen.Bundle(data);
+}
+
+MediaControllerServer.prototype.setSearchRequestListener = function(listener) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'listener', type: types_.FUNCTION }
+ ]);
+
+ if (!native_.isListenerSet('SearchRequestListener')) {
+ var result = native_.callSync('MediaControllerServerAddSearchRequestListener', {
+ listenerId: 'SearchRequestListener'
+ });
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+
+ var callback = function(msg) {
+ var request = [];
+ msg.request.forEach(function(filter) {
+ request.push(
+ new SearchFilter(
+ filter.contentType,
+ filter.category,
+ filter.keyword,
+ filter.extraData
+ )
+ );
+ });
+
+ var reply = args.listener(msg.clientName, request);
+ if (type_.isUndefined(reply)) {
+ reply = new RequestReply(null, 0);
+ }
+
+ var nativeData = {
+ clientName: msg.clientName,
+ requestId: msg.requestId,
+ reply: reply
+ };
+
+ var result = native_.callSync('MediaControllerServerReplyCommand', nativeData);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ };
+
+ native_.addListener('SearchRequestListener', callback);
+};
+
+MediaControllerServer.prototype.unsetSearchRequestListener = function() {
+ var result = native_.callSync('MediaControllerServerRemoveSearchRequestListener');
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ native_.removeListener('SearchRequestListener');
+};
+
+var getPlaybackAbility = function(serverName, action) {
+ var data = {
+ serverName: serverName,
+ action: action
+ };
+
+ var result = native_.callSync('MediaControllerClientGetPlaybackAbility', data);
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+ var ability = native_.getResultObject(result);
+ return ability.value;
+};
+
+var getSimpleAbility = function(name, type) {
+ var data = {
+ serverName: name,
+ abilityType: type
+ };
+ var result = native_.callSync('MediaControllerClientGetSimpleAbility', data);
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+ var ability = native_.getResultObject(result);
+ return ability.value;
+};
+
+var setSimpleAbility = function(abilityType, support) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'abilityType',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerSimpleAbility)
+ },
+ {
+ name: 'support',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerAbilitySupport)
+ }
]);
+ if (MediaControllerAbilitySupport.UNDECIDED === args.support) {
+ throw new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'Cannot set ability value to ' + args.support
+ );
+ }
+
var data = {
- mode: args.mode
+ abilityType: args.abilityType,
+ support: args.support
};
- var result = native_.callSync('MediaControllerServer_updateShuffleMode', data);
+ var result = native_.callSync('MediaControllerServerSetSimpleAbility', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
-
- edit_.allow();
- this.playbackInfo.shuffleMode = args.mode;
- edit_.disallow();
};
-MediaControllerServer.prototype.updateRepeatMode = function(mode) {
+var checkSupportValue = function(support) {
var args = validator_.validateArgs(arguments, [
- { name: 'mode', type: types_.BOOLEAN }
+ {
+ name: 'support',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerAbilitySupport)
+ }
]);
+ if (MediaControllerAbilitySupport.UNDECIDED === args.support) {
+ throw new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'Cannot set ability value to ' + args.support
+ );
+ }
+};
+
+var setDisplayModeAbility = function(mode, val) {
+ checkSupportValue(val);
+
var data = {
- mode: args.mode
+ mode: mode,
+ support: val
};
-
- var result = native_.callSync('MediaControllerServer_updateRepeatMode', data);
+ var result = native_.callSync('MediaControllerServerSetDisplayModeAbility', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
+};
- edit_.allow();
- this.playbackInfo.repeatMode = args.mode;
- edit_.disallow();
+var getDisplayModeAbility = function(serverName, mode) {
+ var data = {
+ serverName: serverName,
+ mode: mode
+ };
+
+ var result = native_.callSync('MediaControllerClientGetDisplayModeAbility', data);
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+ return native_.getResultObject(result);
};
-MediaControllerServer.prototype.updateMetadata = function(metadata) {
- var args = validator_.validateArgs(arguments, [
- {
- name: 'metadata',
- type: types_.PLATFORM_OBJECT,
- values: MediaControllerMetadata
- }
- ]);
+var getDisplayRotationAbility = function(serverName, displayRotation) {
+ var data = {
+ serverName: serverName,
+ displayRotationAbility: displayRotation
+ };
+ var result = native_.callSync(
+ 'MediaControllerClientGetDisplayRotationAbility',
+ data
+ );
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+
+ return native_.getResultObject(result);
+};
+
+var setDisplayRotationAbility = function(displayRotationAbility, support) {
+ checkSupportValue(support);
var data = {
- metadata: args.metadata
+ displayRotationAbility: displayRotationAbility,
+ support: support
};
- var result = native_.callSync('MediaControllerServer_updateMetadata', data);
+ var result = native_.callSync(
+ 'MediaControllerServerSetDisplayRotationAbility',
+ data
+ );
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
-
- edit_.allow();
- this.playbackInfo.metadata = args.metadata;
- edit_.disallow();
};
-MediaControllerServer.prototype.addChangeRequestPlaybackInfoListener = function(
- listener
-) {
- var args = validator_.validateArgs(arguments, [
- {
- name: 'listener',
- type: types_.LISTENER,
- values: [
- 'onplaybackstaterequest',
- 'onplaybackpositionrequest',
- 'onshufflemoderequest',
- 'onrepeatmoderequest'
- ]
- }
- ]);
+MediaControllerServer.prototype.getAllClientsInfo = function() {
+ var nativeResult = native_.callSync('MediaControllerServerGetAllClientsInfo');
+ if (native_.isFailure(nativeResult)) {
+ throw native_.getErrorObject(nativeResult);
+ }
- if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) {
- var result = native_.callSync(
- 'MediaControllerServer_addChangeRequestPlaybackInfoListener',
- {
- listenerId: ServerPlaybackInfoListener.listenerName
- }
- );
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+ var results = native_.getResultObject(nativeResult);
+ if (!type_.isArray(results)) {
+ throw new WebAPIException(WebAPIException.UNKNOWN_ERR, 'Invalid return type.');
}
- return ServerPlaybackInfoListener.addListener(args.listener);
+ var clientsInfo = [];
+ for (var index in results) {
+ clientsInfo.push(new MediaControllerClientInfo(results[index]));
+ }
+
+ return clientsInfo;
};
-MediaControllerServer.prototype.removeChangeRequestPlaybackInfoListener = function(
- watchId
-) {
+function MediaControllerClientInfo(data) {
+ Object.defineProperties(this, {
+ name: {
+ value: data.name,
+ writable: false,
+ enumerable: true
+ }
+ });
+}
+
+MediaControllerClientInfo.prototype.sendEvent = function(event, data, callback) {
var args = validator_.validateArgs(arguments, [
- { name: 'watchId', type: types_.LONG }
+ { name: 'eventName', type: types_.STRING },
+ { name: 'eventData', type: types_.DICTIONARY, nullable: true },
+ { name: 'callback', type: types_.FUNCTION }
]);
- ServerPlaybackInfoListener.removeListener(args.watchId);
+ var replyCallback = function(result, watchId) {
+ if (
+ EventReplyListenerManager.listenerIdToRequestId[watchId] != result.requestId
+ ) {
+ return;
+ }
+ delete EventReplyListenerManager.listenerIdToRequestId[watchId];
+ args.callback(result.data, result.code);
+ };
- if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) {
- native_.callSync('MediaControllerServer_removeChangeRequestPlaybackInfoListener');
+ var nativeData = {
+ eventName: args.eventName,
+ eventData: args.eventData === null ? null : new tizen.Bundle(args.eventData),
+ clientName: this.name,
+ replyListener: EventReplyListenerManager.name
+ };
+
+ var result = native_.callSync('MediaControllerClientInfoSendEvent', nativeData);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
+
+ var replyListenerId = EventReplyListenerManager.addListener(replyCallback);
+ EventReplyListenerManager.listenerIdToRequestId[replyListenerId] = result.requestId;
};
-MediaControllerServer.prototype.addCommandListener = function(listener) {
- var args = validator_.validateArgs(arguments, [
- { name: 'listener', type: types_.FUNCTION }
- ]);
+function MediaControllerClient() {}
- if (type_.isEmptyObject(ServerCommandListener.listeners)) {
- var result = native_.callSync('MediaControllerServer_addCommandListener', {
- listenerId: ServerCommandListener.listenerName
- });
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+var EventReceivedCallback = function(msg, listener) {
+ var result = listener(msg.serverName, msg.eventName, msg.eventData);
+ if (!(result instanceof RequestReply)) {
+ result = new RequestReply(
+ xwalk.utils.type.isNullOrUndefined(result) ? null : result,
+ 0
+ );
}
- return ServerCommandListener.addListener(args.listener);
+ var nativeData = {
+ result: result.data,
+ resultCode: result.code,
+ serverName: msg.serverName,
+ requestId: msg.requestId
+ };
+
+ var nativeResult = native_.callSync(
+ 'MediaControllerClientSendEventReply',
+ nativeData
+ );
+ if (native_.isFailure(nativeResult)) {
+ throw native_.getErrorObject(nativeResult);
+ }
};
-MediaControllerServer.prototype.removeCommandListener = function(watchId) {
+MediaControllerClient.prototype.setCustomEventListener = function(listener) {
var args = validator_.validateArgs(arguments, [
- { name: 'watchId', type: types_.LONG }
+ { name: 'listener', type: types_.FUNCTION }
]);
- ServerCommandListener.removeListener(args.watchId);
+ var result = native_.callSync('MediaControllerClientSetCustomEventListener', {
+ listenerId: '_MediaControllerClientEventsListener'
+ });
- if (type_.isEmptyObject(ServerCommandListener.listeners)) {
- native_.callSync('MediaControllerServer_removeCommandListener');
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
+
+ native_.addListener('_MediaControllerClientEventsListener', function(msg) {
+ EventReceivedCallback(msg, args.listener);
+ });
};
-function MediaControllerClient() {}
+MediaControllerClient.prototype.unsetCustomEventListener = function() {
+ var result = native_.callSync('MediaControllerClientUnsetCustomEventListener', {
+ listenerId: '_MediaControllerClientEventsListener'
+ });
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ } else {
+ native_.removeListener('_MediaControllerClientEventsListener');
+ }
+};
MediaControllerClient.prototype.findServers = function(successCallback, errorCallback) {
var args = validator_.validateArgs(arguments, [
native_.callIfPossible(args.successCallback, info);
};
- native_.call('MediaControllerClient_findServers', {}, callback);
+ native_.call('MediaControllerClientFindServers', {}, callback);
};
MediaControllerClient.prototype.getLatestServerInfo = function() {
- var result = native_.callSync('MediaControllerClient_getLatestServerInfo', {});
+ var result = native_.callSync('MediaControllerClientGetLatestServerInfo', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
return serverInfo;
};
+function SearchFilter(contentType, category, keyword, extraData) {
+ validator_.isConstructorCall(this, SearchFilter);
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'contentType',
+ type: types_.ENUM,
+ values: Object.values(MediaControllerContentType)
+ },
+ {
+ name: 'category',
+ type: types_.ENUM,
+ values: Object.values(MediaControllerSearchCategory),
+ optional: true
+ },
+ { name: 'keyword', type: types_.STRING, nullable: true, optional: true }
+ ]);
+
+ if (!args.hasOwnProperty('category')) {
+ args.category = 'NO_CATEGORY';
+ }
+ if (!args.hasOwnProperty('keyword')) {
+ args.keyword = null;
+ }
+
+ extraData = xwalk.utils.type.isUndefined(extraData) ? null : extraData;
+ args.extraData = xwalk.utils.type.isNull(extraData)
+ ? null
+ : new tizen.Bundle(extraData);
+
+ var extraData_ = args.extraData;
+ var contentType_ = args.contentType;
+ var category_ = args.category;
+ var keyword_ = args.keyword;
+
+ // keyword can be null only when category is NO_CATEGORY
+ if (
+ xwalk.utils.type.isNull(keyword_) &&
+ category_ != MediaControllerSearchCategory.NO_CATEGORY
+ ) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
+ }
+
+ Object.defineProperties(this, {
+ contentType: {
+ enumerable: true,
+ get: function() {
+ return contentType_;
+ },
+ set: function(newContentType) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'newContentType',
+ type: types_.ENUM,
+ values: Object.values(MediaControllerContentType)
+ }
+ ]);
+ contentType_ = args.newContentType;
+ }
+ },
+ category: {
+ enumerable: true,
+ get: function() {
+ return category_;
+ },
+ set: function(newCategory) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'newCategory',
+ type: types_.ENUM,
+ values: Object.values(MediaControllerSearchCategory)
+ }
+ ]);
+
+ // Keyword can be null only if category is NO_CATEGORY.
+ if (
+ xwalk.utils.type.isNull(keyword_) &&
+ args.newCategory != MediaControllerSearchCategory.NO_CATEGORY
+ ) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
+ }
+
+ category_ = args.newCategory;
+ }
+ },
+ keyword: {
+ enumerable: true,
+ get: function() {
+ return keyword_;
+ },
+ set: function(newKeyword) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'newKeyword',
+ type: types_.STRING,
+ nullable: true
+ }
+ ]);
+
+ // Keyword can only be null if category is NO_CATEGORY.
+ if (
+ xwalk.utils.type.isNull(args.newKeyword) &&
+ this.category != MediaControllerSearchCategory.NO_CATEGORY
+ ) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
+ }
+
+ keyword_ = args.newKeyword;
+ }
+ },
+ extraData: {
+ enumerable: true,
+ get: function() {
+ return extraData_;
+ },
+ set: function(newData) {
+ if (xwalk.utils.type.isUndefined(newData)) {
+ newData = null;
+ }
+ extraData_ = xwalk.utils.type.isNull(newData)
+ ? null
+ : new tizen.Bundle(newData);
+ }
+ }
+ });
+}
+
+MediaControllerClient.prototype.addAbilityChangeListener = function(callback) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'callback',
+ type: types_.LISTENER,
+ values: [
+ 'onplaybackabilitychanged',
+ 'ondisplaymodeabilitychanged',
+ 'ondisplayrotationabilitychanged',
+ 'onsimpleabilitychanged'
+ ]
+ }
+ ]);
+
+ if (type_.isEmptyObject(ClientAbilityChangeListener.listeners)) {
+ var nativeData = {
+ listenerId: ClientAbilityChangeListener.listenerName
+ };
+ var result = native_.callSync(
+ 'MediaControllerClientAddAbilityChangeListener',
+ nativeData
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+
+ return ClientAbilityChangeListener.addListener(args.callback);
+};
+
+MediaControllerClient.prototype.removeAbilityChangeListener = function(callbackId) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'callbackId',
+ type: types_.LONG
+ }
+ ]);
+
+ ClientAbilityChangeListener.removeListener(args.callbackId);
+
+ if (type_.isEmptyObject(ClientAbilityChangeListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerClientRemoveAbilityChangeListener'
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+};
+
+MediaControllerClient.prototype.findSubscribedServers = function(
+ successCallback,
+ errorCallback
+) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ var info = [];
+ var data = native_.getResultObject(result);
+ for (var i = 0; i < data.length; i++) {
+ info.push(new MediaControllerServerInfo(data[i]));
+ }
+ native_.callIfPossible(args.successCallback, info);
+ };
+
+ native_.call('MediaControllerClientFindSubscribedServers', {}, callback);
+};
+
function MediaControllerServerInfo(data) {
Object.defineProperties(this, {
name: {
writable: false,
enumerable: true
},
- playbackInfo: {
+ playbackInfo: {
+ get: function() {
+ var result = native_.callSync('MediaControllerClientGetPlaybackInfo', {
+ name: this.name
+ });
+ if (native_.isFailure(result)) {
+ throw new native_.getErrorObject(result);
+ }
+ edit_.allow();
+ var data = native_.getResultObject(result);
+ var playbackInfo = new MediaControllerPlaybackInfo(data);
+ edit_.disallow();
+
+ return playbackInfo;
+ }.bind(this),
+ set: function() {},
+ enumerable: true
+ },
+ iconURI: {
get: function() {
- var result = native_.callSync('MediaControllerClient_getPlaybackInfo', {
+ var result = native_.callSync('MediaControllerServerInfoGetIconURI', {
name: this.name
});
if (native_.isFailure(result)) {
throw new native_.getErrorObject(result);
}
- edit_.allow();
var data = native_.getResultObject(result);
- var playbackInfo = new MediaControllerPlaybackInfo(data);
- edit_.disallow();
-
- return playbackInfo;
+ return data.iconURI;
}.bind(this),
set: function() {},
enumerable: true
+ },
+ abilities: {
+ value: new MediaControllerAbilitiesInfo(data.name),
+ enumerable: true,
+ writable: false
+ },
+ subtitles: {
+ value: new MediaControllerSubtitlesInfo(data.name),
+ enumerable: true,
+ writable: false
+ },
+ mode360: {
+ value: new MediaControllerMode360Info(data.name),
+ enumerable: true,
+ writable: false
+ },
+ displayMode: {
+ value: new MediaControllerDisplayModeInfo(data.name),
+ enumerable: true,
+ writable: false
+ },
+ displayRotation: {
+ value: new MediaControllerDisplayRotationInfo(data.name),
+ enumerable: true,
+ writable: false
}
});
}
native_.callIfPossible(args.successCallback);
};
- native_.call('MediaControllerServerInfo_sendPlaybackState', data, callback);
+ native_.call('MediaControllerServerInfoSendPlaybackState', data, callback);
};
MediaControllerServerInfo.prototype.sendPlaybackPosition = function(
name: this.name
};
- native_.call('MediaControllerServerInfo_sendPlaybackPosition', data, callback);
+ native_.call('MediaControllerServerInfoSendPlaybackPosition', data, callback);
};
MediaControllerServerInfo.prototype.sendShuffleMode = function(
mode: args.mode,
name: this.name
};
- native_.call('MediaControllerServerInfo_sendShuffleMode', data, callback);
+ native_.call('MediaControllerServerInfoSendShuffleMode', data, callback);
};
MediaControllerServerInfo.prototype.sendRepeatMode = function(
successCallback,
errorCallback
) {
+ utils_.printDeprecationWarningFor('sendRepeatMode()', 'sendRepeatState()');
var args = validator_.validateArgs(arguments, [
{ name: 'mode', type: types_.BOOLEAN },
{
mode: args.mode,
name: this.name
};
- native_.call('MediaControllerServerInfo_sendRepeatMode', data, callback);
+ native_.call('MediaControllerServerInfoSendRepeatMode', data, callback);
+};
+
+MediaControllerServerInfo.prototype.sendRepeatState = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'state',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerRepeatState)
+ },
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ native_.callIfPossible(args.successCallback);
+ };
+
+ var data = {
+ state: args.state,
+ name: this.name
+ };
+ native_.call('MediaControllerServerInfoSendRepeatState', data, callback);
};
MediaControllerServerInfo.prototype.sendCommand = function(
) {
var args = validator_.validateArgs(arguments, [
{ name: 'command', type: types_.STRING },
- { name: 'data', type: types_.DICTIONARY },
+ { name: 'data', type: types_.DICTIONARY, nullable: true },
{ name: 'successCallback', type: types_.FUNCTION },
{ name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
]);
}
native_.callIfPossible(
args.successCallback,
- native_.getResultObject(result).data
+ native_.getResultObject(result).data,
+ native_.getResultObject(result).code
);
};
var nativeData = {
command: args.command,
- data: args.data,
+ data: args.data === null ? null : new tizen.Bundle(args.data),
name: this.name,
listenerId: ReplyCommandListener.listenerName
};
var replyListenerId = ReplyCommandListener.addListener(callback);
- var result = native_.callSync('MediaControllerServerInfo_sendCommand', nativeData);
+ var result = native_.callSync('MediaControllerServerInfoSendCommand', nativeData);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
+};
+
+MediaControllerServerInfo.prototype.sendSearchRequest = function(
+ request,
+ successCallback,
+ errorCallback
+) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'request', type: types_.ARRAY, values: SearchFilter },
+ { name: 'successCallback', type: types_.FUNCTION },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ if (args.request.length < 1 || args.request.length > 20) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
+ }
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ var reply = native_.getResultObject(result);
+ native_.callIfPossible(
+ args.successCallback,
+ new RequestReply(reply.data, reply.code)
+ );
+ };
+
+ var nativeData = {
+ request: args.request,
+ name: this.name,
+ listenerId: ReplyCommandListener.listenerName
+ };
+
+ var result = native_.callSync(
+ 'MediaControllerServerInfoSendSearchRequest',
+ nativeData,
+ callback
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ var replyListenerId = ReplyCommandListener.addListener(callback);
ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
};
if (type_.isEmptyObject(ServerInfoStatusListener.listeners)) {
var result = native_.callSync(
- 'MediaControllerServerInfo_addServerStatusChangeListener',
+ 'MediaControllerServerInfoAddServerStatusChangeListener',
{
listenerId: ServerInfoStatusListener.listenerName
}
ServerInfoStatusListener.removeServerInfoListener(args.watchId);
if (type_.isEmptyObject(ServerInfoStatusListener.listeners)) {
- native_.callSync('MediaControllerServerInfo_removeServerStatusChangeListener');
+ native_.callSync('MediaControllerServerInfoRemoveServerStatusChangeListener');
}
};
'onplaybackchanged',
'onshufflemodechanged',
'onrepeatmodechanged',
+ 'onrepeatstatechanged',
'onmetadatachanged'
]
}
if (type_.isEmptyObject(ServerInfoPlaybackInfoListener.listeners)) {
var result = native_.callSync(
- 'MediaControllerServerInfo_addPlaybackInfoChangeListener',
+ 'MediaControllerServerInfoAddPlaybackInfoChangeListener',
{
listenerId: ServerInfoPlaybackInfoListener.listenerName
}
ServerInfoPlaybackInfoListener.removeServerInfoListener(args.watchId);
if (type_.isEmptyObject(ServerInfoPlaybackInfoListener.listeners)) {
- native_.callSync('MediaControllerServerInfo_removePlaybackInfoChangeListener');
+ native_.callSync('MediaControllerServerInfoRemovePlaybackInfoChangeListener');
+ }
+};
+
+MediaControllerServerInfo.prototype.getAllPlaylists = function(
+ successCallback,
+ errorCallback
+) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION,
+ optional: false,
+ nullable: false
+ },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ var data = native_.getResultObject(result);
+ var playlists = [];
+
+ for (var i = 0; i < data.length; i++) {
+ playlists.push(new MediaControllerPlaylist(data[i]));
+ }
+
+ native_.callIfPossible(args.successCallback, playlists);
+ };
+
+ var result = native_.call(
+ 'MediaControllerServerInfoGetAllPlaylists',
+ { name: this.name },
+ callback
+ );
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+};
+
+MediaControllerServerInfo.prototype.sendPlaybackItem = function(
+ playlistName,
+ index,
+ state,
+ position
+) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'playlistName', type: types_.STRING },
+ { name: 'index', type: types_.STRING },
+ {
+ name: 'state',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerPlaybackState)
+ },
+ { name: 'position', type: types_.UNSIGNED_LONG_LONG }
+ ]);
+
+ var data = {
+ name: this.name,
+ playlistName: args.playlistName,
+ index: args.index,
+ state: args.state,
+ position: args.position
+ };
+
+ var result = native_.callSync('MediaControllerServerInfoSendPlaybackItem', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+};
+
+MediaControllerServerInfo.prototype.addPlaylistUpdatedListener = function(listener) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'listener',
+ type: types_.LISTENER,
+ values: ['onplaylistupdated', 'onplaylistdeleted']
+ }
+ ]);
+
+ if (type_.isEmptyObject(ServerInfoPlaylistUpdatedListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerServerInfoAddPlaylistUpdateListener',
+ {
+ listenerId: ServerInfoPlaylistUpdatedListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+
+ return ServerInfoPlaylistUpdatedListener.addListener(args.listener, this.name);
+};
+
+MediaControllerServerInfo.prototype.removePlaylistUpdatedListener = function(watchId) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
+
+ ServerInfoPlaylistUpdatedListener.removeListener(args.watchId);
+
+ if (type_.isEmptyObject(ServerInfoPlaylistUpdatedListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerServerInfoRemovePlaylistUpdateListener'
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+};
+
+var MediaControllerPlaylistItem = function(data) {
+ var _index = '';
+ var _metadata = new MediaControllerMetadata();
+ Object.defineProperties(this, {
+ index: {
+ get: function() {
+ return _index;
+ },
+ set: function(v) {
+ _index = edit_.isAllowed && v ? v : _index;
+ },
+ enumerable: true
+ },
+ metadata: {
+ get: function() {
+ return _metadata;
+ },
+ set: function(v) {
+ _metadata =
+ edit_.isAllowed && v ? new MediaControllerMetadata(v) : _metadata;
+ },
+ enumerable: true
+ }
+ });
+
+ edit_.allow();
+ if (data instanceof _global.Object) {
+ for (var prop in data) {
+ if (data.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
+ this[prop] = data[prop];
+ }
+ }
+ }
+ edit_.disallow();
+};
+
+function MediaControllerPlaylist(data) {
+ var _name = '';
+
+ Object.defineProperties(this, {
+ name: {
+ get: function() {
+ return _name;
+ },
+ set: function(v) {
+ _name = edit_.isAllowed && v ? v : _name;
+ },
+ enumerable: true
+ }
+ });
+ edit_.allow();
+ if (data instanceof _global.Object) {
+ for (var prop in data) {
+ if (data.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
+ this[prop] = data[prop];
+ }
+ }
+ }
+ edit_.disallow();
+}
+
+MediaControllerPlaylist.prototype.addItem = function(index, metadata) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'index', type: types_.STRING },
+ { name: 'metadata', type: types_.DICTIONARY }
+ ]);
+
+ var data = {
+ index: args.index,
+ metadata: new MediaControllerMetadata(args.metadata),
+ name: this.name
+ };
+
+ var result = native_.callSync('MediaControllerPlaylistAddItem', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+};
+
+MediaControllerPlaylist.prototype.getItems = function(successCallback, errorCallback) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION,
+ optional: false,
+ nullable: false
+ },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ var data = {
+ name: this.name
+ };
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ var data = native_.getResultObject(result);
+ var items = [];
+
+ for (var i = 0; i < data.length; i++) {
+ items.push(new MediaControllerPlaylistItem(data[i]));
+ }
+
+ native_.callIfPossible(args.successCallback, items);
+ };
+
+ var result = native_.call('MediaControllerPlaylistGetItems', data, callback);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
exports = new MediaControllerManager();
+exports.SearchFilter = SearchFilter;
+exports.RequestReply = RequestReply;
#include <bundle_internal.h>
#include <memory>
+#include "common/json-utils.h"
#include "common/logger.h"
#include "common/scope_exit.h"
#include "common/tools.h"
-#include "mediacontroller/mediacontroller_types.h"
-
namespace extension {
namespace mediacontroller {
-using common::PlatformResult;
+using namespace attributes;
+
using common::ErrorCode;
+using common::JsonToBundle;
+using common::PlatformResult;
using common::tools::ReportError;
using common::tools::ReportSuccess;
-
-MediaControllerClient::MediaControllerClient() : handle_(nullptr) {
+using common::BundleJsonIterator;
+
+MediaControllerClient::MediaControllerClient()
+ : handle_(nullptr),
+ playback_info_listener_(nullptr),
+ server_status_listener_(nullptr),
+ command_reply_callback_(nullptr),
+ playlist_update_listener_(nullptr),
+ ability_listener_(nullptr),
+ subtitles_update_listener_(nullptr),
+ mode360_update_listener_(nullptr),
+ display_mode_update_listener_(nullptr),
+ display_rotation_update_listener_(nullptr),
+ custom_event_listener_(nullptr),
+ subscribed_servers{} {
ScopeLogger();
}
LoggerE("Failed to unset playback info listener");
}
+ if (nullptr != playlist_update_listener_ && !UnsetPlaylistUpdateListener()) {
+ LoggerE("Failed to unset playlist update listener");
+ }
+
+ if (nullptr != ability_listener_ && !UnsetAbilityChangeListener()) {
+ LoggerE("Failed to unset ability listener");
+ }
+
+ if (nullptr != subtitles_update_listener_ && !UnsetSubtitlesInfoChangeListener()) {
+ LoggerE("Failed to unset subtitles listener");
+ }
+
+ if (nullptr != mode360_update_listener_ && !UnsetMode360InfoChangeListener()) {
+ LoggerE("Failed to unset mode 360 listener");
+ }
+
+ if (nullptr != display_mode_update_listener_ && !UnsetDisplayModeInfoChangeListener()) {
+ LoggerE("Failed to unset display mode listener");
+ }
+
+ if (nullptr != display_rotation_update_listener_ && !UnsetDisplayRotationInfoChangeListener()) {
+ LoggerE("Failed to unset display rotation listener");
+ }
+
+ if (nullptr != custom_event_listener_ && !UnsetCustomEventListener()) {
+ LoggerE("Failed to unset custom event listener");
+ }
+
if (nullptr != handle_ && MEDIA_CONTROLLER_ERROR_NONE != mc_client_destroy(handle_)) {
LoggerE("Unable to destroy media controller client");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult MediaControllerClient::SetCustomEventListener(const JsonCallback& callback) {
+ ScopeLogger();
+ if (nullptr == custom_event_listener_) {
+ int ret = mc_client_set_custom_event_received_cb(handle_, OnEventReceived, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to set custom event listener",
+ ("mc_client_set_custom_event_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+ }
+ custom_event_listener_ = callback;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::UnsetCustomEventListener() {
+ ScopeLogger();
+ int ret = mc_client_unset_custom_event_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to unset custom event listener",
+ ("mc_client_unset_custom_event_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+ custom_event_listener_ = nullptr;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SendEventReply(const char* server_name,
+ const picojson::value& data, int result_code,
+ const char* request_id) {
+ ScopeLogger();
+
+ bundle* data_bundle = bundle_create();
+ if (!data_bundle) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "data_bundle is a nullptr",
+ ("bundle_create() returned a nullptr"));
+ }
+ SCOPE_EXIT {
+ bundle_free(data_bundle);
+ };
+
+ PlatformResult result = common::JsonToBundle(data, &data_bundle);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Converting json to bundle failed.",
+ ("JsonToBundle() failed with error: %s", result.message().c_str()));
+ }
+
+ int ret = mc_client_send_event_reply(handle_, server_name, request_id, result_code, data_bundle);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Failed to send event reply",
+ ("mc_client_send_event_reply() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
PlatformResult MediaControllerClient::FindServers(picojson::array* servers) {
ScopeLogger();
int ret;
return PlatformResult(ErrorCode::NO_ERROR);
}
- const std::string& latest_name = latest_server.get("name").get<std::string>();
+ const std::string& latest_name = latest_server.get(kName).get<std::string>();
// update current server state in list
for (auto& it : *servers) {
picojson::object& server = it.get<picojson::object>();
- if (server["name"].get<std::string>() == latest_name) {
- server["state"] = latest_server.get("state");
+ if (server[kName].get<std::string>() == latest_name) {
+ server[kState] = latest_server.get(kState);
break;
}
}
picojson::value server = picojson::value(picojson::object());
picojson::object& server_o = server.get<picojson::object>();
- server_o["name"] = picojson::value(std::string(server_name));
+ server_o[kName] = picojson::value(std::string(server_name));
// active by default in CAPI
- server_o["state"] = picojson::value(std::string("ACTIVE"));
+ server_o[kState] = picojson::value(std::string("ACTIVE"));
servers->push_back(server);
*server_info = picojson::value(picojson::object());
picojson::object& obj = server_info->get<picojson::object>();
- obj["name"] = picojson::value(std::string(name));
- obj["state"] = picojson::value(state_str);
+ obj[kName] = picojson::value(std::string(name));
+ obj[kState] = picojson::value(state_str);
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::GetPlaybackAbility(const std::string& server_name,
+ const std::string& action,
+ picojson::value* abilities) {
+ ScopeLogger();
+ mc_playback_ability_h ability_h = nullptr;
+
+ SCOPE_EXIT {
+ mc_playback_ability_destroy(ability_h);
+ };
+
+ int ret = mc_client_get_server_playback_ability(handle_, server_name.c_str(), &ability_h);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting playback ability",
+ ("mc_client_get_server_playback_ability() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ std::string ability_str;
+ PlatformResult result = types::ConvertPlaybackAbility(ability_h, action, &ability_str);
+ if (!result) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error getting playback ability",
+ ("types::ConvertPlaybackAbility() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ picojson::object& abilities_obj = abilities->get<picojson::object>();
+ abilities_obj[kValue] = picojson::value(ability_str);
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::GetDisplayModeAbility(const std::string& server_name,
+ const std::string& mode,
+ std::string* abilities) {
+ ScopeLogger();
+
+ mc_display_mode_e mode_e = MC_DISPLAY_MODE_LETTER_BOX;
+ PlatformResult result = types::MediaControllerDisplayModeEnum.getValue(mode, &mode_e);
+ if (!result) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error getting value of display mode",
+ ("MediaControllerDisplayModeEnum.getValue() failed, error: %s", result.message().c_str()));
+ }
+
+ u_int supported_items = 0;
+ int ret =
+ mc_client_get_server_display_mode_ability(handle_, server_name.c_str(), &supported_items);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting display mode ability",
+ ("mc_client_get_server_display_mode_ability() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ *abilities = (supported_items & mode_e) != 0 ? "YES" : "NO";
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::GetDisplayRotationAbility(
+ const std::string& server_name, const std::string& display_rotation_ability,
+ std::string* abilities) {
+ ScopeLogger();
+
+ mc_display_rotation_e display_rotation_e = MC_DISPLAY_ROTATION_NONE;
+
+ PlatformResult result = types::MediaControllerDisplayRotationEnum.getValue(
+ display_rotation_ability, &display_rotation_e);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of display rotation",
+ ("MediaControllerDisplayRotationEnum.getValue() failed, error: %s",
+ result.message().c_str()));
+ }
+
+ u_int supported_items = 0;
+ int ret =
+ mc_client_get_server_display_rotation_ability(handle_, server_name.c_str(), &supported_items);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error getting ability",
+ ("mc_client_get_ability_support() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ *abilities = (supported_items & display_rotation_e) != 0 ? "YES" : "NO";
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::GetSimpleAbility(const std::string& server_name,
+ const std::string& ability_type,
+ picojson::value* ability_val) {
+ ScopeLogger();
+ mc_ability_support_e support_e = MC_ABILITY_SUPPORTED_YES;
+ mc_ability_e ability_e = MC_ABILITY_SHUFFLE;
+ PlatformResult result =
+ types::MediaControllerSimpleAbilityEnum.getValue(ability_type, &ability_e);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of ability",
+ ("MediaControllerSimpleAbilityEnum.getValue() failed, error: %s",
+ result.message().c_str()));
+ }
+
+ int ret =
+ mc_client_get_server_ability_support(handle_, server_name.c_str(), ability_e, &support_e);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error getting ability",
+ ("mc_client_get_ability_support() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ std::string ability_str;
+ result = types::MediaControllerAbilitySupportEnum.getName(support_e, &ability_str);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting name of ability",
+ ("MediaControllerAbilitySupportEnum.getName() failed, error: %s",
+ result.message().c_str()));
+ }
+
+ *ability_val = picojson::value(picojson::object());
+ picojson::object& obj = ability_val->get<picojson::object>();
+ obj[kValue] = picojson::value(ability_str);
return PlatformResult(ErrorCode::NO_ERROR);
}
ScopeLogger();
int ret;
+ char* index = nullptr;
+ char* playlist_name = nullptr;
mc_playback_h playback_h;
ret = mc_client_get_server_playback_info(handle_, server_name.c_str(), &playback_h);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
SCOPE_EXIT {
mc_client_destroy_playback(playback_h);
+ free(index);
+ free(playlist_name);
};
// playback state
return result;
}
+ // content age rating
+ std::string rating;
+ result = types::ConvertContentAgeRating(playback_h, &rating);
+ if (!result) {
+ LoggerE("ConvertContentAgeRating failed, error: %s", result.message().c_str());
+ return result;
+ }
+
+ // content type
+ std::string contentType;
+ result = types::ConvertContentType(playback_h, &contentType);
+ if (!result) {
+ LoggerE("ConvertContentType failed, error: %s", result.message().c_str());
+ return result;
+ }
+
// shuffle mode
mc_shuffle_mode_e shuffle;
ret = mc_client_get_server_shuffle_mode(handle_, server_name.c_str(), &shuffle);
get_error_message(ret)));
}
- // repeat mode
- mc_repeat_mode_e repeat;
- ret = mc_client_get_server_repeat_mode(handle_, server_name.c_str(), &repeat);
+ // repeat mode and state
+ mc_repeat_mode_e repeat_mode;
+ ret = mc_client_get_server_repeat_mode(handle_, server_name.c_str(), &repeat_mode);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, "Error getting repeat mode",
("mc_client_get_server_repeat_mode() error: %d, message: %s", ret, get_error_message(ret)));
}
+ std::string repeat_state;
+ result = types::MediaControllerRepeatModeEnum.getName(repeat_mode, &repeat_state);
+ if (!result) {
+ LoggerE("MediaControllerRepeatModeEnum.getName() failed, error: %s", result.message().c_str());
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Error getting name of repeat state");
+ }
// metadata
picojson::value metadata = picojson::value(picojson::object());
return result;
}
+ ret = mc_client_get_playlist_item_info(playback_h, &playlist_name, &index);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error getting playlistName and index",
+ ("mc_client_get_playlist_item_info() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
// fill return object
- (*playback_info)["state"] = picojson::value(state);
- (*playback_info)["position"] = picojson::value(position);
- (*playback_info)["shuffleMode"] = picojson::value(shuffle == MC_SHUFFLE_MODE_ON);
- (*playback_info)["repeatMode"] = picojson::value(repeat == MC_REPEAT_MODE_ON);
- (*playback_info)["metadata"] = metadata;
+ (*playback_info)[kState] = picojson::value(state);
+ (*playback_info)[kPosition] = picojson::value(position);
+ (*playback_info)[kAgeRating] = picojson::value(rating);
+ (*playback_info)[kContentType] = picojson::value(contentType);
+ (*playback_info)[kShuffleMode] = picojson::value(shuffle == MC_SHUFFLE_MODE_ON);
+ (*playback_info)[kRepeatMode] = picojson::value(repeat_mode == MC_REPEAT_MODE_ON);
+ (*playback_info)[kRepeatState] = picojson::value(repeat_state);
+ (*playback_info)[kMetadata] = metadata;
+ (*playback_info)[kIndex] = picojson::value(std::string(index ? index : ""));
+ (*playback_info)[kPlaylistName] =
+ picojson::value(std::string(playlist_name ? playlist_name : ""));
return PlatformResult(ErrorCode::NO_ERROR);
}
ErrorCode::UNKNOWN_ERR, "Error getting server metadata",
("mc_client_get_server_metadata() error: %d, message: %s", ret, get_error_message(ret)));
}
-
SCOPE_EXIT {
mc_metadata_destroy(metadata_h);
};
- PlatformResult result = types::ConvertMetadata(metadata_h, metadata);
- if (!result) {
- return result;
+ // Native layer has changed behaviour and it allows returning null metadata if it is missing
+ // to keep backward compatibility, we just leave empty object and pass it to Javascript.
+ // This way if metadata will be not present, Web API will return object with all empty members.
+ if (metadata_h) {
+ PlatformResult result = types::ConvertMetadata(metadata_h, metadata);
+ if (!result) {
+ return result;
+ }
+ } else {
+ LoggerD("No metadata, returning empty object");
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::GetServerIconURI(const std::string& name,
+ common::optional<std::string>* icon_uri) {
+ ScopeLogger();
+
+ char* icon_uri_str = nullptr;
+ SCOPE_EXIT {
+ free(icon_uri_str);
+ };
+
+ int ret = mc_client_get_server_icon(handle_, name.c_str(), &icon_uri_str);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return PlatformResult(ErrorCode::UNKNOWN_ERR);
+ }
+
+ *icon_uri = nullptr;
+ if (nullptr != icon_uri_str) {
+ *icon_uri = std::string(icon_uri_str);
}
return PlatformResult(ErrorCode::NO_ERROR);
picojson::value data = picojson::value(picojson::object());
picojson::object& data_o = data.get<picojson::object>();
- data_o["state"] = picojson::value(state_str);
- data_o["name"] = picojson::value(server_name);
+ data_o[kState] = picojson::value(state_str);
+ data_o[kName] = picojson::value(server_name);
client->server_status_listener_(&data);
}
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult MediaControllerClient::SetAbilityChangeListener(const JsonCallback& callback) {
+ ScopeLogger();
+ int failed_setters = 0;
+ SCOPE_EXIT {
+ // Lambda function used to clean all set listeners.
+ // The purpose of this lambda is to unset as many setters as we can in case of failure.
+ int (*unsetters[])(mc_client_h) = {mc_client_unset_playback_ability_updated_cb,
+ mc_client_unset_display_mode_ability_updated_cb,
+ mc_client_unset_display_rotation_ability_updated_cb,
+ mc_client_unset_ability_support_updated_cb};
+
+ // This loop is no-op in case of success.
+ for (int i = 0; i < failed_setters; ++i) {
+ auto ret = unsetters[i](handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ LoggerE("Fail (%d) returned by the [%d] unsetter", ret, i);
+ }
+ }
+ };
+
+ int ret = mc_client_set_playback_ability_updated_cb(handle_, OnPlaybackAbilityUpdate, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Unable to register playback ability listener",
+ ("mc_client_set_playback_ability_updated_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ ret = mc_client_set_display_mode_ability_updated_cb(handle_, OnDisplayModeAbilityUpdate, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ failed_setters = 1;
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to register display mode ability listener",
+ ("mc_client_set_display_mode_ability_updated_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ ret = mc_client_set_display_rotation_ability_updated_cb(handle_, OnDisplayRotationAbilityUpdate,
+ this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ failed_setters = 2;
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to register display rotation ability listener",
+ ("mc_client_set_display_rotation_ability_updated_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ ret = mc_client_set_ability_support_updated_cb(handle_, OnSimpleAbilityUpdate, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ failed_setters = 3;
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to register simple ability listener",
+ ("mc_client_set_ability_support_updated_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ ability_listener_ = callback;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void UnsubscribeAllTypes(mc_client_h handle_, const std::string& server_name) {
+ int ret;
+ for (auto type : types::MediaControllerSubscriptionTypeEnum) {
+ ret = mc_client_unsubscribe(handle_, type.second, server_name.c_str());
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ LoggerE("mc_client_unsubscribe() failed with type %s, error: %d, message: %s",
+ type.first.c_str(), ret, get_error_message(ret));
+ }
+ }
+}
+
+PlatformResult MediaControllerClient::UnsetAbilityChangeListener() {
+ ScopeLogger();
+
+ // we have to unsubscribe all servers before unsetting callback to avoid
+ // calling callback twice if the callback will be set again
+ for (auto srv : subscribed_servers) {
+ UnsubscribeAllTypes(handle_, srv);
+ }
+ subscribed_servers.clear();
+
+ int ret = mc_client_unset_playback_ability_updated_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ LoggerW("mc_client_unset_playback_ability_updated_cb() failed with error %d, message: %s", ret,
+ get_error_message(ret));
+ }
+
+ ret = mc_client_unset_display_mode_ability_updated_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ LoggerE("mc_client_unset_display_mode_ability_updated_cb() failed with error %d, message: %s",
+ ret, get_error_message(ret));
+ }
+
+ ret = mc_client_unset_display_rotation_ability_updated_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ LoggerE(
+ "mc_client_unset_display_rotation_ability_updated_cb() failed with error %d, message: %s",
+ ret, get_error_message(ret));
+ }
+
+ ret = mc_client_unset_ability_support_updated_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ LoggerW("mc_client_unset_ability_support_updated_cb() failed with error %d, message: %s", ret,
+ get_error_message(ret));
+ }
+
+ ability_listener_ = nullptr;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SubscribeServer(const std::string& server_name) {
+ ScopeLogger();
+ int ret = 0;
+ int to_unsubscribe = 0;
+ if (nullptr == ability_listener_) {
+ return PlatformResult(ErrorCode::INVALID_STATE_ERR,
+ "Unable to subscribe server, AbilityChangeListener is not set");
+ }
+
+ auto srv = std::find(subscribed_servers.begin(), subscribed_servers.end(), server_name);
+ if (srv != subscribed_servers.end()) {
+ LoggerD("server %s is already subscribed", server_name.c_str());
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+
+ SCOPE_EXIT {
+ if (to_unsubscribe > 0) {
+ for (auto type : types::MediaControllerSubscriptionTypeEnum) {
+ if (to_unsubscribe > 0) {
+ ret = mc_client_unsubscribe(handle_, type.second, server_name.c_str());
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ LoggerW("mc_client_unsubscribe() failed on type: %s, with error: %d, message: %s",
+ type.first.c_str(), ret, get_error_message(ret));
+ }
+ }
+ --to_unsubscribe;
+ }
+ }
+ };
+
+ for (auto type : types::MediaControllerSubscriptionTypeEnum) {
+ ret = mc_client_subscribe(handle_, type.second, server_name.c_str());
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to subscribe server",
+ ("mc_client_subscribe() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+ ++to_unsubscribe;
+ }
+
+ to_unsubscribe = 0;
+ subscribed_servers.push_back(server_name);
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::UnsubscribeServer(const std::string& server_name) {
+ ScopeLogger();
+
+ UnsubscribeAllTypes(handle_, server_name);
+ subscribed_servers.remove(server_name);
+
+ /**
+ * After unsubscribing last media controller server, unsetting and setting callback
+ * is needed to receive again callbacks from all media controller servers.
+ */
+ if (subscribed_servers.size() <= 0 && nullptr != ability_listener_) {
+ JsonCallback callback = ability_listener_;
+ UnsetAbilityChangeListener();
+ auto result = SetAbilityChangeListener(callback);
+ if (!result) {
+ return result;
+ }
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::FindSubscribedServers(picojson::array* servers) {
+ ScopeLogger();
+
+ /**
+ * If subscription is successful, then servers are subscribed to every subscription type,
+ * so we can check only the one type of subscription to receive all subscribed servers.
+ */
+ int ret = mc_client_foreach_server_subscribed(handle_, MC_SUBSCRIPTION_TYPE_ABILITY_SUPPORT,
+ FindServersCallback, servers);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to fetch active servers.",
+ ("mc_client_foreach_server() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
void MediaControllerClient::OnPlaybackUpdate(const char* server_name, mc_playback_h playback,
void* user_data) {
ScopeLogger();
picojson::value data = picojson::value(picojson::object());
picojson::object& data_o = data.get<picojson::object>();
- data_o["action"] = picojson::value(std::string("onplaybackchanged"));
- data_o["state"] = picojson::value(state);
- data_o["position"] = picojson::value(position);
- data_o["name"] = picojson::value(server_name);
+ data_o[kAction] = picojson::value(std::string("onplaybackchanged"));
+ data_o[kState] = picojson::value(state);
+ data_o[kPosition] = picojson::value(position);
+ data_o[kName] = picojson::value(server_name);
client->playback_info_listener_(&data);
}
-void MediaControllerClient::OnShuffleModeUpdate(const char* server_name, mc_shuffle_mode_e mode,
- void* user_data) {
+void MediaControllerClient::OnPlaybackAbilityUpdate(const char* server_name,
+ mc_playback_ability_h ability,
+ void* user_data) {
ScopeLogger();
MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
picojson::value data = picojson::value(picojson::object());
picojson::object& data_o = data.get<picojson::object>();
- data_o["action"] = picojson::value(std::string("onshufflemodechanged"));
- data_o["mode"] = picojson::value(mode == MC_SHUFFLE_MODE_ON);
- data_o["name"] = picojson::value(server_name);
+ data_o[kAction] = picojson::value(std::string("onplaybackabilitychanged"));
+ data_o[kName] = picojson::value(std::string(server_name));
+ // only active servers can trigger listener, thus state is always "ACTIVE"
+ data_o[kState] = picojson::value(std::string("ACTIVE"));
- client->playback_info_listener_(&data);
+ client->ability_listener_(&data);
}
-void MediaControllerClient::OnRepeatModeUpdate(const char* server_name, mc_repeat_mode_e mode,
- void* user_data) {
+void MediaControllerClient::OnDisplayModeAbilityUpdate(const char* server_name, u_int mode,
+ void* user_data) {
ScopeLogger();
MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
picojson::value data = picojson::value(picojson::object());
picojson::object& data_o = data.get<picojson::object>();
- data_o["action"] = picojson::value(std::string("onrepeatmodechanged"));
- data_o["mode"] = picojson::value(mode == MC_REPEAT_MODE_ON);
- data_o["name"] = picojson::value(server_name);
+ data_o[kAction] = picojson::value(std::string("ondisplaymodeabilitychanged"));
+ data_o[kName] = picojson::value(std::string(server_name));
+ data_o[kState] = picojson::value(std::string("ACTIVE"));
- client->playback_info_listener_(&data);
+ client->ability_listener_(&data);
}
-void MediaControllerClient::OnMetadataUpdate(const char* server_name, mc_metadata_h metadata_h,
- void* user_data) {
+void MediaControllerClient::OnDisplayRotationAbilityUpdate(const char* server_name,
+ u_int supported_items, void* user_data) {
ScopeLogger();
MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
picojson::value data = picojson::value(picojson::object());
picojson::object& data_o = data.get<picojson::object>();
- picojson::value metadata = picojson::value(picojson::object());
- PlatformResult result = types::ConvertMetadata(metadata_h, &metadata.get<picojson::object>());
- if (!result) {
- LoggerE("ConvertMetadata failed, error: %s", result.message().c_str());
- return;
- }
+ data_o[kAction] = picojson::value(std::string("ondisplayrotationabilitychanged"));
+ data_o[kName] = picojson::value(std::string(server_name));
+ // only active servers can trigger listener, thus state is always "ACTIVE"
+ data_o[kState] = picojson::value(std::string("ACTIVE"));
+
+ client->ability_listener_(&data);
+}
+
+void MediaControllerClient::OnShuffleModeUpdate(const char* server_name, mc_shuffle_mode_e mode,
+ void* user_data) {
+ ScopeLogger();
+ MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
- data_o["action"] = picojson::value(std::string("onmetadatachanged"));
- data_o["metadata"] = metadata;
- data_o["name"] = picojson::value(server_name);
+ data_o[kAction] = picojson::value(std::string("onshufflemodechanged"));
+ data_o[kMode] = picojson::value(mode == MC_SHUFFLE_MODE_ON);
+ data_o[kName] = picojson::value(server_name);
client->playback_info_listener_(&data);
}
+void MediaControllerClient::OnSimpleAbilityUpdate(const char* server_name, mc_ability_e type,
+ mc_ability_support_e ability, void* user_data) {
+ ScopeLogger();
+ MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
+
+ std::string type_str;
+ PlatformResult result = types::MediaControllerSimpleAbilityEnum.getName(type, &type_str);
+ if (!result) {
+ LoggerE("MediaControllerSimpleAbilityEnum.getName() failed, error: %s",
+ result.message().c_str());
+ return;
+ }
+
+ std::string ability_str;
+ result = types::MediaControllerAbilitySupportEnum.getName(ability, &ability_str);
+ if (!result) {
+ LoggerE("MediaControllerAbilitySupportEnum.getName() failed, error: %s",
+ result.message().c_str());
+ return;
+ }
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ data_o[kAction] = picojson::value(std::string("onsimpleabilitychanged"));
+ data_o[kName] = picojson::value(std::string(server_name));
+ // only active servers can trigger listener, thus state is always "ACTIVE"
+ data_o[kState] = picojson::value(std::string("ACTIVE"));
+ data_o[kType] = picojson::value(type_str);
+ data_o[kAbility] = picojson::value(ability_str);
+
+ client->ability_listener_(&data);
+}
+
+void MediaControllerClient::OnRepeatModeUpdate(const char* server_name, mc_repeat_mode_e mode,
+ void* user_data) {
+ ScopeLogger();
+ MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ data_o[kName] = picojson::value(server_name);
+ if (MC_REPEAT_MODE_ONE_MEDIA != mode) {
+ // The onrepeatmodechanged event may be reported only with mode equal to true/false. The 3rd
+ // mode is not supported by this event.
+ common::tools::PrintDeprecationWarningFor("onrepeatmodechanged", "onrepeatstatechanged");
+ data_o[kAction] = picojson::value(std::string("onrepeatmodechanged"));
+ data_o[kMode] = picojson::value(mode == MC_REPEAT_MODE_ON);
+ client->playback_info_listener_(&data);
+ }
+ std::string state;
+ PlatformResult result = types::MediaControllerRepeatModeEnum.getName(mode, &state);
+ if (!result) {
+ LoggerE("MediaControllerRepeatModeEnum.getName() failed, error: %s", result.message().c_str());
+ return;
+ }
+ data_o[kAction] = picojson::value(std::string("onrepeatstatechanged"));
+ data_o[kState] = picojson::value(state);
+
+ client->playback_info_listener_(&data);
+}
+
+void MediaControllerClient::OnMetadataUpdate(const char* server_name, mc_metadata_h metadata_h,
+ void* user_data) {
+ ScopeLogger();
+ MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ picojson::value metadata = picojson::value(picojson::object());
+ PlatformResult result = types::ConvertMetadata(metadata_h, &metadata.get<picojson::object>());
+ if (!result) {
+ LoggerE("ConvertMetadata failed, error: %s", result.message().c_str());
+ return;
+ }
+
+ data_o[kAction] = picojson::value(std::string("onmetadatachanged"));
+ data_o[kMetadata] = metadata;
+ data_o[kName] = picojson::value(server_name);
+
+ client->playback_info_listener_(&data);
+}
+
+PlatformResult MediaControllerClient::SendSearchRequest(const std::string& server_name,
+ const picojson::value& request,
+ const JsonCallback& callback,
+ char** request_id) {
+ ScopeLogger();
+ mc_search_h search_request;
+ SCOPE_EXIT {
+ mc_search_destroy(search_request);
+ };
+
+ int ret = mc_search_create(&search_request);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to create search request.",
+ ("mc_search_create error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ if (!request.is<picojson::array>()) {
+ return LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR,
+ "MediaControllerClient::SendSearchRequest request param is not an array.");
+ }
+
+ for (const auto& filter_obj : request.get<picojson::array>()) {
+ const picojson::object& filter = filter_obj.get<picojson::object>();
+
+ // contentType
+ std::string content_type_str = filter.at(kContentType).get<std::string>();
+ mc_content_type_e content_type_e;
+ PlatformResult result =
+ types::MediaControllerContentTypeEnum.getValue(content_type_str, &content_type_e);
+ if (!result) {
+ LoggerE("MediaControllerContentTypeEnum.getValue(%s) failed.", content_type_str.c_str());
+ return result;
+ }
+
+ // category
+ std::string search_category_str = filter.at("category").get<std::string>();
+ mc_search_category_e search_category_e;
+ result =
+ types::MediaControllerSearchCategoryEnum.getValue(search_category_str, &search_category_e);
+ if (!result) {
+ LoggerE("MediaControllerSearchCategoryEnum.getValue(%s) failed.",
+ search_category_str.c_str());
+ return result;
+ }
+
+ // extra data
+ bundle* bundle_data = nullptr;
+ SCOPE_EXIT {
+ bundle_free(bundle_data);
+ };
+ result = JsonToBundle(filter.at(kExtraData), &bundle_data);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Unable to add data to bundle",
+ ("JsonToBundle() error message: %s", result.message().c_str()));
+ }
+
+ // keyword
+ // null is valid search keyword in case of NO_CATEGORY
+ char* search_keyword = nullptr;
+ if (filter.at(kKeyword).is<std::string>()) {
+ search_keyword = (char*)filter.at(kKeyword).get<std::string>().c_str();
+ }
+ ret = mc_search_set_condition(search_request, content_type_e, search_category_e, search_keyword,
+ bundle_data);
+
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to set search condition.",
+ ("mc_search_set_condition error: %d, message: %s", ret, get_error_message(ret)));
+ }
+ }
+
+ ret = mc_client_send_search_cmd(handle_, server_name.c_str(), search_request, request_id);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to send search request.",
+ ("mc_client_send_search_cmd error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ command_reply_callback_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
PlatformResult MediaControllerClient::SendCommand(const std::string& server_name,
const std::string& command,
const picojson::value& data,
const JsonCallback& reply_cb, char** request_id) {
ScopeLogger();
- bundle* bundle = bundle_create();
+ bundle* bundle_data = nullptr;
SCOPE_EXIT {
- bundle_free(bundle);
+ bundle_free(bundle_data);
};
- int ret;
- ret = bundle_add(bundle, "data", data.serialize().c_str());
- if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Unable to add data to bundle",
- ("bundle_add(data) error: %d, message: %s", ret, get_error_message(ret)));
+ PlatformResult result = common::JsonToBundle(data, &bundle_data);
+ if (!result) {
+ LoggerE("JsonToBundle() failed.");
+ return result;
}
- ret =
- mc_client_send_custom_cmd(handle_, server_name.c_str(), command.c_str(), bundle, request_id);
+ if (nullptr == bundle_data) {
+ LoggerD("bundle is null");
+ }
+ int ret = mc_client_send_custom_cmd(handle_, server_name.c_str(), command.c_str(), bundle_data,
+ request_id);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, "Error sending custom command",
}
command_reply_callback_ = reply_cb;
-
return PlatformResult(ErrorCode::NO_ERROR);
}
picojson::value reply = picojson::value(picojson::object());
picojson::object& reply_o = reply.get<picojson::object>();
- int ret;
- char* data_str = nullptr;
- SCOPE_EXIT {
- free(data_str);
- };
picojson::value data;
-
- ret = bundle_get_str(bundle, "data", &data_str);
- if (BUNDLE_ERROR_NONE != ret || nullptr == data_str) {
- LoggerE("bundle_get_str(data) failed, error: %d", ret);
- } else {
- std::string err;
- picojson::parse(data, data_str, data_str + strlen(data_str), &err);
- if (!err.empty()) {
- LoggerE("Failed to parse bundle data: %s", err.c_str());
- ReportError(out_o);
- client->command_reply_callback_(&out);
- return;
- }
+ PlatformResult result = common::BundleToJson(bundle, &data);
+ if (!result) {
+ LoggerE("BundleToJson() failed.");
+ ReportError(out_o);
+ client->command_reply_callback_(&out);
+ return;
}
- reply_o["data"] = data;
- reply_o["name"] = picojson::value(server_name);
+ reply_o[kData] = data;
+ reply_o[kName] = picojson::value(server_name);
+ reply_o[kCode] = picojson::value(static_cast<double>(result_code));
if (nullptr == request_id) {
LoggerE("Request id is null.");
client->command_reply_callback_(&out);
return;
}
- out_o["requestId"] = picojson::value(std::string(request_id));
+ out_o[kRequestId] = picojson::value(std::string(request_id));
ReportSuccess(reply, out_o);
client->command_reply_callback_(&out);
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult MediaControllerClient::SendRepeatState(const std::string& server_name,
+ const std::string& state) {
+ ScopeLogger();
+ /* TODO: Prepare an ACR and propose use case for request_id.
+ char* request_id = nullptr;
+ SCOPE_EXIT {
+ free(request_id);
+ };*/
+ mc_repeat_mode_e state_e;
+ PlatformResult result = types::MediaControllerRepeatModeEnum.getValue(state, &state_e);
+ if (!result) {
+ return result;
+ }
+
+ int ret = mc_client_send_repeat_mode_cmd(handle_, server_name.c_str(), state_e, nullptr);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error sending repeat state",
+ ("mc_client_send_repeat_mode_cmd() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SendPlaybackItem(const std::string& name,
+ const std::string& playlist_name,
+ const std::string& index,
+ const std::string& state, double position) {
+ ScopeLogger();
+
+ // In Native API, since Tizen 5.0 an action instead of a state is sent to change the state of a
+ // server. In Web API the names were not refactored.
+ mc_playback_action_e action_e;
+ PlatformResult result = types::MediaControllerPlaybackActionEnum.getValue(state, &action_e);
+ if (!result) {
+ return result;
+ }
+
+ auto position_ull = static_cast<unsigned long long>(position);
+ int ret = mc_client_send_playlist_cmd(handle_, name.c_str(), playlist_name.c_str(), index.c_str(),
+ action_e, position_ull, nullptr);
+
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error sending playlist item",
+ ("mc_client_send_playlist_cmd() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void MediaControllerClient::OnPlaylistUpdate(const char* server_name,
+ mc_playlist_update_mode_e mode,
+ const char* playlist_name, mc_playlist_h playlist,
+ void* user_data) {
+ ScopeLogger();
+ MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ if (MC_PLAYLIST_UPDATED == mode) {
+ // Create or Update playlist
+ data_o[kAction] = picojson::value(std::string("onplaylistupdated"));
+ } else {
+ data_o[kAction] = picojson::value(std::string("onplaylistdeleted"));
+ }
+
+ data_o[kName] = picojson::value(std::string(playlist_name));
+ data_o[kServerName] = picojson::value(std::string(server_name));
+
+ client->playlist_update_listener_(&data);
+}
+
+PlatformResult MediaControllerClient::SetPlaylistUpdateListener(const JsonCallback& callback) {
+ ScopeLogger();
+
+ int ret = mc_client_set_playlist_updated_cb(handle_, OnPlaylistUpdate, this);
+
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to add playlist listener",
+ ("mc_client_set_playlist_updated_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ playlist_update_listener_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::UnsetPlaylistUpdateListener() {
+ ScopeLogger();
+
+ int ret = mc_client_unset_playlist_updated_cb(handle_);
+
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to remove playlist listener",
+ ("mc_client_unset_playlist_updated_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ playlist_update_listener_ = nullptr;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+// subtitles
+PlatformResult MediaControllerClient::GetSubtitlesEnabled(const std::string& name, bool* enabled) {
+ ScopeLogger();
+
+ int ret = mc_client_get_server_subtitles_enabled(handle_, name.c_str(), enabled);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting subtitle enabled",
+ ("mc_client_get_server_subtitles_enabled() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SendSubtitlesEnabled(const std::string& server_name,
+ bool enabled,
+ const JsonCallback& reply_cb,
+ char** request_id) {
+ ScopeLogger();
+ int ret = mc_client_send_subtitles_cmd(handle_, server_name.c_str(), enabled, request_id);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ utils::ConvertMediaControllerError(ret), "Error sending subtitle command",
+ ("mc_client_send_subtitles_cmd() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ command_reply_callback_ = reply_cb;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SetSubtitlesInfoChangeListener(const JsonCallback& callback) {
+ ScopeLogger();
+
+ int ret = mc_client_set_subtitles_updated_cb(handle_, OnSubtitlesUpdate, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set subtitles listener",
+ ("mc_client_set_subtitles_updated_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ subtitles_update_listener_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::UnsetSubtitlesInfoChangeListener() {
+ ScopeLogger();
+ int ret = mc_client_unset_subtitles_updated_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to unset subtitles listener",
+ ("mc_client_unset_subtitles_updated_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+ subtitles_update_listener_ = nullptr;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void MediaControllerClient::OnSubtitlesUpdate(const char* server_name, bool enabled,
+ void* user_data) {
+ ScopeLogger();
+ MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ data_o[kEnabled] = picojson::value(enabled);
+ data_o[kName] = picojson::value(server_name);
+
+ client->subtitles_update_listener_(&data);
+}
+
+// mode360
+PlatformResult MediaControllerClient::GetMode360Enabled(const std::string& name, bool* enabled) {
+ ScopeLogger();
+
+ int ret = mc_client_get_server_360_mode_enabled(handle_, name.c_str(), enabled);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting mode 360 enabled",
+ ("mc_client_get_server_360_mode_enabled() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SendMode360Enabled(const std::string& server_name,
+ bool enabled, const JsonCallback& reply_cb,
+ char** request_id) {
+ ScopeLogger();
+ int ret = mc_client_send_360_mode_cmd(handle_, server_name.c_str(), enabled, request_id);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ utils::ConvertMediaControllerError(ret), "Error sending 360 mode command",
+ ("mc_client_send_360_mode_cmd() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ command_reply_callback_ = reply_cb;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SetMode360InfoChangeListener(const JsonCallback& callback) {
+ ScopeLogger();
+
+ int ret = mc_client_set_360_mode_updated_cb(handle_, OnMode360Update, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set mode 360 listener",
+ ("mc_client_set_360_mode_updated_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ mode360_update_listener_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::UnsetMode360InfoChangeListener() {
+ ScopeLogger();
+ int ret = mc_client_unset_360_mode_updated_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to unset mode 360 listener",
+ ("mc_client_unset_360_mode_updated_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+ mode360_update_listener_ = nullptr;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void MediaControllerClient::OnMode360Update(const char* server_name, bool enabled,
+ void* user_data) {
+ ScopeLogger();
+ MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ data_o[kEnabled] = picojson::value(enabled);
+ data_o[kName] = picojson::value(server_name);
+
+ client->mode360_update_listener_(&data);
+}
+
+// displayMode
+PlatformResult MediaControllerClient::GetDisplayModeType(const std::string& name,
+ std::string* type) {
+ ScopeLogger();
+ mc_display_mode_e mode = MC_DISPLAY_MODE_FULL_SCREEN;
+
+ int ret = mc_client_get_server_display_mode(handle_, name.c_str(), &mode);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting display mode type",
+ ("mc_client_get_server_display_mode() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ PlatformResult result = types::MediaControllerDisplayModeEnum.getName(mode, type);
+ if (!result) {
+ LoggerE("MediaControllerDisplayModeEnum.getName() failed, error: %s", result.message().c_str());
+ return result;
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SendDisplayModeType(const std::string& server_name,
+ const std::string& type,
+ const JsonCallback& reply_cb,
+ char** request_id) {
+ ScopeLogger();
+ mc_display_mode_e mode = MC_DISPLAY_MODE_FULL_SCREEN;
+ PlatformResult result = types::MediaControllerDisplayModeEnum.getValue(type, &mode);
+ if (!result) {
+ LoggerE("MediaControllerDisplayModeEnum.getValue() failed, error: %s",
+ result.message().c_str());
+ return result;
+ }
+
+ int ret = mc_client_send_display_mode_cmd(handle_, server_name.c_str(), mode, request_id);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ utils::ConvertMediaControllerError(ret), "Error sending display mode command",
+ ("mc_client_send_display_mode_cmd() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ command_reply_callback_ = reply_cb;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SetDisplayModeInfoChangeListener(
+ const JsonCallback& callback) {
+ ScopeLogger();
+
+ int ret = mc_client_set_display_mode_updated_cb(handle_, OnDisplayModeUpdate, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set display mode listener",
+ ("mc_client_set_display_mode_updated_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ display_mode_update_listener_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::UnsetDisplayModeInfoChangeListener() {
+ ScopeLogger();
+ int ret = mc_client_unset_display_mode_updated_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to unset display mode listener",
+ ("mc_client_unset_display_mode_updated_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+ display_mode_update_listener_ = nullptr;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void MediaControllerClient::OnDisplayModeUpdate(const char* server_name, mc_display_mode_e mode,
+ void* user_data) {
+ ScopeLogger();
+ MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ std::string mode_str;
+ PlatformResult result = types::MediaControllerDisplayModeEnum.getName(mode, &mode_str);
+ if (!result) {
+ LoggerW("MediaControllerDisplayModeEnum.getName() failed, error: %s, ignoring event",
+ result.message().c_str());
+ return;
+ }
+
+ data_o[kDisplayMode] = picojson::value(mode_str);
+ data_o[kName] = picojson::value(server_name);
+
+ client->display_mode_update_listener_(&data);
+}
+
+// displayRotation
+PlatformResult MediaControllerClient::GetDisplayRotation(const std::string& name,
+ std::string* display_rotation) {
+ ScopeLogger();
+ mc_display_rotation_e rotation = MC_DISPLAY_ROTATION_NONE;
+
+ int ret = mc_client_get_server_display_rotation(handle_, name.c_str(), &rotation);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting display rotation",
+ ("mc_client_get_server_display_rotation() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ PlatformResult result =
+ types::MediaControllerDisplayRotationEnum.getName(rotation, display_rotation);
+ if (!result) {
+ LoggerE("MediaControllerDisplayRotationEnum.getName() failed, error: %s",
+ result.message().c_str());
+ return PlatformResult(ErrorCode::UNKNOWN_ERR);
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SendDisplayRotation(const std::string& server_name,
+ const std::string& display_rotation,
+ const JsonCallback& reply_cb,
+ char** request_id) {
+ ScopeLogger("Rotation to send: %s", display_rotation.c_str());
+ mc_display_rotation_e rotation = MC_DISPLAY_ROTATION_NONE;
+ PlatformResult result =
+ types::MediaControllerDisplayRotationEnum.getValue(display_rotation, &rotation);
+ if (!result) {
+ LoggerE("MediaControllerDisplayRotationEnum.getValue() failed, error: %s",
+ result.message().c_str());
+ return PlatformResult(ErrorCode::UNKNOWN_ERR);
+ }
+
+ int ret = mc_client_send_display_rotation_cmd(handle_, server_name.c_str(), rotation, request_id);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(utils::ConvertMediaControllerError(ret),
+ "Error sending display rotation command",
+ ("mc_client_send_display_rotation_cmd() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ command_reply_callback_ = reply_cb;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::SetDisplayRotationInfoChangeListener(
+ const JsonCallback& callback) {
+ ScopeLogger();
+
+ if (nullptr != display_rotation_update_listener_) {
+ LoggerD("Native callback already set");
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+
+ int ret = mc_client_set_display_rotation_updated_cb(handle_, OnDisplayRotationUpdate, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set display rotation listener",
+ ("mc_client_set_display_rotation_updated_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ display_rotation_update_listener_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerClient::UnsetDisplayRotationInfoChangeListener() {
+ ScopeLogger();
+ int ret = mc_client_unset_display_rotation_updated_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to unset display rotation listener",
+ ("mc_client_unset_display_rotation_updated_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+ display_rotation_update_listener_ = nullptr;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void MediaControllerClient::OnDisplayRotationUpdate(const char* server_name,
+ mc_display_rotation_e rotation,
+ void* user_data) {
+ ScopeLogger();
+ MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ std::string display_rotation;
+ PlatformResult result =
+ types::MediaControllerDisplayRotationEnum.getName(rotation, &display_rotation);
+ if (!result) {
+ LoggerW("MediaControllerDisplayRotationEnum.getName() failed, error: %s, ignoring event",
+ result.message().c_str());
+ return;
+ }
+
+ data_o[kDisplayRotation] = picojson::value(display_rotation);
+ data_o[kName] = picojson::value(server_name);
+
+ client->display_rotation_update_listener_(&data);
+}
+
+void MediaControllerClient::OnEventReceived(const char* server_name, const char* request_id,
+ const char* event_name, bundle* data, void* user_data) {
+ ScopeLogger();
+ auto* client = static_cast<MediaControllerClient*>(user_data);
+
+ if (!client->custom_event_listener_) {
+ LoggerW("custom_event_listener_ is not set");
+ return;
+ }
+
+ auto args = picojson::value(picojson::object());
+ auto& args_obj = args.get<picojson::object>();
+
+ picojson::value data_json;
+ PlatformResult result = common::BundleToJson(data, &data_json);
+ if (!result) {
+ LoggerE("BundleToJson() failed.");
+ return;
+ }
+
+ args_obj[kServerName] = picojson::value(std::string(server_name));
+ args_obj[kEventName] = picojson::value(std::string(event_name));
+ args_obj[kEventData] = data_json;
+ args_obj[kRequestId] = picojson::value(std::string(request_id));
+
+ client->custom_event_listener_(&args);
+}
+
} // namespace mediacontroller
} // namespace extension
#define MEDIACONTROLLER_MEDIACONTROLLER_CLIENT_H_
#include <media_controller_client.h>
+#include <list>
#include <string>
+#include "common/optional.h"
#include "common/platform_result.h"
-#include "mediacontroller/mediacontroller_types.h"
+#include "mediacontroller/mediacontroller_utils.h"
namespace extension {
namespace mediacontroller {
common::PlatformResult GetPlaybackInfo(const std::string& server_name,
picojson::object* playback_info);
common::PlatformResult GetMetadata(const std::string& server_name, picojson::object* metadata);
-
common::PlatformResult SendPlaybackState(const std::string& server_name,
const std::string& state);
common::PlatformResult SendPlaybackPosition(const std::string& server_name, double position);
common::PlatformResult SendShuffleMode(const std::string& server_name, bool mode);
common::PlatformResult SendRepeatMode(const std::string& server_name, bool mode);
-
+ common::PlatformResult SendRepeatState(const std::string& server_name, const std::string& state);
+ common::PlatformResult SendSearchRequest(const std::string& server_name,
+ const picojson::value& request,
+ const JsonCallback& callback, char** request_id);
common::PlatformResult SendCommand(const std::string& server_name, const std::string& command,
const picojson::value& data, const JsonCallback& reply_cb,
char** request_id);
-
common::PlatformResult SetServerStatusChangeListener(const JsonCallback& callback);
common::PlatformResult UnsetServerStatusChangeListener();
-
common::PlatformResult SetPlaybackInfoListener(const JsonCallback& callback);
common::PlatformResult UnsetPlaybackInfoListener();
+ common::PlatformResult SendPlaybackItem(const std::string& name, const std::string& playlist_name,
+ const std::string& index, const std::string& state,
+ double position);
+ common::PlatformResult SetPlaylistUpdateListener(const JsonCallback& callback);
+ common::PlatformResult UnsetPlaylistUpdateListener();
+ common::PlatformResult GetServerIconURI(const std::string& name,
+ common::optional<std::string>* icon_uri);
+ common::PlatformResult GetPlaybackAbility(const std::string& server_name,
+ const std::string& action, picojson::value* abilities);
+ common::PlatformResult GetDisplayModeAbility(const std::string& server_name,
+ const std::string& mode, std::string* abilities);
+ common::PlatformResult SetAbilityChangeListener(const JsonCallback& callback);
+ common::PlatformResult UnsetAbilityChangeListener();
+ common::PlatformResult GetSimpleAbility(const std::string& server_name,
+ const std::string& ability_type,
+ picojson::value* ability_val);
+ common::PlatformResult GetDisplayRotationAbility(const std::string& server_name,
+ const std::string& display_rotation_ability,
+ std::string* ability_val);
+ common::PlatformResult SubscribeServer(const std::string& server_name);
+ common::PlatformResult UnsubscribeServer(const std::string& server_name);
+ common::PlatformResult FindSubscribedServers(picojson::array* servers);
+ // TODO subtitles
+ common::PlatformResult GetSubtitlesEnabled(const std::string& name, bool* enabled);
+ common::PlatformResult SendSubtitlesEnabled(const std::string& server_name, bool enabled,
+ const JsonCallback& reply_cb, char** request_id);
+ common::PlatformResult SetSubtitlesInfoChangeListener(const JsonCallback& callback);
+ common::PlatformResult UnsetSubtitlesInfoChangeListener();
+ // mode360
+ common::PlatformResult GetMode360Enabled(const std::string& name, bool* enabled);
+ common::PlatformResult SendMode360Enabled(const std::string& server_name, bool enabled,
+ const JsonCallback& reply_cb, char** request_id);
+ common::PlatformResult SetMode360InfoChangeListener(const JsonCallback& callback);
+ common::PlatformResult UnsetMode360InfoChangeListener();
+ // displayMode
+ common::PlatformResult GetDisplayModeType(const std::string& name, std::string* type);
+ common::PlatformResult SendDisplayModeType(const std::string& server_name,
+ const std::string& type, const JsonCallback& reply_cb,
+ char** request_id);
+ common::PlatformResult SetDisplayModeInfoChangeListener(const JsonCallback& callback);
+ common::PlatformResult UnsetDisplayModeInfoChangeListener();
+ // displayRotation
+ common::PlatformResult GetDisplayRotation(const std::string& name, std::string* display_rotation);
+ common::PlatformResult SendDisplayRotation(const std::string& server_name,
+ const std::string& display_rotation,
+ const JsonCallback& reply_cb, char** request_id);
+ common::PlatformResult SetDisplayRotationInfoChangeListener(const JsonCallback& callback);
+ common::PlatformResult UnsetDisplayRotationInfoChangeListener();
+
+ common::PlatformResult SetCustomEventListener(const JsonCallback& callback);
+ common::PlatformResult UnsetCustomEventListener();
+
+ common::PlatformResult SendEventReply(const char* server_name, const picojson::value& data,
+ int result_code, const char* request_id);
private:
mc_client_h handle_;
JsonCallback playback_info_listener_;
JsonCallback server_status_listener_;
JsonCallback command_reply_callback_;
+ JsonCallback playlist_update_listener_;
+ JsonCallback ability_listener_;
+ JsonCallback subtitles_update_listener_;
+ JsonCallback mode360_update_listener_;
+ JsonCallback display_mode_update_listener_;
+ JsonCallback display_rotation_update_listener_;
+ JsonCallback custom_event_listener_;
+
+ std::list<std::string> subscribed_servers;
static bool FindServersCallback(const char* server_name, void* user_data);
static void OnShuffleModeUpdate(const char* server_name, mc_shuffle_mode_e mode, void* user_data);
static void OnRepeatModeUpdate(const char* server_name, mc_repeat_mode_e mode, void* user_data);
static void OnMetadataUpdate(const char* server_name, mc_metadata_h metadata_h, void* user_data);
+ static void OnPlaylistUpdate(const char* server_name, mc_playlist_update_mode_e mode,
+ const char* playlist_name, mc_playlist_h playlist, void* user_data);
+ static void OnPlaybackAbilityUpdate(const char* server_name, mc_playback_ability_h ability,
+ void* user_data);
+ static void OnDisplayModeAbilityUpdate(const char* server_name, u_int mode, void* user_data);
+ static void OnDisplayRotationAbilityUpdate(const char* server_name, u_int supported_items,
+ void* user_data);
+ static void OnSimpleAbilityUpdate(const char* server_name, mc_ability_e type,
+ mc_ability_support_e mode, void* user_data);
+ // subtitles
+ static void OnSubtitlesUpdate(const char* server_name, bool enabled, void* user_data);
+ // mode360
+ static void OnMode360Update(const char* server_name, bool enabled, void* user_data);
+ // displayMode
+ static void OnDisplayModeUpdate(const char* server_name, mc_display_mode_e mode, void* user_data);
+ // displayRotation
+ static void OnDisplayRotationUpdate(const char* server_name, mc_display_rotation_e rotation,
+ void* user_data);
+ static void OnEventReceived(const char* server_name, const char* request_id, const char* event,
+ bundle* data, void* user_data);
};
} // namespace mediacontroller
#include "mediacontroller/mediacontroller_instance.h"
+#include "common/current_application.h"
#include "common/logger.h"
#include "common/picojson.h"
#include "common/platform_result.h"
#include "common/task-queue.h"
#include "common/tools.h"
-#include "mediacontroller/mediacontroller_types.h"
+#include "mediacontroller/mediacontroller_utils.h"
+
+#define MediaControllerUnknownErrorMsg "Unknown error occurred."
+#define MediaControllerServerUnknownErrorMsg "Failed: server_"
+#define MediaControllerClientUnknownErrorMsg "Failed: client_"
namespace extension {
namespace mediacontroller {
-namespace {
-
-const std::string kPrivilegeMediaControllerClient =
- "http://tizen.org/privilege/mediacontroller.client";
-const std::string kPrivilegeMediaControllerServer =
- "http://tizen.org/privilege/mediacontroller.server";
-
-} // namespace
+using namespace privileges;
+using namespace attributes;
using common::ErrorCode;
using common::PlatformResult;
ScopeLogger();
using namespace std::placeholders;
-#define REGISTER_SYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&MediaControllerInstance::x, this, _1, _2));
-#define REGISTER_ASYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&MediaControllerInstance::x, this, _1, _2));
+#define REGISTER_METHOD(M) \
+ RegisterSyncHandler(#M, std::bind(&MediaControllerInstance::M, this, _1, _2))
// server
- REGISTER_SYNC("MediaControllerManager_createServer", MediaControllerManagerCreateServer);
- REGISTER_SYNC("MediaControllerServer_updatePlaybackState",
- MediaControllerServerUpdatePlaybackState);
- REGISTER_SYNC("MediaControllerServer_updatePlaybackPosition",
- MediaControllerServerUpdatePlaybackPosition);
- REGISTER_SYNC("MediaControllerServer_updateRepeatMode", MediaControllerServerUpdateRepeatMode);
- REGISTER_SYNC("MediaControllerServer_updateShuffleMode", MediaControllerServerUpdateShuffleMode);
- REGISTER_SYNC("MediaControllerServer_updateMetadata", MediaControllerServerUpdateMetadata);
- REGISTER_SYNC("MediaControllerServer_addChangeRequestPlaybackInfoListener",
- MediaControllerServerAddChangeRequestPlaybackInfoListener);
- REGISTER_SYNC("MediaControllerServer_removeChangeRequestPlaybackInfoListener",
- MediaControllerServerRemoveChangeRequestPlaybackInfoListener);
- REGISTER_SYNC("MediaControllerServer_addCommandListener",
- MediaControllerServerAddCommandListener);
- REGISTER_SYNC("MediaControllerServer_replyCommand", MediaControllerServerReplyCommand);
- REGISTER_SYNC("MediaControllerServer_removeCommandListener",
- MediaControllerServerRemoveCommandListener);
+ REGISTER_METHOD(MediaControllerManagerCreateServer);
+ REGISTER_METHOD(MediaControllerServerUpdatePlaybackState);
+ REGISTER_METHOD(MediaControllerServerUpdatePlaybackPosition);
+ REGISTER_METHOD(MediaControllerServerUpdatePlaybackAgeRating);
+ REGISTER_METHOD(MediaControllerServerUpdateRepeatMode);
+ REGISTER_METHOD(MediaControllerServerUpdateRepeatState);
+ REGISTER_METHOD(MediaControllerServerUpdateShuffleMode);
+ REGISTER_METHOD(MediaControllerServerUpdateMetadata);
+ REGISTER_METHOD(MediaControllerServerUpdatePlaybackContentType);
+ REGISTER_METHOD(MediaControllerServerUpdatePlaybackContentType);
+ REGISTER_METHOD(MediaControllerServerAddChangeRequestPlaybackInfoListener);
+ REGISTER_METHOD(MediaControllerServerRemoveChangeRequestPlaybackInfoListener);
+ REGISTER_METHOD(MediaControllerServerAddSearchRequestListener);
+ REGISTER_METHOD(MediaControllerServerRemoveSearchRequestListener);
+ REGISTER_METHOD(MediaControllerServerAddCommandListener);
+ REGISTER_METHOD(MediaControllerServerReplyCommand);
+ REGISTER_METHOD(MediaControllerServerRemoveCommandListener);
+ REGISTER_METHOD(MediaControllerServerCreatePlaylist);
+ REGISTER_METHOD(MediaControllerServerSavePlaylist);
+ REGISTER_METHOD(MediaControllerServerDeletePlaylist);
+ REGISTER_METHOD(MediaControllerServerUpdatePlaybackItem);
+
+ REGISTER_METHOD(MediaControllerServerGetAllPlaylists);
+ REGISTER_METHOD(MediaControllerServerUpdateIconURI);
+ REGISTER_METHOD(MediaControllerServerSavePlaybackAbilities);
+ REGISTER_METHOD(MediaControllerServerSetDisplayModeAbility);
+ REGISTER_METHOD(MediaControllerServerSetDisplayRotationAbility);
+ REGISTER_METHOD(MediaControllerServerSetSimpleAbility);
+ REGISTER_METHOD(MediaControllerServerGetAllClientsInfo);
+
+ // client info
+ REGISTER_METHOD(MediaControllerClientInfoSendEvent);
// client
- REGISTER_SYNC("MediaControllerManager_getClient", MediaControllerManagerGetClient);
- REGISTER_ASYNC("MediaControllerClient_findServers", MediaControllerClientFindServers);
- REGISTER_SYNC("MediaControllerClient_getLatestServerInfo",
- MediaControllerClientGetLatestServerInfo);
- REGISTER_SYNC("MediaControllerClient_getPlaybackInfo", MediaControllerClientGetPlaybackInfo);
- REGISTER_SYNC("MediaControllerServerInfo_sendPlaybackState",
- MediaControllerServerInfoSendPlaybackState);
- REGISTER_ASYNC("MediaControllerServerInfo_sendPlaybackPosition",
- MediaControllerServerInfoSendPlaybackPosition);
- REGISTER_ASYNC("MediaControllerServerInfo_sendRepeatMode",
- MediaControllerServerInfoSendRepeatMode);
- REGISTER_ASYNC("MediaControllerServerInfo_sendShuffleMode",
- MediaControllerServerInfoSendShuffleMode);
- REGISTER_ASYNC("MediaControllerServerInfo_sendCommand", MediaControllerServerInfoSendCommand);
- REGISTER_SYNC("MediaControllerServerInfo_addServerStatusChangeListener",
- MediaControllerServerInfoAddServerStatusChangeListener);
- REGISTER_SYNC("MediaControllerServerInfo_removeServerStatusChangeListener",
- MediaControllerServerInfoRemoveServerStatusChangeListener);
- REGISTER_SYNC("MediaControllerServerInfo_addPlaybackInfoChangeListener",
- MediaControllerServerInfoAddPlaybackInfoChangeListener);
- REGISTER_SYNC("MediaControllerServerInfo_removePlaybackInfoChangeListener",
- MediaControllerServerInfoRemovePlaybackInfoChangeListener);
-
-#undef REGISTER_SYNC
-#undef REGISTER_ASYNC
+ REGISTER_METHOD(MediaControllerManagerGetClient);
+ REGISTER_METHOD(MediaControllerClientFindServers);
+ REGISTER_METHOD(MediaControllerClientGetLatestServerInfo);
+ REGISTER_METHOD(MediaControllerClientGetPlaybackInfo);
+ REGISTER_METHOD(MediaControllerClientGetPlaybackAbility);
+ REGISTER_METHOD(MediaControllerClientGetDisplayModeAbility);
+ REGISTER_METHOD(MediaControllerClientGetDisplayRotationAbility);
+ REGISTER_METHOD(MediaControllerClientGetSimpleAbility);
+ REGISTER_METHOD(MediaControllerClientFindSubscribedServers);
+ REGISTER_METHOD(MediaControllerClientSendEventReply);
+ REGISTER_METHOD(MediaControllerClientSetCustomEventListener);
+ REGISTER_METHOD(MediaControllerClientUnsetCustomEventListener);
+
+ // server_info
+ REGISTER_METHOD(MediaControllerServerInfoSendPlaybackState);
+ REGISTER_METHOD(MediaControllerServerInfoSendPlaybackPosition);
+ REGISTER_METHOD(MediaControllerServerInfoSendRepeatMode);
+ REGISTER_METHOD(MediaControllerServerInfoSendRepeatState);
+ REGISTER_METHOD(MediaControllerServerInfoSendShuffleMode);
+ REGISTER_METHOD(MediaControllerServerInfoSendSearchRequest);
+ REGISTER_METHOD(MediaControllerServerInfoSendCommand);
+ REGISTER_METHOD(MediaControllerServerInfoAddServerStatusChangeListener);
+ REGISTER_METHOD(MediaControllerServerInfoRemoveServerStatusChangeListener);
+ REGISTER_METHOD(MediaControllerServerInfoAddPlaybackInfoChangeListener);
+ REGISTER_METHOD(MediaControllerServerInfoRemovePlaybackInfoChangeListener);
+ REGISTER_METHOD(MediaControllerServerInfoSendPlaybackItem);
+ REGISTER_METHOD(MediaControllerServerInfoAddPlaylistUpdateListener);
+ REGISTER_METHOD(MediaControllerServerInfoRemovePlaylistUpdateListener);
+ REGISTER_METHOD(MediaControllerServerInfoGetAllPlaylists);
+ REGISTER_METHOD(MediaControllerServerInfoGetIconURI);
+ REGISTER_METHOD(MediaControllerClientAddAbilityChangeListener);
+ REGISTER_METHOD(MediaControllerClientRemoveAbilityChangeListener);
+
+ // abilities_info
+ REGISTER_METHOD(MediaControllerAbilitiesInfoSubscribe);
+ REGISTER_METHOD(MediaControllerAbilitiesInfoUnsubscribe);
+
+ // playlist
+ REGISTER_METHOD(MediaControllerPlaylistAddItem);
+ REGISTER_METHOD(MediaControllerPlaylistGetItems);
+
+ // subtitles
+ REGISTER_METHOD(MediaControllerSubtitlesUpdateEnabled);
+ REGISTER_METHOD(MediaControllerSubtitlesAddChangeRequestListener);
+ REGISTER_METHOD(MediaControllerSubtitlesRemoveChangeRequestListener);
+
+ REGISTER_METHOD(MediaControllerSubtitlesInfoGetEnabled);
+ REGISTER_METHOD(MediaControllerSubtitlesInfoSendRequest);
+ REGISTER_METHOD(MediaControllerSubtitlesInfoAddModeChangeListener);
+ REGISTER_METHOD(MediaControllerSubtitlesInfoRemoveModeChangeListener);
+
+ // mode360
+ REGISTER_METHOD(MediaControllerMode360UpdateEnabled);
+ REGISTER_METHOD(MediaControllerMode360AddChangeRequestListener);
+ REGISTER_METHOD(MediaControllerMode360RemoveChangeRequestListener);
+
+ REGISTER_METHOD(MediaControllerMode360InfoGetEnabled);
+ REGISTER_METHOD(MediaControllerMode360InfoSendRequest);
+ REGISTER_METHOD(MediaControllerMode360InfoAddModeChangeListener);
+ REGISTER_METHOD(MediaControllerMode360InfoRemoveModeChangeListener);
+
+ // displayMode
+ REGISTER_METHOD(MediaControllerDisplayModeUpdateType);
+ REGISTER_METHOD(MediaControllerDisplayModeAddChangeRequestListener);
+ REGISTER_METHOD(MediaControllerDisplayModeRemoveChangeRequestListener);
+
+ REGISTER_METHOD(MediaControllerDisplayModeInfoGetType);
+ REGISTER_METHOD(MediaControllerDisplayModeInfoSendType);
+ REGISTER_METHOD(MediaControllerDisplayModeInfoAddModeChangeListener);
+ REGISTER_METHOD(MediaControllerDisplayModeInfoRemoveModeChangeListener);
+
+ // displayRotation
+ REGISTER_METHOD(MediaControllerDisplayRotationUpdate);
+ REGISTER_METHOD(MediaControllerDisplayRotationAddChangeRequestListener);
+ REGISTER_METHOD(MediaControllerDisplayRotationRemoveChangeRequestListener);
+
+ REGISTER_METHOD(MediaControllerDisplayRotationInfoGet);
+ REGISTER_METHOD(MediaControllerDisplayRotationInfoSend);
+ REGISTER_METHOD(MediaControllerDisplayRotationInfoAddChangeListener);
+ REGISTER_METHOD(MediaControllerDisplayRotationInfoRemoveChangeListener);
+
+#undef REGISTER_METHOD
}
MediaControllerInstance::~MediaControllerInstance() {
ScopeLogger();
}
-#define CHECK_EXIST(args, name, out) \
- if (!args.contains(name)) { \
- LogAndReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, name " is required argument"), \
- &out); \
- return; \
+#define CHECK_EXIST(args, name, out) \
+ if (!args.contains(name)) { \
+ std::string msg = std::string(name) + " is required argument"; \
+ LogAndReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, msg), &out); \
+ return; \
+ }
+
+#define CHECK_TYPE(args, name, type, out) \
+ if (!args.get(name).is<type>()) { \
+ std::string msg = std::string(name) + " is not a " + #type; \
+ LogAndReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, msg), &out); \
+ return; \
}
+#define CHECK_ARGS(args, name, type, out) \
+ CHECK_EXIST(args, name, out) \
+ CHECK_TYPE(args, name, type, out)
+
void MediaControllerInstance::MediaControllerManagerCreateServer(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
void MediaControllerInstance::MediaControllerServerUpdatePlaybackState(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
- CHECK_EXIST(args, "state", out)
+ CHECK_EXIST(args, kState, out)
if (!server_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: server_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- const std::string& state = args.get("state").get<std::string>();
+ const std::string& state = args.get(kState).get<std::string>();
const PlatformResult& result = server_->SetPlaybackState(state);
if (!result) {
LogAndReportError(result, &out, ("Failed server_->SetPlaybackState()"));
ReportSuccess(out);
}
+void MediaControllerInstance::MediaControllerServerUpdateIconURI(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ CHECK_EXIST(args, kIconURI, out);
+
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ const char* icon_uri = nullptr;
+ if (args.get(kIconURI).is<std::string>()) {
+ icon_uri = args.get(kIconURI).get<std::string>().c_str();
+ } else if (!args.get(kIconURI).is<picojson::null>()) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Icon URI must be a string or null."), &out,
+ ("Icon URI is not a string or null."));
+ return;
+ }
+
+ PlatformResult result = server_->UpdateIconURI(icon_uri);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed server_->UpdateIconURI()"));
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
void MediaControllerInstance::MediaControllerServerUpdatePlaybackPosition(
const picojson::value& args, picojson::object& out) {
ScopeLogger();
if (!server_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: server_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "position", out)
+ CHECK_EXIST(args, kPosition, out)
- double position = args.get("position").get<double>();
+ double position = args.get(kPosition).get<double>();
const PlatformResult& result = server_->SetPlaybackPosition(position);
if (!result) {
LogAndReportError(result, &out, ("Failed: server_->SetPlaybackPosition()"));
ReportSuccess(out);
}
+void MediaControllerInstance::MediaControllerServerUpdatePlaybackAgeRating(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Server handle not initialized."),
+ &out, (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kRating, out)
+
+ const std::string& rating = args.get(kRating).get<std::string>();
+ const PlatformResult& result = server_->SetContentAgeRating(rating);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: server_->SetContentAgeRating()"));
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
void MediaControllerInstance::MediaControllerServerUpdateShuffleMode(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
if (!server_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: server_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "mode", out)
+ CHECK_EXIST(args, kMode, out)
- bool mode = args.get("mode").get<bool>();
+ bool mode = args.get(kMode).get<bool>();
const PlatformResult& result = server_->SetShuffleMode(mode);
if (!result) {
ReportSuccess(out);
}
+void MediaControllerInstance::MediaControllerServerUpdatePlaybackContentType(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kContentType, std::string, out);
+ std::string content_type = args.get(kContentType).get<std::string>();
+
+ PlatformResult result = server_->SetContentType(content_type);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: server_>SetContentType()"));
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
void MediaControllerInstance::MediaControllerServerUpdateRepeatMode(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ common::tools::PrintDeprecationWarningFor("updateRepeatMode()", "updateRepeatState()");
if (!server_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: server_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "mode", out)
+ CHECK_EXIST(args, kMode, out)
- bool mode = args.get("mode").get<bool>();
+ bool mode = args.get(kMode).get<bool>();
const PlatformResult& result = server_->SetRepeatMode(mode);
if (!result) {
ReportSuccess(out);
}
+void MediaControllerInstance::MediaControllerServerUpdateRepeatState(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ CHECK_EXIST(args, kState, out)
+
+ const std::string& state = args.get(kState).get<std::string>();
+
+ const PlatformResult& result = server_->SetRepeatState(state);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: server_->SetRepeatState()"));
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
void MediaControllerInstance::MediaControllerServerUpdateMetadata(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
if (!server_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: server_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "metadata", out)
+ CHECK_EXIST(args, kMetadata, out)
- const picojson::object& metadata = args.get("metadata").get<picojson::object>();
+ const picojson::object& metadata = args.get(kMetadata).get<picojson::object>();
const PlatformResult& result = server_->SetMetadata(metadata);
if (!result) {
const picojson::value& args, picojson::object& out) {
ScopeLogger();
if (!server_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: server_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "listenerId", out)
+ CHECK_EXIST(args, kListenerId, out)
JsonCallback callback = [this, args](picojson::value* data) -> void {
if (!data) {
}
picojson::object& request_o = data->get<picojson::object>();
- request_o["listenerId"] = args.get("listenerId");
+ request_o[kListenerId] = args.get(kListenerId);
Instance::PostMessage(this, data->serialize().c_str());
};
const picojson::value& args, picojson::object& out) {
ScopeLogger();
if (!server_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: server_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
}
}
-void MediaControllerInstance::MediaControllerServerAddCommandListener(const picojson::value& args,
- picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerAddSearchRequestListener(
+ const picojson::value& args, picojson::object& out) {
ScopeLogger();
+
if (!server_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: server_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Server not initialized."), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- JsonCallback on_command = [this, args](picojson::value* request) -> void {
+ JsonCallback on_request = [this, args](picojson::value* request) -> void {
picojson::object& request_o = request->get<picojson::object>();
- request_o["listenerId"] = args.get("listenerId");
-
+ request_o[kListenerId] = args.get(kListenerId);
Instance::PostMessage(this, request->serialize().c_str());
};
- auto result = server_->SetCommandListener(on_command);
+ auto result = server_->SetSearchRequestListener(on_request);
if (!result) {
LogAndReportError(result, &out);
+ return;
}
ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerServerReplyCommand(const picojson::value& args,
- picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerRemoveSearchRequestListener(
+ const picojson::value& args, picojson::object& out) {
ScopeLogger();
+
if (!server_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: server_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Server not initialized."), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "clientName", out)
- CHECK_EXIST(args, "requestId", out)
- CHECK_EXIST(args, "data", out)
-
- auto result = server_->CommandReply(args.get("clientName").get<std::string>(),
- args.get("requestId").get<std::string>(), args.get("data"));
-
+ auto result = server_->UnsetSearchRequestListener();
if (!result) {
LogAndReportError(result, &out);
return;
}
-
- ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerServerRemoveCommandListener(
- const picojson::value& args, picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerAddCommandListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
if (!server_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: server_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- auto result = server_->UnsetCommandListener();
- if (!result) {
- LogAndReportError(result, &out);
- }
-
- ReportSuccess(out);
-}
-
-void MediaControllerInstance::MediaControllerManagerGetClient(const picojson::value& args,
- picojson::object& out) {
- ScopeLogger();
-
- CHECK_PRIVILEGE_ACCESS(kPrivilegeMediaControllerClient, &out);
+ JsonCallback on_command = [this, args](picojson::value* request) -> void {
+ picojson::object& request_o = request->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
- if (client_) {
- ReportSuccess(out);
- return;
- }
+ Instance::PostMessage(this, request->serialize().c_str());
+ };
- client_ = std::make_shared<MediaControllerClient>();
- const PlatformResult& result = client_->Init();
+ auto result = server_->SetCommandListener(on_command);
if (!result) {
- client_.reset();
- LogAndReportError(result, &out, ("Failed: client_->Init()"));
+ LogAndReportError(result, &out);
}
ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerClientFindServers(const picojson::value& args,
- picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerReplyCommand(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
- if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "callbackId", out)
-
- auto search = [this, args]() -> void {
- picojson::value response = picojson::value(picojson::object());
- picojson::object& response_obj = response.get<picojson::object>();
+ CHECK_EXIST(args, kClientName, out);
+ CHECK_EXIST(args, kRequestId, out);
+ CHECK_EXIST(args, kReply, out);
- picojson::value servers = picojson::value(picojson::array());
- PlatformResult result = client_->FindServers(&servers.get<picojson::array>());
+ auto client_name = args.get(kClientName).get<std::string>();
+ auto request_id = args.get(kRequestId).get<std::string>();
- response_obj["callbackId"] = args.get("callbackId");
- if (result) {
- ReportSuccess(servers, response_obj);
- } else {
- LogAndReportError(result, &response_obj, ("Failed to find servers"));
- }
+ auto reply = args.get(kReply);
+ CHECK_EXIST(reply, kCode, out);
+ CHECK_EXIST(reply, kData, out);
- Instance::PostMessage(this, response.serialize().c_str());
- };
+ LoggerD("reply json: %s", reply.serialize().c_str());
+ int code = static_cast<int>(reply.get(kCode).get<double>());
+ auto data = reply.get(kData);
- TaskQueue::GetInstance().Async(search);
+ auto result = server_->CommandReply(client_name, request_id, code, data);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerClientGetLatestServerInfo(const picojson::value& args,
- picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerRemoveCommandListener(
+ const picojson::value& args, picojson::object& out) {
ScopeLogger();
- if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- picojson::value server_info = picojson::value();
- PlatformResult result = client_->GetLatestServerInfo(&server_info);
+ auto result = server_->UnsetCommandListener();
if (!result) {
- LogAndReportError(result, &out, ("Failed: client_->GetLatestServerInfo"));
- return;
+ LogAndReportError(result, &out);
}
- ReportSuccess(server_info, out);
+ ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerClientGetPlaybackInfo(const picojson::value& args,
- picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerCreatePlaylist(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
- if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "name", out)
+ CHECK_ARGS(args, kName, std::string, out)
- picojson::value playback_info = picojson::value(picojson::object());
- PlatformResult result = client_->GetPlaybackInfo(args.get("name").get<std::string>(),
- &playback_info.get<picojson::object>());
+ picojson::value playlist_info = picojson::value();
+ auto result = server_->CreatePlaylist(args.get(kName).get<std::string>(), &playlist_info);
if (!result) {
- LogAndReportError(result, &out, ("Failed: client_->GetPlaybackInfo"));
+ LogAndReportError(result, &out, ("Failed: server_->CreatePlaylist["));
return;
}
- ReportSuccess(playback_info, out);
+ ReportSuccess(playlist_info, out);
}
-void MediaControllerInstance::MediaControllerServerInfoSendPlaybackState(
- const picojson::value& args, picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerSavePlaylist(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
- if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "callbackId", out)
- CHECK_EXIST(args, "name", out)
- CHECK_EXIST(args, "state", out)
+ CHECK_EXIST(args, kCallbackId, out)
+ CHECK_ARGS(args, kName, std::string, out)
- auto send = [this, args]() -> void {
+ auto save = [this, args]() -> void {
picojson::value response = picojson::value(picojson::object());
picojson::object& response_obj = response.get<picojson::object>();
- response_obj["callbackId"] = args.get("callbackId");
+ response_obj[kCallbackId] = args.get(kCallbackId);
- PlatformResult result = client_->SendPlaybackState(args.get("name").get<std::string>(),
- args.get("state").get<std::string>());
+ auto result = server_->SavePlaylist(args.get(kName).get<std::string>());
if (result) {
ReportSuccess(response_obj);
} else {
- LogAndReportError(result, &response_obj, ("Failed: client_->SendPlaybackState"));
+ LogAndReportError(result, &response_obj, ("Failed: server_->SavePlaylist"));
}
Instance::PostMessage(this, response.serialize().c_str());
};
- TaskQueue::GetInstance().Async(send);
+ TaskQueue::GetInstance().Async(save);
ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerServerInfoSendPlaybackPosition(
- const picojson::value& args, picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerDeletePlaylist(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
- if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "callbackId", out)
- CHECK_EXIST(args, "name", out)
- CHECK_EXIST(args, "position", out)
+ CHECK_EXIST(args, kCallbackId, out)
+ CHECK_ARGS(args, kName, std::string, out)
- auto send = [this, args]() -> void {
+ auto del = [this, args]() -> void {
picojson::value response = picojson::value(picojson::object());
picojson::object& response_obj = response.get<picojson::object>();
- response_obj["callbackId"] = args.get("callbackId");
+ response_obj[kCallbackId] = args.get(kCallbackId);
- PlatformResult result = client_->SendPlaybackPosition(args.get("name").get<std::string>(),
- args.get("position").get<double>());
+ auto result = server_->DeletePlaylist(args.get(kName).get<std::string>());
if (result) {
ReportSuccess(response_obj);
} else {
- LogAndReportError(result, &response_obj, ("Failed: client_->SendPlaybackPosition"));
+ LogAndReportError(result, &response_obj, ("Failed: server_->DeletePlaylist"));
}
Instance::PostMessage(this, response.serialize().c_str());
};
- TaskQueue::GetInstance().Async(send);
+ TaskQueue::GetInstance().Async(del);
ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerServerInfoSendShuffleMode(const picojson::value& args,
- picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerUpdatePlaybackItem(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
- if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+ CHECK_ARGS(args, kPlaylistName, std::string, out)
+ CHECK_ARGS(args, kIndex, std::string, out)
+
+ auto result = server_->UpdatePlaybackItem(args.get(kPlaylistName).get<std::string>(),
+ args.get(kIndex).get<std::string>());
+ if (!result) {
+ LogAndReportError(result, &out);
return;
}
- CHECK_EXIST(args, "callbackId", out)
- CHECK_EXIST(args, "name", out)
- CHECK_EXIST(args, "mode", out)
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerGetAllPlaylists(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
- auto send = [this, args]() -> void {
+ auto get = [this, args]() -> void {
picojson::value response = picojson::value(picojson::object());
picojson::object& response_obj = response.get<picojson::object>();
- response_obj["callbackId"] = args.get("callbackId");
- PlatformResult result =
- client_->SendShuffleMode(args.get("name").get<std::string>(), args.get("mode").get<bool>());
+ response_obj[kCallbackId] = args.get(kCallbackId);
- if (result) {
- ReportSuccess(response_obj);
- } else {
- LogAndReportError(result, &response_obj, ("Failed to send shuffle mode."));
+ std::string app_id = common::CurrentApplication::GetInstance().GetApplicationId();
+
+ if (app_id.empty()) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error while get playlists"),
+ &response_obj, ("CurrentApplication::GetInstance().GetApplicationId()"));
+ Instance::PostMessage(this, response.serialize().c_str());
+ return;
+ }
+
+ picojson::value playlists{picojson::array{}};
+ auto result = utils::GetAllPlaylists(app_id, &playlists.get<picojson::array>());
+
+ if (!result) {
+ LogAndReportError(result, &response_obj, ("Failed: utils::GetAllPlaylists"));
+ Instance::PostMessage(this, response.serialize().c_str());
+ return;
}
+ response_obj[kResult] = picojson::value{playlists};
+ ReportSuccess(response_obj);
Instance::PostMessage(this, response.serialize().c_str());
};
- TaskQueue::GetInstance().Async(send);
+ TaskQueue::GetInstance().Async(get);
ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerServerInfoSendRepeatMode(const picojson::value& args,
- picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerSavePlaybackAbilities(
+ const picojson::value& args, picojson::object& out) {
ScopeLogger();
- if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "callbackId", out)
- CHECK_EXIST(args, "name", out)
- CHECK_EXIST(args, "mode", out)
-
- auto send = [this, args]() -> void {
- picojson::value response = picojson::value(picojson::object());
- picojson::object& response_obj = response.get<picojson::object>();
- response_obj["callbackId"] = args.get("callbackId");
-
- PlatformResult result =
- client_->SendRepeatMode(args.get("name").get<std::string>(), args.get("mode").get<bool>());
-
- if (result) {
- ReportSuccess(response_obj);
- } else {
- LogAndReportError(result, &response_obj, ("Failed to send repeat mode."));
- }
-
- Instance::PostMessage(this, response.serialize().c_str());
- };
+ for (auto e : types::MediaControllerPlaybackActionEnum) {
+ CHECK_ARGS(args, e.first, std::string, out);
+ }
+ CHECK_ARGS(args, "TOGGLE_PLAY_PAUSE", std::string, out)
- TaskQueue::GetInstance().Async(send);
+ const PlatformResult& result = server_->SavePlaybackAbilities(args);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed server_->SavePlaybackAbilities()"));
+ return;
+ }
ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerServerInfoSendCommand(const picojson::value& args,
- picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerSetDisplayModeAbility(
+ const picojson::value& args, picojson::object& out) {
ScopeLogger();
- if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "listenerId", out)
- CHECK_EXIST(args, "name", out)
- CHECK_EXIST(args, "command", out)
- CHECK_EXIST(args, "data", out)
+ CHECK_ARGS(args, kMode, std::string, out)
+ CHECK_ARGS(args, kSupport, std::string, out)
- JsonCallback reply_cb = [this, args](picojson::value* reply) -> void {
- picojson::object& reply_obj = reply->get<picojson::object>();
- reply_obj["listenerId"] = args.get("listenerId");
- Instance::PostMessage(this, reply->serialize().c_str());
- };
+ std::string support = args.get(kSupport).get<std::string>();
+ std::string mode = args.get(kMode).get<std::string>();
- char* request_id = nullptr;
- SCOPE_EXIT {
+ const PlatformResult& result = server_->SetDisplayModeAbility(mode, support);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed server_->SetDisplayModeAbility()"));
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerSetDisplayRotationAbility(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kDisplayRotationAbility, std::string, out)
+ CHECK_ARGS(args, kSupport, std::string, out)
+
+ std::string display_rotation_ability = args.get(kDisplayRotationAbility).get<std::string>();
+ std::string support = args.get(kSupport).get<std::string>();
+ const PlatformResult& result =
+ server_->SetDisplayRotationAbility(display_rotation_ability, support);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed server_->SetDisplayRotationAbility()"));
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerSetSimpleAbility(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kAbilityType, std::string, out)
+ CHECK_ARGS(args, kSupport, std::string, out)
+
+ std::string ability_type = args.get(kAbilityType).get<std::string>();
+ std::string support = args.get(kSupport).get<std::string>();
+ const PlatformResult& result = server_->SetSimpleAbility(ability_type, support);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed server_->SetSimpleAbility()"));
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerGetAllClientsInfo(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occurred."), &out,
+ ("Failed: server_"));
+ return;
+ }
+
+ picojson::array clientsInfo;
+ auto result = server_->GetAllClientsInfo(&clientsInfo);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(picojson::value(clientsInfo), out);
+}
+
+void MediaControllerInstance::MediaControllerClientInfoSendEvent(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occurred."), &out,
+ ("Failed: server_"));
+ return;
+ }
+
+ CHECK_ARGS(args, kEventName, std::string, out);
+ CHECK_EXIST(args, kEventData, out);
+ CHECK_ARGS(args, kClientName, std::string, out);
+ CHECK_ARGS(args, kReplyListener, std::string, out);
+
+ JsonCallback reply_cb = [this, args](picojson::value* reply) -> void {
+ picojson::object& reply_obj = reply->get<picojson::object>();
+ reply_obj[kListenerId] = args.get(kReplyListener);
+ Instance::PostMessage(this, reply->serialize().c_str());
+ };
+
+ char* request_id = nullptr;
+ SCOPE_EXIT {
+ free(request_id);
+ };
+
+ PlatformResult result =
+ server_->SendEvent(args.get(kEventName).get<std::string>().c_str(), args.get(kEventData),
+ args.get(kClientName).get<std::string>().c_str(), reply_cb, &request_id);
+
+ if (result) {
+ out[kRequestId] = picojson::value(std::string(request_id));
+ ReportSuccess(out);
+ } else {
+ LogAndReportError(result, &out, ("Failed to send event."));
+ }
+}
+
+void MediaControllerInstance::MediaControllerManagerGetClient(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeMediaControllerClient, &out);
+
+ if (client_) {
+ ReportSuccess(out);
+ return;
+ }
+
+ client_ = std::make_shared<MediaControllerClient>();
+ const PlatformResult& result = client_->Init();
+ if (!result) {
+ client_.reset();
+ LogAndReportError(result, &out, ("Failed: client_->Init()"));
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerClientSendEventReply(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occurred."), &out,
+ ("Failed: client_"));
+ return;
+ }
+
+ CHECK_ARGS(args, kServerName, std::string, out);
+ CHECK_EXIST(args, kResult, out);
+ CHECK_ARGS(args, kRequestId, std::string, out);
+ CHECK_ARGS(args, kResultCode, double, out);
+
+ auto result =
+ client_->SendEventReply(args.get(kServerName).get<std::string>().c_str(), args.get(kResult),
+ static_cast<int>(args.get(kResultCode).get<double>()),
+ args.get(kRequestId).get<std::string>().c_str());
+
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerClientSetCustomEventListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occurred."), &out,
+ ("Failed: client_"));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out);
+
+ JsonCallback callback = [this, args](picojson::value* data) -> void {
+ if (nullptr == data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
+
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = client_->SetCustomEventListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerClientUnsetCustomEventListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occurred."), &out,
+ ("Failed: client_"));
+ return;
+ }
+
+ auto result = client_->UnsetCustomEventListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerClientFindServers(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kCallbackId, out)
+
+ auto search = [this, args]() -> void {
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& response_obj = response.get<picojson::object>();
+
+ picojson::value servers = picojson::value(picojson::array());
+ PlatformResult result = client_->FindServers(&servers.get<picojson::array>());
+
+ response_obj[kCallbackId] = args.get(kCallbackId);
+ if (result) {
+ ReportSuccess(servers, response_obj);
+ } else {
+ LogAndReportError(result, &response_obj, ("Failed to find servers"));
+ }
+
+ Instance::PostMessage(this, response.serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Async(search);
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerClientGetLatestServerInfo(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ picojson::value server_info = picojson::value();
+ PlatformResult result = client_->GetLatestServerInfo(&server_info);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: client_->GetLatestServerInfo"));
+ return;
+ }
+
+ ReportSuccess(server_info, out);
+}
+
+void MediaControllerInstance::MediaControllerClientGetPlaybackInfo(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kName, out)
+
+ picojson::value playback_info = picojson::value(picojson::object());
+ PlatformResult result = client_->GetPlaybackInfo(args.get(kName).get<std::string>(),
+ &playback_info.get<picojson::object>());
+
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: client_->GetPlaybackInfo"));
+ return;
+ }
+
+ ReportSuccess(playback_info, out);
+}
+
+void MediaControllerInstance::MediaControllerClientGetPlaybackAbility(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kServerName, std::string, out)
+ CHECK_ARGS(args, kAction, std::string, out)
+
+ std::string server_name = args.get(kServerName).get<std::string>();
+ std::string action = args.get(kAction).get<std::string>();
+ picojson::value ability = picojson::value(picojson::object());
+ PlatformResult result = client_->GetPlaybackAbility(server_name, action, &ability);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: client_->GetPlaybackAbility"));
+ return;
+ }
+
+ ReportSuccess(ability, out);
+}
+
+void MediaControllerInstance::MediaControllerClientGetDisplayModeAbility(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kServerName, std::string, out)
+ CHECK_ARGS(args, kMode, std::string, out)
+
+ std::string server_name = args.get(kServerName).get<std::string>();
+ std::string mode = args.get(kMode).get<std::string>();
+ std::string ability;
+ PlatformResult result = client_->GetDisplayModeAbility(server_name, mode, &ability);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: client_->GetDisplayModeAbility"));
+ return;
+ }
+
+ ReportSuccess(picojson::value(ability), out);
+}
+
+void MediaControllerInstance::MediaControllerClientGetDisplayRotationAbility(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kServerName, std::string, out)
+ CHECK_ARGS(args, kDisplayRotationAbility, std::string, out)
+
+ std::string server_name = args.get(kServerName).get<std::string>();
+ std::string display_rotation_ability = args.get(kDisplayRotationAbility).get<std::string>();
+ std::string ability;
+
+ PlatformResult result =
+ client_->GetDisplayRotationAbility(server_name, display_rotation_ability, &ability);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: client_->GetDisplayRotationAbility"));
+ return;
+ }
+
+ ReportSuccess(picojson::value(ability), out);
+}
+
+void MediaControllerInstance::MediaControllerClientGetSimpleAbility(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kAbilityType, std::string, out)
+ CHECK_ARGS(args, kServerName, std::string, out)
+
+ picojson::value ability_val = picojson::value();
+ std::string ability_type = args.get(kAbilityType).get<std::string>();
+ std::string server_name = args.get(kServerName).get<std::string>();
+ PlatformResult result = client_->GetSimpleAbility(server_name, ability_type, &ability_val);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: client_->GetSimpleAbility"));
+ return;
+ }
+
+ ReportSuccess(ability_val, out);
+}
+
+void MediaControllerInstance::MediaControllerClientFindSubscribedServers(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kCallbackId, out)
+
+ picojson::value callback_id = args.get(kCallbackId);
+
+ auto search = [this, callback_id]() -> void {
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& response_obj = response.get<picojson::object>();
+
+ picojson::value servers = picojson::value(picojson::array());
+ PlatformResult result = client_->FindSubscribedServers(&servers.get<picojson::array>());
+
+ response_obj[kCallbackId] = callback_id;
+ if (result) {
+ ReportSuccess(servers, response_obj);
+ } else {
+ LogAndReportError(result, &response_obj, ("Failed to find subscribed servers"));
+ }
+
+ Instance::PostMessage(this, response.serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Async(search);
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoSendPlaybackState(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kCallbackId, out)
+ CHECK_EXIST(args, kName, out)
+ CHECK_EXIST(args, kState, out)
+
+ auto send = [this, args]() -> void {
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& response_obj = response.get<picojson::object>();
+ response_obj[kCallbackId] = args.get(kCallbackId);
+
+ PlatformResult result = client_->SendPlaybackState(args.get(kName).get<std::string>(),
+ args.get(kState).get<std::string>());
+
+ if (result) {
+ ReportSuccess(response_obj);
+ } else {
+ LogAndReportError(result, &response_obj, ("Failed: client_->SendPlaybackState"));
+ }
+
+ Instance::PostMessage(this, response.serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Async(send);
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoSendPlaybackPosition(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kCallbackId, out)
+ CHECK_EXIST(args, kName, out)
+ CHECK_EXIST(args, kPosition, out)
+
+ auto send = [this, args]() -> void {
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& response_obj = response.get<picojson::object>();
+ response_obj[kCallbackId] = args.get(kCallbackId);
+
+ PlatformResult result = client_->SendPlaybackPosition(args.get(kName).get<std::string>(),
+ args.get(kPosition).get<double>());
+
+ if (result) {
+ ReportSuccess(response_obj);
+ } else {
+ LogAndReportError(result, &response_obj, ("Failed: client_->SendPlaybackPosition"));
+ }
+
+ Instance::PostMessage(this, response.serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Async(send);
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoSendShuffleMode(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kCallbackId, out)
+ CHECK_EXIST(args, kName, out)
+ CHECK_EXIST(args, kMode, out)
+
+ auto send = [this, args]() -> void {
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& response_obj = response.get<picojson::object>();
+ response_obj[kCallbackId] = args.get(kCallbackId);
+
+ PlatformResult result =
+ client_->SendShuffleMode(args.get(kName).get<std::string>(), args.get(kMode).get<bool>());
+
+ if (result) {
+ ReportSuccess(response_obj);
+ } else {
+ LogAndReportError(result, &response_obj, ("Failed to send shuffle mode."));
+ }
+
+ Instance::PostMessage(this, response.serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Async(send);
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoSendRepeatMode(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ common::tools::PrintDeprecationWarningFor("sendRepeatMode()", "sendRepeatState()");
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kCallbackId, out)
+ CHECK_EXIST(args, kName, out)
+ CHECK_EXIST(args, kMode, out)
+
+ auto send = [this, args]() -> void {
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& response_obj = response.get<picojson::object>();
+ response_obj[kCallbackId] = args.get(kCallbackId);
+
+ PlatformResult result =
+ client_->SendRepeatMode(args.get(kName).get<std::string>(), args.get(kMode).get<bool>());
+
+ if (result) {
+ ReportSuccess(response_obj);
+ } else {
+ LogAndReportError(result, &response_obj, ("Failed to send repeat mode."));
+ }
+
+ Instance::PostMessage(this, response.serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Async(send);
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoSendRepeatState(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ auto send = [this, args]() {
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& response_obj = response.get<picojson::object>();
+ response_obj[kCallbackId] = args.get(kCallbackId);
+
+ PlatformResult result = client_->SendRepeatState(args.get(kName).get<std::string>(),
+ args.get(kState).get<std::string>());
+
+ if (result) {
+ ReportSuccess(response_obj);
+ } else {
+ LogAndReportError(result, &response_obj, ("Failed to send repeat state."));
+ }
+
+ Instance::PostMessage(this, response.serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Async(send);
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoSendSearchRequest(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Client not initialized."), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kListenerId, out);
+ CHECK_EXIST(args, kName, out);
+ CHECK_EXIST(args, kRequest, out);
+
+ JsonCallback reply_cb = [this, args](picojson::value* reply) -> void {
+ picojson::object& reply_obj = reply->get<picojson::object>();
+ reply_obj[kListenerId] = args.get(kListenerId);
+ Instance::PostMessage(this, reply->serialize().c_str());
+ };
+
+ char* request_id = nullptr;
+ SCOPE_EXIT {
+ free(request_id);
+ };
+
+ PlatformResult result = client_->SendSearchRequest(args.get(kName).get<std::string>(),
+ args.get(kRequest), reply_cb, &request_id);
+
+ if (result) {
+ ReportSuccess(out);
+ out[kRequestId] = picojson::value(std::string(request_id));
+ } else {
+ LogAndReportError(result, &out, ("Failed to send command."));
+ }
+}
+
+void MediaControllerInstance::MediaControllerServerInfoSendCommand(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kListenerId, out)
+ CHECK_EXIST(args, kName, out)
+ CHECK_EXIST(args, kCommand, out)
+ CHECK_EXIST(args, kData, out)
+
+ JsonCallback reply_cb = [this, args](picojson::value* reply) -> void {
+ picojson::object& reply_obj = reply->get<picojson::object>();
+ reply_obj[kListenerId] = args.get(kListenerId);
+ Instance::PostMessage(this, reply->serialize().c_str());
+ };
+
+ char* request_id = nullptr;
+ SCOPE_EXIT {
+ free(request_id);
+ };
+
+ PlatformResult result = client_->SendCommand(args.get(kName).get<std::string>(),
+ args.get(kCommand).get<std::string>(),
+ args.get(kData), reply_cb, &request_id);
+
+ if (result) {
+ ReportSuccess(out);
+ out[kRequestId] = picojson::value(std::string(request_id));
+ } else {
+ LogAndReportError(result, &out, ("Failed to send command."));
+ }
+}
+
+void MediaControllerInstance::MediaControllerServerInfoAddServerStatusChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kListenerId, out)
+
+ JsonCallback callback = [this, args](picojson::value* data) -> void {
+ if (nullptr == data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
+
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = client_->SetServerStatusChangeListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoRemoveServerStatusChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ auto result = client_->UnsetServerStatusChangeListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ }
+}
+
+void MediaControllerInstance::MediaControllerServerInfoAddPlaybackInfoChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kListenerId, out)
+
+ JsonCallback callback = [this, args](picojson::value* data) -> void {
+ if (!data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
+
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = client_->SetPlaybackInfoListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoRemovePlaybackInfoChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ auto result = client_->UnsetPlaybackInfoListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ }
+}
+
+void MediaControllerInstance::MediaControllerServerInfoSendPlaybackItem(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Client not initialized."), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kName, std::string, out)
+ CHECK_ARGS(args, kPlaylistName, std::string, out)
+ CHECK_ARGS(args, kIndex, std::string, out)
+ CHECK_ARGS(args, kState, std::string, out)
+ CHECK_ARGS(args, kPosition, double, out)
+
+ auto result = client_->SendPlaybackItem(
+ args.get(kName).get<std::string>(), args.get(kPlaylistName).get<std::string>(),
+ args.get(kIndex).get<std::string>(), args.get(kState).get<std::string>(),
+ args.get(kPosition).get<double>());
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoAddPlaylistUpdateListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kListenerId, out)
+
+ JsonCallback callback = [this, args](picojson::value* data) -> void {
+ if (!data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
+
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = client_->SetPlaylistUpdateListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoRemovePlaylistUpdateListener(
+ const picojson::value& args, picojson::object& out) {
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ auto result = client_->UnsetPlaylistUpdateListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoGetAllPlaylists(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ CHECK_ARGS(args, kName, std::string, out)
+
+ auto get = [this, args]() -> void {
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& response_obj = response.get<picojson::object>();
+
+ response_obj[kCallbackId] = args.get(kCallbackId);
+
+ picojson::value playlists{picojson::array{}};
+
+ auto result = utils::GetAllPlaylists(args.get(kName).get<std::string>(),
+ &playlists.get<picojson::array>());
+
+ if (!result) {
+ LogAndReportError(result, &response_obj, ("Failed: utils::GetAllPlaylists"));
+ Instance::PostMessage(this, response.serialize().c_str());
+ return;
+ }
+
+ response_obj[kResult] = picojson::value{playlists};
+ ReportSuccess(response_obj);
+ Instance::PostMessage(this, response.serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Async(get);
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerServerInfoGetIconURI(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ CHECK_ARGS(args, kName, std::string, out);
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ std::string server_name = args.get(kName).get<std::string>();
+
+ common::optional<std::string> icon_uri;
+ PlatformResult status = client_->GetServerIconURI(server_name, &icon_uri);
+ if (!status) {
+ LogAndReportError(status, &out, ("Failed: client_->GetServerIconURI()"));
+ return;
+ }
+
+ picojson::object result;
+ if (icon_uri) {
+ result[kIconURI] = picojson::value(*icon_uri);
+ } else {
+ result[kIconURI] = picojson::value();
+ }
+
+ ReportSuccess(picojson::value(result), out);
+}
+
+void MediaControllerInstance::MediaControllerClientAddAbilityChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_EXIST(args, kListenerId, out)
+
+ picojson::value listener_id = args.get(kListenerId);
+
+ JsonCallback callback = [this, listener_id](picojson::value* data) -> void {
+ if (!data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
+
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = listener_id;
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = client_->SetAbilityChangeListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerClientRemoveAbilityChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ auto result = client_->UnsetAbilityChangeListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerAbilitiesInfoSubscribe(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kServerName, std::string, out)
+
+ const std::string& server_name = args.get(kServerName).get<std::string>();
+ auto result = client_->SubscribeServer(server_name);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerAbilitiesInfoUnsubscribe(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kServerName, std::string, out)
+
+ const std::string& server_name = args.get(kServerName).get<std::string>();
+ auto result = client_->UnsubscribeServer(server_name);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerPlaylistAddItem(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ // MediaControllerPlaylistAddItem is implemented in MediaControllerServer because
+ // mc_server_add_item_to_playlist need mc_server_h as parameter
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Server not initialized."), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kIndex, std::string, out)
+ CHECK_ARGS(args, kMetadata, picojson::object, out)
+ CHECK_ARGS(args, kName, std::string, out)
+
+ const picojson::object& metadata = args.get(kMetadata).get<picojson::object>();
+
+ auto result = server_->MediaControllerPlaylistAddItem(
+ args.get(kName).get<std::string>(), args.get(kIndex).get<std::string>(), metadata);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerPlaylistGetItems(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ // MediaControllerPlaylistGetItems is implemented in MediaControllerServer because
+ // mc_playlist_foreach_item need mc_playlist_h as parameter which is already stored in server
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+ CHECK_EXIST(args, kCallbackId, out)
+ CHECK_ARGS(args, kName, std::string, out)
+
+ auto get = [this, args]() -> void {
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& response_obj = response.get<picojson::object>();
+
+ response_obj[kCallbackId] = args.get(kCallbackId);
+
+ picojson::value items{picojson::array{}};
+
+ auto result = server_->MediaControllerPlaylistGetItems(args.get(kName).get<std::string>(),
+ &items.get<picojson::array>());
+
+ if (!result) {
+ LogAndReportError(result, &response_obj,
+ ("Failed: server_->MediaControllerPlaylistGetItems"));
+ Instance::PostMessage(this, response.serialize().c_str());
+ return;
+ }
+
+ response_obj[kResult] = picojson::value{items};
+ ReportSuccess(response_obj);
+ Instance::PostMessage(this, response.serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Async(get);
+
+ ReportSuccess(out);
+}
+
+// subtitles
+void MediaControllerInstance::MediaControllerSubtitlesUpdateEnabled(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kEnabled, bool, out);
+
+ const bool enabled = args.get(kEnabled).get<bool>();
+ PlatformResult result = server_->UpdateSubtitlesEnabled(enabled);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed server_->UpdateSubtitlesEnabled()"));
+ return;
+ }
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerSubtitlesAddChangeRequestListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out)
+
+ JsonCallback callback = [this, args](picojson::value* data) -> void {
+ if (!data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = server_->SetSubtitlesChangeRequestListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerSubtitlesRemoveChangeRequestListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ auto result = server_->UnsetSubtitlesChangeRequestListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerSubtitlesInfoGetEnabled(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kName, std::string, out)
+
+ bool enabled = false;
+ PlatformResult result =
+ client_->GetSubtitlesEnabled(args.get(kName).get<std::string>(), &enabled);
+
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: client_->GetSubtitlesEnabled"));
+ return;
+ }
+
+ ReportSuccess(picojson::value(enabled), out);
+}
+
+void MediaControllerInstance::MediaControllerSubtitlesInfoSendRequest(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out)
+ CHECK_ARGS(args, kName, std::string, out)
+ CHECK_ARGS(args, kEnabled, bool, out)
+
+ JsonCallback reply_cb = [this, args](picojson::value* reply) -> void {
+ if (reply) {
+ picojson::object& reply_obj = reply->get<picojson::object>();
+ reply_obj[kListenerId] = args.get(kListenerId);
+ Instance::PostMessage(this, reply->serialize().c_str());
+ } else {
+ LoggerW("No reply passed to json callback, ignoring");
+ }
+ };
+
+ char* request_id = nullptr;
+ SCOPE_EXIT {
+ free(request_id);
+ };
+
+ PlatformResult result = client_->SendSubtitlesEnabled(
+ args.get(kName).get<std::string>(), args.get(kEnabled).get<bool>(), reply_cb, &request_id);
+
+ if (result) {
+ ReportSuccess(out);
+ out[kRequestId] = picojson::value(std::string(request_id));
+ } else {
+ LogAndReportError(result, &out, ("Failed to send command."));
+ }
+}
+
+void MediaControllerInstance::MediaControllerSubtitlesInfoAddModeChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out)
+
+ JsonCallback callback = [this, args](picojson::value* data) -> void {
+ if (nullptr == data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
+
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = client_->SetSubtitlesInfoChangeListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerSubtitlesInfoRemoveModeChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ auto result = client_->UnsetSubtitlesInfoChangeListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+// mode360
+void MediaControllerInstance::MediaControllerMode360UpdateEnabled(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kEnabled, bool, out)
+
+ const bool enabled = args.get(kEnabled).get<bool>();
+ PlatformResult result = server_->UpdateMode360Enabled(enabled);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed server_->UpdateMode360Enabled()"));
+ return;
+ }
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerMode360AddChangeRequestListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out)
+
+ JsonCallback callback = [this, args](picojson::value* data) -> void {
+ if (!data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = server_->SetMode360ChangeRequestListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerMode360RemoveChangeRequestListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ auto result = server_->UnsetMode360ChangeRequestListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerMode360InfoGetEnabled(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kName, std::string, out)
+
+ bool enabled = false;
+ PlatformResult result = client_->GetMode360Enabled(args.get(kName).get<std::string>(), &enabled);
+
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: client_->GetMode360Enabled"));
+ return;
+ }
+
+ ReportSuccess(picojson::value(enabled), out);
+}
+
+void MediaControllerInstance::MediaControllerMode360InfoSendRequest(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out)
+ CHECK_ARGS(args, kName, std::string, out)
+ CHECK_ARGS(args, kEnabled, bool, out)
+
+ JsonCallback reply_cb = [this, args](picojson::value* reply) -> void {
+ if (reply) {
+ picojson::object& reply_obj = reply->get<picojson::object>();
+ reply_obj[kListenerId] = args.get(kListenerId);
+ Instance::PostMessage(this, reply->serialize().c_str());
+ } else {
+ LoggerW("No reply passed to json callback, ignoring");
+ }
+ };
+
+ char* request_id = nullptr;
+ SCOPE_EXIT {
free(request_id);
};
- PlatformResult result = client_->SendCommand(args.get("name").get<std::string>(),
- args.get("command").get<std::string>(),
- args.get("data"), reply_cb, &request_id);
+ PlatformResult result = client_->SendMode360Enabled(
+ args.get(kName).get<std::string>(), args.get(kEnabled).get<bool>(), reply_cb, &request_id);
if (result) {
ReportSuccess(out);
- out["requestId"] = picojson::value(std::string(request_id));
+ out[kRequestId] = picojson::value(std::string(request_id));
} else {
LogAndReportError(result, &out, ("Failed to send command."));
}
}
-void MediaControllerInstance::MediaControllerServerInfoAddServerStatusChangeListener(
+void MediaControllerInstance::MediaControllerMode360InfoAddModeChangeListener(
const picojson::value& args, picojson::object& out) {
ScopeLogger();
if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "listenerId", out)
+ CHECK_ARGS(args, kListenerId, std::string, out)
JsonCallback callback = [this, args](picojson::value* data) -> void {
if (nullptr == data) {
}
picojson::object& request_o = data->get<picojson::object>();
- request_o["listenerId"] = args.get("listenerId");
+ request_o[kListenerId] = args.get(kListenerId);
Instance::PostMessage(this, data->serialize().c_str());
};
- auto result = client_->SetServerStatusChangeListener(callback);
+ auto result = client_->SetMode360InfoChangeListener(callback);
if (!result) {
LogAndReportError(result, &out);
+ return;
}
ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerServerInfoRemoveServerStatusChangeListener(
+void MediaControllerInstance::MediaControllerMode360InfoRemoveModeChangeListener(
const picojson::value& args, picojson::object& out) {
ScopeLogger();
if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
return;
}
- auto result = client_->UnsetServerStatusChangeListener();
+ auto result = client_->UnsetMode360InfoChangeListener();
if (!result) {
LogAndReportError(result, &out);
+ return;
}
+
+ ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerServerInfoAddPlaybackInfoChangeListener(
+// displayMode
+void MediaControllerInstance::MediaControllerDisplayModeUpdateType(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kType, std::string, out);
+
+ const std::string type = args.get(kType).get<std::string>();
+ PlatformResult result = server_->UpdateDisplayModeType(type);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed server_->UpdateDisplayModeType()"));
+ return;
+ }
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerDisplayModeAddChangeRequestListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out)
+
+ JsonCallback callback = [this, args](picojson::value* data) -> void {
+ if (!data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = server_->SetDisplayModeChangeRequestListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerDisplayModeRemoveChangeRequestListener(
const picojson::value& args, picojson::object& out) {
ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ auto result = server_->UnsetDisplayModeChangeRequestListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerDisplayModeInfoGetType(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kName, std::string, out)
+
+ std::string type;
+ PlatformResult result = client_->GetDisplayModeType(args.get(kName).get<std::string>(), &type);
+
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: client_->GetDisplayModeType"));
+ return;
+ }
+
+ ReportSuccess(picojson::value(type), out);
+}
+
+void MediaControllerInstance::MediaControllerDisplayModeInfoSendType(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out)
+ CHECK_ARGS(args, kName, std::string, out)
+ CHECK_ARGS(args, kType, std::string, out)
+
+ JsonCallback reply_cb = [this, args](picojson::value* reply) -> void {
+ picojson::object& reply_obj = reply->get<picojson::object>();
+ reply_obj[kListenerId] = args.get(kListenerId);
+ Instance::PostMessage(this, reply->serialize().c_str());
+ };
+
+ char* request_id = nullptr;
+ SCOPE_EXIT {
+ free(request_id);
+ };
+
+ PlatformResult result =
+ client_->SendDisplayModeType(args.get(kName).get<std::string>(),
+ args.get(kType).get<std::string>(), reply_cb, &request_id);
+
+ if (result) {
+ ReportSuccess(out);
+ out[kRequestId] = picojson::value(std::string(request_id));
+ } else {
+ LogAndReportError(result, &out, ("Failed to send command."));
+ }
+}
+
+void MediaControllerInstance::MediaControllerDisplayModeInfoAddModeChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out)
+
+ JsonCallback callback = [this, args](picojson::value* data) -> void {
+ if (nullptr == data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
+
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = client_->SetDisplayModeInfoChangeListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerDisplayModeInfoRemoveModeChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ auto result = client_->UnsetDisplayModeInfoChangeListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+// displayRotation
+void MediaControllerInstance::MediaControllerDisplayRotationUpdate(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kDisplayRotation, std::string, out)
+
+ const std::string display_rotation = args.get(kDisplayRotation).get<std::string>();
+ PlatformResult result = server_->UpdateDisplayRotation(display_rotation);
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed server_->UpdateDisplayRotation()"));
+ return;
+ }
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerDisplayRotationAddChangeRequestListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
return;
}
- CHECK_EXIST(args, "listenerId", out)
+ CHECK_ARGS(args, kListenerId, std::string, out)
JsonCallback callback = [this, args](picojson::value* data) -> void {
if (!data) {
LoggerE("No data passed to json callback");
return;
}
+ picojson::object& request_o = data->get<picojson::object>();
+ request_o[kListenerId] = args.get(kListenerId);
+
+ Instance::PostMessage(this, data->serialize().c_str());
+ };
+
+ auto result = server_->SetDisplayRotationChangeRequestListener(callback);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerDisplayRotationRemoveChangeRequestListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!server_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerServerUnknownErrorMsg));
+ return;
+ }
+
+ auto result = server_->UnsetDisplayRotationChangeRequestListener();
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+ ReportSuccess(out);
+}
+
+void MediaControllerInstance::MediaControllerDisplayRotationInfoGet(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kName, std::string, out)
+
+ std::string rotation;
+ PlatformResult result =
+ client_->GetDisplayRotation(args.get(kName).get<std::string>(), &rotation);
+
+ if (!result) {
+ LogAndReportError(result, &out, ("Failed: client_->GetDisplayRotation"));
+ return;
+ }
+
+ ReportSuccess(picojson::value(rotation), out);
+}
+
+void MediaControllerInstance::MediaControllerDisplayRotationInfoSend(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out)
+ CHECK_ARGS(args, kName, std::string, out)
+ CHECK_ARGS(args, kDisplayRotation, std::string, out)
+
+ JsonCallback reply_cb = [this, args](picojson::value* reply) -> void {
+ if (reply) {
+ picojson::object& reply_obj = reply->get<picojson::object>();
+ reply_obj[kListenerId] = args.get(kListenerId);
+ Instance::PostMessage(this, reply->serialize().c_str());
+ } else {
+ LoggerW("No reply passed to json callback, ignoring");
+ }
+ };
+
+ char* request_id = nullptr;
+ SCOPE_EXIT {
+ free(request_id);
+ };
+
+ PlatformResult result = client_->SendDisplayRotation(
+ args.get(kName).get<std::string>(), args.get(kDisplayRotation).get<std::string>(), reply_cb,
+ &request_id);
+
+ if (result) {
+ ReportSuccess(out);
+ out[kRequestId] = picojson::value(std::string(request_id));
+ } else {
+ LogAndReportError(result, &out, ("Failed to send display rotation command."));
+ }
+}
+
+void MediaControllerInstance::MediaControllerDisplayRotationInfoAddChangeListener(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kListenerId, std::string, out)
+
+ JsonCallback callback = [this, args](picojson::value* data) -> void {
+ if (nullptr == data) {
+ LoggerE("No data passed to json callback");
+ return;
+ }
picojson::object& request_o = data->get<picojson::object>();
- request_o["listenerId"] = args.get("listenerId");
+ request_o[kListenerId] = args.get(kListenerId);
Instance::PostMessage(this, data->serialize().c_str());
};
- auto result = client_->SetPlaybackInfoListener(callback);
+ auto result = client_->SetDisplayRotationInfoChangeListener(callback);
if (!result) {
LogAndReportError(result, &out);
+ return;
}
ReportSuccess(out);
}
-void MediaControllerInstance::MediaControllerServerInfoRemovePlaybackInfoChangeListener(
+void MediaControllerInstance::MediaControllerDisplayRotationInfoRemoveChangeListener(
const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
if (!client_) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
- ("Failed: client_"));
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
return;
}
- auto result = client_->UnsetPlaybackInfoListener();
+ auto result = client_->UnsetDisplayRotationInfoChangeListener();
if (!result) {
LogAndReportError(result, &out);
+ return;
}
+
+ ReportSuccess(out);
}
#undef CHECK_EXIST
void MediaControllerServerUpdatePlaybackState(const picojson::value& args, picojson::object& out);
void MediaControllerServerUpdatePlaybackPosition(const picojson::value& args,
picojson::object& out);
+ void MediaControllerServerUpdatePlaybackAgeRating(const picojson::value& args,
+ picojson::object& out);
void MediaControllerServerUpdateRepeatMode(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerUpdateRepeatState(const picojson::value& args, picojson::object& out);
void MediaControllerServerUpdateShuffleMode(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerUpdatePlaybackContentType(const picojson::value& args,
+ picojson::object& out);
void MediaControllerServerUpdateMetadata(const picojson::value& args, picojson::object& out);
void MediaControllerServerAddChangeRequestPlaybackInfoListener(const picojson::value& args,
picojson::object& out);
void MediaControllerServerRemoveChangeRequestPlaybackInfoListener(const picojson::value& args,
picojson::object& out);
- void MediaControllerServerAddCommandListener(const picojson::value& args, picojson::object& out);
+
+ void MediaControllerServerAddSearchRequestListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerServerRemoveSearchRequestListener(const picojson::value& args,
+ picojson::object& out);
+
void MediaControllerServerReplyCommand(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerAddCommandListener(const picojson::value& args, picojson::object& out);
void MediaControllerServerRemoveCommandListener(const picojson::value& args,
picojson::object& out);
+ void MediaControllerServerCreatePlaylist(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerSavePlaylist(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerDeletePlaylist(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerUpdatePlaybackItem(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerGetAllPlaylists(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerUpdateIconURI(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerSavePlaybackAbilities(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerServerSetDisplayModeAbility(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerServerSetDisplayRotationAbility(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerServerSetSimpleAbility(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerGetAllClientsInfo(const picojson::value& args, picojson::object& out);
+
+ // client info
+ void MediaControllerClientInfoSendEvent(const picojson::value& args, picojson::object& out);
// client
void MediaControllerManagerGetClient(const picojson::value& args, picojson::object& out);
void MediaControllerClientFindServers(const picojson::value& args, picojson::object& out);
void MediaControllerClientGetLatestServerInfo(const picojson::value& args, picojson::object& out);
void MediaControllerClientGetPlaybackInfo(const picojson::value& args, picojson::object& out);
+ void MediaControllerClientGetPlaybackAbility(const picojson::value& args, picojson::object& out);
+ void MediaControllerClientGetDisplayModeAbility(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerClientGetDisplayRotationAbility(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerClientGetSimpleAbility(const picojson::value& args, picojson::object& out);
+ void MediaControllerClientAddAbilityChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerClientRemoveAbilityChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerClientFindSubscribedServers(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerClientSetCustomEventListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerClientUnsetCustomEventListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerClientSendEventReply(const picojson::value& args, picojson::object& out);
+
+ // serverInfo
void MediaControllerServerInfoSendPlaybackState(const picojson::value& args,
picojson::object& out);
void MediaControllerServerInfoSendPlaybackPosition(const picojson::value& args,
picojson::object& out);
void MediaControllerServerInfoSendRepeatMode(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerInfoSendRepeatState(const picojson::value& args, picojson::object& out);
void MediaControllerServerInfoSendShuffleMode(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerInfoSendSearchRequest(const picojson::value& args,
+ picojson::object& out);
void MediaControllerServerInfoSendCommand(const picojson::value& args, picojson::object& out);
void MediaControllerServerInfoAddServerStatusChangeListener(const picojson::value& args,
picojson::object& out);
picojson::object& out);
void MediaControllerServerInfoRemovePlaybackInfoChangeListener(const picojson::value& args,
picojson::object& out);
+ void MediaControllerServerInfoSendPlaybackItem(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerServerInfoAddPlaylistUpdateListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerServerInfoRemovePlaylistUpdateListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerServerInfoGetAllPlaylists(const picojson::value& args, picojson::object& out);
+ void MediaControllerServerInfoGetIconURI(const picojson::value& args, picojson::object& out);
+
+ // abilities_info
+ void MediaControllerAbilitiesInfoSubscribe(const picojson::value& args, picojson::object& out);
+ void MediaControllerAbilitiesInfoUnsubscribe(const picojson::value& args, picojson::object& out);
+
+ // playlist
+ void MediaControllerPlaylistAddItem(const picojson::value& args, picojson::object& out);
+ void MediaControllerPlaylistGetItems(const picojson::value& args, picojson::object& out);
+
+ // subtitles
+ void MediaControllerSubtitlesUpdateEnabled(const picojson::value& args, picojson::object& out);
+ void MediaControllerSubtitlesAddChangeRequestListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerSubtitlesRemoveChangeRequestListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerSubtitlesInfoGetEnabled(const picojson::value& args, picojson::object& out);
+ void MediaControllerSubtitlesInfoSendRequest(const picojson::value& args, picojson::object& out);
+ void MediaControllerSubtitlesInfoAddModeChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerSubtitlesInfoRemoveModeChangeListener(const picojson::value& args,
+ picojson::object& out);
+
+ // mode360
+ void MediaControllerMode360UpdateEnabled(const picojson::value& args, picojson::object& out);
+ void MediaControllerMode360AddChangeRequestListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerMode360RemoveChangeRequestListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerMode360InfoGetEnabled(const picojson::value& args, picojson::object& out);
+ void MediaControllerMode360InfoSendRequest(const picojson::value& args, picojson::object& out);
+ void MediaControllerMode360InfoAddModeChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerMode360InfoRemoveModeChangeListener(const picojson::value& args,
+ picojson::object& out);
+
+ // displayMode
+ void MediaControllerDisplayModeUpdateType(const picojson::value& args, picojson::object& out);
+ void MediaControllerDisplayModeAddChangeRequestListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerDisplayModeRemoveChangeRequestListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerDisplayModeInfoGetType(const picojson::value& args, picojson::object& out);
+ void MediaControllerDisplayModeInfoSendType(const picojson::value& args, picojson::object& out);
+ void MediaControllerDisplayModeInfoAddModeChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerDisplayModeInfoRemoveModeChangeListener(const picojson::value& args,
+ picojson::object& out);
+
+ // displayRotation
+ void MediaControllerDisplayRotationUpdate(const picojson::value& args, picojson::object& out);
+ void MediaControllerDisplayRotationAddChangeRequestListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerDisplayRotationRemoveChangeRequestListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerDisplayRotationInfoGet(const picojson::value& args, picojson::object& out);
+ void MediaControllerDisplayRotationInfoSend(const picojson::value& args, picojson::object& out);
+ void MediaControllerDisplayRotationInfoAddChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void MediaControllerDisplayRotationInfoRemoveChangeListener(const picojson::value& args,
+ picojson::object& out);
std::shared_ptr<MediaControllerClient> client_;
std::shared_ptr<MediaControllerServer> server_;
#include <bundle.h>
#include <bundle_internal.h>
+#include "common/json-utils.h"
#include "common/logger.h"
#include "common/scope_exit.h"
-
-#include "mediacontroller/mediacontroller_types.h"
+#include "common/tools.h"
namespace extension {
namespace mediacontroller {
-using common::PlatformResult;
+using namespace attributes;
+
+using common::BundleJsonIterator;
using common::ErrorCode;
+using common::PlatformResult;
MediaControllerServer::MediaControllerServer()
: handle_(nullptr),
+ change_request_playback_info_listener_(nullptr),
+ event_reply_callback_(nullptr),
+ command_listener_(nullptr),
+ search_request_listener_(nullptr),
+ subtitles_change_request_listener_(nullptr),
+ mode360_change_request_listener_(nullptr),
+ display_mode_change_request_listener_(nullptr),
+ display_rotation_change_request_listener_(nullptr),
playback_state_(MC_PLAYBACK_STATE_STOPPED),
position_(0ULL),
+ age_rating_(MC_CONTENT_RATING_ALL),
+ content_type_(MC_CONTENT_TYPE_UNDECIDED),
shuffle_mode_(MC_SHUFFLE_MODE_OFF),
repeat_mode_(MC_REPEAT_MODE_OFF),
is_shuffle_mode_set_(false),
LoggerE("Failed to unset command listener");
}
+ if (nullptr != search_request_listener_ && !UnsetSearchRequestListener()) {
+ LoggerE("Failed to unset search request listener");
+ }
+
+ if (nullptr != subtitles_change_request_listener_ && !UnsetSubtitlesChangeRequestListener()) {
+ LoggerE("Failed to unset subtitles listener");
+ }
+
+ if (nullptr != mode360_change_request_listener_ && !UnsetMode360ChangeRequestListener()) {
+ LoggerE("Failed to unset mode 360 request listener");
+ }
+
+ if (nullptr != display_mode_change_request_listener_ &&
+ !UnsetDisplayModeChangeRequestListener()) {
+ LoggerE("Failed to unset display mode request listener");
+ }
+
+ if (nullptr != display_rotation_change_request_listener_ &&
+ !UnsetDisplayRotationChangeRequestListener()) {
+ LoggerE("Failed to unset display rotation listener");
+ }
+
+ int ret = mc_server_unset_event_reply_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ LoggerE("Failed to unset event reply received callback");
+ }
+
+ for (auto const& v : playlist_handle_map_) {
+ if (MEDIA_CONTROLLER_ERROR_NONE != mc_playlist_destroy(v.second)) {
+ LoggerE("Unable to destroy playlist %s", v.first.c_str());
+ }
+ }
+
if (nullptr != handle_ && MEDIA_CONTROLLER_ERROR_NONE != mc_server_destroy(handle_)) {
LoggerE("Unable to destroy media controller server");
}
("mc_server_create() error: %d, message: %s", ret, get_error_message(ret)));
}
+ ret = mc_server_set_event_reply_received_cb(handle_, OnEventReply, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Unable to register event reply received callback",
+ ("mc_server_set_event_reply_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
return PlatformResult(ErrorCode::NO_ERROR);
}
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult MediaControllerServer::SetContentAgeRating(const std::string& rating) {
+ ScopeLogger();
+
+ mc_content_age_rating_e rating_e;
+ PlatformResult result = types::MediaControllerContentAgeRatingEnum.getValue(rating, &rating_e);
+ if (!result) {
+ return result;
+ }
+
+ int ret = mc_server_set_content_age_rating(handle_, rating_e);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error setting content age rating",
+ ("mc_server_set_content_age_rating() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ age_rating_ = rating_e;
+
+ ret = mc_server_update_playback_info(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error updating playback info",
+ ("mc_server_update_playback_info() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::SetContentType(const std::string& content_type) {
+ ScopeLogger();
+
+ mc_content_type_e content_type_e;
+ PlatformResult result =
+ types::MediaControllerContentTypeEnum.getValue(content_type, &content_type_e);
+ if (!result) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Converting string to platform enum failed",
+ ("MediaControllerContentTypeEnum.getValue() error message: %s", result.message().c_str()));
+ }
+
+ int ret = mc_server_set_playback_content_type(handle_, content_type_e);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error updating playback content type",
+ ("mc_server_set_playback_content_type() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ content_type_ = content_type_e;
+
+ ret = mc_server_update_playback_info(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error updating playback info",
+ ("mc_server_update_playback_info() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
PlatformResult MediaControllerServer::SetShuffleMode(bool mode) {
ScopeLogger();
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult MediaControllerServer::SetRepeatState(const std::string& state) {
+ ScopeLogger();
+
+ mc_repeat_mode_e mode_e;
+ PlatformResult result = types::MediaControllerRepeatModeEnum.getValue(state, &mode_e);
+ if (!result) {
+ return result;
+ }
+
+ if ((mode_e == repeat_mode_) && (is_repeat_mode_set_)) {
+ LoggerD("No change in repeat mode requested, skipping");
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+
+ int ret = mc_server_update_repeat_mode(handle_, mode_e);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error updating repeat mode",
+ ("mc_server_update_repeat_mode() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ repeat_mode_ = mode_e;
+ is_repeat_mode_set_ = true;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
PlatformResult MediaControllerServer::SetMetadata(const picojson::object& metadata) {
ScopeLogger();
- for (picojson::object::const_iterator i = metadata.begin(); i != metadata.end(); ++i) {
+ picojson::object encoded;
+ PlatformResult result = utils::EncodeMetadata(metadata, &encoded);
+ if (!result) {
+ return result;
+ }
+
+ for (picojson::object::const_iterator i = encoded.begin(); i != encoded.end(); ++i) {
mc_meta_e attr_e;
- PlatformResult result = types::MediaControllerMetadataAttributeEnum.getValue(i->first, &attr_e);
+ result = types::MediaControllerMetadataAttributeEnum.getValue(i->first, &attr_e);
if (!result) {
return result;
}
return PlatformResult(ErrorCode::NO_ERROR);
}
+void MediaControllerServer::OnSearchRequestReceived(const char* client_name, const char* request_id,
+ mc_search_h request, void* user_data) {
+ ScopeLogger();
+ MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
+ if (nullptr == server->search_request_listener_) {
+ LoggerW("search_request_listener_ is not set");
+ return;
+ }
+
+ auto request_json = picojson::value(picojson::object());
+ auto& request_o = request_json.get<picojson::object>();
+
+ request_o[kClientName] = picojson::value(std::string(client_name));
+ request_o[kRequestId] = picojson::value(std::string(request_id));
+
+ auto condition_cb = [](mc_content_type_e content_type, mc_search_category_e category,
+ const char* keyword, bundle* data, void* user_data) -> bool {
+ LoggerD("condition callback for: %s", keyword);
+ auto filters = static_cast<picojson::array*>(user_data);
+
+ auto value = picojson::value(picojson::object());
+ auto& object = value.get<picojson::object>();
+
+ std::string temp;
+ PlatformResult result = types::MediaControllerContentTypeEnum.getName(content_type, &temp);
+ if (!result) {
+ LoggerE("MediaControllerContentTypeEnum.getName() failed with error message: %s",
+ result.message().c_str());
+ return false;
+ }
+ object[kContentType] = picojson::value(temp);
+
+ result = types::MediaControllerSearchCategoryEnum.getName(category, &temp);
+ if (!result) {
+ LoggerE("MediaControllerSearchCategoryEnum.getName() failed with error message: %s",
+ result.message().c_str());
+ return false;
+ }
+ object[kCategory] = picojson::value(temp);
+
+ if (keyword) {
+ object[kKeyword] = picojson::value(std::string(keyword));
+ } else {
+ // null is valid search keyword in case of NO_CATEGORY
+ object[kKeyword] = picojson::value();
+ }
+
+ picojson::value data_json;
+ result = common::BundleToJson(data, &data_json);
+ if (!result) {
+ LoggerE("BundleToJson failed with error message: %s", result.message().c_str());
+ return false;
+ }
+ object[kExtraData] = data_json;
+
+ filters->push_back(value);
+ return true;
+ };
+
+ picojson::array filters;
+ int ret = mc_search_foreach_condition(request, condition_cb, &filters);
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
+ LoggerE("mc_search_foreach_condition failed with error: %d", ret);
+ return;
+ }
+
+ request_o[kRequest] = picojson::value(filters);
+ server->search_request_listener_(&request_json);
+}
+
void MediaControllerServer::OnCommandReceived(const char* client_name, const char* request_id,
const char* command, bundle* bundle,
void* user_data) {
ScopeLogger();
-
MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
- int ret;
- char* data_str = nullptr;
- SCOPE_EXIT {
- free(data_str);
- };
picojson::value data;
-
- ret = bundle_get_str(bundle, "data", &data_str);
- if (BUNDLE_ERROR_NONE != ret || nullptr == data_str) {
- LoggerE("bundle_get_str(data) failed, error: %d", ret);
- } else {
- std::string err;
- picojson::parse(data, data_str, data_str + strlen(data_str), &err);
- if (!err.empty()) {
- LoggerE("Failed to parse bundle data: %s", err.c_str());
- return;
- }
+ PlatformResult result = common::BundleToJson(bundle, &data);
+ if (!result) {
+ LoggerE("BundleToJson() failed.");
+ return;
}
picojson::value request = picojson::value(picojson::object());
picojson::object& request_o = request.get<picojson::object>();
- request_o["clientName"] = picojson::value(std::string(client_name));
- request_o["command"] = picojson::value(std::string(command));
- request_o["requestId"] = picojson::value(std::string(request_id));
- request_o["data"] = data;
+ request_o[kClientName] = picojson::value(std::string(client_name));
+ request_o[kCommand] = picojson::value(std::string(command));
+ request_o[kRequestId] = picojson::value(std::string(request_id));
+ request_o[kData] = data;
server->command_listener_(&request);
}
PlatformResult MediaControllerServer::CommandReply(const std::string& client_name,
- const std::string& request_id,
+ const std::string& request_id, int code,
const picojson::value& data) {
ScopeLogger();
-
- int ret;
-
- bundle* bundle = bundle_create();
+ bundle* bundle = nullptr;
SCOPE_EXIT {
bundle_free(bundle);
};
- ret = bundle_add(bundle, "data", data.serialize().c_str());
- if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Unable to add data to bundle",
- ("bundle_add(data) error: %d, message: %s", ret, get_error_message(ret)));
+ PlatformResult result = common::JsonToBundle(data, &bundle);
+ if (!result) {
+ LoggerE("JsonToBundle() failed.");
+ return result;
}
- ret = mc_server_send_cmd_reply(handle_, client_name.c_str(), request_id.c_str(), 0, bundle);
+ int ret =
+ mc_server_send_cmd_reply(handle_, client_name.c_str(), request_id.c_str(), code, bundle);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, "Error sending command reply",
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult MediaControllerServer::SetSearchRequestListener(const JsonCallback& callback) {
+ ScopeLogger();
+
+ int ret = mc_server_set_search_cmd_received_cb(handle_, OnSearchRequestReceived, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set search request callback.",
+ ("mc_server_set_search_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ search_request_listener_ = callback;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::UnsetSearchRequestListener() {
+ ScopeLogger();
+ int ret = mc_server_unset_search_cmd_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to unset search request callback.",
+ ("mc_server_unset_search_cmd_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+ search_request_listener_ = nullptr;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
PlatformResult MediaControllerServer::SetCommandListener(const JsonCallback& callback) {
ScopeLogger();
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult MediaControllerServer::SetChangeRequestPlaybackInfoListener(
- const JsonCallback& callback) {
+PlatformResult MediaControllerServer::CreatePlaylist(const std::string& name,
+ picojson::value* playlist_info) {
ScopeLogger();
- int failed_setter = 0;
- SCOPE_EXIT {
- // Lambda function used to clean all set listeners (in case of failure of
- // SetPlaybackInfoListener method).
- // The purpose of this lambda is to unset as many setters as we can in case of failure.
- int (*unsetters[])(mc_server_h) = {
- mc_server_unset_playback_action_cmd_received_cb,
- mc_server_unset_playback_position_cmd_received_cb,
- mc_server_unset_shuffle_mode_cmd_received_cb,
- /*mc_server_unset_repeat_mode_cmd_received_cb the last unsetter will never be used*/};
+ if (playlist_handle_map_.find(name) != playlist_handle_map_.end()) {
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
+ "Playlist with given name already exists");
+ }
- // This loop is no-op in case of success.
- for (int i = 0; i < failed_setter; ++i) {
- auto ret = unsetters[i](handle_);
- if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
- LoggerE("Fail (%d) returned by the [%d] unsetter", ret, i);
- }
- }
- };
+ mc_playlist_h playlist_handle_ = nullptr;
- // In Native API, since Tizen 5.0 an action instead of a state is sent to change the state of a
- // server. In Web API the names were not refactored.
- int ret = mc_server_set_playback_action_cmd_received_cb(handle_, OnPlaybackActionCommand, this);
- if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Unable to set playback state command listener",
- ("mc_server_set_playback_action_cmd_received_cb() error: %d, message: %s", ret,
- get_error_message(ret)));
- }
+ int ret = mc_server_create_playlist(handle_, name.c_str(), &playlist_handle_);
- ret = mc_server_set_playback_position_cmd_received_cb(handle_, OnPlaybackPositionCommand, this);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
- failed_setter = 1;
return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Unable to set playback position command listener",
- ("mc_server_set_playback_position_cmd_received_cb() error: %d, message: %s", ret,
- get_error_message(ret)));
+ ErrorCode::UNKNOWN_ERR, "Unable to createPlaylist",
+ ("mc_server_create_playlist() error: %d, message: %s", ret, get_error_message(ret)));
}
- ret = mc_server_set_shuffle_mode_cmd_received_cb(handle_, OnShuffleModeCommand, this);
- if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
- failed_setter = 2;
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Unable to set shuffle mode command listener",
- ("mc_server_set_shuffle_mode_cmd_received_cb() error: %d, message: %s", ret,
- get_error_message(ret)));
- }
+ playlist_handle_map_[name] = playlist_handle_;
- ret = mc_server_set_repeat_mode_cmd_received_cb(handle_, OnRepeatModeCommand, this);
- if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
- failed_setter = 3;
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set repeat mode command listener",
- ("mc_server_set_repeat_mode_cmd_received_cb() error: %d, message: %s",
- ret, get_error_message(ret)));
+ if (playlist_info == nullptr) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to createPlaylist",
+ ("playlist_info is nullptr"));
}
- change_request_playback_info_listener_ = callback;
+ *playlist_info = picojson::value(picojson::object());
+ picojson::object& obj = playlist_info->get<picojson::object>();
+ obj[kName] = picojson::value(name);
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult MediaControllerServer::UnsetChangeRequestPlaybackInfoListener() {
+PlatformResult MediaControllerServer::SavePlaylist(const std::string& name) {
ScopeLogger();
- int ret = mc_server_unset_playback_action_cmd_received_cb(handle_);
+ if (playlist_handle_map_.find(name) == playlist_handle_map_.end()) {
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
+ "Playlist with given name doesn't exist");
+ }
+
+ int ret = mc_server_update_playlist_done(handle_, playlist_handle_map_[name]);
+
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Unable to unset playback state command listener",
- ("mc_server_unset_playback_action_cmd_received_cb() error: %d, message: %s", ret,
- get_error_message(ret)));
+ ErrorCode::UNKNOWN_ERR, "Error saving playlist",
+ ("mc_server_update_playlist_done() error: %d, message: %s", ret, get_error_message(ret)));
}
- ret = mc_server_unset_playback_position_cmd_received_cb(handle_);
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::DeletePlaylist(const std::string& name) {
+ ScopeLogger();
+
+ if (playlist_handle_map_.find(name) == playlist_handle_map_.end()) {
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
+ "Playlist with given name doesn't exist");
+ }
+
+ int ret = mc_server_delete_playlist(handle_, playlist_handle_map_[name]);
+
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Unable to unset playback position command listener",
- ("mc_server_unset_playback_position_cmd_received_cb() error: %d, message: %s", ret,
- get_error_message(ret)));
+ ErrorCode::UNKNOWN_ERR, "Error deleting playlist",
+ ("mc_server_delete_playlist() error: %d, message: %s", ret, get_error_message(ret)));
}
- ret = mc_server_unset_shuffle_mode_cmd_received_cb(handle_);
+ playlist_handle_map_.erase(name);
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::UpdatePlaybackItem(const std::string& playlist_name,
+ const std::string& index) {
+ ScopeLogger();
+
+ int ret = mc_server_set_playlist_item_info(handle_, playlist_name.c_str(), index.c_str());
+
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Unable to unset shuffle mode command listener",
- ("mc_server_unset_shuffle_mode_cmd_received_cb() error: %d, message: %s", ret,
- get_error_message(ret)));
+ ErrorCode::UNKNOWN_ERR, "Error updating playback item",
+ ("mc_server_set_playlist_item_info() error: %d, message: %s", ret, get_error_message(ret)));
}
- ret = mc_server_unset_repeat_mode_cmd_received_cb(handle_);
+ ret = mc_server_update_playback_info(handle_);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Unable to unset repeat mode command listener",
- ("mc_server_unset_repeat_mode_cmd_received_cb() error: %d, message: %s", ret,
- get_error_message(ret)));
+ ErrorCode::UNKNOWN_ERR, "Error updating playback info",
+ ("mc_server_update_playback_info() error: %d, message: %s", ret, get_error_message(ret)));
}
- change_request_playback_info_listener_ = nullptr;
-
return PlatformResult(ErrorCode::NO_ERROR);
}
-void MediaControllerServer::OnPlaybackActionCommand(const char* client_name, const char* request_id,
- mc_playback_action_e action, void* user_data) {
+common::PlatformResult MediaControllerServer::UpdateIconURI(const char* icon_uri) {
ScopeLogger();
+ int ret = mc_server_set_icon(handle_, icon_uri);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error setting server icon uri",
+ ("mc_server_set_icon() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
- MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
+PlatformResult MediaControllerServer::MediaControllerPlaylistAddItem(
+ const std::string& name, const std::string& index, const picojson::object& metadata) {
+ ScopeLogger();
- // Here, we need to convert mc_playback_action_e enum to mc_playback_states_e enum.
- std::string action_str;
- PlatformResult result = types::MediaControllerPlaybackActionEnum.getName(action, &action_str);
- if (!result) {
- LoggerW("MediaControllerPlaybackActionEnum.getName() failed, error: %s",
- result.message().c_str());
- return;
+ if (playlist_handle_map_.find(name) == playlist_handle_map_.end()) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Playlist with given name doesn't exist");
}
- mc_playback_states_e state_e;
- result = types::MediaControllerPlaybackStateEnum.getValue(action_str, &state_e);
+ picojson::object encoded;
+ PlatformResult result = utils::EncodeMetadata(metadata, &encoded);
if (!result) {
- LoggerE("MediaControllerPlaybackStateEnum.getValue() failed, error: %s",
- result.message().c_str());
- return;
+ return result;
}
- if (server->playback_state_ == state_e) {
- LoggerD("The media playback state did not change, skipping");
- return;
+ for (auto v : types::MediaControllerMetadataAttributeEnum) {
+ std::string value = encoded[v.first].get<std::string>();
+ LoggerD("Key: %s - Value: %s", v.first.c_str(), value.c_str());
+
+ int ret = mc_server_add_item_to_playlist(handle_, playlist_handle_map_[name], index.c_str(),
+ v.second, value.c_str());
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error adding playlist item",
+ ("mc_server_add_item_to_playlist() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::MediaControllerPlaylistGetItems(const std::string& name,
+ picojson::array* items) {
+ ScopeLogger();
+
+ if (playlist_handle_map_.find(name) == playlist_handle_map_.end()) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Playlist with given name doesn't exist");
+ }
+
+ auto OnPlaylistItemCommand = [](const char* index, mc_metadata_h metadata,
+ void* user_data) -> bool {
+ ScopeLogger();
+
+ auto items = static_cast<picojson::array*>(user_data);
+
+ picojson::value metadata_v = picojson::value(picojson::object());
+ picojson::object& metadata_obj = metadata_v.get<picojson::object>();
+
+ auto result = types::ConvertMetadata(metadata, &metadata_obj);
+ if (!result) {
+ return false;
+ }
+
+ picojson::value value = picojson::value(picojson::object());
+ picojson::object& obj = value.get<picojson::object>();
+
+ obj.insert(std::make_pair(kIndex, picojson::value{index}));
+ obj.insert(std::make_pair(kMetadata, metadata_v));
+ items->push_back(value);
+
+ return true;
+ };
+
+ int ret = mc_playlist_foreach_item(playlist_handle_map_[name], OnPlaylistItemCommand, items);
+
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while get playlist item",
+ ("mc_playlist_foreach_item() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::SetPlaybackAbility(const std::string& action,
+ const std::string& support_str,
+ bool* is_changed) {
+ ScopeLogger();
+ PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+ // UNDECIDED should not be used while setting playback ability, thus we skip these cases
+ if (support_str == "UNDECIDED") {
+ return result;
+ }
+
+ mc_playback_action_e action_e;
+ // Currently MediaControllerPlaybackActionEnum does not have member "TOGGLE_PLAY_PAUSE".
+ // It should be fixed in the future.
+ if ("TOGGLE_PLAY_PAUSE" == action) {
+ action_e = MC_PLAYBACK_ACTION_TOGGLE_PLAY_PAUSE;
+ } else {
+ result = types::MediaControllerPlaybackActionEnum.getValue(action, &action_e);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of playback action",
+ ("MediaControllerPlaybackActionEnum.getValue() failed, error: %s",
+ result.message().c_str()));
+ }
+ }
+
+ mc_ability_support_e support;
+ result = types::MediaControllerAbilitySupportEnum.getValue(support_str, &support);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of ability",
+ ("MediaControllerAbilitySupportEnum.getValue() failed, error: %s",
+ result.message().c_str()));
+ }
+
+ if (abilities_.end() != abilities_.find(action)) {
+ if (support == abilities_[action]) {
+ LoggerD("No change in ability support, skipping");
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+ }
+
+ int ret = mc_server_set_playback_ability(handle_, action_e, support);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error setting playback ability",
+ ("mc_server_set_playback_ability() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ abilities_[action] = support;
+ *is_changed = true;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::SavePlaybackAbilities(const picojson::value& abilities) {
+ ScopeLogger();
+ bool is_changed = false;
+ // Currently MediaControllerPlaybackActionEnum does not have member "TOGGLE_PLAY_PAUSE".
+ // It should be fixed in the future.
+ PlatformResult result = SetPlaybackAbility(
+ "TOGGLE_PLAY_PAUSE", abilities.get("TOGGLE_PLAY_PAUSE").get<std::string>(), &is_changed);
+ if (!result) {
+ return result;
+ }
+ for (auto action : types::MediaControllerPlaybackActionEnum) {
+ const std::string& action_str = action.first.c_str();
+ const std::string& support_str = abilities.get(action_str).get<std::string>();
+ result = SetPlaybackAbility(action_str, support_str, &is_changed);
+ if (!result) {
+ return result;
+ }
+ }
+
+ if (is_changed) {
+ int ret = mc_server_update_playback_ability(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error updating playback ability",
+ ("mc_server_update_playback_ability() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::SetDisplayModeAbility(const std::string& mode,
+ const std::string& support_str) {
+ ScopeLogger();
+
+ mc_display_mode_e mode_e;
+ PlatformResult result = types::MediaControllerDisplayModeEnum.getValue(mode, &mode_e);
+ if (!result) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error getting value of display mode",
+ ("MediaControllerDisplayModeEnum.getValue() failed, error: %s", result.message().c_str()));
+ }
+
+ mc_ability_support_e support_e;
+ result = types::MediaControllerAbilitySupportEnum.getValue(support_str, &support_e);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of ability support",
+ ("MediaControllerAbilitySupportEnum.getValue() failed, error: %s",
+ result.message().c_str()));
+ }
+
+ int ret = mc_server_set_display_mode_ability(handle_, mode_e, support_e);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error setting playback ability",
+ ("mc_server_set_display_mode_ability() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::SetDisplayRotationAbility(
+ std::string& display_rotation_ability, const std::string& support_str) {
+ ScopeLogger();
+
+ mc_display_rotation_e display_rotation_e;
+ PlatformResult result = types::MediaControllerDisplayRotationEnum.getValue(
+ display_rotation_ability, &display_rotation_e);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of display rotation",
+ ("MediaControllerDisplayRotationEnum.getValue() failed, error: %s",
+ result.message().c_str()));
+ }
+
+ mc_ability_support_e support_e;
+ result = types::MediaControllerAbilitySupportEnum.getValue(support_str, &support_e);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of ability",
+ ("MediaControllerAbilitySupportEnum.getValue() failed, error: %s",
+ result.message().c_str()));
+ }
+
+ int ret = mc_server_set_display_rotation_ability(handle_, display_rotation_e, support_e);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error setting ability",
+ ("mc_server_set_display_rotation_ability() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::SetSimpleAbility(const std::string& ability_type,
+ const std::string& support_str) {
+ ScopeLogger();
+
+ mc_ability_support_e support_e;
+ PlatformResult result =
+ types::MediaControllerAbilitySupportEnum.getValue(support_str, &support_e);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of ability",
+ ("MediaControllerAbilitySupportEnum.getValue() failed, error: %s",
+ result.message().c_str()));
+ }
+
+ if (abilities_.end() != abilities_.find(ability_type)) {
+ if (support_e == abilities_[ability_type]) {
+ LoggerD("No change in ability support, skipping");
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+ }
+
+ mc_ability_e ability_e;
+ result = types::MediaControllerSimpleAbilityEnum.getValue(ability_type, &ability_e);
+ if (!result) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of ability",
+ ("MediaControllerSimpleAbilityEnum.getValue() failed, error: %s",
+ result.message().c_str()));
+ }
+
+ int ret = mc_server_set_ability_support(handle_, ability_e, support_e);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error setting ability",
+ ("mc_server_set_ability_support() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ abilities_[ability_type] = support_e;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::SetChangeRequestPlaybackInfoListener(
+ const JsonCallback& callback) {
+ ScopeLogger();
+ int failed_setter = 0;
+
+ SCOPE_EXIT {
+ // Lambda function used to clean all set listeners (in case of failure of
+ // SetPlaybackInfoListener method).
+ // The purpose of this lambda is to unset as many setters as we can in case of failure.
+
+ int (*unsetters[])(mc_server_h) = {
+ mc_server_unset_playback_action_cmd_received_cb,
+ mc_server_unset_playback_position_cmd_received_cb,
+ mc_server_unset_shuffle_mode_cmd_received_cb, mc_server_unset_repeat_mode_cmd_received_cb,
+ /*mc_server_unset_playlist_cmd_received_cb the last unsetter will never be used*/};
+
+ // This loop is no-op in case of success.
+ for (int i = 0; i < failed_setter; ++i) {
+ auto ret = unsetters[i](handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ LoggerE("Fail (%d) returned by the [%d] unsetter", ret, i);
+ }
+ }
+ };
+
+ // In Native API, since Tizen 5.0 an action instead of a state is sent to change the state of a
+ // server. In Web API the names were not refactored.
+ int ret = mc_server_set_playback_action_cmd_received_cb(handle_, OnPlaybackActionCommand, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to set playback action command listener",
+ ("mc_server_set_playback_action_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ ret = mc_server_set_playback_position_cmd_received_cb(handle_, OnPlaybackPositionCommand, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ failed_setter = 1;
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to set playback position command listener",
+ ("mc_server_set_playback_position_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ ret = mc_server_set_shuffle_mode_cmd_received_cb(handle_, OnShuffleModeCommand, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ failed_setter = 2;
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to set shuffle mode command listener",
+ ("mc_server_set_shuffle_mode_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ ret = mc_server_set_repeat_mode_cmd_received_cb(handle_, OnRepeatModeCommand, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ failed_setter = 3;
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set repeat mode command listener",
+ ("mc_server_set_repeat_mode_cmd_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ ret = mc_server_set_playlist_cmd_received_cb(handle_, OnPlaybackItemCommand, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ failed_setter = 4;
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Unable to set playback item command listener",
+ ("mc_server_set_playlist_cmd_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ change_request_playback_info_listener_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::UnsetChangeRequestPlaybackInfoListener() {
+ ScopeLogger();
+
+ int ret = mc_server_unset_playback_action_cmd_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to unset playback state command listener",
+ ("mc_server_unset_playback_action_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ ret = mc_server_unset_playback_position_cmd_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to unset playback position command listener",
+ ("mc_server_unset_playback_position_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ ret = mc_server_unset_shuffle_mode_cmd_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to unset shuffle mode command listener",
+ ("mc_server_unset_shuffle_mode_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ ret = mc_server_unset_repeat_mode_cmd_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to unset repeat mode command listener",
+ ("mc_server_unset_repeat_mode_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ ret = mc_server_unset_playlist_cmd_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Unable to unset playback item command listener",
+ ("mc_server_unset_playlist_cmd_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ change_request_playback_info_listener_ = nullptr;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void MediaControllerServer::OnPlaybackActionCommand(const char* client_name, const char* request_id,
+ mc_playback_action_e action, void* user_data) {
+ ScopeLogger();
+
+ MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
+
+ // Here, we need to convert mc_playback_action_e enum to mc_playback_states_e enum.
+ std::string action_str;
+ PlatformResult result = types::MediaControllerPlaybackActionEnum.getName(action, &action_str);
+ if (!result) {
+ LoggerW("MediaControllerPlaybackActionEnum.getName() failed, error: %s",
+ result.message().c_str());
+ return;
}
picojson::value data = picojson::value(picojson::object());
picojson::object& data_o = data.get<picojson::object>();
- data_o["action"] = picojson::value(std::string("onplaybackstaterequest"));
- data_o["state"] = picojson::value(action_str);
+ data_o[kAction] = picojson::value(std::string("onplaybackstaterequest"));
+ data_o[kState] = picojson::value(action_str);
+ data_o[kClientName] = picojson::value(client_name);
server->change_request_playback_info_listener_(&data);
}
MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
- if (server->position_ == position) {
- LoggerD("The position did not change, skipping");
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ data_o[kAction] = picojson::value(std::string("onplaybackpositionrequest"));
+ data_o[kPosition] = picojson::value(static_cast<double>(position));
+ data_o[kClientName] = picojson::value(client_name);
+
+ server->change_request_playback_info_listener_(&data);
+}
+
+void MediaControllerServer::OnEventReply(const char* client_name, const char* request_id,
+ int result_code, bundle* data, void* user_data) {
+ ScopeLogger();
+ auto server = static_cast<MediaControllerServer*>(user_data);
+
+ picojson::value json_data = picojson::value(picojson::object());
+ auto& json_data_obj = json_data.get<picojson::object>();
+
+ json_data_obj[kCode] = picojson::value(static_cast<double>(result_code));
+ json_data_obj[kClientName] = picojson::value(std::string(client_name));
+ json_data_obj[kRequestId] = picojson::value(std::string(request_id));
+
+ picojson::value data_json;
+ auto result = common::BundleToJson(data, &data_json);
+ if (!result) {
+ LoggerE("BundleToJson() failed in OnEventReply.");
return;
}
+ json_data_obj[kData] = data_json;
+
+ server->event_reply_callback_(&json_data);
+}
+
+void MediaControllerServer::OnShuffleModeCommand(const char* client_name, const char* request_id,
+ mc_shuffle_mode_e mode, void* user_data) {
+ ScopeLogger();
+
+ MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
picojson::value data = picojson::value(picojson::object());
picojson::object& data_o = data.get<picojson::object>();
- data_o["action"] = picojson::value(std::string("onplaybackpositionrequest"));
- data_o["position"] = picojson::value(static_cast<double>(position));
+ data_o[kAction] = picojson::value(std::string("onshufflemoderequest"));
+ data_o[kMode] = picojson::value(mode == MC_SHUFFLE_MODE_ON);
+ data_o[kClientName] = picojson::value(client_name);
server->change_request_playback_info_listener_(&data);
}
-void MediaControllerServer::OnShuffleModeCommand(const char* client_name, const char* request_id,
- mc_shuffle_mode_e mode, void* user_data) {
+void MediaControllerServer::OnRepeatModeCommand(const char* client_name, const char* request_id,
+ mc_repeat_mode_e mode, void* user_data) {
+ ScopeLogger();
+
+ MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+ data_o[kClientName] = picojson::value(client_name);
+
+ if (MC_REPEAT_MODE_ONE_MEDIA != mode) {
+ // The onrepeatmoderequest event may be reported only with mode equal to true/false. The 3rd
+ // mode is not supported by this event.
+ common::tools::PrintDeprecationWarningFor("onrepeatmoderequest", "onrepeatstaterequest");
+ data_o[kAction] = picojson::value(std::string("onrepeatmoderequest"));
+ data_o[kMode] = picojson::value(mode == MC_REPEAT_MODE_ON);
+ server->change_request_playback_info_listener_(&data);
+ }
+
+ std::string state;
+ PlatformResult result = types::MediaControllerRepeatModeEnum.getName(mode, &state);
+ if (!result) {
+ LoggerE("MediaControllerRepeatModeEnum.getName() failed, error: %s", result.message().c_str());
+ return;
+ }
+ data_o[kAction] = picojson::value(std::string("onrepeatstaterequest"));
+ data_o[kState] = picojson::value(state);
+
+ server->change_request_playback_info_listener_(&data);
+}
+
+void MediaControllerServer::OnPlaybackItemCommand(const char* client_name, const char* request_id,
+ const char* playlist_name, const char* index,
+ mc_playback_action_e action,
+ unsigned long long position, void* user_data) {
ScopeLogger();
MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
- if (server->shuffle_mode_ == mode) {
- LoggerD("The shuffle mode did not change, skipping");
+ std::string action_str;
+ PlatformResult result = types::MediaControllerPlaybackActionEnum.getName(action, &action_str);
+ if (!result) {
+ LoggerE("MediaControllerPlaybackActionEnum.getName() failed, error: %s",
+ result.message().c_str());
return;
}
picojson::value data = picojson::value(picojson::object());
picojson::object& data_o = data.get<picojson::object>();
- data_o["action"] = picojson::value(std::string("onshufflemoderequest"));
- data_o["mode"] = picojson::value(mode == MC_SHUFFLE_MODE_ON);
+ data_o[kAction] = picojson::value(std::string("onplaybackitemrequest"));
+ data_o[kPlaylistName] = picojson::value(playlist_name);
+ data_o[kIndex] = picojson::value(index);
+ data_o[kState] = picojson::value(action_str);
+ data_o[kPosition] = picojson::value(static_cast<double>(position));
+ data_o[kClientName] = picojson::value(client_name);
server->change_request_playback_info_listener_(&data);
}
-void MediaControllerServer::OnRepeatModeCommand(const char* client_name, const char* request_id,
- mc_repeat_mode_e mode, void* user_data) {
+// subtitles
+common::PlatformResult MediaControllerServer::UpdateSubtitlesEnabled(bool enabled) {
+ ScopeLogger();
+ int ret = mc_server_update_subtitles_enabled(handle_, enabled);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error setting server subtitles",
+ ("mc_server_update_subtitles_enabled() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void MediaControllerServer::OnSubtitlesChangeCommand(const char* client_name,
+ const char* request_id, bool enabled,
+ void* user_data) {
ScopeLogger();
MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
- if (server->repeat_mode_ == mode) {
- LoggerD("The repeat mode did not change, skipping");
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ data_o[kEnabled] = picojson::value(enabled);
+ data_o[kClientName] = picojson::value(client_name);
+ data_o[kRequestId] = picojson::value(std::string(request_id));
+
+ server->subtitles_change_request_listener_(&data);
+}
+
+PlatformResult MediaControllerServer::SetSubtitlesChangeRequestListener(
+ const JsonCallback& callback) {
+ ScopeLogger();
+
+ int ret = mc_server_set_subtitles_cmd_received_cb(handle_, OnSubtitlesChangeCommand, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set subtitles command listener",
+ ("mc_server_set_subtitles_cmd_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ subtitles_change_request_listener_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::UnsetSubtitlesChangeRequestListener() {
+ ScopeLogger();
+
+ int ret = mc_server_unset_subtitles_cmd_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to unset subtitles command listener",
+ ("mc_server_unset_subtitles_cmd_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+ subtitles_change_request_listener_ = nullptr;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+// mode360
+common::PlatformResult MediaControllerServer::UpdateMode360Enabled(bool enabled) {
+ ScopeLogger();
+ int ret = mc_server_update_360_mode_enabled(handle_, enabled);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error setting server mode 360",
+ ("mc_server_update_360_mode_enabled() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void MediaControllerServer::OnMode360ChangeCommand(const char* client_name, const char* request_id,
+ bool enabled, void* user_data) {
+ ScopeLogger();
+
+ MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ data_o[kEnabled] = picojson::value(enabled);
+ data_o[kClientName] = picojson::value(client_name);
+ data_o[kRequestId] = picojson::value(std::string(request_id));
+
+ server->mode360_change_request_listener_(&data);
+}
+
+PlatformResult MediaControllerServer::SetMode360ChangeRequestListener(
+ const JsonCallback& callback) {
+ ScopeLogger();
+
+ int ret = mc_server_set_360_mode_cmd_received_cb(handle_, OnMode360ChangeCommand, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set mode 360 command listener",
+ ("mc_server_set_360_mode_cmd_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+
+ mode360_change_request_listener_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::UnsetMode360ChangeRequestListener() {
+ ScopeLogger();
+
+ int ret = mc_server_unset_360_mode_cmd_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to unset mode 360 command listener",
+ ("mc_server_unset_360_mode_cmd_received_cb() error: %d, message: %s",
+ ret, get_error_message(ret)));
+ }
+ mode360_change_request_listener_ = nullptr;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+// displayMode
+common::PlatformResult MediaControllerServer::UpdateDisplayModeType(const std::string& type) {
+ ScopeLogger();
+ mc_display_mode_e mode = MC_DISPLAY_MODE_FULL_SCREEN;
+ PlatformResult result = types::MediaControllerDisplayModeEnum.getValue(type, &mode);
+ if (!result) {
+ LoggerE("MediaControllerDisplayModeEnum.getValue() failed, error: %s",
+ result.message().c_str());
+ return result;
+ }
+
+ int ret = mc_server_update_display_mode(handle_, mode);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error setting server display mode",
+ ("mc_server_update_display_mode() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void MediaControllerServer::OnDisplayModeChangeCommand(const char* client_name,
+ const char* request_id,
+ mc_display_mode_e mode, void* user_data) {
+ ScopeLogger();
+
+ MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
+
+ std::string type;
+ PlatformResult result = types::MediaControllerDisplayModeEnum.getName(mode, &type);
+ if (!result) {
+ LoggerW("MediaControllerDisplayModeEnum.getName() failed, error: %s, ignoring event",
+ result.message().c_str());
return;
}
picojson::value data = picojson::value(picojson::object());
picojson::object& data_o = data.get<picojson::object>();
- data_o["action"] = picojson::value(std::string("onrepeatmoderequest"));
- data_o["mode"] = picojson::value(mode == MC_REPEAT_MODE_ON);
+ data_o[kType] = picojson::value(type);
+ data_o[kClientName] = picojson::value(client_name);
+ data_o[kRequestId] = picojson::value(std::string(request_id));
- server->change_request_playback_info_listener_(&data);
+ server->display_mode_change_request_listener_(&data);
+}
+
+PlatformResult MediaControllerServer::SetDisplayModeChangeRequestListener(
+ const JsonCallback& callback) {
+ ScopeLogger();
+
+ int ret = mc_server_set_display_mode_cmd_received_cb(handle_, OnDisplayModeChangeCommand, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to set display mode command listener",
+ ("mc_server_set_display_mode_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ display_mode_change_request_listener_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::UnsetDisplayModeChangeRequestListener() {
+ ScopeLogger();
+
+ int ret = mc_server_unset_display_mode_cmd_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to unset display mode command listener",
+ ("mc_server_unset_display_mode_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+ display_mode_change_request_listener_ = nullptr;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+// displayRotation
+PlatformResult MediaControllerServer::UpdateDisplayRotation(const std::string& display_rotation) {
+ ScopeLogger();
+ mc_display_rotation_e rotation = MC_DISPLAY_ROTATION_NONE;
+ PlatformResult result =
+ types::MediaControllerDisplayRotationEnum.getValue(display_rotation, &rotation);
+ if (!result) {
+ LoggerE("MediaControllerDisplayRotationEnum.getValue() failed, error: %s",
+ result.message().c_str());
+ return PlatformResult(ErrorCode::UNKNOWN_ERR);
+ }
+
+ int ret = mc_server_update_display_rotation(handle_, rotation);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error setting server display rotation",
+ ("mc_server_update_display_rotation() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void MediaControllerServer::OnDisplayRotationChangeCommand(const char* client_name,
+ const char* request_id,
+ mc_display_rotation_e rotation,
+ void* user_data) {
+ ScopeLogger();
+
+ MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
+
+ std::string display_rotation;
+ PlatformResult result =
+ types::MediaControllerDisplayRotationEnum.getName(rotation, &display_rotation);
+ if (!result) {
+ LoggerW("MediaControllerDisplayRotationEnum.getName() failed, error: %s, ignoring event",
+ result.message().c_str());
+ return;
+ }
+
+ picojson::value data = picojson::value(picojson::object());
+ picojson::object& data_o = data.get<picojson::object>();
+
+ data_o[kDisplayRotation] = picojson::value(display_rotation);
+ data_o[kClientName] = picojson::value(client_name);
+ data_o[kRequestId] = picojson::value(std::string(request_id));
+ server->display_rotation_change_request_listener_(&data);
+}
+
+PlatformResult MediaControllerServer::SetDisplayRotationChangeRequestListener(
+ const JsonCallback& callback) {
+ ScopeLogger();
+
+ int ret =
+ mc_server_set_display_rotation_cmd_received_cb(handle_, OnDisplayRotationChangeCommand, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to set display rotation command listener",
+ ("mc_server_set_display_rotation_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ display_rotation_change_request_listener_ = callback;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::UnsetDisplayRotationChangeRequestListener() {
+ ScopeLogger();
+
+ int ret = mc_server_unset_display_rotation_cmd_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to unset display rotation command listener",
+ ("mc_server_unset_display_rotation_cmd_received_cb() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+ display_rotation_change_request_listener_ = nullptr;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::GetAllClientsInfo(picojson::array* clients_info) {
+ ScopeLogger();
+
+ auto client_cb = [](const char* name, void* data) -> bool {
+ auto clients = static_cast<picojson::array*>(data);
+ picojson::object client_info = {{"name", picojson::value(name)}};
+ clients->push_back(picojson::value(client_info));
+ return true;
+ };
+
+ int ret = mc_server_foreach_client(handle_, client_cb, clients_info);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Iterating over active clients failed",
+ ("mc_server_foreach_client() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult MediaControllerServer::SendEvent(const char* event_name,
+ const picojson::value& event_data,
+ const char* client_name,
+ const JsonCallback& reply_cb, char** request_id) {
+ ScopeLogger();
+
+ bundle* event_data_bundle = bundle_create();
+ if (!event_data_bundle) {
+ LoggerE("failed to create bundle object");
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "failed to create bundle object");
+ }
+
+ SCOPE_EXIT {
+ bundle_free(event_data_bundle);
+ };
+
+ PlatformResult result = common::JsonToBundle(event_data, &event_data_bundle);
+ if (!result) {
+ return LogAndCreateResult(result.error_code(), "Event data to bundle conversion failed",
+ ("JsonToBundle() failed with error: %s", result.message().c_str()));
+ }
+
+ if (!event_data_bundle) {
+ LoggerD("data is null");
+ }
+
+ int ret =
+ mc_server_send_custom_event(handle_, client_name, event_name, event_data_bundle, request_id);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "sending custom event failed",
+ ("mc_server_send_custom_event() returned error code: %d. Error message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ event_reply_callback_ = reply_cb;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
}
} // namespace mediacontroller
#include <string>
#include "common/platform_result.h"
-#include "mediacontroller/mediacontroller_types.h"
+#include "mediacontroller/mediacontroller_utils.h"
namespace extension {
namespace mediacontroller {
common::PlatformResult Init();
common::PlatformResult SetPlaybackState(const std::string& state);
common::PlatformResult SetPlaybackPosition(double position);
+ common::PlatformResult SetContentAgeRating(const std::string& rating);
+ common::PlatformResult SetContentType(const std::string& content_type);
common::PlatformResult SetShuffleMode(bool mode);
common::PlatformResult SetRepeatMode(bool mode);
+ common::PlatformResult SetRepeatState(const std::string& state);
common::PlatformResult SetMetadata(const picojson::object& metadata);
common::PlatformResult SetChangeRequestPlaybackInfoListener(const JsonCallback& callback);
common::PlatformResult UnsetChangeRequestPlaybackInfoListener();
+ common::PlatformResult SetSearchRequestListener(const JsonCallback& callback);
+ common::PlatformResult UnsetSearchRequestListener();
+
common::PlatformResult CommandReply(const std::string& client_name, const std::string& request_id,
- const picojson::value& data);
+ int code, const picojson::value& data);
common::PlatformResult SetCommandListener(const JsonCallback& callback);
common::PlatformResult UnsetCommandListener();
+ common::PlatformResult CreatePlaylist(const std::string& name, picojson::value* playlist_info);
+ common::PlatformResult SavePlaylist(const std::string& name);
+ common::PlatformResult DeletePlaylist(const std::string& name);
+ common::PlatformResult UpdatePlaybackItem(const std::string& name, const std::string& index);
+
+ common::PlatformResult MediaControllerPlaylistAddItem(const std::string& name,
+ const std::string& index,
+ const picojson::object& metadata);
+ common::PlatformResult MediaControllerPlaylistGetItems(const std::string& name,
+ picojson::array* items);
+ common::PlatformResult UpdateIconURI(const char* icon_uri);
+ common::PlatformResult SetPlaybackAbility(const std::string& action,
+ const std::string& support_str, bool* is_changed);
+ common::PlatformResult SavePlaybackAbilities(const picojson::value& abilities);
+ common::PlatformResult SetDisplayModeAbility(const std::string& mode,
+ const std::string& support_str);
+ common::PlatformResult SetDisplayRotationAbility(std::string& display_rotation_ability,
+ const std::string& support_str);
+ common::PlatformResult SetSimpleAbility(const std::string& ability_type,
+ const std::string& support_str);
+
+ common::PlatformResult GetAllClientsInfo(picojson::array* clientsInfo);
+
+ common::PlatformResult UpdateSubtitlesEnabled(bool enabled);
+ common::PlatformResult SetSubtitlesChangeRequestListener(const JsonCallback& callback);
+ common::PlatformResult UnsetSubtitlesChangeRequestListener();
+
+ common::PlatformResult UpdateMode360Enabled(bool enabled);
+ common::PlatformResult SetMode360ChangeRequestListener(const JsonCallback& callback);
+ common::PlatformResult UnsetMode360ChangeRequestListener();
+
+ common::PlatformResult UpdateDisplayModeType(const std::string& type);
+ common::PlatformResult SetDisplayModeChangeRequestListener(const JsonCallback& callback);
+ common::PlatformResult UnsetDisplayModeChangeRequestListener();
+
+ common::PlatformResult UpdateDisplayRotation(const std::string& display_rotation);
+ common::PlatformResult SetDisplayRotationChangeRequestListener(const JsonCallback& callback);
+ common::PlatformResult UnsetDisplayRotationChangeRequestListener();
+
+ common::PlatformResult SendEvent(const char* event_name, const picojson::value& event_data,
+ const char* client_name, const JsonCallback& reply_cb,
+ char** request_id);
+
private:
mc_server_h handle_;
JsonCallback change_request_playback_info_listener_;
+ JsonCallback event_reply_callback_;
+ JsonCallback command_listener_;
+ JsonCallback search_request_listener_;
+ JsonCallback subtitles_change_request_listener_;
+ JsonCallback mode360_change_request_listener_;
+ JsonCallback display_mode_change_request_listener_;
+ JsonCallback display_rotation_change_request_listener_;
+
mc_playback_states_e playback_state_;
unsigned long long position_;
+ mc_content_age_rating_e age_rating_;
+ mc_content_type_e content_type_;
mc_shuffle_mode_e shuffle_mode_;
mc_repeat_mode_e repeat_mode_;
bool is_shuffle_mode_set_;
bool is_repeat_mode_set_;
+ std::map<std::string, mc_ability_support_e> abilities_;
- JsonCallback command_listener_;
+ std::map<std::string, mc_playlist_h> playlist_handle_map_;
static void OnPlaybackActionCommand(const char* client_name, const char* request_id,
mc_playback_action_e action, void* user_data);
mc_shuffle_mode_e mode, void* user_data);
static void OnRepeatModeCommand(const char* client_name, const char* request_id,
mc_repeat_mode_e mode, void* user_data);
-
+ static void OnPlaybackItemCommand(const char* client_name, const char* request_id,
+ const char* playlist_name, const char* index,
+ mc_playback_action_e action, unsigned long long position,
+ void* user_data);
+ static void OnEventReply(const char* client_name, const char* request_id, int result_code,
+ bundle* data, void* user_data);
+ static void OnSearchRequestReceived(const char* client_name, const char* request_id,
+ mc_search_h request, void* user_data);
static void OnCommandReceived(const char* client_name, const char* request_id,
const char* command, bundle* data, void* user_data);
+ static void OnSubtitlesChangeCommand(const char* client_name, const char* request_id,
+ bool enabled, void* user_data);
+ static void OnMode360ChangeCommand(const char* client_name, const char* request_id, bool enabled,
+ void* user_data);
+
+ static void OnDisplayModeChangeCommand(const char* client_name, const char* request_id,
+ mc_display_mode_e type, void* user_data);
+
+ static void OnDisplayRotationChangeCommand(const char* client_name, const char* request_id,
+ mc_display_rotation_e type, void* user_data);
};
} // namespace mediacontroller
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "mediacontroller/mediacontroller_types.h"
-
-#include <media_controller_client.h>
-
-#include "common/logger.h"
-#include "common/platform_result.h"
-#include "common/scope_exit.h"
-
-namespace extension {
-namespace mediacontroller {
-
-using common::PlatformResult;
-using common::ErrorCode;
-
-namespace types {
-
-const common::PlatformEnum<mc_server_state_e> MediaControllerServerStateEnum{
- {"NONE", MC_SERVER_STATE_NONE},
- {"ACTIVE", MC_SERVER_STATE_ACTIVATE},
- {"INACTIVE", MC_SERVER_STATE_DEACTIVATE}};
-
-const common::PlatformEnum<mc_playback_states_e> MediaControllerPlaybackStateEnum{
- {"PLAY", MC_PLAYBACK_STATE_PLAYING},
- {"PAUSE", MC_PLAYBACK_STATE_PAUSED},
- {"STOP", MC_PLAYBACK_STATE_STOPPED},
- {"NEXT", MC_PLAYBACK_STATE_MOVING_TO_NEXT},
- {"PREV", MC_PLAYBACK_STATE_MOVING_TO_PREVIOUS},
- {"FORWARD", MC_PLAYBACK_STATE_FAST_FORWARDING},
- {"REWIND", MC_PLAYBACK_STATE_REWINDING}};
-
-const common::PlatformEnum<mc_playback_action_e> MediaControllerPlaybackActionEnum{
- {"PLAY", MC_PLAYBACK_ACTION_PLAY}, {"PAUSE", MC_PLAYBACK_ACTION_PAUSE},
- {"STOP", MC_PLAYBACK_ACTION_STOP}, {"NEXT", MC_PLAYBACK_ACTION_NEXT},
- {"PREV", MC_PLAYBACK_ACTION_PREV}, {"FORWARD", MC_PLAYBACK_ACTION_FAST_FORWARD},
- {"REWIND", MC_PLAYBACK_ACTION_REWIND}};
-
-const common::PlatformEnum<mc_meta_e> MediaControllerMetadataAttributeEnum{
- {"title", MC_META_MEDIA_TITLE},
- {"artist", MC_META_MEDIA_ARTIST},
- {"album", MC_META_MEDIA_ALBUM},
- {"author", MC_META_MEDIA_AUTHOR},
- {"genre", MC_META_MEDIA_GENRE},
- {"duration", MC_META_MEDIA_DURATION},
- {"date", MC_META_MEDIA_DATE},
- {"copyright", MC_META_MEDIA_COPYRIGHT},
- {"description", MC_META_MEDIA_DESCRIPTION},
- {"trackNum", MC_META_MEDIA_TRACK_NUM},
- {"picture", MC_META_MEDIA_PICTURE}};
-
-const common::PlatformEnum<mc_repeat_mode_e> MediaControllerRepeatModeEnum{
- {"REPEAT_OFF", MC_REPEAT_MODE_OFF},
- {"REPEAT_ONE", MC_REPEAT_MODE_ONE_MEDIA},
- {"REPEAT_ALL", MC_REPEAT_MODE_ON}};
-
-const common::PlatformEnum<mc_content_age_rating_e> MediaControllerContentAgeRatingEnum{
- {"ALL", MC_CONTENT_RATING_ALL}, {"1", MC_CONTENT_RATING_1_PLUS},
- {"2", MC_CONTENT_RATING_2_PLUS}, {"3", MC_CONTENT_RATING_3_PLUS},
- {"4", MC_CONTENT_RATING_4_PLUS}, {"5", MC_CONTENT_RATING_5_PLUS},
- {"6", MC_CONTENT_RATING_6_PLUS}, {"7", MC_CONTENT_RATING_7_PLUS},
- {"8", MC_CONTENT_RATING_8_PLUS}, {"9", MC_CONTENT_RATING_9_PLUS},
- {"10", MC_CONTENT_RATING_10_PLUS}, {"11", MC_CONTENT_RATING_11_PLUS},
- {"12", MC_CONTENT_RATING_12_PLUS}, {"13", MC_CONTENT_RATING_13_PLUS},
- {"14", MC_CONTENT_RATING_14_PLUS}, {"15", MC_CONTENT_RATING_15_PLUS},
- {"16", MC_CONTENT_RATING_16_PLUS}, {"17", MC_CONTENT_RATING_17_PLUS},
- {"18", MC_CONTENT_RATING_18_PLUS}, {"19", MC_CONTENT_RATING_19_PLUS}};
-
-const common::PlatformEnum<mc_content_type_e> MediaControllerContentTypeEnum{
- {"IMAGE", MC_CONTENT_TYPE_IMAGE},
- {"MUSIC", MC_CONTENT_TYPE_MUSIC},
- {"VIDEO", MC_CONTENT_TYPE_VIDEO},
- {"OTHER", MC_CONTENT_TYPE_OTHER},
- {"UNDECIDED", MC_CONTENT_TYPE_UNDECIDED}};
-
-PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state) {
- ScopeLogger();
-
- int ret;
- mc_playback_states_e state_e;
- ret = mc_client_get_playback_state(playback_h, &state_e);
- if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Error getting playback state",
- ("mc_client_get_playback_state() error: %d, message: %s", ret, get_error_message(ret)));
- }
- if (state_e == MC_PLAYBACK_STATE_NONE) {
- state_e = MC_PLAYBACK_STATE_STOPPED;
- }
-
- PlatformResult result = MediaControllerPlaybackStateEnum.getName(state_e, state);
- if (!result) {
- LoggerE("MediaControllerPlaybackStateEnum.getName() failed, error: %s",
- result.message().c_str());
- return result;
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult ConvertPlaybackPosition(mc_playback_h playback_h, double* position) {
- ScopeLogger();
-
- int ret;
-
- unsigned long long pos;
- ret = mc_client_get_playback_position(playback_h, &pos);
- if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Error getting playback position",
- ("mc_client_get_playback_position() error: %d, message: %s", ret, get_error_message(ret)));
- }
-
- *position = static_cast<double>(pos);
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult ConvertMetadata(mc_metadata_h metadata_h, picojson::object* metadata) {
- ScopeLogger();
-
- char* value = nullptr;
- SCOPE_EXIT {
- free(value);
- };
-
- for (auto entry : MediaControllerMetadataAttributeEnum) {
- int ret = mc_metadata_get(metadata_h, entry.second, &value);
- if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting metadata",
- ("mc_metadata_get(%s) error: %d, message: %s", entry.first.c_str(),
- ret, get_error_message(ret)));
- }
-
- (*metadata)[entry.first] = picojson::value(std::string(value ? value : ""));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-} // types
-
-} // namespace mediacontroller
-} // namespace extension
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef MEDIACONTROLLER_MEDIACONTROLLER_TYPES_H_
-#define MEDIACONTROLLER_MEDIACONTROLLER_TYPES_H_
-
-#include <media_controller_type.h>
-#include <functional>
-#include <map>
-#include <string>
-
-#include "common/platform_enum.h"
-#include "common/platform_result.h"
-
-namespace extension {
-namespace mediacontroller {
-
-typedef std::function<void(picojson::value*)> JsonCallback;
-
-namespace types {
-
-common::PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state);
-common::PlatformResult ConvertContentAgeRating(mc_playback_h playback_h, std::string* state);
-common::PlatformResult ConvertPlaybackPosition(mc_playback_h playback_h, double* position);
-common::PlatformResult ConvertMetadata(mc_metadata_h metadata_h, picojson::object* metadata);
-common::PlatformResult ConvertContentType(mc_playback_h playback_h, std::string* contentType);
-
-extern const common::PlatformEnum<mc_server_state_e> MediaControllerServerStateEnum;
-extern const common::PlatformEnum<mc_playback_states_e> MediaControllerPlaybackStateEnum;
-extern const common::PlatformEnum<mc_playback_action_e> MediaControllerPlaybackActionEnum;
-extern const common::PlatformEnum<mc_meta_e> MediaControllerMetadataAttributeEnum;
-extern const common::PlatformEnum<mc_repeat_mode_e> MediaControllerRepeatModeEnum;
-extern const common::PlatformEnum<mc_content_age_rating_e> MediaControllerContentAgeRatingEnum;
-extern const common::PlatformEnum<mc_content_type_e> MediaControllerContentTypeEnum;
-
-} // namespace types
-
-} // namespace mediacontroller
-} // namespace extension
-
-#endif // MEDIACONTROLLER_MEDIACONTROLLER_TYPES_H_
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "mediacontroller/mediacontroller_utils.h"
+
+#include <media_controller_client.h>
+
+#include "common/logger.h"
+#include "common/platform_result.h"
+#include "common/scope_exit.h"
+
+namespace extension {
+namespace mediacontroller {
+
+using common::ErrorCode;
+using common::PlatformResult;
+using namespace attributes;
+
+namespace privileges {
+
+const char* kPrivilegeMediaControllerClient = "http://tizen.org/privilege/mediacontroller.client";
+const char* kPrivilegeMediaControllerServer = "http://tizen.org/privilege/mediacontroller.server";
+
+} // privileges
+
+namespace attributes {
+
+const char* kAbility = "ability";
+const char* kAbilityType = "abilityType";
+const char* kAction = "action";
+const char* kAgeRating = "ageRating";
+const char* kCallbackId = "callbackId";
+const char* kCategory = "category";
+const char* kClientName = "clientName";
+const char* kCode = "code";
+const char* kCommand = "command";
+const char* kContentType = "contentType";
+const char* kData = "data";
+const char* kDisplayMode = "displayMode";
+const char* kDisplayRotation = "displayRotation";
+const char* kDisplayRotationAbility = "displayRotationAbility";
+const char* kEnabled = "enabled";
+const char* kEpisode = "episode";
+const char* kEpisodeNumber = "episodeNumber";
+const char* kEpisodeTitle = "episodeTitle";
+const char* kEventData = "eventData";
+const char* kEventName = "eventName";
+const char* kExtraData = "extraData";
+const char* kIconURI = "iconURI";
+const char* kIndex = "index";
+const char* kKeyword = "keyword";
+const char* kListenerId = "listenerId";
+const char* kMetadata = "metadata";
+const char* kMode = "mode";
+const char* kName = "name";
+const char* kPlaylistName = "playlistName";
+const char* kPosition = "position";
+const char* kRating = "rating";
+const char* kRepeatMode = "repeatMode";
+const char* kRepeatState = "repeatState";
+const char* kReply = "reply";
+const char* kReplyListener = "replyListener";
+const char* kRequest = "request";
+const char* kRequestId = "requestId";
+const char* kResolution = "resolution";
+const char* kResolutionHeight = "resolutionHeight";
+const char* kResolutionWidth = "resolutionWidth";
+const char* kResult = "result";
+const char* kResultCode = "resultCode";
+const char* kSeason = "season";
+const char* kSeasonNumber = "seasonNumber";
+const char* kSeasonTitle = "seasonTitle";
+const char* kServerName = "serverName";
+const char* kShuffleMode = "shuffleMode";
+const char* kState = "state";
+const char* kSupport = "support";
+const char* kType = "type";
+const char* kValue = "value";
+
+} // attributes
+
+namespace types {
+
+const common::PlatformEnum<mc_server_state_e> MediaControllerServerStateEnum{
+ {"NONE", MC_SERVER_STATE_NONE},
+ {"ACTIVE", MC_SERVER_STATE_ACTIVATE},
+ {"INACTIVE", MC_SERVER_STATE_DEACTIVATE}};
+
+const common::PlatformEnum<mc_playback_states_e> MediaControllerPlaybackStateEnum{
+ {"PLAY", MC_PLAYBACK_STATE_PLAYING},
+ {"PAUSE", MC_PLAYBACK_STATE_PAUSED},
+ {"STOP", MC_PLAYBACK_STATE_STOPPED},
+ {"NEXT", MC_PLAYBACK_STATE_MOVING_TO_NEXT},
+ {"PREV", MC_PLAYBACK_STATE_MOVING_TO_PREVIOUS},
+ {"FORWARD", MC_PLAYBACK_STATE_FAST_FORWARDING},
+ {"REWIND", MC_PLAYBACK_STATE_REWINDING}};
+
+const common::PlatformEnum<mc_playback_action_e> MediaControllerPlaybackActionEnum{
+ {"PLAY", MC_PLAYBACK_ACTION_PLAY}, {"PAUSE", MC_PLAYBACK_ACTION_PAUSE},
+ {"STOP", MC_PLAYBACK_ACTION_STOP}, {"NEXT", MC_PLAYBACK_ACTION_NEXT},
+ {"PREV", MC_PLAYBACK_ACTION_PREV}, {"FORWARD", MC_PLAYBACK_ACTION_FAST_FORWARD},
+ {"REWIND", MC_PLAYBACK_ACTION_REWIND}};
+
+const common::PlatformEnum<mc_meta_e> MediaControllerMetadataAttributeEnum{
+ {"title", MC_META_MEDIA_TITLE},
+ {"artist", MC_META_MEDIA_ARTIST},
+ {"album", MC_META_MEDIA_ALBUM},
+ {"author", MC_META_MEDIA_AUTHOR},
+ {"genre", MC_META_MEDIA_GENRE},
+ {"duration", MC_META_MEDIA_DURATION},
+ {"date", MC_META_MEDIA_DATE},
+ {"copyright", MC_META_MEDIA_COPYRIGHT},
+ {"description", MC_META_MEDIA_DESCRIPTION},
+ {"trackNum", MC_META_MEDIA_TRACK_NUM},
+ {"picture", MC_META_MEDIA_PICTURE},
+ {"season", MC_META_MEDIA_SEASON},
+ {"episode", MC_META_MEDIA_EPISODE},
+ {"resolution", MC_META_MEDIA_RESOLUTION}};
+
+const common::PlatformEnum<mc_repeat_mode_e> MediaControllerRepeatModeEnum{
+ {"REPEAT_OFF", MC_REPEAT_MODE_OFF},
+ {"REPEAT_ONE", MC_REPEAT_MODE_ONE_MEDIA},
+ {"REPEAT_ALL", MC_REPEAT_MODE_ON}};
+
+const common::PlatformEnum<mc_content_age_rating_e> MediaControllerContentAgeRatingEnum{
+ {"ALL", MC_CONTENT_RATING_ALL}, {"1", MC_CONTENT_RATING_1_PLUS},
+ {"2", MC_CONTENT_RATING_2_PLUS}, {"3", MC_CONTENT_RATING_3_PLUS},
+ {"4", MC_CONTENT_RATING_4_PLUS}, {"5", MC_CONTENT_RATING_5_PLUS},
+ {"6", MC_CONTENT_RATING_6_PLUS}, {"7", MC_CONTENT_RATING_7_PLUS},
+ {"8", MC_CONTENT_RATING_8_PLUS}, {"9", MC_CONTENT_RATING_9_PLUS},
+ {"10", MC_CONTENT_RATING_10_PLUS}, {"11", MC_CONTENT_RATING_11_PLUS},
+ {"12", MC_CONTENT_RATING_12_PLUS}, {"13", MC_CONTENT_RATING_13_PLUS},
+ {"14", MC_CONTENT_RATING_14_PLUS}, {"15", MC_CONTENT_RATING_15_PLUS},
+ {"16", MC_CONTENT_RATING_16_PLUS}, {"17", MC_CONTENT_RATING_17_PLUS},
+ {"18", MC_CONTENT_RATING_18_PLUS}, {"19", MC_CONTENT_RATING_19_PLUS}};
+
+const common::PlatformEnum<mc_content_type_e> MediaControllerContentTypeEnum{
+ {"IMAGE", MC_CONTENT_TYPE_IMAGE},
+ {"MUSIC", MC_CONTENT_TYPE_MUSIC},
+ {"VIDEO", MC_CONTENT_TYPE_VIDEO},
+ {"OTHER", MC_CONTENT_TYPE_OTHER},
+ {"UNDECIDED", MC_CONTENT_TYPE_UNDECIDED}};
+
+const common::PlatformEnum<mc_search_category_e> MediaControllerSearchCategoryEnum{
+ {"NO_CATEGORY", MC_SEARCH_NO_CATEGORY},
+ {"TITLE", MC_SEARCH_TITLE},
+ {"ARTIST", MC_SEARCH_ARTIST},
+ {"ALBUM", MC_SEARCH_ALBUM},
+ {"GENRE", MC_SEARCH_GENRE},
+ {"TPO", MC_SEARCH_TPO}};
+
+const common::PlatformEnum<mc_ability_support_e> MediaControllerAbilitySupportEnum{
+ {"YES", MC_ABILITY_SUPPORTED_YES},
+ {"NO", MC_ABILITY_SUPPORTED_NO},
+ {"UNDECIDED", MC_ABILITY_SUPPORTED_UNDECIDED}};
+
+const common::PlatformEnum<mc_subscription_type_e> MediaControllerSubscriptionTypeEnum{
+ {"PLAYBACK_ABILITY", MC_SUBSCRIPTION_TYPE_PLAYBACK_ABILITY},
+ {"SIMPLE_ABILITIES", MC_SUBSCRIPTION_TYPE_ABILITY_SUPPORT}};
+
+const common::PlatformEnum<mc_ability_e> MediaControllerSimpleAbilityEnum{
+ {"PLAYBACK_POSITION", MC_ABILITY_PLAYBACK_POSITION},
+ {"SHUFFLE", MC_ABILITY_SHUFFLE},
+ {"REPEAT", MC_ABILITY_REPEAT},
+ {"PLAYLIST", MC_ABILITY_PLAYLIST},
+ {"CLIENT_CUSTOM", MC_ABILITY_CLIENT_CUSTOM},
+ {"SEARCH", MC_ABILITY_SEARCH},
+ {"SUBTITLES", MC_ABILITY_SUBTITLES},
+ {"MODE_360", MC_ABILITY_360_MODE}};
+
+const common::PlatformEnum<mc_display_mode_e> MediaControllerDisplayModeEnum{
+ {"LETTER_BOX", MC_DISPLAY_MODE_LETTER_BOX},
+ {"ORIGIN_SIZE", MC_DISPLAY_MODE_ORIGIN_SIZE},
+ {"FULL_SCREEN", MC_DISPLAY_MODE_FULL_SCREEN},
+ {"CROPPED_FULL", MC_DISPLAY_MODE_CROPPED_FULL}};
+
+const common::PlatformEnum<mc_display_rotation_e> MediaControllerDisplayRotationEnum{
+ {"ROTATION_NONE", MC_DISPLAY_ROTATION_NONE},
+ {"ROTATION_90", MC_DISPLAY_ROTATION_90},
+ {"ROTATION_180", MC_DISPLAY_ROTATION_180},
+ {"ROTATION_270", MC_DISPLAY_ROTATION_270}};
+
+PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state) {
+ ScopeLogger();
+
+ int ret;
+ mc_playback_states_e state_e;
+ ret = mc_client_get_playback_state(playback_h, &state_e);
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error getting playback state",
+ ("mc_client_get_playback_state() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+ if (state_e == MC_PLAYBACK_STATE_NONE) {
+ state_e = MC_PLAYBACK_STATE_STOPPED;
+ }
+
+ PlatformResult result = MediaControllerPlaybackStateEnum.getName(state_e, state);
+ if (!result) {
+ LoggerE("MediaControllerPlaybackStateEnum.getName() failed, error: %s",
+ result.message().c_str());
+ return result;
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ConvertContentAgeRating(mc_playback_h playback_h, std::string* rating) {
+ ScopeLogger();
+
+ mc_content_age_rating_e rating_e = MC_CONTENT_RATING_ALL;
+ int ret = mc_client_get_age_rating(playback_h, &rating_e);
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error getting content age rating",
+ ("mc_client_get_age_rating() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ PlatformResult result = MediaControllerContentAgeRatingEnum.getName(rating_e, rating);
+ if (!result) {
+ LoggerE("MediaControllerContentAgeRatingEnum.getName() failed, error: %s",
+ result.message().c_str());
+ return result;
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ConvertContentType(mc_playback_h playback_h, std::string* contentType) {
+ ScopeLogger();
+ mc_content_type_e content_type_e = MC_CONTENT_TYPE_UNDECIDED;
+ int ret = mc_client_get_playback_content_type(playback_h, &content_type_e);
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting content type",
+ ("mc_client_get_playback_content_type() error: %d, message: %s", ret,
+ get_error_message(ret)));
+ }
+
+ PlatformResult result = MediaControllerContentTypeEnum.getName(content_type_e, contentType);
+ if (!result) {
+ LoggerE("MediaControllerContentTypeEnum.getName() failed, error: %s", result.message().c_str());
+ return result;
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ConvertPlaybackPosition(mc_playback_h playback_h, double* position) {
+ ScopeLogger();
+
+ int ret;
+
+ unsigned long long pos;
+ ret = mc_client_get_playback_position(playback_h, &pos);
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error getting playback position",
+ ("mc_client_get_playback_position() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ *position = static_cast<double>(pos);
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ConvertMetadata(mc_metadata_h metadata_h, picojson::object* metadata) {
+ ScopeLogger();
+
+ char* value = nullptr;
+ SCOPE_EXIT {
+ free(value);
+ };
+
+ picojson::value to_decode = picojson::value(picojson::object());
+ picojson::object& obj = to_decode.get<picojson::object>();
+
+ for (auto entry : MediaControllerMetadataAttributeEnum) {
+ int ret = mc_metadata_get(metadata_h, entry.second, &value);
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting metadata",
+ ("mc_metadata_get(%s) error: %d, message: %s", entry.first.c_str(),
+ ret, get_error_message(ret)));
+ }
+
+ obj[entry.first] = value ? picojson::value(value) : picojson::value();
+ }
+
+ PlatformResult result = utils::DecodeMetadata(to_decode, metadata);
+ if (!result) {
+ return result;
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ConvertPlaybackAbility(mc_playback_ability_h ability_h, const std::string& action,
+ std::string* ability_str) {
+ ScopeLogger();
+
+ mc_ability_support_e ability_e;
+ mc_playback_action_e action_e;
+ PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+
+ if ("TOGGLE_PLAY_PAUSE" == action) {
+ action_e = MC_PLAYBACK_ACTION_TOGGLE_PLAY_PAUSE;
+ } else {
+ result = MediaControllerPlaybackActionEnum.getValue(action, &action_e);
+ if (!result) {
+ LoggerE("MediaControllerPlaybackActionEnum.getValue() failed, error: %s",
+ result.message().c_str());
+ return result;
+ }
+ }
+
+ int ret = mc_playback_action_is_supported(ability_h, action_e, &ability_e);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error checking playback action ability support",
+ ("mc_playback_action_is_supported() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+ result = MediaControllerAbilitySupportEnum.getName(ability_e, ability_str);
+ if (!result) {
+ LoggerE("MediaControllerAbilitySupportEnum.getName() failed, error: %s",
+ result.message().c_str());
+ return result;
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+} // namespace types
+
+PlatformResult utils::GetAllPlaylists(const std::string& app_id, picojson::array* playlists) {
+ ScopeLogger();
+
+ auto OnPlaylists = [](mc_playlist_h playlist, void* user_data) -> bool {
+ char* name = nullptr;
+
+ SCOPE_EXIT {
+ free(name);
+ };
+
+ int ret = mc_playlist_get_name(playlist, &name);
+
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return false;
+ }
+
+ auto playlists = static_cast<picojson::array*>(user_data);
+
+ picojson::value value = picojson::value(picojson::object());
+ picojson::object& obj = value.get<picojson::object>();
+
+ obj.insert(std::make_pair(kName, picojson::value{name}));
+ playlists->push_back(value);
+
+ return true;
+ };
+
+ int ret = mc_playlist_foreach_playlist(app_id.c_str(), OnPlaylists, playlists);
+
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while get playlists",
+ ("mc_playlist_foreach_playlist() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+ErrorCode utils::ConvertMediaControllerError(int e) {
+ ScopeLogger();
+ ErrorCode error;
+
+ switch (e) {
+ case MEDIA_CONTROLLER_ERROR_ABILITY_LIMITED_BY_SERVER_APP:
+ error = ErrorCode::NOT_SUPPORTED_ERR;
+ break;
+ default:
+ error = ErrorCode::UNKNOWN_ERR;
+ break;
+ }
+ return error;
+}
+
+bool utils::isMetadataAttributeEncodable(const std::string& name) {
+ return name == kSeason || name == kEpisode || name == kResolution;
+}
+
+PlatformResult utils::EncodeMetadata(const picojson::object& to_encode, picojson::object* encoded) {
+ ScopeLogger();
+
+ int ret = 0;
+ char* encoded_value = nullptr;
+ int number = 0;
+
+ SCOPE_EXIT {
+ free(encoded_value);
+ };
+
+ // season
+ try {
+ number = static_cast<int>(to_encode.at(kSeasonNumber).get<double>());
+ const char* season_title = to_encode.at(kSeasonTitle).is<picojson::null>()
+ ? nullptr
+ : to_encode.at(kSeasonTitle).get<std::string>().c_str();
+
+ ret = mc_metadata_encode_season(number, season_title, &encoded_value);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while encoding season",
+ ("mc_metadata_encode_season() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ (*encoded).insert(std::make_pair(kSeason, picojson::value(encoded_value)));
+ } catch (...) {
+ LoggerE("Season formation missing! - This should never happened.");
+ }
+
+ // episode
+ try {
+ number = static_cast<int>(to_encode.at(kEpisodeNumber).get<double>());
+ const char* episode_title = to_encode.at(kEpisodeTitle).is<picojson::null>()
+ ? nullptr
+ : to_encode.at(kEpisodeTitle).get<std::string>().c_str();
+
+ ret = mc_metadata_encode_episode(number, episode_title, &encoded_value);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while encoding episode",
+ ("mc_metadata_encode_episode() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ (*encoded).insert(std::make_pair(kEpisode, picojson::value(encoded_value)));
+ } catch (...) {
+ LoggerE("Episode formation missing! - This should never happened.");
+ }
+
+ // resolution
+ try {
+ u_int width = static_cast<u_int>(to_encode.at(kResolutionWidth).get<double>());
+ u_int height = static_cast<u_int>(to_encode.at(kResolutionHeight).get<double>());
+
+ ret = mc_metadata_encode_resolution(width, height, &encoded_value);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while encoding resolution",
+ ("mc_metadata_encode_resolution() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ (*encoded).insert(std::make_pair(kResolution, picojson::value(encoded_value)));
+ } catch (...) {
+ LoggerE("Resolution formation missing! - This should never happened.");
+ }
+
+ // other metadata attributes
+ for (auto entry : types::MediaControllerMetadataAttributeEnum) {
+ std::string name = entry.first;
+ if (!isMetadataAttributeEncodable(name)) {
+ try {
+ std::string value_str = to_encode.at(name).get<std::string>();
+ (*encoded).insert(std::make_pair(name, picojson::value(value_str)));
+ } catch (...) {
+ LoggerE("%s formation missing! - This should never happened.", name.c_str());
+ }
+ }
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult utils::DecodeMetadata(const picojson::value& to_decode, picojson::object* decoded) {
+ ScopeLogger();
+
+ int ret = 0;
+ int number = 0;
+ char* season_title = nullptr;
+ char* episode_title = nullptr;
+ std::string val;
+
+ SCOPE_EXIT {
+ free(season_title);
+ free(episode_title);
+ };
+
+ // decode season
+ if (!to_decode.get(kSeason).is<picojson::null>()) {
+ val = to_decode.get(kSeason).get<std::string>();
+
+ ret = mc_metadata_decode_season(val.c_str(), &number, &season_title);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while decoding season",
+ ("mc_metadata_decode_season() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ (*decoded)[kSeasonNumber] = picojson::value((double)number);
+ (*decoded)[kSeasonTitle] =
+ season_title ? picojson::value(std::string(season_title)) : picojson::value();
+ }
+
+ // decode episode
+ if (!to_decode.get(kEpisode).is<picojson::null>()) {
+ val = to_decode.get(kEpisode).get<std::string>();
+
+ ret = mc_metadata_decode_episode(val.c_str(), &number, &episode_title);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while decoding episode",
+ ("mc_metadata_decode_episode() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ (*decoded)[kEpisodeNumber] = picojson::value((double)number);
+ (*decoded)[kEpisodeTitle] =
+ episode_title ? picojson::value(std::string(episode_title)) : picojson::value();
+ }
+
+ // decode resolution
+ if (!to_decode.get(kResolution).is<picojson::null>()) {
+ val = to_decode.get(kResolution).get<std::string>();
+ u_int width = 0;
+ u_int height = 0;
+
+ ret = mc_metadata_decode_resolution(val.c_str(), &width, &height);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while decoding resolution",
+ ("mc_metadata_decode_resolution() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
+ (*decoded)[kResolutionWidth] = picojson::value((double)width);
+ (*decoded)[kResolutionHeight] = picojson::value((double)height);
+ }
+
+ // now rewrite not encoded attributes
+ for (auto entry : types::MediaControllerMetadataAttributeEnum) {
+ std::string name = entry.first;
+ if (!isMetadataAttributeEncodable(name)) {
+ (*decoded)[name] =
+ to_decode.get(name).is<picojson::null>() ? picojson::value("") : to_decode.get(name);
+ }
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+} // namespace mediacontroller
+} // namespace extension
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MEDIACONTROLLER_MEDIACONTROLLER_UTILS_H_
+#define MEDIACONTROLLER_MEDIACONTROLLER_UTILS_H_
+
+#include <media_controller_type.h>
+#include <functional>
+#include <map>
+#include <string>
+
+#include "common/platform_enum.h"
+#include "common/platform_result.h"
+
+namespace extension {
+namespace mediacontroller {
+
+typedef std::function<void(picojson::value*)> JsonCallback;
+
+namespace privileges {
+
+extern const char* kPrivilegeMediaControllerClient;
+extern const char* kPrivilegeMediaControllerServer;
+
+} // privileges
+
+namespace attributes {
+
+extern const char* kAbility;
+extern const char* kAbilityType;
+extern const char* kAction;
+extern const char* kAgeRating;
+extern const char* kCallbackId;
+extern const char* kCategory;
+extern const char* kClientName;
+extern const char* kCode;
+extern const char* kCommand;
+extern const char* kContentType;
+extern const char* kData;
+extern const char* kDisplayMode;
+extern const char* kDisplayRotation;
+extern const char* kDisplayRotationAbility;
+extern const char* kEnabled;
+extern const char* kEventData;
+extern const char* kEventName;
+extern const char* kExtraData;
+extern const char* kIconURI;
+extern const char* kIndex;
+extern const char* kKeyword;
+extern const char* kListenerId;
+extern const char* kMetadata;
+extern const char* kMode;
+extern const char* kName;
+extern const char* kPlaylistName;
+extern const char* kPosition;
+extern const char* kRating;
+extern const char* kRepeatMode;
+extern const char* kRepeatState;
+extern const char* kReply;
+extern const char* kReplyListener;
+extern const char* kRequest;
+extern const char* kRequestId;
+extern const char* kResult;
+extern const char* kResultCode;
+extern const char* kServerName;
+extern const char* kShuffleMode;
+extern const char* kState;
+extern const char* kSupport;
+extern const char* kType;
+extern const char* kValue;
+extern const char* kSeason;
+extern const char* kSeasonNumber;
+extern const char* kSeasonTitle;
+extern const char* kEpisode;
+extern const char* kEpisodeNumber;
+extern const char* kEpisodeTitle;
+extern const char* kResolution;
+extern const char* kResolutionWidth;
+extern const char* kResolutionHeight;
+
+} // attributes
+
+namespace types {
+
+common::PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state);
+common::PlatformResult ConvertContentAgeRating(mc_playback_h playback_h, std::string* state);
+common::PlatformResult ConvertPlaybackPosition(mc_playback_h playback_h, double* position);
+common::PlatformResult ConvertMetadata(mc_metadata_h metadata_h, picojson::object* metadata);
+common::PlatformResult ConvertContentType(mc_playback_h playback_h, std::string* contentType);
+common::PlatformResult ConvertPlaybackAbility(mc_playback_ability_h ability_h,
+ const std::string& action, std::string* ability_str);
+
+extern const common::PlatformEnum<mc_server_state_e> MediaControllerServerStateEnum;
+extern const common::PlatformEnum<mc_playback_states_e> MediaControllerPlaybackStateEnum;
+extern const common::PlatformEnum<mc_playback_action_e> MediaControllerPlaybackActionEnum;
+extern const common::PlatformEnum<mc_meta_e> MediaControllerMetadataAttributeEnum;
+extern const common::PlatformEnum<mc_repeat_mode_e> MediaControllerRepeatModeEnum;
+extern const common::PlatformEnum<mc_content_age_rating_e> MediaControllerContentAgeRatingEnum;
+extern const common::PlatformEnum<mc_content_type_e> MediaControllerContentTypeEnum;
+extern const common::PlatformEnum<mc_search_category_e> MediaControllerSearchCategoryEnum;
+extern const common::PlatformEnum<mc_ability_support_e> MediaControllerAbilitySupportEnum;
+extern const common::PlatformEnum<mc_subscription_type_e> MediaControllerSubscriptionTypeEnum;
+extern const common::PlatformEnum<mc_ability_e> MediaControllerSimpleAbilityEnum;
+extern const common::PlatformEnum<mc_display_mode_e> MediaControllerDisplayModeEnum;
+extern const common::PlatformEnum<mc_display_rotation_e> MediaControllerDisplayRotationEnum;
+
+} // namespace types
+
+namespace utils {
+common::PlatformResult GetAllPlaylists(const std::string& app_id, picojson::array* playlists);
+common::ErrorCode ConvertMediaControllerError(int e);
+bool isMetadataAttributeEncodable(const std::string& name);
+common::PlatformResult EncodeMetadata(const picojson::object& to_encode, picojson::object* encoded);
+common::PlatformResult DecodeMetadata(const picojson::value& to_decode, picojson::object* decoded);
+} // namespace utils
+
+} // namespace mediacontroller
+} // namespace extension
+
+#endif // MEDIACONTROLLER_MEDIACONTROLLER_UTILS_H_
}
]);
- var ret = native.callSync('MediaKeyManager_setMediaKeyEventListener', {});
+ var ret = native.callSync('SetMediaKeyEventListener', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
};
MediaKeyManager.prototype.unsetMediaKeyEventListener = function() {
- var ret = native.callSync('MediaKeyManager_unsetMediaKeyEventListener', {});
+ var ret = native.callSync('UnsetMediaKeyEventListener', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
ScopeLogger();
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&MediaKeyInstance::x, this, _1, _2));
- REGISTER_SYNC("MediaKeyManager_setMediaKeyEventListener", SetMediaKeyEventListener);
- REGISTER_SYNC("MediaKeyManager_unsetMediaKeyEventListener", UnsetMediaKeyEventListener);
-#undef REGISTER_SYNC
+
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&MediaKeyInstance::M, this, _1, _2))
+ REGISTER_METHOD(SetMediaKeyEventListener);
+ REGISTER_METHOD(UnsetMediaKeyEventListener);
+#undef REGISTER_METHOD
}
MediaKeyInstance::~MediaKeyInstance() {
};
var result = native_.callSync(
- 'MessagePortManager_requestLocalMessagePort',
+ 'MessagePortManagerRequestLocalMessagePort',
nativeParam
);
};
var result = native_.callSync(
- 'MessagePortManager_requestTrustedLocalMessagePort',
+ 'MessagePortManagerRequestTrustedLocalMessagePort',
nativeParam
);
};
var result = native_.callSync(
- 'MessagePortManager_requestRemoteMessagePort',
+ 'MessagePortManagerRequestRemoteMessagePort',
nativeParam
);
};
var result = native_.callSync(
- 'MessagePortManager_requestTrustedRemoteMessagePort',
+ 'MessagePortManagerRequestTrustedRemoteMessagePort',
nativeParam
);
: -1
};
- var result = native_.callSync('RemoteMessagePort_sendMessage', nativeParam);
+ var result = native_.callSync('RemoteMessagePortSendMessage', nativeParam);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
#include <string>
#include <vector>
+#include "common/json-utils.h"
#include "common/logger.h"
#include "common/picojson.h"
#include "common/platform_exception.h"
using common::UnknownException;
using common::NotFoundException;
using common::QuotaExceededException;
+using common::BundleJsonIterator;
MessageportInstance::MessageportInstance() {
ScopeLogger();
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&MessageportInstance::x, this, _1, _2));
- REGISTER_SYNC("MessagePortManager_requestTrustedRemoteMessagePort",
- MessagePortManagerRequesttrustedremotemessageport);
- REGISTER_SYNC("MessagePortManager_requestLocalMessagePort",
- MessagePortManagerRequestlocalmessageport);
- REGISTER_SYNC("MessagePortManager_requestTrustedLocalMessagePort",
- MessagePortManagerRequesttrustedlocalmessageport);
- REGISTER_SYNC("MessagePortManager_requestRemoteMessagePort",
- MessagePortManagerRequestremotemessageport);
- REGISTER_SYNC("RemoteMessagePort_sendMessage", RemoteMessagePortSendmessage);
-#undef REGISTER_SYNC
+
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&MessageportInstance::M, this, _1, _2))
+ REGISTER_METHOD(MessagePortManagerRequestTrustedRemoteMessagePort);
+ REGISTER_METHOD(MessagePortManagerRequestLocalMessagePort);
+ REGISTER_METHOD(MessagePortManagerRequestTrustedLocalMessagePort);
+ REGISTER_METHOD(MessagePortManagerRequestRemoteMessagePort);
+ REGISTER_METHOD(RemoteMessagePortSendMessage);
+#undef REGISTER_METHOD
}
MessageportInstance::~MessageportInstance() {
LocalMessagePortAddmessageportlistenerCallback
};
-static void BundleJsonIterator(const char* key, const int type, const bundle_keyval_t* kv,
- void* d) {
- ScopeLogger();
-
- void* basic_val = nullptr;
- size_t basic_size = 0;
-
- picojson::value::array* array = static_cast<picojson::value::array*>(d);
- picojson::value::object o;
-
- switch (bundle_keyval_get_type(const_cast<bundle_keyval_t*>(kv))) {
- case BUNDLE_TYPE_STR:
- bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(kv), &basic_val, &basic_size);
- o["key"] = picojson::value(key);
- o["value"] = picojson::value(static_cast<char*>(basic_val));
- break;
-
- case BUNDLE_TYPE_STR_ARRAY: {
- picojson::value::array tab;
- void** array_val = nullptr;
- unsigned int array_len = 0;
- size_t* array_elem_size = nullptr;
-
- bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(kv), &array_val, &array_len,
- &array_elem_size);
-
- for (unsigned int i = 0; i < array_len; i++) {
- tab.push_back(picojson::value(((char**)array_val)[i]));
- }
-
- o["key"] = picojson::value(key);
- o["value"] = picojson::value(picojson::value(tab));
-
- break;
- }
-
- case BUNDLE_TYPE_BYTE: {
- picojson::value::array tab;
-
- unsigned char* basic_val = nullptr;
- size_t basic_size = 0;
-
- bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(kv), (void**)&basic_val,
- &basic_size);
-
- for (unsigned int i = 0; i < basic_size; i++) {
- tab.push_back(picojson::value(static_cast<double>(basic_val[i])));
- }
-
- o["key"] = picojson::value(key);
- o["value"] = picojson::value(picojson::value(tab));
- break;
- }
- case BUNDLE_TYPE_BYTE_ARRAY: {
- picojson::value::array tab;
-
- unsigned char** array_value = nullptr;
- size_t* array_ele_size = nullptr;
- unsigned int ele_nos = 0;
-
- bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(kv), (void***)&array_value, &ele_nos,
- &array_ele_size);
-
- for (unsigned int i = 0; i < ele_nos; i++) {
- picojson::value::array tab2;
- for (unsigned int j = 0; j < array_ele_size[i]; j++) {
- tab2.push_back(picojson::value(static_cast<double>(array_value[i][j])));
- }
- tab.push_back(picojson::value(tab2));
- }
-
- o["key"] = picojson::value(key);
- o["value"] = picojson::value(picojson::value(tab));
- break;
- }
- default:
- o["key"] = picojson::value(key);
- o["value"] = picojson::value();
- break;
- }
- array->push_back(picojson::value(o));
-}
-
#define CHECK_EXIST(args, name, out) \
if (!args.contains(name)) { \
LogAndReportError(TypeMismatchException(name " is required argument"), out); \
common::Instance::PostMessage(object, picojson::value(o).serialize().c_str());
}
-void MessageportInstance::MessagePortManagerRequestlocalmessageport(const picojson::value& args,
+void MessageportInstance::MessagePortManagerRequestLocalMessagePort(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
CHECK_EXIST(args, "localMessagePortName", out)
}
}
-void MessageportInstance::MessagePortManagerRequesttrustedlocalmessageport(
+void MessageportInstance::MessagePortManagerRequestTrustedLocalMessagePort(
const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_EXIST(args, "localMessagePortName", out)
}
}
-void MessageportInstance::MessagePortManagerRequestremotemessageport(const picojson::value& args,
+void MessageportInstance::MessagePortManagerRequestRemoteMessagePort(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
CHECK_EXIST(args, "remoteMessagePortName", out)
}
}
-void MessageportInstance::MessagePortManagerRequesttrustedremotemessageport(
+void MessageportInstance::MessagePortManagerRequestTrustedRemoteMessagePort(
const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_EXIST(args, "remoteMessagePortName", out)
}
}
-void MessageportInstance::RemoteMessagePortSendmessage(const picojson::value& args,
+void MessageportInstance::RemoteMessagePortSendMessage(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
const std::string& appId = args.get("appId").get<std::string>();
const std::string& valueType = (*it).get("valueType").get<std::string>();
if ("stringValueType" == valueType) {
LoggerD("value is string");
- bundle_add(bundle, (*it).get("key").to_str().c_str(), (*it).get("value").to_str().c_str());
+ result = bundle_add(bundle, (*it).get("key").to_str().c_str(),
+ (*it).get("value").to_str().c_str());
+ if (BUNDLE_ERROR_NONE != result) {
+ LogAndReportError(
+ UnknownException("Unable to add data to bundle."), out,
+ ("bundle_add(data) error: %d, message: %s", result, get_error_message(result)));
+ }
} else if ("stringArrayValueType" == valueType) {
LoggerD("value is string array");
std::vector<picojson::value> value_array = (*it).get("value").get<picojson::array>();
arr[i] = iter->get<std::string>().c_str();
}
- bundle_add_str_array(bundle, (*it).get("key").to_str().c_str(), arr, size);
+ result = bundle_add_str_array(bundle, (*it).get("key").to_str().c_str(), arr, size);
+ if (BUNDLE_ERROR_NONE != result) {
+ LoggerE("bundle_add_str_array failed, error: %d (%s)", result, get_error_message(result));
+ }
delete[] arr;
} else if ("byteStreamValueType" == valueType) {
LoggerD("value is byte stream");
for (auto iter = value_array.begin(); iter != value_array.end(); ++iter, ++i) {
arr[i] = (int)(*iter).get<double>();
}
- bundle_add_byte(bundle, (*it).get("key").to_str().c_str(), arr, size);
+ result = bundle_add_byte(bundle, (*it).get("key").to_str().c_str(), arr, size);
+ if (BUNDLE_ERROR_NONE != result) {
+ LoggerE("bundle_add_byte failed, error: %d (%s)", result, get_error_message(result));
+ }
delete[] arr;
} else if ("byteStreamArrayValueType" == valueType) {
LoggerD("value is byte stream array");
std::vector<picojson::value> byteStreamArray = (*it).get("value").get<picojson::array>();
const size_t size = byteStreamArray.size();
- bundle_add_byte_array(bundle, (*it).get("key").to_str().c_str(), nullptr, size);
+ result = bundle_init_byte_array(bundle, (*it).get("key").to_str().c_str(), size);
+ if (BUNDLE_ERROR_NONE != result) {
+ LoggerE("bundle_init_byte_array failed, error: %d (%s)", result, get_error_message(result));
+ }
size_t i = 0;
for (auto iter = byteStreamArray.begin(); iter != byteStreamArray.end(); ++iter, ++i) {
virtual ~MessageportInstance();
private:
- void MessagePortManagerRequestlocalmessageport(const picojson::value& args,
+ void MessagePortManagerRequestLocalMessagePort(const picojson::value& args,
picojson::object& out);
- void MessagePortManagerRequesttrustedlocalmessageport(const picojson::value& args,
+ void MessagePortManagerRequestTrustedLocalMessagePort(const picojson::value& args,
picojson::object& out);
- void MessagePortManagerRequestremotemessageport(const picojson::value& args,
+ void MessagePortManagerRequestRemoteMessagePort(const picojson::value& args,
picojson::object& out);
- void MessagePortManagerRequesttrustedremotemessageport(const picojson::value& args,
+ void MessagePortManagerRequestTrustedRemoteMessagePort(const picojson::value& args,
picojson::object& out);
- void RemoteMessagePortSendmessage(const picojson::value& args, picojson::object& out);
+ void RemoteMessagePortSendMessage(const picojson::value& args, picojson::object& out);
std::vector<int> local_ports;
std::vector<int> local_trusted_ports;
};
//#include "JSCompositeFilter.h"
#include "common/logger.h"
#include "common/platform_exception.h"
+#include "common/tools.h"
//#include <JSUtil.h>
#include <algorithm>
+#include <limits>
namespace extension {
namespace tizen {
namespace {
-inline std::string convertToLowerCase(const std::string& input_string) {
+std::string convertToLowerCase(const std::string& input_string) {
std::string output_string = input_string;
std::transform(output_string.begin(), output_string.end(), output_string.begin(), ::tolower);
return output_string;
}
-} // Anonymous namespace
-
-bool FilterUtils::isStringMatching(const std::string& key, const std::string& value,
- tizen::FilterMatchFlag flag) {
+// This function assumes, that the flag is not "EXISTS"
+bool isMatchingString(const std::string& match_value, const std::string& value,
+ AttributeMatchFlag flag) {
ScopeLogger();
+
+ if (match_value.empty() && value.empty()) {
+ return true;
+ }
+
switch (flag) {
- case tizen::ENDSWITH: {
- if (key.empty()) {
+ case AttributeMatchFlag::kEndsWith: {
+ if (match_value.empty()) {
return false;
}
- if (key.size() > value.size()) {
+ if (match_value.size() > value.size()) {
return false;
}
std::string lvalue = convertToLowerCase(value);
- std::string lkey = convertToLowerCase(key);
- return lvalue.substr(lvalue.size() - lkey.size(), lkey.size()) == lkey;
+ std::string lmatch_value = convertToLowerCase(match_value);
+ return lvalue.substr(lvalue.size() - lmatch_value.size(), lmatch_value.size()) ==
+ lmatch_value;
}
- case tizen::EXACTLY: {
- return key == value;
+ case AttributeMatchFlag::kExactly: {
+ return match_value == value;
}
- case tizen::STARTSWITH: {
- if (key.empty()) {
+ case AttributeMatchFlag::kStartsWith: {
+ if (match_value.empty()) {
return false;
}
- if (key.size() > value.size()) {
+ if (match_value.size() > value.size()) {
return false;
}
std::string lvalue = convertToLowerCase(value);
- std::string lkey = convertToLowerCase(key);
- return lvalue.substr(0, lkey.size()) == lkey;
+ std::string lmatch_value = convertToLowerCase(match_value);
+ return lvalue.substr(0, lmatch_value.size()) == lmatch_value;
}
- case tizen::CONTAINS: {
- if (key.empty()) {
+ case AttributeMatchFlag::kContains: {
+ if (match_value.empty()) {
return false;
}
- if (key.size() > value.size()) {
+ if (match_value.size() > value.size()) {
return false;
}
std::string lvalue = convertToLowerCase(value);
- std::string lkey = convertToLowerCase(key);
- return lvalue.find(lkey) != std::string::npos;
+ std::string lmatch_value = convertToLowerCase(match_value);
+ return lvalue.find(lmatch_value) != std::string::npos;
+ }
+
+ case AttributeMatchFlag::kFullString: {
+ return convertToLowerCase(match_value) == convertToLowerCase(value);
}
default: {
}
}
+}; // namespace
+
+bool FilterUtils::isMatching(const Any& match_value, const std::string& value,
+ AttributeMatchFlag flag) {
+ ScopeLogger();
+
+ const auto match_value_json = match_value.getValue();
+ if (match_value_json.is<std::string>()) {
+ return isMatchingString(match_value_json.get<std::string>(), value, flag);
+ }
+
+ LoggerD("The type of match_value passed to the filter does not match the type of the attribute");
+ return false;
+}
+
+namespace {
+
+bool isANumberAndConvertibleToULong(const picojson::value& value) {
+ ScopeLogger();
+
+ if (!value.is<double>()) {
+ return false;
+ }
+
+ auto number = value.get<double>();
+ auto minimum = static_cast<double>(std::numeric_limits<unsigned long>::min());
+ auto maximum = static_cast<double>(std::numeric_limits<unsigned long>::max());
+ auto in_ul_range = minimum <= number && number <= maximum;
+
+ auto is_integer = std::ceil(number) == number;
+
+ return in_ul_range && is_integer;
+}
+
+}; // namespace
+
+bool FilterUtils::isMatching(const Any& match_value, const unsigned long value,
+ AttributeMatchFlag flag) {
+ ScopeLogger();
+
+ const auto match_value_json = match_value.getValue();
+ if (flag == AttributeMatchFlag::kExactly && isANumberAndConvertibleToULong(match_value_json)) {
+ return static_cast<unsigned long>(match_value_json.get<double>()) == value;
+ }
+
+ LoggerD("The type of match_value passed to the filter does not match the type of the attribute");
+ return false;
+}
+
+bool FilterUtils::isMatching(const Any& match_value, const bool value, AttributeMatchFlag flag) {
+ ScopeLogger();
+
+ const auto match_value_json = match_value.getValue();
+ if (match_value_json.is<bool>() && AttributeMatchFlag::kExactly == flag) {
+ return match_value_json.get<bool>() == value;
+ }
+
+ LoggerD("The type of matchValue passed to the filter does not match the type of the attribute");
+ return false;
+}
+
bool FilterUtils::isAnyStringMatching(const std::string& key,
const std::vector<std::string>& values,
- tizen::FilterMatchFlag flag) {
+ AttributeMatchFlag flag) {
ScopeLogger();
for (auto it = values.begin(); it != values.end(); ++it) {
- if (isStringMatching(key, *it, flag)) {
+ if (isMatchingString(key, *it, flag)) {
return true;
}
}
bool FilterUtils::isTimeStampInRange(const time_t& time_stamp, tizen::AnyPtr& initial_value,
tizen::AnyPtr& end_value) {
ScopeLogger();
- time_t from_time = 0;
- if (initial_value && !initial_value->isNullOrUndefined()) {
- struct tm ftime = *initial_value->toDateTm();
- from_time = mktime(&ftime);
- } else {
- LoggerE("initialValue is not Time!");
+ if (!initial_value || !end_value) {
+ LoggerD("initial_value is %snull. end_value is %snull", initial_value ? "NOT " : "",
+ end_value ? "NOT " : "");
return false;
}
- time_t to_time = 0;
- if (end_value && !end_value->isNullOrUndefined()) {
- struct tm ttime = *end_value->toDateTm();
- to_time = mktime(&ttime);
- } else {
- LoggerE("endValue is not Time!");
- return false;
- }
+ time_t from_time = initial_value->isNullOrUndefined() ? std::numeric_limits<time_t>::min()
+ : initial_value->toTimeT();
+
+ time_t to_time =
+ end_value->isNullOrUndefined() ? std::numeric_limits<time_t>::max() : end_value->toTimeT();
bool is_in_range = FilterUtils::isBetweenTimeRange(time_stamp, from_time, to_time);
#ifndef __TIZEN_TIZEN_ABSTRACT_FILTER_H__
#define __TIZEN_TIZEN_ABSTRACT_FILTER_H__
+#include <time.h>
#include <memory>
#include <sstream>
#include <vector>
//#include <JSArray.h>
#include "Any.h"
+#include "common/filter-utils.h"
namespace extension {
namespace tizen {
enum FilterType { ABSTRACT_FILTER = 0, ATTRIBUTE_FILTER, ATTRIBUTE_RANGE_FILTER, COMPOSITE_FILTER };
-enum FilterMatchFlag { EXACTLY = 0, FULLSTRING, CONTAINS, STARTSWITH, ENDSWITH, EXISTS };
-
class FilterableObject {
public:
virtual ~FilterableObject() {
}
virtual bool isMatchingAttribute(const std::string& attribute_name,
- const FilterMatchFlag match_flag, AnyPtr match_value) const = 0;
+ const common::AttributeMatchFlag match_flag,
+ AnyPtr match_value) const = 0;
virtual bool isMatchingAttributeRange(const std::string& attribute_name, AnyPtr initial_value,
AnyPtr end_value) const = 0;
// }
//};
-class FilterUtils {
- public:
- static bool isStringMatching(const std::string& key, const std::string& value,
- tizen::FilterMatchFlag flag);
- static bool isAnyStringMatching(const std::string& key, const std::vector<std::string>& values,
- tizen::FilterMatchFlag flag);
- static bool isTimeStampInRange(const time_t& time_stamp, tizen::AnyPtr& initial_value,
- tizen::AnyPtr& end_value);
-
- static inline bool isBetweenTimeRange(const time_t current, const time_t from, const time_t to) {
- return ((current - from) >= 0) && ((to - current) >= 0);
- }
+namespace FilterUtils {
- static inline std::string boolToString(const bool src) {
- if (src) {
- return "true";
- } else {
- return "false";
- }
- }
-};
+bool isAnyStringMatching(const std::string& key, const std::vector<std::string>& values,
+ common::AttributeMatchFlag flag);
+bool isTimeStampInRange(const time_t& time_stamp, tizen::AnyPtr& initial_value,
+ tizen::AnyPtr& end_value);
+bool isInRange(const unsigned long messageCount, const unsigned long initial_value,
+ const unsigned long end_value);
+inline bool isBetweenTimeRange(const time_t timestamp, const time_t from, const time_t to) {
+ return (difftime(timestamp, from) >= 0.0) && (difftime(to, timestamp) >= 0.0);
+}
+
+/*
+ * isMatching() behavior for different common::AttributeMatchFlags:
+ * - EXACTLY - value and filter_value's value must be identical
+ * - EXISTS - false is returned always. isMatching do not check if EXISTS filter matches.
+ * Testing against EXISTS match flag has to be done in another function, i.e. before calling
+ * isMatching.
+ * - FULLSTRING, CONTAINS, STARTSWITH, ENDSWITH - applicable for strings only,
+ * used to filter values of other types result in no-match
+ */
+bool isMatching(const Any& filter_value, const std::string& value, common::AttributeMatchFlag flag);
+bool isMatching(const Any& filter_value, const bool value, common::AttributeMatchFlag flag);
+bool isMatching(const Any& filter_value, const unsigned long value,
+ common::AttributeMatchFlag flag);
+
+} // namespace FilterUtils
} // Tizen
} // DeviceAPI
namespace extension {
namespace tizen {
+/*
+ * TODO: remove this enum, if won't be used in database_manager.cc anymore
+ */
enum PrimitiveType {
PrimitiveType_NoType,
PrimitiveType_Null,
PrimitiveType_PlatformObject
};
+/*
+ * TODO: remove this class completely, if will not be used in database_manager.cc
+ * For use cases, other than filtering in DB, picojson will suffice.
+ */
class Any;
typedef std::shared_ptr<Any> AnyPtr;
namespace tizen {
AttributeFilter::AttributeFilter(const std::string &attribute_name)
- : AbstractFilter(ATTRIBUTE_FILTER), m_attribute_name(attribute_name), m_match_flag(EXACTLY) {
+ : AbstractFilter(ATTRIBUTE_FILTER),
+ m_attribute_name(attribute_name),
+ m_match_flag(common::AttributeMatchFlag::kExactly) {
ScopeLogger();
}
m_attribute_name = attribute_name;
}
-FilterMatchFlag AttributeFilter::getMatchFlag() const {
+common::AttributeMatchFlag AttributeFilter::getMatchFlag() const {
return m_match_flag;
}
-void AttributeFilter::setMatchFlag(FilterMatchFlag match_flag) {
+void AttributeFilter::setMatchFlag(common::AttributeMatchFlag match_flag) {
m_match_flag = match_flag;
}
#include <string>
#include "AbstractFilter.h"
#include "Any.h"
+#include "common/filter-utils.h"
namespace extension {
namespace tizen {
std::string getAttributeName() const;
void setAttributeName(const std::string &attribute_name);
- FilterMatchFlag getMatchFlag() const;
- void setMatchFlag(FilterMatchFlag match_flag);
+ common::AttributeMatchFlag getMatchFlag() const;
+ void setMatchFlag(common::AttributeMatchFlag match_flag);
AnyPtr getMatchValue() const;
void setMatchValue(AnyPtr match_value);
private:
std::string m_attribute_name;
- FilterMatchFlag m_match_flag;
+ common::AttributeMatchFlag m_match_flag;
AnyPtr m_match_value;
};
}
int slot_size = -1;
- vconf_get_int("db/private/email-service/slot_size", &(slot_size));
- if (slot_size > 0) {
+ ntv_ret = vconf_get_int("db/private/email-service/slot_size", &(slot_size));
+
+ if (0 == ntv_ret && slot_size > 0) {
m_slot_size = slot_size;
}
#include "messaging_util.h"
#include "short_message_manager.h"
+#include "MsgCommon/AbstractFilter.h"
+
using common::ErrorCode;
using common::PlatformResult;
* ----------------+-----------------+------------------------
* id | Yes | No
* serviceId | Yes | No
- * conversationId | No | No
+ * conversationId | Yes | No
* folderId | Yes | No
* type | Yes | No
* timestamp | No | Yes
* hasAttachment | Yes | No
* isHighPriority | Yes | No
* subject | Yes | No
- * isResponseTo | No | No
- * messageStatus | No | No
+ * inResponseTo | Yes | No
+ * messageStatus | Yes | No
* attachments | No | No
**/
-namespace MESSAGE_FILTER_ATTRIBUTE {
-
-const std::string ID = MESSAGE_ATTRIBUTE_ID;
-const std::string SERVICE_ID = "serviceId";
-const std::string CONVERSATION_ID = MESSAGE_ATTRIBUTE_CONVERSATION_ID;
-const std::string FOLDER_ID = MESSAGE_ATTRIBUTE_FOLDER_ID;
-const std::string TYPE = MESSAGE_ATTRIBUTE_TYPE;
-const std::string TIMESTAMP = MESSAGE_ATTRIBUTE_TIMESTAMP;
-const std::string FROM = MESSAGE_ATTRIBUTE_FROM;
-const std::string TO = MESSAGE_ATTRIBUTE_TO;
-const std::string CC = MESSAGE_ATTRIBUTE_CC;
-const std::string BCC = MESSAGE_ATTRIBUTE_BCC;
-const std::string BODY_PLAIN_BODY = "body.plainBody";
-const std::string IS_READ = MESSAGE_ATTRIBUTE_IS_READ;
-const std::string HAS_ATTACHMENT = MESSAGE_ATTRIBUTE_HAS_ATTACHMENT;
-const std::string IS_HIGH_PRIORITY = MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY;
-const std::string SUBJECT = MESSAGE_ATTRIBUTE_SUBJECT;
-
-} // namespace MESSAGE_FILTER_ATTRIBUTE
bool Message::isMatchingAttribute(const std::string& attribute_name,
- const FilterMatchFlag match_flag, AnyPtr match_value) const {
+ const AttributeMatchFlag match_flag, AnyPtr match_value) const {
ScopeLogger();
- auto key = match_value->toString();
- LoggerD("attribute_name:%s match_flag:%d matchValue:%s", attribute_name.c_str(), match_flag,
- key.c_str());
+ LoggerD("attribute_name: (%s), match_flag: (%s), matchValue: (%s)", attribute_name.c_str(),
+ common::AttributeMatchFlagToString(match_flag).c_str(), match_value->toString().c_str());
- using namespace MESSAGE_FILTER_ATTRIBUTE;
+ if (AttributeMatchFlag::kExists == match_flag) {
+ return m_message_filterable_attributes.find(attribute_name) !=
+ m_message_filterable_attributes.end();
+ }
- if (ID == attribute_name) {
- return FilterUtils::isStringMatching(key, std::to_string(getId()), match_flag);
- } else if (SERVICE_ID == attribute_name) {
+ if (MESSAGE_ATTRIBUTE_ID == attribute_name) {
+ return FilterUtils::isMatching(*match_value, std::to_string(getId()), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_SERVICE_ID == attribute_name) {
if (is_service_is_set()) {
- return FilterUtils::isStringMatching(key, std::to_string(getServiceId()), match_flag);
+ return FilterUtils::isMatching(*match_value, std::to_string(getServiceId()), match_flag);
}
- } else if (FOLDER_ID == attribute_name) {
- return FilterUtils::isStringMatching(key, std::to_string(getFolderIdForUser()), match_flag);
- } else if (TYPE == attribute_name) {
- return FilterUtils::isStringMatching(key, getTypeString(), match_flag);
- } else if (FROM == attribute_name) {
- return FilterUtils::isStringMatching(key, getFrom(), match_flag);
- } else if (TO == attribute_name) {
- return FilterUtils::isAnyStringMatching(key, getTO(), match_flag);
- } else if (CC == attribute_name) {
- return FilterUtils::isAnyStringMatching(key, getCC(), match_flag);
- } else if (BCC == attribute_name) {
- return FilterUtils::isAnyStringMatching(key, getBCC(), match_flag);
- } else if (BODY_PLAIN_BODY == attribute_name) {
+ } else if (MESSAGE_ATTRIBUTE_CONVERSATION_ID == attribute_name) {
+ return FilterUtils::isMatching(*match_value, std::to_string(getConversationId()), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_FOLDER_ID == attribute_name) {
+ return FilterUtils::isMatching(*match_value, std::to_string(getFolderIdForUser()), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_TYPE == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getTypeString(), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_FROM == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getFrom(), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_TO == attribute_name) {
+ return FilterUtils::isAnyStringMatching(match_value->toString(), getTO(), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_CC == attribute_name) {
+ return FilterUtils::isAnyStringMatching(match_value->toString(), getCC(), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_BCC == attribute_name) {
+ return FilterUtils::isAnyStringMatching(match_value->toString(), getBCC(), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_BODY_PLAIN_BODY == attribute_name) {
if (getBody()) {
- return FilterUtils::isStringMatching(key, getBody()->getPlainBody(), match_flag);
+ return FilterUtils::isMatching(*match_value, getBody()->getPlainBody(), match_flag);
}
- } else if (IS_READ == attribute_name) {
- return FilterUtils::isStringMatching(key, FilterUtils::boolToString(getIsRead()), match_flag);
- } else if (HAS_ATTACHMENT == attribute_name) {
- return FilterUtils::isStringMatching(key, FilterUtils::boolToString(getHasAttachment()),
- match_flag);
- } else if (IS_HIGH_PRIORITY == attribute_name) {
- return FilterUtils::isStringMatching(key, FilterUtils::boolToString(getIsHighPriority()),
- match_flag);
- } else if (SUBJECT == attribute_name) {
- return FilterUtils::isStringMatching(key, getSubject(), match_flag);
- } else {
- LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
- }
-
+ } else if (MESSAGE_ATTRIBUTE_IS_READ == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getIsRead(), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_HAS_ATTACHMENT == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getHasAttachment(), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getIsHighPriority(), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_SUBJECT == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getSubject(), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_IN_RESPONSE_TO == attribute_name) {
+ return FilterUtils::isMatching(*match_value, std::to_string(getInResponseTo()), match_flag);
+ } else if (MESSAGE_ATTRIBUTE_MESSAGE_STATUS == attribute_name) {
+ return FilterUtils::isMatching(
+ *match_value, MessagingUtil::messageStatusToString(getMessageStatus()), match_flag);
+ }
+
+ LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
return false;
}
bool Message::isMatchingAttributeRange(const std::string& attribute_name, AnyPtr initial_value,
AnyPtr end_value) const {
- ScopeLogger("attribute name: %s", attribute_name.c_str());
+ ScopeLogger("attribute name: (%s)", attribute_name.c_str());
- using namespace MESSAGE_FILTER_ATTRIBUTE;
- if (TIMESTAMP == attribute_name) {
+ if (MESSAGE_ATTRIBUTE_TIMESTAMP == attribute_name) {
return FilterUtils::isTimeStampInRange(getTimestamp(), initial_value, end_value);
- } else {
- LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
}
+ LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
return false;
}
+const std::set<std::string> Message::m_message_filterable_attributes = {
+ MESSAGE_ATTRIBUTE_ID,
+ MESSAGE_ATTRIBUTE_CONVERSATION_ID,
+ MESSAGE_ATTRIBUTE_FOLDER_ID,
+ MESSAGE_ATTRIBUTE_TYPE,
+ MESSAGE_ATTRIBUTE_TIMESTAMP,
+ MESSAGE_ATTRIBUTE_FROM,
+ MESSAGE_ATTRIBUTE_TO,
+ MESSAGE_ATTRIBUTE_CC,
+ MESSAGE_ATTRIBUTE_BCC,
+ MESSAGE_ATTRIBUTE_BODY,
+ MESSAGE_ATTRIBUTE_IS_READ,
+ MESSAGE_ATTRIBUTE_HAS_ATTACHMENT,
+ MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY,
+ MESSAGE_ATTRIBUTE_SUBJECT,
+ MESSAGE_ATTRIBUTE_IN_RESPONSE_TO,
+ MESSAGE_ATTRIBUTE_MESSAGE_STATUS,
+ MESSAGE_ATTRIBUTE_ATTACHMENTS};
+
} // messaging
} // extension
#include <time.h>
#include <unistd.h>
#include <memory>
+#include <set>
#include <string>
#include <vector>
#include "MsgCommon/AbstractFilter.h"
+#include "common/filter-utils.h"
#include "common/platform_result.h"
#include "message_attachment.h"
#include "message_body.h"
// tizen::FilterableObject
virtual bool isMatchingAttribute(const std::string& attribute_name,
- const FilterMatchFlag match_flag, AnyPtr match_value) const;
+ const common::AttributeMatchFlag match_flag,
+ AnyPtr match_value) const;
virtual bool isMatchingAttributeRange(const std::string& attribute_name, AnyPtr initial_value,
AnyPtr end_value) const;
private:
static std::vector<std::string> split(const std::string& input, char delimiter);
+
+ static const std::set<std::string> m_message_filterable_attributes;
};
} // messaging
#include "common/logger.h"
#include "common/platform_exception.h"
+#include "MsgCommon/AbstractFilter.h"
#include "message.h"
#include "message_conversation.h"
#include "messaging_util.h"
* id | Yes | No
* type | Yes | No
* timestamp | No | Yes
- * messageCount | Yes | No
- * unreadMessages | Yes | No
+ * messageCount | Yes | Yes
+ * unreadMessages | Yes | Yes
* preview | Yes | No
- * subject | No | No
- * isRead | No | No
+ * subject | Yes | No
+ * isRead | Yes | No
* from | Yes | No
* to | Yes | No
- * cc | No | No
- * bcc | No | No
- * lastMessageId | No | No
+ * cc | Yes | No
+ * bcc | Yes | No
+ * lastMessageId | Yes | No
*/
-namespace CONVERSATION_FILTER_ATTRIBUTE {
-const std::string ID = MESSAGE_CONVERSATION_ATTRIBUTE_ID;
-const std::string TYPE = MESSAGE_CONVERSATION_ATTRIBUTE_TYPE;
-const std::string TIMESTAMP = MESSAGE_CONVERSATION_ATTRIBUTE_TIMESTAMP;
-const std::string MESSAGE_COUNT = MESSAGE_CONVERSATION_ATTRIBUTE_MESSAGE_COUNT;
-const std::string UNREAD_MESSAGES = MESSAGE_CONVERSATION_ATTRIBUTE_UNREAD_MESSAGES;
-const std::string PREVIEW = MESSAGE_CONVERSATION_ATTRIBUTE_PREVIEW;
-const std::string FROM = MESSAGE_CONVERSATION_ATTRIBUTE_FROM;
-const std::string TO = MESSAGE_CONVERSATION_ATTRIBUTE_TO;
-} // namespace CONVERSATION_FILTER_ATTRIBUTE
-
bool MessageConversation::isMatchingAttribute(const std::string& attribute_name,
- const FilterMatchFlag match_flag,
+ const common::AttributeMatchFlag match_flag,
AnyPtr match_value) const {
ScopeLogger();
- auto key = match_value->toString();
- LoggerD("attribute_name: %s match_flag:%d match_value:%s", attribute_name.c_str(), match_flag,
- key.c_str());
-
- using namespace CONVERSATION_FILTER_ATTRIBUTE;
-
- if (ID == attribute_name) {
- return FilterUtils::isStringMatching(key, std::to_string(getConversationId()), match_flag);
- } else if (TYPE == attribute_name) {
- return FilterUtils::isStringMatching(key, getTypeString(), match_flag);
- } else if (MESSAGE_COUNT == attribute_name) {
- return FilterUtils::isStringMatching(key, std::to_string(getMessageCount()), match_flag);
- } else if (UNREAD_MESSAGES == attribute_name) {
- return FilterUtils::isStringMatching(key, std::to_string(getUnreadMessages()), match_flag);
- } else if (PREVIEW == attribute_name) {
- return FilterUtils::isStringMatching(key, getPreview(), match_flag);
- } else if (FROM == attribute_name) {
- return FilterUtils::isStringMatching(key, getFrom(), match_flag);
- } else if (TO == attribute_name) {
- return FilterUtils::isAnyStringMatching(key, getTo(), match_flag);
- } else {
- LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
+ LoggerD("attribute_name: (%s), match_flag: (%s), match_value: (%s)", attribute_name.c_str(),
+ common::AttributeMatchFlagToString(match_flag).c_str(), match_value->toString().c_str());
+
+ if (common::AttributeMatchFlag::kExists == match_flag) {
+ return m_message_conversation_filterable_attributes.find(attribute_name) !=
+ m_message_conversation_filterable_attributes.end();
}
+ /* Some attributes are converted to strings before passing to isMatching,
+ because they are strings in the JS Web API */
+ if (MESSAGE_CONVERSATION_ATTRIBUTE_ID == attribute_name) {
+ return FilterUtils::isMatching(*match_value, std::to_string(getConversationId()), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_TYPE == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getTypeString(), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_MESSAGE_COUNT == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getMessageCount(), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_UNREAD_MESSAGES == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getUnreadMessages(), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_PREVIEW == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getPreview(), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_SUBJECT == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getSubject(), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_IS_READ == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getIsRead(), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_FROM == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getFrom(), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_TO == attribute_name) {
+ return FilterUtils::isAnyStringMatching(match_value->toString(), getTo(), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_CC == attribute_name) {
+ return FilterUtils::isAnyStringMatching(match_value->toString(), getCC(), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_BCC == attribute_name) {
+ return FilterUtils::isAnyStringMatching(match_value->toString(), getBCC(), match_flag);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_LAST_MESSAGE_ID == attribute_name) {
+ return FilterUtils::isMatching(*match_value, std::to_string(getLastMessageId()), match_flag);
+ }
+
+ LoggerD("attribute: %s is NOT SUPPORTED", attribute_name.c_str());
return false;
}
bool MessageConversation::isMatchingAttributeRange(const std::string& attribute_name,
AnyPtr initial_value, AnyPtr end_value) const {
- ScopeLogger("attribute_name: %s", attribute_name.c_str());
+ ScopeLogger("attribute_name: (%s), initial_value: (%s), end_value: (%s)", attribute_name.c_str(),
+ initial_value->toString().c_str(), end_value->toString().c_str());
- using namespace CONVERSATION_FILTER_ATTRIBUTE;
-
- if (TIMESTAMP == attribute_name) {
+ if (MESSAGE_CONVERSATION_ATTRIBUTE_TIMESTAMP == attribute_name) {
return FilterUtils::isTimeStampInRange(getTimestamp(), initial_value, end_value);
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_MESSAGE_COUNT == attribute_name) {
+ return initial_value->toULong() <= getMessageCount() &&
+ getMessageCount() <= end_value->toULong();
+ } else if (MESSAGE_CONVERSATION_ATTRIBUTE_UNREAD_MESSAGES == attribute_name) {
+ return initial_value->toULong() <= getUnreadMessages() &&
+ getUnreadMessages() <= end_value->toULong();
} else {
LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
}
};
// clang-format on
+const std::set<std::string> MessageConversation::m_message_conversation_filterable_attributes = {
+ MESSAGE_CONVERSATION_ATTRIBUTE_ID,
+ MESSAGE_CONVERSATION_ATTRIBUTE_TYPE,
+ MESSAGE_CONVERSATION_ATTRIBUTE_TIMESTAMP,
+ MESSAGE_CONVERSATION_ATTRIBUTE_MESSAGE_COUNT,
+ MESSAGE_CONVERSATION_ATTRIBUTE_UNREAD_MESSAGES,
+ MESSAGE_CONVERSATION_ATTRIBUTE_PREVIEW,
+ MESSAGE_CONVERSATION_ATTRIBUTE_SUBJECT,
+ MESSAGE_CONVERSATION_ATTRIBUTE_IS_READ,
+ MESSAGE_CONVERSATION_ATTRIBUTE_FROM,
+ MESSAGE_CONVERSATION_ATTRIBUTE_TO,
+ MESSAGE_CONVERSATION_ATTRIBUTE_CC,
+ MESSAGE_CONVERSATION_ATTRIBUTE_BCC,
+ MESSAGE_CONVERSATION_ATTRIBUTE_LAST_MESSAGE_ID};
+
MessageConversation::MessageConversationComparator MessageConversation::getComparator(
const std::string& attribute) {
auto comparator_it = m_message_conversation_comparators.find(attribute);
#include <msg_storage.h>
#include <time.h>
#include <memory>
+#include <set>
#include <string>
#include <vector>
#include "MsgCommon/AbstractFilter.h"
+#include "common/filter-utils.h"
#include "common/platform_result.h"
#include "messaging_util.h"
// tizen::FilterableObject
virtual bool isMatchingAttribute(const std::string& attribute_name,
- const tizen::FilterMatchFlag match_flag,
+ const common::AttributeMatchFlag match_flag,
tizen::AnyPtr match_value) const;
virtual bool isMatchingAttributeRange(const std::string& attribute_name,
using MessageConversationComparatorMap = std::map<std::string, MessageConversationComparator>;
static const MessageConversationComparatorMap m_message_conversation_comparators;
+
+ static const std::set<std::string> m_message_conversation_filterable_attributes;
};
} // messaging
*/
#include "message_folder.h"
+#include "MsgCommon/AbstractFilter.h"
#include "messaging_util.h"
namespace extension {
* Attribute | Attribute filter| Attribute range filter
* | supported | supported
* ----------------+-----------------+------------------------
- * id | No | No
- * parentId | No | No
+ * id | Yes | No
+ * parentId | Yes | No
* serviceId | Yes | No
- * contentType | No | No
- * name | No | No
- * path | No | No
- * type | No | No
- * synchronizable | No | No
+ * contentType | Yes | No
+ * name | Yes | No
+ * path | Yes | No
+ * type | Yes | No
+ * synchronizable | Yes | No
*/
-namespace FOLDER_FILTER_ATTRIBUTE {
-const std::string SERVICE_ID = "serviceId";
-} // namespace FOLDER_FILTER_ATTRIBUTE
-
bool MessageFolder::isMatchingAttribute(const std::string& attribute_name,
- const FilterMatchFlag match_flag,
+ const common::AttributeMatchFlag match_flag,
AnyPtr match_value) const {
ScopeLogger();
- auto key = match_value->toString();
- LoggerD("attribute_name: %s match_flag:%d match_value:%s", attribute_name.c_str(), match_flag,
- key.c_str());
+ LoggerD("attribute_name: (%s), match_flag: (%s), match_value: (%s)", attribute_name.c_str(),
+ common::AttributeMatchFlagToString(match_flag).c_str(), match_value->toString().c_str());
- using namespace FOLDER_FILTER_ATTRIBUTE;
+ if (common::AttributeMatchFlag::kExists == match_flag) {
+ return m_message_folder_filterable_attributes.find(attribute_name) !=
+ m_message_folder_filterable_attributes.end();
+ }
- if (SERVICE_ID == attribute_name) {
- return FilterUtils::isStringMatching(key, getServiceId(), match_flag);
- } else {
- LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
+ if (MESSAGE_FOLDER_ATTRIBUTE_ID == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getId(), match_flag);
+ } else if (MESSAGE_FOLDER_ATTRIBUTE_PARENT_ID == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getParentId(), match_flag);
+ } else if (MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getServiceId(), match_flag);
+ } else if (MESSAGE_FOLDER_ATTRIBUTE_CONTENT_TYPE == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getContentType(), match_flag);
+ } else if (MESSAGE_FOLDER_ATTRIBUTE_NAME == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getName(), match_flag);
+ } else if (MESSAGE_FOLDER_ATTRIBUTE_PATH == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getPath(), match_flag);
+ } else if (MESSAGE_FOLDER_ATTRIBUTE_TYPE == attribute_name) {
+ return FilterUtils::isMatching(*match_value,
+ MessagingUtil::messageFolderTypeToString(getType()), match_flag);
+ } else if (MESSAGE_FOLDER_ATTRIBUTE_SYNCHRONIZABLE == attribute_name) {
+ return FilterUtils::isMatching(*match_value, getSynchronizable(), match_flag);
}
+ LoggerD("attribute: %s is NOT SUPPORTED", attribute_name.c_str());
return false;
}
bool MessageFolder::isMatchingAttributeRange(const std::string& attribute_name,
AnyPtr initial_value, AnyPtr end_value) const {
ScopeLogger();
- LoggerD("attribute_name: %s NOT SUPPORTED", attribute_name.c_str());
+ LoggerD("attribute_name: (%s) is NOT SUPPORTED", attribute_name.c_str());
return false;
}
+// clang-format off
+const std::set<std::string> MessageFolder::m_message_folder_filterable_attributes = {
+ MESSAGE_FOLDER_ATTRIBUTE_ID,
+ MESSAGE_FOLDER_ATTRIBUTE_PARENT_ID,
+ MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID,
+ MESSAGE_FOLDER_ATTRIBUTE_CONTENT_TYPE,
+ MESSAGE_FOLDER_ATTRIBUTE_NAME,
+ MESSAGE_FOLDER_ATTRIBUTE_PATH,
+ MESSAGE_FOLDER_ATTRIBUTE_TYPE,
+ MESSAGE_FOLDER_ATTRIBUTE_SYNCHRONIZABLE};
+// clang-format on
+
} // messaging
} // extension
#define __TIZEN_MESSAGING_MESSAGE_FOLDER_H__
#include <memory>
+#include <set>
#include <string>
#include <vector>
#include <email-types.h>
#include "MsgCommon/AbstractFilter.h"
+#include "common/filter-utils.h"
namespace extension {
namespace messaging {
// tizen::FilterableObject
virtual bool isMatchingAttribute(const std::string& attribute_name,
- const tizen::FilterMatchFlag match_flag,
+ const common::AttributeMatchFlag match_flag,
tizen::AnyPtr match_value) const;
virtual bool isMatchingAttributeRange(const std::string& attribute_name,
std::string m_path;
MessageFolderType m_type;
bool m_synchronizable;
+
+ static const std::set<std::string> m_message_folder_filterable_attributes;
};
} // messaging
if (data instanceof tizen.AttributeFilter) {
filter.filterType = 'AttributeFilter';
- //convert to string
- filter.matchValue = String(filter.matchValue);
} else if (data instanceof tizen.AttributeRangeFilter) {
filter.filterType = 'AttributeRangeFilter';
} else if (data instanceof tizen.CompositeFilter) {
id: _internal.id,
type: _internal.type
};
- var result = native.callSync('Message_messageStatus', callArgs);
+ var result = native.callSync('MessageGetMessageStatus', callArgs);
if (native.isSuccess(result)) {
return native.getResultObject(result);
}
args.successCallback(servicesArr);
}
};
- var result = native.call('Messaging_getMessageServices', callArgs, callback);
+ var result = native.call('GetMessageServices', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
native.callIfPossible(args.successCallback, data.recipients);
}
};
- var result = native.call('MessageService_sendMessage', callArgs, callback);
+ var result = native.call('MessageServiceSendMessage', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
}
};
- var result = native.call('MessageService_loadMessageBody', callArgs, callback);
+ var result = native.call('MessageServiceLoadMessageBody', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
- var result = native.call('MessageService_loadMessageAttachment', callArgs, callback);
+ var result = native.call('MessageServiceLoadMessageAttachment', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
- var result = native.call('MessageService_sync', callArgs, callback);
+ var result = native.call('MessageServiceSync', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
- var result = native.call('MessageService_syncFolder', callArgs, callback);
+ var result = native.call('MessageServiceSyncFolder', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
id: self.id,
opId: args.opId
};
- var result = native.callSync('MessageService_stopSync', callArgs);
+ var result = native.callSync('MessageServiceStopSync', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
native.callIfPossible(args.successCallback, data.recipients);
}
};
- var result = native.call('MessageStorage_addDraftMessage', callArgs, callback);
+ var result = native.call('MessageStorageAddDraftMessage', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
native.callIfPossible(args.successCallback, messages);
}
};
- var result = native.call('MessageStorage_findMessages', callArgs, callback);
+ var result = native.call('MessageStorageFindMessages', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
native.callIfPossible(args.successCallback);
}
};
- var result = native.call('MessageStorage_removeMessages', callArgs, callback);
+ var result = native.call('MessageStorageRemoveMessages', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
native.callIfPossible(args.successCallback);
}
};
- var result = native.call('MessageStorage_updateMessages', callArgs, callback);
+ var result = native.call('MessageStorageUpdateMessages', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
args.successCallback(conversations);
}
};
- var result = native.call('MessageStorage_findConversations', callArgs, callback);
+ var result = native.call('MessageStorageFindConversations', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
native.callIfPossible(args.successCallback);
}
};
- var result = native.call('MessageStorage_removeConversations', callArgs, callback);
+ var result = native.call('MessageStorageRemoveConversations', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
args.successCallback(folders);
}
};
- var result = native.call('MessageStorage_findFolders', callArgs, callback);
+ var result = native.call('MessageStorageFindFolders', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
filter: args.filter ? addTypeToFilter_(args.filter) : null,
serviceId: self.service.id
};
- var result = native.callSync('MessageStorage_addMessagesChangeListener', callArgs);
+ var result = native.callSync('MessageStorageAddMessagesChangeListener', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
} else {
serviceId: self.service.id
};
var result = native.callSync(
- 'MessageStorage_addConversationsChangeListener',
+ 'MessageStorageAddConversationsChangeListener',
callArgs
);
if (native.isFailure(result)) {
filter: args.filter ? addTypeToFilter_(args.filter) : null,
serviceId: self.service.id
};
- var result = native.callSync('MessageStorage_addFoldersChangeListener', callArgs);
+ var result = native.callSync('MessageStorageAddFolderChangeListener', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
} else {
watchId: args.watchId,
serviceId: self.service.id
};
- var result = native.callSync('MessageStorage_removeChangeListener', callArgs);
+ var result = native.callSync('MessageStorageRemoveChangeListener', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
} else {
#include <msg_storage.h>
#include <tzplatform_config.h>
+#include "common/filter-utils.h"
#include "common/logger.h"
#include "common/platform_exception.h"
#include "common/scope_exit.h"
AnyPtr match_value_any_ptr = attr_filter->getMatchValue();
const AttributeInfo& attr_info = it->second;
std::string match_value = getMatchString(match_value_any_ptr, attr_info.any_type);
- const FilterMatchFlag match_flag = attr_filter->getMatchFlag();
+ const AttributeMatchFlag match_flag = attr_filter->getMatchFlag();
LoggerD("match_value_any_ptr:%p any_type:%d attr_name:%s match_value:%s",
match_value_any_ptr.get(), attr_info.any_type, attribute_name.c_str(),
match_value.erase(foundPos, 1);
}
- if (EXACTLY == match_flag) {
+ if (AttributeMatchFlag::kExactly == match_flag) {
match_value = "%<" + match_value + ">%";
- } else if (CONTAINS == match_flag) {
+ } else if (AttributeMatchFlag::kContains == match_flag) {
match_value = "%<%" + match_value + "%>%";
- } else if (STARTSWITH == match_flag) {
+ } else if (AttributeMatchFlag::kStartsWith == match_flag) {
match_value = "%<" + match_value + "%>%";
- } else if (ENDSWITH == match_flag) {
+ } else if (AttributeMatchFlag::kEndsWith == match_flag) {
match_value = "%<%" + match_value + ">%";
}
} else if ("folderId" == attribute_name &&
}
break;
}*/
- case EXACTLY: {
+ case AttributeMatchFlag::kExactly: {
// Determines if the apostrophes have to be added over match value
if (TEXT == attribute_map[attribute_name].sql_type) {
sqlQuery << "LIKE '" << match_value << "'";
}
break;
}
- case CONTAINS: {
+ case AttributeMatchFlag::kContains: {
sqlQuery << "LIKE '%" << match_value << "%'";
break;
}
- case STARTSWITH: {
+ case AttributeMatchFlag::kStartsWith: {
sqlQuery << "LIKE '" << match_value << "%'";
break;
}
- case ENDSWITH: {
+ case AttributeMatchFlag::kEndsWith: {
sqlQuery << "LIKE '%" << match_value << "'";
break;
}
- case EXISTS: {
+ case AttributeMatchFlag::kExists: {
if ("unreadMessages" != attribute_name) {
sqlQuery << "IS NOT NULL";
} else {
break;
}
default:
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "The match flag is incorrect.",
- ("The match flag is incorrect: %d", match_flag));
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "The match flag is incorrect.",
+ ("The match flag is incorrect: %s", AttributeMatchFlagToString(match_flag).c_str()));
}
if (MessageType::SMS == msgType || MessageType::MMS == msgType) {
namespace messaging {
namespace {
-const char* FUN_GET_MESSAGE_SERVICES = "Messaging_getMessageServices";
const char* GET_MESSAGE_SERVICES_ARGS_MESSAGE_SERVICE_TYPE = "messageServiceType";
-
-const char* FUN_MESSAGE_SERVICE_SEND_MESSAGE = "MessageService_sendMessage";
const char* SEND_MESSAGE_ARGS_MESSAGE = "message";
const char* SEND_MESSAGE_ARGS_SIMINDEX = "simIndex";
-
-const char* FUN_MESSAGE_SERVICE_LOAD_MESSAGE_BODY = "MessageService_loadMessageBody";
-
-const char* FUN_MESSAGE_SERVICE_LOAD_MESSAGE_ATTACHMENT = "MessageService_loadMessageAttachment";
const char* LOAD_MESSAGE_ATTACHMENT_ARGS_ATTACHMENT = "attachment";
-
-const char* FUN_MESSAGE_SERVICE_SYNC = "MessageService_sync";
const char* SYNC_ARGS_ID = "id";
const char* SYNC_ARGS_LIMIT = "limit";
-
-const char* FUN_MESSAGE_SERVICE_SYNC_FOLDER = "MessageService_syncFolder";
const char* SYNC_FOLDER_ARGS_ID = "id";
const char* SYNC_FOLDER_ARGS_FOLDER = "folder";
const char* SYNC_FOLDER_ARGS_LIMIT = "limit";
-
-const char* FUN_MESSAGE_SERVICE_STOP_SYNC = "MessageService_stopSync";
const char* STOP_SYNC_ARGS_ID = "id";
const char* STOP_SYNC_ARGS_OPID = "opId";
-
-const char* FUN_MESSAGE_STORAGE_ADD_DRAFT_MESSAGE = "MessageStorage_addDraftMessage";
const char* ADD_DRAFT_MESSAGE_ARGS_MESSAGE = "message";
-
-const char* FUN_MESSAGE_STORAGE_FIND_MESSAGES = "MessageStorage_findMessages";
-
-const char* FUN_MESSAGE_STORAGE_REMOVE_MESSAGES = "MessageStorage_removeMessages";
const char* REMOVE_MESSAGES_ARGS_MESSAGES = "messages";
-
-const char* FUN_MESSAGE_STORAGE_UPDATE_MESSAGES = "MessageStorage_updateMessages";
const char* UPDATE_MESSAGES_ARGS_MESSAGES = "messages";
-
-const char* FUN_MESSAGE_STORAGE_FIND_CONVERSATIONS = "MessageStorage_findConversations";
const char* FIND_CONVERSATIONS_ARGS_LIMIT = "limit";
const char* FIND_CONVERSATIONS_ARGS_OFFSET = "offset";
-
-const char* FUN_MESSAGE_STORAGE_REMOVE_CONVERSATIONS = "MessageStorage_removeConversations";
const char* REMOVE_CONVERSATIONS_ARGS_CONVERSATIONS = "conversations";
-
-const char* FUN_MESSAGE_STORAGE_FIND_FOLDERS = "MessageStorage_findFolders";
const char* FIND_FOLDERS_ARGS_LIMIT = "limit";
const char* FIND_FOLDERS_ARGS_OFFSET = "offset";
-
-const char* FUN_MESSAGE_STORAGE_ADD_MESSAGES_CHANGE_LISTENER =
- "MessageStorage_addMessagesChangeListener";
-
-const char* FUN_MESSAGE_STORAGE_ADD_CONVERSATIONS_CHANGE_LISTENER =
- "MessageStorage_addConversationsChangeListener";
-
-const char* FUN_MESSAGE_STORAGE_ADD_FOLDER_CHANGE_LISTENER =
- "MessageStorage_addFoldersChangeListener";
-
-const char* FUN_MESSAGE_STORAGE_REMOVE_CHANGE_LISTENER = "MessageStorage_removeChangeListener";
const char* REMOVE_CHANGE_LISTENER_ARGS_WATCHID = "watchId";
-
const char* FUNCTIONS_HIDDEN_ARGS_SERVICE_ID = "serviceId";
-const char* FUN_MESSAGE_GET_MESSAGE_STATUS = "Message_messageStatus";
const char* FUN_MESSAGE_MESSAGING_EMAIL = "messaging.email";
auto getServiceIdFromJSON = [](picojson::object& data) -> int {
ScopeLogger();
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&MessagingInstance::x, this, _1, _2));
- REGISTER_ASYNC(FUN_GET_MESSAGE_SERVICES, GetMessageServices);
- REGISTER_ASYNC(FUN_MESSAGE_SERVICE_SEND_MESSAGE, MessageServiceSendMessage);
- REGISTER_ASYNC(FUN_MESSAGE_SERVICE_LOAD_MESSAGE_BODY, MessageServiceLoadMessageBody);
- REGISTER_ASYNC(FUN_MESSAGE_SERVICE_LOAD_MESSAGE_ATTACHMENT, MessageServiceLoadMessageAttachment);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_ADD_DRAFT_MESSAGE, MessageStorageAddDraft);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_FIND_MESSAGES, MessageStorageFindMessages);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_REMOVE_MESSAGES, MessageStorageRemoveMessages);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_UPDATE_MESSAGES, MessageStorageUpdateMessages);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_FIND_CONVERSATIONS, MessageStorageFindConversations);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_REMOVE_CONVERSATIONS, MessageStorageRemoveConversations);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_FIND_FOLDERS, MessageStorageFindFolders);
-#undef REGISTER_ASYNC
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&MessagingInstance::x, this, _1, _2));
- REGISTER_SYNC(FUN_MESSAGE_SERVICE_SYNC, MessageServiceSync);
- REGISTER_SYNC(FUN_MESSAGE_SERVICE_STOP_SYNC, MessageServiceStopSync);
- REGISTER_SYNC(FUN_MESSAGE_SERVICE_SYNC_FOLDER, MessageServiceSyncFolder);
- REGISTER_SYNC(FUN_MESSAGE_STORAGE_ADD_MESSAGES_CHANGE_LISTENER,
- MessageStorageAddMessagesChangeListener);
- REGISTER_SYNC(FUN_MESSAGE_STORAGE_ADD_CONVERSATIONS_CHANGE_LISTENER,
- MessageStorageAddConversationsChangeListener);
- REGISTER_SYNC(FUN_MESSAGE_STORAGE_ADD_FOLDER_CHANGE_LISTENER,
- MessageStorageAddFolderChangeListener);
- REGISTER_SYNC(FUN_MESSAGE_STORAGE_REMOVE_CHANGE_LISTENER, MessageStorageRemoveChangeListener);
- REGISTER_SYNC(FUN_MESSAGE_GET_MESSAGE_STATUS, MessageGetMessageStatus);
-#undef REGISTER_SYNC
+
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&MessagingInstance::M, this, _1, _2))
+ REGISTER_METHOD(GetMessageServices);
+ REGISTER_METHOD(MessageServiceSendMessage);
+ REGISTER_METHOD(MessageServiceLoadMessageBody);
+ REGISTER_METHOD(MessageServiceLoadMessageAttachment);
+ REGISTER_METHOD(MessageStorageAddDraftMessage);
+ REGISTER_METHOD(MessageStorageFindMessages);
+ REGISTER_METHOD(MessageStorageRemoveMessages);
+ REGISTER_METHOD(MessageStorageUpdateMessages);
+ REGISTER_METHOD(MessageStorageFindConversations);
+ REGISTER_METHOD(MessageStorageRemoveConversations);
+ REGISTER_METHOD(MessageStorageFindFolders);
+
+ REGISTER_METHOD(MessageServiceSync);
+ REGISTER_METHOD(MessageServiceStopSync);
+ REGISTER_METHOD(MessageServiceSyncFolder);
+ REGISTER_METHOD(MessageStorageAddMessagesChangeListener);
+ REGISTER_METHOD(MessageStorageAddConversationsChangeListener);
+ REGISTER_METHOD(MessageStorageAddFolderChangeListener);
+ REGISTER_METHOD(MessageStorageRemoveChangeListener);
+ REGISTER_METHOD(MessageGetMessageStatus);
+#undef REGISTER_METHOD
}
MessagingInstance::~MessagingInstance() {
}
}
-void MessagingInstance::MessageStorageAddDraft(const picojson::value& args, picojson::object& out) {
+void MessagingInstance::MessageStorageAddDraftMessage(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);
void MessageServiceSyncFolder(const picojson::value& args, picojson::object& out);
void MessageServiceStopSync(const picojson::value& args, picojson::object& out);
- void MessageStorageAddDraft(const picojson::value& args, picojson::object& out);
+ void MessageStorageAddDraftMessage(const picojson::value& args, picojson::object& out);
void MessageStorageFindMessages(const picojson::value& args, picojson::object& out);
void MessageStorageRemoveMessages(const picojson::value& args, picojson::object& out);
void MessageStorageUpdateMessages(const picojson::value& args, picojson::object& out);
const char* JSON_DATA_RECIPIENTS = "recipients";
const char* MESSAGE_ATTRIBUTE_ID = "id";
+const char* MESSAGE_ATTRIBUTE_SERVICE_ID = "serviceId";
const char* MESSAGE_ATTRIBUTE_OLD_ID = "oldId";
const char* MESSAGE_ATTRIBUTE_CONVERSATION_ID = "conversationId";
const char* MESSAGE_ATTRIBUTE_FOLDER_ID = "folderId";
const char* MESSAGE_ATTRIBUTE_CC = "cc"; // used also in dictionary
const char* MESSAGE_ATTRIBUTE_BCC = "bcc"; // used also in dictionary
const char* MESSAGE_ATTRIBUTE_BODY = "body";
+const char* MESSAGE_ATTRIBUTE_BODY_PLAIN_BODY = "body.plainBody";
const char* MESSAGE_ATTRIBUTE_IS_READ = "isRead";
const char* MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY = "isHighPriority"; // used also in dictionary
const char* MESSAGE_ATTRIBUTE_SUBJECT = "subject"; // used also in dictionary
auto name = getValueFromJSONObject<std::string>(filter, JSON_TO_ATTRIBUTE_NAME);
auto matchFlagStr = getValueFromJSONObject<std::string>(filter, JSON_TO_MATCH_FLAG);
- FilterMatchFlag filterMatch;
+ AttributeMatchFlag filterMatch;
if (STR_MATCH_EXACTLY == matchFlagStr) {
- filterMatch = FilterMatchFlag::EXACTLY;
+ filterMatch = AttributeMatchFlag::kExactly;
} else if (STR_MATCH_FULLSTRING == matchFlagStr) {
- filterMatch = FilterMatchFlag::FULLSTRING;
+ filterMatch = AttributeMatchFlag::kFullString;
} else if (STR_MATCH_CONTAINS == matchFlagStr) {
- filterMatch = FilterMatchFlag::CONTAINS;
+ filterMatch = AttributeMatchFlag::kContains;
} else if (STR_MATCH_STARTSWITH == matchFlagStr) {
- filterMatch = FilterMatchFlag::STARTSWITH;
+ filterMatch = AttributeMatchFlag::kStartsWith;
} else if (STR_MATCH_ENDSWITH == matchFlagStr) {
- filterMatch = FilterMatchFlag::ENDSWITH;
+ filterMatch = AttributeMatchFlag::kEndsWith;
} else if (STR_MATCH_EXISTS == matchFlagStr) {
- filterMatch = FilterMatchFlag::EXISTS;
+ filterMatch = AttributeMatchFlag::kExists;
} else {
return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR, "Filter name is not recognized",
("Filter name is not recognized: %s", matchFlagStr.c_str()));
#include <stdexcept>
#include <string>
#include <vector>
+#include "common/filter-utils.h"
#include "common/logger.h"
#include "common/picojson.h"
#include "common/platform_result.h"
extern const char* JSON_DATA_RECIPIENTS;
extern const char* MESSAGE_ATTRIBUTE_ID;
+extern const char* MESSAGE_ATTRIBUTE_SERVICE_ID;
extern const char* MESSAGE_ATTRIBUTE_CONVERSATION_ID;
extern const char* MESSAGE_ATTRIBUTE_FOLDER_ID;
extern const char* MESSAGE_ATTRIBUTE_TYPE;
extern const char* MESSAGE_ATTRIBUTE_CC; // used also in dictionary
extern const char* MESSAGE_ATTRIBUTE_BCC; // used also in dictionary
extern const char* MESSAGE_ATTRIBUTE_BODY;
+extern const char* MESSAGE_ATTRIBUTE_BODY_PLAIN_BODY;
extern const char* MESSAGE_ATTRIBUTE_IS_READ;
extern const char* MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY; // used also in dictionary
extern const char* MESSAGE_ATTRIBUTE_SUBJECT; // used also in dictionary
extern const char* MESSAGE_ATTACHMENT_ATTRIBUTE_MIME_TYPE;
extern const char* MESSAGE_ATTACHMENT_ATTRIBUTE_FILE_PATH;
+extern const char* MESSAGE_FOLDER_ATTRIBUTE_ID;
+extern const char* MESSAGE_FOLDER_ATTRIBUTE_PARENT_ID;
extern const char* MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID;
+extern const char* MESSAGE_FOLDER_ATTRIBUTE_CONTENT_TYPE;
+extern const char* MESSAGE_FOLDER_ATTRIBUTE_NAME;
+extern const char* MESSAGE_FOLDER_ATTRIBUTE_PATH;
+extern const char* MESSAGE_FOLDER_ATTRIBUTE_TYPE;
+extern const char* MESSAGE_FOLDER_ATTRIBUTE_SYNCHRONIZABLE;
extern const char* MESSAGE_CONVERSATION_ATTRIBUTE_ID;
extern const char* MESSAGE_CONVERSATION_ATTRIBUTE_TYPE;
_networkBearerSelectionCallback
);
var result = native_.callSync(
- 'NetworkBearerSelection_requestRouteToHost',
+ 'NetworkBearerSelectionRequestRouteToHost',
nativeParam
);
};
var result = native_.call(
- 'NetworkBearerSelection_releaseRouteToHost',
+ 'NetworkBearerSelectionReleaseRouteToHost',
nativeParam,
callback
);
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&NetworkBearerSelectionInstance::x, this, _1, _2));
-#define REGISTER_ASYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&NetworkBearerSelectionInstance::x, this, _1, _2));
- REGISTER_SYNC("NetworkBearerSelection_requestRouteToHost",
- NetworkBearerSelectionRequestRouteToHost);
- REGISTER_ASYNC("NetworkBearerSelection_releaseRouteToHost",
- NetworkBearerSelectionReleaseRouteToHost);
-#undef REGISTER_SYNC
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) \
+ RegisterSyncHandler(#M, std::bind(&NetworkBearerSelectionInstance::M, this, _1, _2))
+ REGISTER_METHOD(NetworkBearerSelectionRequestRouteToHost);
+ REGISTER_METHOD(NetworkBearerSelectionReleaseRouteToHost);
+#undef REGISTER_METHOD
NetworkBearerSelectionManager::GetInstance()->AddListener(this);
}
NFCManager.prototype.getDefaultAdapter = function() {
// First check NFC suppor on C++ level
- var result = native_.callSync('NFCManager_getDefaultAdapter', {});
+ var result = native_.callSync('NFCManagerGetDefaultAdapter', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
{ name: 'exclusiveMode', type: types_.BOOLEAN }
]);
- var result = native_.callSync('NFCManager_setExclusiveMode', {
+ var result = native_.callSync('NFCManagerSetExclusiveMode', {
exclusiveMode: args.exclusiveMode
});
function NFCAdapter() {
function poweredGetter() {
- var ret = native_.callSync('NFCAdapter_getPowered');
+ var ret = native_.callSync('NFCAdapterGetPowered');
if (native_.isFailure(ret)) {
return false;
}
function cardEmulationModeGetter() {
- var result = native_.callSync('NFCAdapter_cardEmulationModeGetter');
+ var result = native_.callSync('NFCAdapterCardEmulationModeGetter');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
{ name: 'emulationMode', type: types_.STRING }
]);
- var result = native_.callSync('NFCAdapter_cardEmulationModeSetter', {
+ var result = native_.callSync('NFCAdapterCardEmulationModeSetter', {
emulationMode: args.emulationMode
});
}
function activeSecureElementGetter() {
- var result = native_.callSync('NFCAdapter_activeSecureElementGetter');
+ var result = native_.callSync('NFCAdapterActiveSecureElementGetter');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
{ name: 'secureElement', type: types_.STRING }
]);
- var result = native_.callSync('NFCAdapter_activeSecureElementSetter', {
+ var result = native_.callSync('NFCAdapterActiveSecureElementSetter', {
secureElement: args.secureElement
});
]);
var result = native_.call(
- 'NFCAdapter_setPowered',
+ 'NFCAdapterSetPowered',
{
powered: args.powered
},
// Register (acivate) core listener if not done yet
if (!native_.isListenerSet(TAG_LISTENER)) {
- var result = native_.callSync('NFCAdapter_setTagListener');
+ var result = native_.callSync('NFCAdapterSetTagListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
if (!native_.isListenerSet(PEER_LISTENER)) {
- var result = native_.callSync('NFCAdapter_setPeerListener');
+ var result = native_.callSync('NFCAdapterSetPeerListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
NFCAdapter.prototype.unsetTagListener = function() {
native_.removeListener(TAG_LISTENER);
- var result = native_.callSync('NFCAdapter_unsetTagListener');
+ var result = native_.callSync('NFCAdapterUnsetTagListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
NFCAdapter.prototype.unsetPeerListener = function() {
native_.removeListener(PEER_LISTENER);
- var result = native_.callSync('NFCAdapter_unsetPeerListener');
+ var result = native_.callSync('NFCAdapterUnsetPeerListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
type_.isEmptyObject(cardEmulationModeListener.listeners) &&
type_.isEmptyObject(activeSecureElementChangeListener.listeners)
) {
- var result = native_.callSync('NFCAdapter_addCardEmulationModeChangeListener');
+ var result = native_.callSync('NFCAdapterAddCardEmulationModeChangeListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
type_.isEmptyObject(cardEmulationModeListener.listeners) &&
type_.isEmptyObject(activeSecureElementChangeListener.listeners)
) {
- var result = native_.callSync('NFCAdapter_removeCardEmulationModeChangeListener');
+ var result = native_.callSync('NFCAdapterRemoveCardEmulationModeChangeListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
if (SecureElementType.ESE === args.type) {
if (type_.isEmptyObject(transactionEventListenerEse.listeners)) {
- result = native_.callSync('NFCAdapter_addTransactionEventListener', {
+ result = native_.callSync('NFCAdapterAddTransactionEventListener', {
type: args.type
});
if (native_.isFailure(result)) {
return transactionEventListenerEse.addListener(args.callback);
} else {
if (type_.isEmptyObject(transactionEventListenerUicc.listeners)) {
- result = native_.callSync('NFCAdapter_addTransactionEventListener', {
+ result = native_.callSync('NFCAdapterAddTransactionEventListener', {
type: args.type
});
if (native_.isFailure(result)) {
transactionEventListenerUicc.removeListener(args.watchId);
if (type_.isEmptyObject(transactionEventListenerEse.listeners) && !ese_empty) {
- var result = native_.callSync('NFCAdapter_removeTransactionEventListener', {
+ var result = native_.callSync('NFCAdapterRemoveTransactionEventListener', {
type: SecureElementType.ESE
});
}
if (type_.isEmptyObject(transactionEventListenerUicc.listeners) && !uicc_empty) {
- var result = native_.callSync('NFCAdapter_removeTransactionEventListener', {
+ var result = native_.callSync('NFCAdapterRemoveTransactionEventListener', {
type: SecureElementType.UICC
});
type_.isEmptyObject(cardEmulationModeListener.listeners) &&
type_.isEmptyObject(activeSecureElementChangeListener.listeners)
) {
- var result = native_.callSync('NFCAdapter_addActiveSecureElementChangeListener');
+ var result = native_.callSync('NFCAdapterAddActiveSecureElementChangeListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
type_.isEmptyObject(cardEmulationModeListener.listeners) &&
type_.isEmptyObject(activeSecureElementChangeListener.listeners)
) {
- var result = native_.callSync('NFCAdapter_removeCardEmulationModeChangeListener');
+ var result = native_.callSync('NFCAdapterRemoveCardEmulationModeChangeListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
};
NFCAdapter.prototype.getCachedMessage = function() {
- var result = native_.callSync('NFCAdapter_getCachedMessage');
+ var result = native_.callSync('NFCAdapterGetCachedMessage');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
]);
- var result = native_.callSync('NFCAdapter_setExclusiveModeForTransaction', {
+ var result = native_.callSync('NFCAdapterSetExclusiveModeForTransaction', {
transactionMode: args.transactionMode
});
}
if (type_.isEmptyObject(HCEEventListener.listeners)) {
- var result = native_.callSync('NFCAdapter_addHCEEventListener');
+ var result = native_.callSync('NFCAdapterAddHCEEventListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
HCEEventListener.removeListener(args.watchId);
if (type_.isEmptyObject(HCEEventListener.listeners)) {
- var result = native_.callSync('NFCAdapter_removeHCEEventListener');
+ var result = native_.callSync('NFCAdapterRemoveHCEEventListener');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
native_.callIfPossible(args.successCallback);
};
- var result = native_.call('NFCAdapter_sendHostAPDUResponse', data, callback);
+ var result = native_.call('NFCAdapterSendHostAPDUResponse', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
aid: args.aid
};
- var result = native_.callSync('NFCAdapter_isActivatedHandlerForAID', data);
+ var result = native_.callSync('NFCAdapterIsActivatedHandlerForAID', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
category: args.category
};
- var result = native_.callSync('NFCAdapter_isActivatedHandlerForCategory', data);
+ var result = native_.callSync('NFCAdapterIsActivatedHandlerForCategory', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
category: args.category
};
- var result = native_.callSync('NFCAdapter_registerAID', data);
+ var result = native_.callSync('NFCAdapterRegisterAID', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
category: args.category
};
- var result = native_.callSync('NFCAdapter_unregisterAID', data);
+ var result = native_.callSync('NFCAdapterUnregisterAID', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
native_.callIfPossible(args.successCallback, aids);
};
- var result = native_.call('NFCAdapter_getAIDsForCategory', data, callback);
+ var result = native_.call('NFCAdapterGetAIDsForCategory', data, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
function WebkitVisibilityChangeListener() {
var result;
if (true === privUtils_.global.document.hidden) {
- result = native_.call('NFCAdapter_unsetPreferredApp');
+ result = native_.call('NFCAdapterUnsetPreferredApp');
} else if (false === privUtils_.global.document.hidden) {
- result = native_.call('NFCAdapter_setPreferredApp');
+ result = native_.call('NFCAdapterSetPreferredApp');
}
if (native_.isFailure(result)) {
}
NFCAdapter.prototype.setPreferredApp = function() {
- var result = native_.call('NFCAdapter_setPreferredApp');
+ var result = native_.call('NFCAdapterSetPreferredApp');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
};
NFCAdapter.prototype.unsetPreferredApp = function() {
- var result = native_.call('NFCAdapter_unsetPreferredApp');
+ var result = native_.call('NFCAdapterUnsetPreferredApp');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
var _my_id = tagid;
function TypeGetter() {
- var result = native_.callSync('NFCTag_typeGetter', { id: _my_id });
+ var result = native_.callSync('NFCTagTypeGetter', { id: _my_id });
if (native_.isFailure(result)) {
return;
}
function IsSupportedNDEFGetter() {
- var result = native_.callSync('NFCTag_isSupportedNDEFGetter', { id: _my_id });
+ var result = native_.callSync('NFCTagIsSupportedNDEFGetter', { id: _my_id });
if (native_.isFailure(result)) {
return;
}
function NDEFSizeGetter() {
- var result = native_.callSync('NFCTag_NDEFSizeGetter', { id: _my_id });
+ var result = native_.callSync('NFCTagNDEFSizeGetter', { id: _my_id });
if (native_.isFailure(result)) {
return;
}
function PropertiesGetter() {
- var result = native_.callSync('NFCTag_propertiesGetter', { id: _my_id });
+ var result = native_.callSync('NFCTagPropertiesGetter', { id: _my_id });
if (native_.isFailure(result)) {
return;
}
function IsConnectedGetter() {
- var result = native_.callSync('NFCTag_isConnectedGetter', { id: _my_id });
+ var result = native_.callSync('NFCTagIsConnectedGetter', { id: _my_id });
if (native_.isFailure(result)) {
return;
}
]);
- var result = native_.call('NFCTag_readNDEF', { id: _my_id }, function(result) {
+ var result = native_.call('NFCTagReadNDEF', { id: _my_id }, function(result) {
if (native_.isFailure(result)) {
if (!type_.isNullOrUndefined(args.errorCallback)) {
args.errorCallback(native_.getErrorObject(result));
]);
var result = native_.call(
- 'NFCTag_writeNDEF',
+ 'NFCTagWriteNDEF',
{
id: _my_id,
records: args.message.records,
]);
var result = native_.call(
- 'NFCTag_transceive',
+ 'NFCTagTransceive',
{
id: _my_id,
data: args.data
var _my_id = peerid;
function isConnectedGetter() {
- var ret = native_.callSync('NFCAdapter_PeerIsConnectedGetter', { id: _my_id });
+ var ret = native_.callSync('NFCAdapterPeerIsConnectedGetter', { id: _my_id });
if (native_.isFailure(ret)) {
return false;
}
]);
var result = native_.call(
- 'NFCPeer_sendNDEF',
+ 'NFCPeerSendNDEF',
{
id: _my_id,
records: args.message.records,
args.listener(data);
};
- var result = native_.callSync('NFCPeer_setReceiveNDEFListener', { id: _my_id });
+ var result = native_.callSync('NFCPeerSetReceiveNDEFListener', { id: _my_id });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
native_.removeListener(RECEIVE_NDEF_LISTENER);
- var result = native_.callSync('NFCPeer_unsetReceiveNDEFListener', { id: _my_id });
+ var result = native_.callSync('NFCPeerUnsetReceiveNDEFListener', { id: _my_id });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
records_ = data;
} else {
var raw_data_ = toByteArray(data);
- var result = native_.callSync('NDEFMessage_constructor', {
+ var result = native_.callSync('NDEFMessageConstructor', {
rawData: raw_data_,
rawDataSize: raw_data_.length
});
};
tizen.NDEFMessage.prototype.toByte = function() {
- var result = native_.callSync('NDEFMessage_toByte', {
+ var result = native_.callSync('NDEFMessageToByte', {
records: this.records,
recordsSize: this.recordCount
});
if (arguments.length >= 1) {
if (type_.isArray(first)) {
var raw_data_ = toByteArray(first);
- var result = native_.callSync('NDEFRecord_constructor', {
+ var result = native_.callSync('NDEFRecordConstructor', {
rawData: raw_data_,
rawDataSize: raw_data_.length
});
internal_.id
);
} else {
- var result = native_.callSync('NDEFRecordText_constructor', {
+ var result = native_.callSync('NDEFRecordTextConstructor', {
text: text_,
languageCode: languageCode_,
encoding: encoding_
internal_.id
);
} else {
- var result = native_.callSync('NDEFRecordURI_constructor', {
+ var result = native_.callSync('NDEFRecordURIConstructor', {
uri: uri_
});
if (native_.isFailure(result)) {
);
} else {
data_ = toByteArray(data, Math.pow(2, 32) - 1);
- var result = native_.callSync('NDEFRecordMedia_constructor', {
+ var result = native_.callSync('NDEFRecordMediaConstructor', {
mimeType: mimeType_,
data: data_,
dataSize: data_.length
ScopeLogger();
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&NFCInstance::x, this, _1, _2));
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&NFCInstance::x, this, _1, _2));
- REGISTER_SYNC("NFCManager_getDefaultAdapter", GetDefaultAdapter);
- REGISTER_SYNC("NFCManager_setExclusiveMode", SetExclusiveMode);
- REGISTER_ASYNC("NFCAdapter_setPowered", SetPowered);
- REGISTER_SYNC("NFCAdapter_getPowered", GetPowered);
- REGISTER_SYNC("NFCAdapter_cardEmulationModeSetter", CardEmulationModeSetter);
- REGISTER_SYNC("NFCAdapter_cardEmulationModeGetter", CardEmulationModeGetter);
- REGISTER_SYNC("NFCAdapter_activeSecureElementSetter", ActiveSecureElementSetter);
- REGISTER_SYNC("NFCAdapter_activeSecureElementGetter", ActiveSecureElementGetter);
- REGISTER_SYNC("NFCAdapter_setPeerListener", SetPeerListener);
- REGISTER_SYNC("NFCAdapter_setTagListener", SetTagListener);
- REGISTER_SYNC("NFCAdapter_PeerIsConnectedGetter", PeerIsConnectedGetter);
- REGISTER_SYNC("NFCAdapter_unsetTagListener", UnsetTagListener);
- REGISTER_SYNC("NFCAdapter_unsetPeerListener", UnsetPeerListener);
- REGISTER_SYNC("NFCAdapter_addCardEmulationModeChangeListener",
- AddCardEmulationModeChangeListener);
- REGISTER_SYNC("NFCAdapter_removeCardEmulationModeChangeListener",
- RemoveCardEmulationModeChangeListener);
- REGISTER_SYNC("NFCAdapter_addTransactionEventListener", AddTransactionEventListener);
- REGISTER_SYNC("NFCAdapter_removeTransactionEventListener", RemoveTransactionEventListener);
- REGISTER_SYNC("NFCAdapter_addActiveSecureElementChangeListener",
- AddActiveSecureElementChangeListener);
- REGISTER_SYNC("NFCAdapter_removeActiveSecureElementChangeListener",
- RemoveActiveSecureElementChangeListener);
- REGISTER_SYNC("NFCAdapter_getCachedMessage", GetCachedMessage);
- REGISTER_SYNC("NFCAdapter_setExclusiveModeForTransaction", SetExclusiveModeForTransaction);
+
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&NFCInstance::M, this, _1, _2))
+ REGISTER_METHOD(NFCManagerGetDefaultAdapter);
+ REGISTER_METHOD(NFCManagerSetExclusiveMode);
+ REGISTER_METHOD(NFCAdapterSetPowered);
+ REGISTER_METHOD(NFCAdapterGetPowered);
+ REGISTER_METHOD(NFCAdapterCardEmulationModeSetter);
+ REGISTER_METHOD(NFCAdapterCardEmulationModeGetter);
+ REGISTER_METHOD(NFCAdapterActiveSecureElementSetter);
+ REGISTER_METHOD(NFCAdapterActiveSecureElementGetter);
+ REGISTER_METHOD(NFCAdapterSetPeerListener);
+ REGISTER_METHOD(NFCAdapterSetTagListener);
+ REGISTER_METHOD(NFCAdapterPeerIsConnectedGetter);
+ REGISTER_METHOD(NFCAdapterUnsetTagListener);
+ REGISTER_METHOD(NFCAdapterUnsetPeerListener);
+ REGISTER_METHOD(NFCAdapterAddCardEmulationModeChangeListener);
+ REGISTER_METHOD(NFCAdapterRemoveCardEmulationModeChangeListener);
+ REGISTER_METHOD(NFCAdapterAddTransactionEventListener);
+ REGISTER_METHOD(NFCAdapterRemoveTransactionEventListener);
+ REGISTER_METHOD(NFCAdapterAddActiveSecureElementChangeListener);
+ REGISTER_METHOD(NFCAdapterRemoveActiveSecureElementChangeListener);
+ REGISTER_METHOD(NFCAdapterGetCachedMessage);
+ REGISTER_METHOD(NFCAdapterSetExclusiveModeForTransaction);
// HCE related methods
- REGISTER_SYNC("NFCAdapter_addHCEEventListener", AddHCEEventListener);
- REGISTER_SYNC("NFCAdapter_removeHCEEventListener", RemoveHCEEventListener);
- REGISTER_ASYNC("NFCAdapter_sendHostAPDUResponse", SendHostAPDUResponse);
- REGISTER_SYNC("NFCAdapter_isActivatedHandlerForAID", IsActivatedHandlerForAID);
- REGISTER_SYNC("NFCAdapter_isActivatedHandlerForCategory", IsActivatedHandlerForCategory);
- REGISTER_SYNC("NFCAdapter_registerAID", RegisterAID);
- REGISTER_SYNC("NFCAdapter_unregisterAID", UnregisterAID);
- REGISTER_ASYNC("NFCAdapter_getAIDsForCategory", GetAIDsForCategory);
- REGISTER_SYNC("NFCAdapter_setPreferredApp", SetPreferredApp);
- REGISTER_SYNC("NFCAdapter_unsetPreferredApp", UnsetPreferredApp);
-
- REGISTER_SYNC("NFCPeer_setReceiveNDEFListener", SetReceiveNDEFListener);
- REGISTER_SYNC("NFCPeer_unsetReceiveNDEFListener", UnsetReceiveNDEFListener);
- REGISTER_SYNC("NDEFMessage_toByte", ToByte);
+ REGISTER_METHOD(NFCAdapterAddHCEEventListener);
+ REGISTER_METHOD(NFCAdapterRemoveHCEEventListener);
+ REGISTER_METHOD(NFCAdapterSendHostAPDUResponse);
+ REGISTER_METHOD(NFCAdapterIsActivatedHandlerForAID);
+ REGISTER_METHOD(NFCAdapterIsActivatedHandlerForCategory);
+ REGISTER_METHOD(NFCAdapterRegisterAID);
+ REGISTER_METHOD(NFCAdapterUnregisterAID);
+ REGISTER_METHOD(NFCAdapterGetAIDsForCategory);
+ REGISTER_METHOD(NFCAdapterSetPreferredApp);
+ REGISTER_METHOD(NFCAdapterUnsetPreferredApp);
+
+ REGISTER_METHOD(NFCPeerSetReceiveNDEFListener);
+ REGISTER_METHOD(NFCPeerUnsetReceiveNDEFListener);
+
// Message related methods
- REGISTER_SYNC("NDEFMessage_constructor", NDEFMessageContructor);
- REGISTER_SYNC("NDEFRecord_constructor", NDEFRecordContructor);
- REGISTER_SYNC("NDEFRecordText_constructor", NDEFRecordTextContructor);
- REGISTER_SYNC("NDEFRecordURI_constructor", NDEFRecordURIContructor);
- REGISTER_SYNC("NDEFRecordMedia_constructor", NDEFRecordMediaContructor);
+ REGISTER_METHOD(NDEFMessageToByte);
+ REGISTER_METHOD(NDEFMessageConstructor);
+ REGISTER_METHOD(NDEFRecordConstructor);
+ REGISTER_METHOD(NDEFRecordTextConstructor);
+ REGISTER_METHOD(NDEFRecordURIConstructor);
+ REGISTER_METHOD(NDEFRecordMediaConstructor);
// NFCTag attributes getters
- REGISTER_SYNC("NFCTag_typeGetter", TagTypeGetter);
- REGISTER_SYNC("NFCTag_isSupportedNDEFGetter", TagIsSupportedNDEFGetter);
- REGISTER_SYNC("NFCTag_NDEFSizeGetter", TagNDEFSizeGetter);
- REGISTER_SYNC("NFCTag_propertiesGetter", TagPropertiesGetter);
- REGISTER_SYNC("NFCTag_isConnectedGetter", TagIsConnectedGetter);
-
- REGISTER_ASYNC("NFCTag_readNDEF", ReadNDEF);
- REGISTER_ASYNC("NFCTag_writeNDEF", WriteNDEF);
- REGISTER_ASYNC("NFCTag_transceive", Transceive);
- REGISTER_ASYNC("NFCPeer_sendNDEF", SendNDEF);
-#undef REGISTER_SYNC
-#undef REGISTER_ASYNC
+ REGISTER_METHOD(NFCTagTypeGetter);
+ REGISTER_METHOD(NFCTagIsSupportedNDEFGetter);
+ REGISTER_METHOD(NFCTagNDEFSizeGetter);
+ REGISTER_METHOD(NFCTagPropertiesGetter);
+ REGISTER_METHOD(NFCTagIsConnectedGetter);
+
+ REGISTER_METHOD(NFCTagReadNDEF);
+ REGISTER_METHOD(NFCTagWriteNDEF);
+ REGISTER_METHOD(NFCTagTransceive);
+ REGISTER_METHOD(NFCPeerSendNDEF);
+#undef REGISTER_METHOD
// Set a PostMessageHandler at NFCAdapter to provide mechanizm of returning
// asynchronous response
NFCAdapter::GetInstance()->SetResponder(nullptr);
}
-void NFCInstance::GetDefaultAdapter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCManagerGetDefaultAdapter(const picojson::value& args, picojson::object& out) {
// Default NFC adapter is created at JS level
// Here there's only check for NFC support
ScopeLogger();
}
}
-void NFCInstance::SetExclusiveMode(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCManagerSetExclusiveMode(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCommon, &out);
}
// TODO(g.rynkowski): Rewrite to asynchronous approach
-void NFCInstance::SetPowered(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterSetPowered(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. Let "
}
}
-void NFCInstance::GetPowered(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterGetPowered(const picojson::value& args, picojson::object& out) {
ScopeLogger();
bool ret = NFCAdapter::GetInstance()->GetPowered();
ReportSuccess(picojson::value(ret), out);
}
-void NFCInstance::CardEmulationModeSetter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterCardEmulationModeSetter(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::CardEmulationModeGetter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterCardEmulationModeGetter(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::ActiveSecureElementSetter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterActiveSecureElementSetter(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::ActiveSecureElementGetter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterActiveSecureElementGetter(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::SetTagListener(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterSetTagListener(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcTag, &out);
bool supported = isTagSupported();
}
}
-void NFCInstance::PeerIsConnectedGetter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterPeerIsConnectedGetter(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_EXIST(args, "id", out);
}
}
-void NFCInstance::SetPeerListener(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterSetPeerListener(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcP2P, &out);
bool supported = isP2PSupported();
}
}
-void NFCInstance::UnsetTagListener(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterUnsetTagListener(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcTag, &out);
bool supported = isTagSupported();
ReportSuccess(out);
}
-void NFCInstance::UnsetPeerListener(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterUnsetPeerListener(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcP2P, &out);
bool supported = isP2PSupported();
}
}
-void NFCInstance::AddCardEmulationModeChangeListener(const picojson::value& args,
- picojson::object& out) {
+void NFCInstance::NFCAdapterAddCardEmulationModeChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::RemoveCardEmulationModeChangeListener(const picojson::value& args,
- picojson::object& out) {
+void NFCInstance::NFCAdapterRemoveCardEmulationModeChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::AddTransactionEventListener(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterAddTransactionEventListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::RemoveTransactionEventListener(const picojson::value& args,
- picojson::object& out) {
+void NFCInstance::NFCAdapterRemoveTransactionEventListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::AddActiveSecureElementChangeListener(const picojson::value& args,
- picojson::object& out) {
+void NFCInstance::NFCAdapterAddActiveSecureElementChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::RemoveActiveSecureElementChangeListener(const picojson::value& args,
- picojson::object& out) {
+void NFCInstance::NFCAdapterRemoveActiveSecureElementChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::GetCachedMessage(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterGetCachedMessage(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCommon, &out);
}
}
-void NFCInstance::SetExclusiveModeForTransaction(const picojson::value& args,
- picojson::object& out) {
+void NFCInstance::NFCAdapterSetExclusiveModeForTransaction(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
// TODO(g.rynkowski): Rewrite to asynchronous approach
-void NFCInstance::ReadNDEF(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCTagReadNDEF(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcTag, &out);
}
// TODO(g.rynkowski): Rewrite to asynchronous approach
-void NFCInstance::WriteNDEF(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCTagWriteNDEF(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcTag, &out);
}
// TODO(g.rynkowski): Rewrite to asynchronous approach
-void NFCInstance::Transceive(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCTagTransceive(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcTag, &out);
}
}
-void NFCInstance::SetReceiveNDEFListener(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCPeerSetReceiveNDEFListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcP2P, &out);
}
}
-void NFCInstance::UnsetReceiveNDEFListener(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCPeerUnsetReceiveNDEFListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcP2P, &out);
}
// TODO(g.rynkowski): Rewrite to asynchronous approach
-void NFCInstance::SendNDEF(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCPeerSendNDEF(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcP2P, &out);
}
}
-void NFCInstance::ToByte(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NDEFMessageToByte(const picojson::value& args, picojson::object& out) {
ScopeLogger();
picojson::value result = picojson::value(picojson::object());
}
// Message related methods
-void NFCInstance::NDEFMessageContructor(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NDEFMessageConstructor(const picojson::value& args, picojson::object& out) {
ScopeLogger();
picojson::value result = picojson::value(picojson::object());
picojson::object& result_obj = result.get<picojson::object>();
}
}
-void NFCInstance::NDEFRecordContructor(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NDEFRecordConstructor(const picojson::value& args, picojson::object& out) {
ScopeLogger();
picojson::value result = picojson::value(picojson::object());
picojson::object& result_obj = result.get<picojson::object>();
}
}
-void NFCInstance::NDEFRecordTextContructor(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NDEFRecordTextConstructor(const picojson::value& args, picojson::object& out) {
ScopeLogger();
picojson::value result = picojson::value(picojson::object());
}
}
-void NFCInstance::NDEFRecordURIContructor(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NDEFRecordURIConstructor(const picojson::value& args, picojson::object& out) {
ScopeLogger();
picojson::value result = picojson::value(picojson::object());
picojson::object& result_obj = result.get<picojson::object>();
}
}
-void NFCInstance::NDEFRecordMediaContructor(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NDEFRecordMediaConstructor(const picojson::value& args, picojson::object& out) {
ScopeLogger();
picojson::value result = picojson::value(picojson::object());
}
// NFCTag attributes getters
-void NFCInstance::TagTypeGetter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCTagTypeGetter(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_EXIST(args, "id", out);
}
}
-void NFCInstance::TagIsSupportedNDEFGetter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCTagIsSupportedNDEFGetter(const picojson::value& args, picojson::object& out) {
ScopeLogger();
int tag_id = (int)args.get("id").get<double>();
}
}
-void NFCInstance::TagNDEFSizeGetter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCTagNDEFSizeGetter(const picojson::value& args, picojson::object& out) {
ScopeLogger();
int tag_id = (int)args.get("id").get<double>();
}
}
-void NFCInstance::TagPropertiesGetter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCTagPropertiesGetter(const picojson::value& args, picojson::object& out) {
ScopeLogger();
int tag_id = (int)args.get("id").get<double>();
}
}
-void NFCInstance::TagIsConnectedGetter(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCTagIsConnectedGetter(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_EXIST(args, "id", out);
}
}
-void NFCInstance::AddHCEEventListener(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterAddHCEEventListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::RemoveHCEEventListener(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterRemoveHCEEventListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::SendHostAPDUResponse(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterSendHostAPDUResponse(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
&NFCAdapter::SendHostAPDUResponse, NFCAdapter::GetInstance(), apdu, success_cb, error_cb));
}
-void NFCInstance::IsActivatedHandlerForAID(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterIsActivatedHandlerForAID(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::IsActivatedHandlerForCategory(const picojson::value& args,
- picojson::object& out) {
+void NFCInstance::NFCAdapterIsActivatedHandlerForCategory(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::RegisterAID(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterRegisterAID(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::UnregisterAID(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterUnregisterAID(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::GetAIDsForCategory(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterGetAIDsForCategory(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
required_category, success_cb, error_cb));
}
-void NFCInstance::SetPreferredApp(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterSetPreferredApp(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
}
}
-void NFCInstance::UnsetPreferredApp(const picojson::value& args, picojson::object& out) {
+void NFCInstance::NFCAdapterUnsetPreferredApp(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcCardEmulation, &out);
void RespondAsync(const char* msg);
private:
- void GetDefaultAdapter(const picojson::value& args, picojson::object& out);
- void SetExclusiveMode(const picojson::value& args, picojson::object& out);
- void SetPowered(const picojson::value& args, picojson::object& out);
- void GetPowered(const picojson::value& args, picojson::object& out);
- void CardEmulationModeSetter(const picojson::value& args, picojson::object& out);
- void CardEmulationModeGetter(const picojson::value& args, picojson::object& out);
- void ActiveSecureElementSetter(const picojson::value& args, picojson::object& out);
- void ActiveSecureElementGetter(const picojson::value& args, picojson::object& out);
- void SetTagListener(const picojson::value& args, picojson::object& out);
- void PeerIsConnectedGetter(const picojson::value& args, picojson::object& out);
- void SetPeerListener(const picojson::value& args, picojson::object& out);
- void UnsetTagListener(const picojson::value& args, picojson::object& out);
- void UnsetPeerListener(const picojson::value& args, picojson::object& out);
- void AddCardEmulationModeChangeListener(const picojson::value& args, picojson::object& out);
- void RemoveCardEmulationModeChangeListener(const picojson::value& args, picojson::object& out);
- void AddTransactionEventListener(const picojson::value& args, picojson::object& out);
- void RemoveTransactionEventListener(const picojson::value& args, picojson::object& out);
- void AddActiveSecureElementChangeListener(const picojson::value& args, picojson::object& out);
- void RemoveActiveSecureElementChangeListener(const picojson::value& args, picojson::object& out);
- void GetCachedMessage(const picojson::value& args, picojson::object& out);
- void SetExclusiveModeForTransaction(const picojson::value& args, picojson::object& out);
- void ReadNDEF(const picojson::value& args, picojson::object& out);
- void WriteNDEF(const picojson::value& args, picojson::object& out);
- void Transceive(const picojson::value& args, picojson::object& out);
- void SetReceiveNDEFListener(const picojson::value& args, picojson::object& out);
- void UnsetReceiveNDEFListener(const picojson::value& args, picojson::object& out);
- void SendNDEF(const picojson::value& args, picojson::object& out);
- void ToByte(const picojson::value& args, picojson::object& out);
+ void NFCManagerGetDefaultAdapter(const picojson::value& args, picojson::object& out);
+ void NFCManagerSetExclusiveMode(const picojson::value& args, picojson::object& out);
+ void NFCAdapterSetPowered(const picojson::value& args, picojson::object& out);
+ void NFCAdapterGetPowered(const picojson::value& args, picojson::object& out);
+ void NFCAdapterCardEmulationModeSetter(const picojson::value& args, picojson::object& out);
+ void NFCAdapterCardEmulationModeGetter(const picojson::value& args, picojson::object& out);
+ void NFCAdapterActiveSecureElementSetter(const picojson::value& args, picojson::object& out);
+ void NFCAdapterActiveSecureElementGetter(const picojson::value& args, picojson::object& out);
+ void NFCAdapterSetTagListener(const picojson::value& args, picojson::object& out);
+ void NFCAdapterPeerIsConnectedGetter(const picojson::value& args, picojson::object& out);
+ void NFCAdapterSetPeerListener(const picojson::value& args, picojson::object& out);
+ void NFCAdapterUnsetTagListener(const picojson::value& args, picojson::object& out);
+ void NFCAdapterUnsetPeerListener(const picojson::value& args, picojson::object& out);
+ void NFCAdapterAddCardEmulationModeChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void NFCAdapterRemoveCardEmulationModeChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void NFCAdapterAddTransactionEventListener(const picojson::value& args, picojson::object& out);
+ void NFCAdapterRemoveTransactionEventListener(const picojson::value& args, picojson::object& out);
+ void NFCAdapterAddActiveSecureElementChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void NFCAdapterRemoveActiveSecureElementChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void NFCAdapterGetCachedMessage(const picojson::value& args, picojson::object& out);
+ void NFCAdapterSetExclusiveModeForTransaction(const picojson::value& args, picojson::object& out);
+ void NFCTagReadNDEF(const picojson::value& args, picojson::object& out);
+ void NFCTagWriteNDEF(const picojson::value& args, picojson::object& out);
+ void NFCTagTransceive(const picojson::value& args, picojson::object& out);
+ void NFCPeerSetReceiveNDEFListener(const picojson::value& args, picojson::object& out);
+ void NFCPeerUnsetReceiveNDEFListener(const picojson::value& args, picojson::object& out);
+ void NFCPeerSendNDEF(const picojson::value& args, picojson::object& out);
// Message related methods
- void NDEFMessageContructor(const picojson::value& args, picojson::object& out);
+ void NDEFMessageConstructor(const picojson::value& args, picojson::object& out);
void NDEFMessageToByte(const picojson::value& args, picojson::object& out);
- void NDEFRecordContructor(const picojson::value& args, picojson::object& out);
- void NDEFRecordTextContructor(const picojson::value& args, picojson::object& out);
- void NDEFRecordURIContructor(const picojson::value& args, picojson::object& out);
- void NDEFRecordMediaContructor(const picojson::value& args, picojson::object& out);
+ void NDEFRecordConstructor(const picojson::value& args, picojson::object& out);
+ void NDEFRecordTextConstructor(const picojson::value& args, picojson::object& out);
+ void NDEFRecordURIConstructor(const picojson::value& args, picojson::object& out);
+ void NDEFRecordMediaConstructor(const picojson::value& args, picojson::object& out);
// NFCTag attributes getters
- void TagTypeGetter(const picojson::value& args, picojson::object& out);
- void TagIsSupportedNDEFGetter(const picojson::value& args, picojson::object& out);
- void TagNDEFSizeGetter(const picojson::value& args, picojson::object& out);
- void TagPropertiesGetter(const picojson::value& args, picojson::object& out);
- void TagIsConnectedGetter(const picojson::value& args, picojson::object& out);
+ void NFCTagTypeGetter(const picojson::value& args, picojson::object& out);
+ void NFCTagIsSupportedNDEFGetter(const picojson::value& args, picojson::object& out);
+ void NFCTagNDEFSizeGetter(const picojson::value& args, picojson::object& out);
+ void NFCTagPropertiesGetter(const picojson::value& args, picojson::object& out);
+ void NFCTagIsConnectedGetter(const picojson::value& args, picojson::object& out);
// HCE related methods
- void AddHCEEventListener(const picojson::value& args, picojson::object& out);
- void RemoveHCEEventListener(const picojson::value& args, picojson::object& out);
- void SendHostAPDUResponse(const picojson::value& args, picojson::object& out);
- void IsActivatedHandlerForAID(const picojson::value& args, picojson::object& out);
- void IsActivatedHandlerForCategory(const picojson::value& args, picojson::object& out);
- void RegisterAID(const picojson::value& args, picojson::object& out);
- void UnregisterAID(const picojson::value& args, picojson::object& out);
- void GetAIDsForCategory(const picojson::value& args, picojson::object& out);
- void SetPreferredApp(const picojson::value& args, picojson::object& out);
- void UnsetPreferredApp(const picojson::value& args, picojson::object& out);
+ void NFCAdapterAddHCEEventListener(const picojson::value& args, picojson::object& out);
+ void NFCAdapterRemoveHCEEventListener(const picojson::value& args, picojson::object& out);
+ void NFCAdapterSendHostAPDUResponse(const picojson::value& args, picojson::object& out);
+ void NFCAdapterIsActivatedHandlerForAID(const picojson::value& args, picojson::object& out);
+ void NFCAdapterIsActivatedHandlerForCategory(const picojson::value& args, picojson::object& out);
+ void NFCAdapterRegisterAID(const picojson::value& args, picojson::object& out);
+ void NFCAdapterUnregisterAID(const picojson::value& args, picojson::object& out);
+ void NFCAdapterGetAIDsForCategory(const picojson::value& args, picojson::object& out);
+ void NFCAdapterSetPreferredApp(const picojson::value& args, picojson::object& out);
+ void NFCAdapterUnsetPreferredApp(const picojson::value& args, picojson::object& out);
};
} // namespace nfc
notification: args.notification
};
- var result = native_.callSync('NotificationManager_post', data);
+ var result = native_.callSync('NotificationManagerPost', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
notification: args.notification
};
- var result = native_.callSync('NotificationManager_update', data);
+ var result = native_.callSync('NotificationManagerUpdate', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
id: args.id
};
- var result = native_.callSync('NotificationManager_remove', data);
+ var result = native_.callSync('NotificationManagerRemove', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
};
NotificationManager.prototype.removeAll = function() {
- var result = native_.callSync('NotificationManager_removeAll', {});
+ var result = native_.callSync('NotificationManagerRemoveAll', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
id: args.id
};
- var result = native_.callSync('NotificationManager_get', data);
+ var result = native_.callSync('NotificationManagerGet', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
id: args.id
};
- var result = native_.callSync('NotificationManager_get', data);
+ var result = native_.callSync('NotificationManagerGet', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
'Use getAllNotifications() instead.'
);
- var result = native_.callSync('NotificationManager_getAll', {});
+ var result = native_.callSync('NotificationManagerGetAll', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
};
NotificationManager.prototype.getAllNotifications = function() {
- var result = native_.callSync('NotificationManager_getAll', {
+ var result = native_.callSync('NotificationManagerGetAll', {
//add marker for UserNotification implementation
newImpl: true
});
}
args.color = convertColorToInt(args.color);
- var result = native_.callSync('NotificationManager_playLEDCustomEffect', args);
+ var result = native_.callSync('NotificationManagerPlayLEDCustomEffect', args);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
* Stops the custom effect of the service LED that is located to the front of a device.
*/
NotificationManager.prototype.stopLEDCustomEffect = function() {
- var result = native_.callSync('NotificationManager_stopLEDCustomEffect');
+ var result = native_.callSync('NotificationManagerStopLEDCustomEffect');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
//add marker for UserNotification implementation
args.newImpl = args.notification instanceof tizen.UserNotification;
- var result = native_.callSync('NotificationManager_saveNotificationAsTemplate', args);
+ var result = native_.callSync('NotificationManagerSaveNotificationAsTemplate', args);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
var result = native_.callSync(
- 'NotificationManager_createNotificationFromTemplate',
+ 'NotificationManagerCreateNotificationFromTemplate',
args
);
ScopeLogger();
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&NotificationInstance::x, this, _1, _2));
- REGISTER_SYNC("NotificationManager_get", NotificationManagerGet);
- REGISTER_SYNC("NotificationManager_update", NotificationManagerUpdate);
- REGISTER_SYNC("NotificationManager_remove", NotificationManagerRemove);
- REGISTER_SYNC("NotificationManager_getAll", NotificationManagerGetAll);
- REGISTER_SYNC("NotificationManager_post", NotificationManagerPost);
- REGISTER_SYNC("NotificationManager_removeAll", NotificationManagerRemoveAll);
- REGISTER_SYNC("NotificationManager_playLEDCustomEffect", NotificationManagerPlayLEDCustomEffect);
- REGISTER_SYNC("NotificationManager_stopLEDCustomEffect", NotificationManagerStopLEDCustomEffect);
- REGISTER_SYNC("NotificationManager_saveNotificationAsTemplate", NotificationManagerSaveTemplate);
- REGISTER_SYNC("NotificationManager_createNotificationFromTemplate",
- NotificationManagerCreateFromTemplate);
-#undef REGISTER_SYNC
+
+#define REGISTER_METHOD(M) \
+ RegisterSyncHandler(#M, std::bind(&NotificationInstance::M, this, _1, _2))
+ REGISTER_METHOD(NotificationManagerGet);
+ REGISTER_METHOD(NotificationManagerUpdate);
+ REGISTER_METHOD(NotificationManagerRemove);
+ REGISTER_METHOD(NotificationManagerGetAll);
+ REGISTER_METHOD(NotificationManagerPost);
+ REGISTER_METHOD(NotificationManagerRemoveAll);
+ REGISTER_METHOD(NotificationManagerPlayLEDCustomEffect);
+ REGISTER_METHOD(NotificationManagerStopLEDCustomEffect);
+ REGISTER_METHOD(NotificationManagerSaveNotificationAsTemplate);
+ REGISTER_METHOD(NotificationManagerCreateNotificationFromTemplate);
+#undef REGISTER_METHOD
manager_ = NotificationManager::GetInstance();
}
}
}
-void NotificationInstance::NotificationManagerSaveTemplate(const picojson::value& args,
- picojson::object& out) {
+void NotificationInstance::NotificationManagerSaveNotificationAsTemplate(
+ const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out);
}
}
-void NotificationInstance::NotificationManagerCreateFromTemplate(const picojson::value& args,
- picojson::object& out) {
+void NotificationInstance::NotificationManagerCreateNotificationFromTemplate(
+ const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out);
picojson::value val{picojson::object{}};
void NotificationManagerPlayLEDCustomEffect(const picojson::value& args, picojson::object& out);
void NotificationManagerStopLEDCustomEffect(const picojson::value& args, picojson::object& out);
- void NotificationManagerSaveTemplate(const picojson::value& args, picojson::object& out);
- void NotificationManagerCreateFromTemplate(const picojson::value& args, picojson::object& out);
+ void NotificationManagerSaveNotificationAsTemplate(const picojson::value& args,
+ picojson::object& out);
+ void NotificationManagerCreateNotificationFromTemplate(const picojson::value& args,
+ picojson::object& out);
};
} // namespace notification
set: function() {},
get: function() {
if (undefined === totalSize) {
- var result = native_.callSync('PackageManager_getTotalSize', {
+ var result = native_.callSync('PackageManagerGetTotalSize', {
id: this.id
});
if (native_.isSuccess(result)) {
set: function() {},
get: function() {
if (undefined === dataSize) {
- var result = native_.callSync('PackageManager_getDataSize', {
+ var result = native_.callSync('PackageManagerGetDataSize', {
id: this.id
});
if (native_.isSuccess(result)) {
progressCallbackId: progressCallbackId
};
- var result = native_.call('PackageManager_install', nativeParam, function(result) {
+ var result = native_.call('PackageManagerInstall', nativeParam, function(result) {
if (native_.isFailure(result)) {
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
delete callbacks[result['progressCallbackId']];
var nativeParam = { id: args.id, progressCallbackId: progressCallbackId };
- var result = native_.call('PackageManager_uninstall', nativeParam, function(result) {
+ var result = native_.call('PackageManagerUninstall', nativeParam, function(result) {
if (native_.isFailure(result)) {
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
delete callbacks[result['progressCallbackId']];
}
]);
- var result = native_.call('PackageManager_getPackagesInfo', {}, function(result) {
+ var result = native_.call('PackageManagerGetPackagesInfo', {}, function(result) {
if (native_.isSuccess(result)) {
for (var i = 0; i < result.informationArray.length; i++) {
result.informationArray[i] = new PackageInformation(
nativeParam['id'] = args.id;
}
- var result = native_.callSync('PackageManager_getPackageInfo', nativeParam);
+ var result = native_.callSync('PackageManagerGetPackageInfo', nativeParam);
if (native_.isSuccess(result)) {
return new PackageInformation(native_.getResultObject(result));
} else {
}
]);
- var result = native_.callSync('PackageManager_setPackageInfoEventListener', {});
+ var result = native_.callSync('PackageManagerSetPackageInfoEventListener', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
var nativeParam = {};
var result = native_.callSync(
- 'PackageManager_unsetPackageInfoEventListener',
+ 'PackageManagerUnsetPackageInfoEventListener',
nativeParam
);
};
picojson::array array_data;
- ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_ALLAPP, PackageAppInfoCb,
- &array_data);
+ ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_APP_COMPONENT_TYPE_ALL,
+ PackageAppInfoCb, &array_data);
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
LoggerE("Failed to get app info: %d (%s)", ret, get_error_message(ret));
return false;
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&PackageInstance::x, this, _1, _2));
- REGISTER_SYNC("PackageManager_setPackageInfoEventListener",
- PackageManagerSetpackageinfoeventlistener);
- REGISTER_SYNC("PackageManager_install", PackageManagerInstall);
- REGISTER_SYNC("PackageManager_getPackagesInfo", PackageManagerGetpackagesinfo);
- REGISTER_SYNC("PackageManager_uninstall", PackageManagerUninstall);
- REGISTER_SYNC("PackageManager_unsetPackageInfoEventListener",
- PackageManagerUnsetpackageinfoeventlistener);
- REGISTER_SYNC("PackageManager_getPackageInfo", PackageManagerGetpackageinfo);
- REGISTER_SYNC("PackageManager_getTotalSize", PackageManagerGetTotalSize);
- REGISTER_SYNC("PackageManager_getDataSize", PackageManagerGetDataSize);
-#undef REGISTER_SYNC
+
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&PackageInstance::M, this, _1, _2))
+ REGISTER_METHOD(PackageManagerSetPackageInfoEventListener);
+ REGISTER_METHOD(PackageManagerInstall);
+ REGISTER_METHOD(PackageManagerGetPackagesInfo);
+ REGISTER_METHOD(PackageManagerUninstall);
+ REGISTER_METHOD(PackageManagerUnsetPackageInfoEventListener);
+ REGISTER_METHOD(PackageManagerGetPackageInfo);
+ REGISTER_METHOD(PackageManagerGetTotalSize);
+ REGISTER_METHOD(PackageManagerGetDataSize);
+#undef REGISTER_METHOD
}
PackageInstance::~PackageInstance() {
ReportSuccess(out);
}
-void PackageInstance::PackageManagerGetpackagesinfo(const picojson::value& args,
+void PackageInstance::PackageManagerGetPackagesInfo(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
TaskQueue::GetInstance().Queue<PackageUserData>(PackageThreadWork, PackageAfterWork, userData);
ReportSuccess(out);
}
-void PackageInstance::PackageManagerGetpackageinfo(const picojson::value& args,
+void PackageInstance::PackageManagerGetPackageInfo(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
Instance::PostMessage(this, result.serialize().c_str());
}
-void PackageInstance::PackageManagerSetpackageinfoeventlistener(const picojson::value& args,
+void PackageInstance::PackageManagerSetPackageInfoEventListener(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
ReportSuccess(out);
}
-void PackageInstance::PackageManagerUnsetpackageinfoeventlistener(const picojson::value& args,
+void PackageInstance::PackageManagerUnsetPackageInfoEventListener(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
void PackageManagerInstall(const picojson::value& args, picojson::object& out);
void PackageManagerUninstall(const picojson::value& args, picojson::object& out);
- void PackageManagerGetpackagesinfo(const picojson::value& args, picojson::object& out);
- void PackageManagerGetpackageinfo(const picojson::value& args, picojson::object& out);
+ void PackageManagerGetPackagesInfo(const picojson::value& args, picojson::object& out);
+ void PackageManagerGetPackageInfo(const picojson::value& args, picojson::object& out);
void PackageManagerGetTotalSize(const picojson::value& args, picojson::object& out);
void PackageManagerGetDataSize(const picojson::value& args, picojson::object& out);
- void PackageManagerSetpackageinfoeventlistener(const picojson::value& args,
+ void PackageManagerSetPackageInfoEventListener(const picojson::value& args,
picojson::object& out);
- void PackageManagerUnsetpackageinfoeventlistener(const picojson::value& args,
+ void PackageManagerUnsetPackageInfoEventListener(const picojson::value& args,
picojson::object& out);
};
function PlayerUtil() {}
PlayerUtil.prototype.getLatencyMode = function() {
- var result = native.callSync('PlayerUtil_getLatencyMode', {});
+ var result = native.callSync('PlayerUtilGetLatencyMode', {});
if (native.isSuccess(result)) {
return native.getResultObject(result);
var callArgs = {};
callArgs.latencyMode = args.latencyMode;
- var result = native.callSync('PlayerUtil_setLatencyMode', callArgs);
+ var result = native.callSync('PlayerUtilSetLatencyMode', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&PlayerUtilInstance::x, this, _1))
-
- REGISTER_SYNC("PlayerUtil_getLatencyMode", GetLatencyMode);
- REGISTER_SYNC("PlayerUtil_setLatencyMode", SetLatencyMode);
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&PlayerUtilInstance::M, this, _1))
+ REGISTER_METHOD(PlayerUtilGetLatencyMode);
+ REGISTER_METHOD(PlayerUtilSetLatencyMode);
+#undef REGISTER_METHOD
}
PlayerUtilInstance::~PlayerUtilInstance() {
ScopeLogger();
}
-common::TizenResult PlayerUtilInstance::GetLatencyMode(const picojson::object& args) {
+common::TizenResult PlayerUtilInstance::PlayerUtilGetLatencyMode(const picojson::object& args) {
ScopeLogger();
Ewk_Context* context = ewk_context_default_get();
return common::TizenSuccess{picojson::value{PlayerUtilUtils::FromLatencyMode(latency_mode)}};
}
-common::TizenResult PlayerUtilInstance::SetLatencyMode(const picojson::object& args) {
+common::TizenResult PlayerUtilInstance::PlayerUtilSetLatencyMode(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kLatencyMode);
virtual ~PlayerUtilInstance();
private:
- common::TizenResult GetLatencyMode(const picojson::object& args);
- common::TizenResult SetLatencyMode(const picojson::object& args);
+ common::TizenResult PlayerUtilGetLatencyMode(const picojson::object& args);
+ common::TizenResult PlayerUtilSetLatencyMode(const picojson::object& args);
};
} // namespace playerutil
state: args.state
};
- var ret = native_.callSync('PowerManager_request', nativeParam);
+ var ret = native_.callSync('PowerManagerRequest', nativeParam);
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
resource: args.resource
};
- var ret = native_.callSync('PowerManager_release', nativeParam);
+ var ret = native_.callSync('PowerManagerRelease', nativeParam);
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
]);
if (!screenStateChangeListener.isListenerSet()) {
- var ret = native_.callSync('PowerManager_setScreenStateChangeListener', {});
+ var ret = native_.callSync('PowerManagerSetScreenStateChangeListener', {});
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
*/
PowerManager.prototype.unsetScreenStateChangeListener = function() {
if (screenStateChangeListener.isListenerSet()) {
- var ret = native_.callSync('PowerManager_unsetScreenStateChangeListener', {});
+ var ret = native_.callSync('PowerManagerUnsetScreenStateChangeListener', {});
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
* @return {number} Current screen brightness value.
*/
PowerManager.prototype.getScreenBrightness = function() {
- var ret = native_.callSync('PowerManager_getScreenBrightness', {});
+ var ret = native_.callSync('PowerManagerGetScreenBrightness', {});
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
} else {
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var ret = native_.callSync('PowerManager_setScreenBrightness', {
+ var ret = native_.callSync('PowerManagerSetScreenBrightness', {
brightness: args.brightness
});
if (native_.isFailure(ret)) {
* @return {boolean} true if screen is on.
*/
PowerManager.prototype.isScreenOn = function() {
- var ret = native_.callSync('PowerManager_isScreenOn', {});
+ var ret = native_.callSync('PowerManagerIsScreenOn', {});
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
} else {
* Restores the screen brightness to the system default setting value.
*/
PowerManager.prototype.restoreScreenBrightness = function() {
- var ret = native_.callSync('PowerManager_restoreScreenBrightness', {});
+ var ret = native_.callSync('PowerManagerRestoreScreenBrightness', {});
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
'next release. Use request() instead.'
);
- var ret = native_.callSync('PowerManager_turnScreenOn', {});
+ var ret = native_.callSync('PowerManagerTurnScreenOn', {});
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
'next release. Use release() instead.'
);
- var ret = native_.callSync('PowerManager_turnScreenOff', {});
+ var ret = native_.callSync('PowerManagerTurnScreenOff', {});
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&PowerInstance::x, this, _1, _2));
- REGISTER_SYNC("PowerManager_request", Request);
- REGISTER_SYNC("PowerManager_release", Release);
- REGISTER_SYNC("PowerManager_setScreenStateChangeListener", SetScreenStateChangeListener);
- REGISTER_SYNC("PowerManager_unsetScreenStateChangeListener", UnsetScreenStateChangeListener);
- REGISTER_SYNC("PowerManager_getScreenBrightness", GetScreenBrightness);
- REGISTER_SYNC("PowerManager_setScreenBrightness", SetScreenBrightness);
- REGISTER_SYNC("PowerManager_isScreenOn", IsScreenOn);
- REGISTER_SYNC("PowerManager_restoreScreenBrightness", RestoreScreenBrightness);
- REGISTER_SYNC("PowerManager_turnScreenOn", TurnScreenOn);
- REGISTER_SYNC("PowerManager_turnScreenOff", TurnScreenOff);
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&PowerInstance::M, this, _1, _2))
+ REGISTER_METHOD(PowerManagerRequest);
+ REGISTER_METHOD(PowerManagerRelease);
+ REGISTER_METHOD(PowerManagerSetScreenStateChangeListener);
+ REGISTER_METHOD(PowerManagerUnsetScreenStateChangeListener);
+ REGISTER_METHOD(PowerManagerGetScreenBrightness);
+ REGISTER_METHOD(PowerManagerSetScreenBrightness);
+ REGISTER_METHOD(PowerManagerIsScreenOn);
+ REGISTER_METHOD(PowerManagerRestoreScreenBrightness);
+ REGISTER_METHOD(PowerManagerTurnScreenOn);
+ REGISTER_METHOD(PowerManagerTurnScreenOff);
+#undef REGISTER_METHOD
}
PowerInstance::~PowerInstance() {
return; \
}
-void PowerInstance::Request(const picojson::value& args, picojson::object& out) {
+void PowerInstance::PowerManagerRequest(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegePower, &out);
}
}
-void PowerInstance::Release(const picojson::value& args, picojson::object& out) {
+void PowerInstance::PowerManagerRelease(const picojson::value& args, picojson::object& out) {
ScopeLogger();
const std::string& resource = args.get("resource").get<std::string>();
PlatformResult result = manager_.Release(kPowerResourceMap.at(resource));
}
}
-void PowerInstance::SetScreenStateChangeListener(const picojson::value& args,
- picojson::object& out) {
+void PowerInstance::PowerManagerSetScreenStateChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
PlatformResult result = manager_.SetScreenStateChangeListener();
if (result.IsError()) {
}
}
-void PowerInstance::UnsetScreenStateChangeListener(const picojson::value& args,
- picojson::object& out) {
+void PowerInstance::PowerManagerUnsetScreenStateChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
PlatformResult result = manager_.UnsetScreenStateChangeListener();
if (result.IsError()) {
}
}
-void PowerInstance::GetScreenBrightness(const picojson::value& args, picojson::object& out) {
+void PowerInstance::PowerManagerGetScreenBrightness(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
double brightness;
PlatformResult result = manager_.GetScreenBrightness(&brightness);
}
}
-void PowerInstance::SetScreenBrightness(const picojson::value& args, picojson::object& out) {
+void PowerInstance::PowerManagerSetScreenBrightness(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegePower, &out);
}
}
-void PowerInstance::IsScreenOn(const picojson::value& args, picojson::object& out) {
+void PowerInstance::PowerManagerIsScreenOn(const picojson::value& args, picojson::object& out) {
ScopeLogger();
bool state = false;
PlatformResult result = manager_.IsScreenOn(&state);
}
}
-void PowerInstance::RestoreScreenBrightness(const picojson::value& args, picojson::object& out) {
+void PowerInstance::PowerManagerRestoreScreenBrightness(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
PlatformResult result = manager_.RestoreScreenBrightness();
if (result.IsError()) {
}
}
-void PowerInstance::TurnScreenOn(const picojson::value& args, picojson::object& out) {
+void PowerInstance::PowerManagerTurnScreenOn(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: turnScreenOn() is deprecated and will be removed from next release. "
}
}
-void PowerInstance::TurnScreenOff(const picojson::value& args, picojson::object& out) {
+void PowerInstance::PowerManagerTurnScreenOff(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: turnScreenOff() is deprecated and will be removed from next release. "
virtual ~PowerInstance();
private:
- void Request(const picojson::value& args, picojson::object& out);
- void Release(const picojson::value& args, picojson::object& out);
- void SetScreenStateChangeListener(const picojson::value& args, picojson::object& out);
- void UnsetScreenStateChangeListener(const picojson::value& args, picojson::object& out);
- void GetScreenBrightness(const picojson::value& args, picojson::object& out);
- void SetScreenBrightness(const picojson::value& args, picojson::object& out);
- void IsScreenOn(const picojson::value& args, picojson::object& out);
- void RestoreScreenBrightness(const picojson::value& args, picojson::object& out);
- void TurnScreenOn(const picojson::value& args, picojson::object& out);
- void TurnScreenOff(const picojson::value& args, picojson::object& out);
+ void PowerManagerRequest(const picojson::value& args, picojson::object& out);
+ void PowerManagerRelease(const picojson::value& args, picojson::object& out);
+ void PowerManagerSetScreenStateChangeListener(const picojson::value& args, picojson::object& out);
+ void PowerManagerUnsetScreenStateChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void PowerManagerGetScreenBrightness(const picojson::value& args, picojson::object& out);
+ void PowerManagerSetScreenBrightness(const picojson::value& args, picojson::object& out);
+ void PowerManagerIsScreenOn(const picojson::value& args, picojson::object& out);
+ void PowerManagerRestoreScreenBrightness(const picojson::value& args, picojson::object& out);
+ void PowerManagerTurnScreenOn(const picojson::value& args, picojson::object& out);
+ void PowerManagerTurnScreenOff(const picojson::value& args, picojson::object& out);
PowerManager manager_;
};
privilege: args.privilege
};
- var result = native_.callSync('PPMManager_checkPermission', callArgs);
+ var result = native_.callSync('PPMManagerCheckPermission', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
privileges: args.privileges
};
- var result = native_.callSync('PPMManager_checkPermissions', callArgs);
+ var result = native_.callSync('PPMManagerCheckPermissions', callArgs);
var data = [];
privilege: args.privilege
};
- var result = native_.call('PPMManager_requestPermission', callArgs, callback);
+ var result = native_.call('PPMManagerRequestPermission', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
privileges: args.privileges
};
- var result = native_.call('PPMManager_requestPermissions', callArgs, callback);
+ var result = native_.call('PPMManagerRequestPermissions', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER(c, x) RegisterSyncHandler(c, std::bind(&PPMInstance::x, this, _1, _2));
-
- REGISTER("PPMManager_checkPermission", checkPermission);
- REGISTER("PPMManager_checkPermissions", checkPermissions);
- REGISTER("PPMManager_requestPermission", requestPermission);
- REGISTER("PPMManager_requestPermissions", requestPermissions);
-
-#undef REGISTER
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&PPMInstance::M, this, _1, _2))
+ REGISTER_METHOD(PPMManagerCheckPermission);
+ REGISTER_METHOD(PPMManagerCheckPermissions);
+ REGISTER_METHOD(PPMManagerRequestPermission);
+ REGISTER_METHOD(PPMManagerRequestPermissions);
+#undef REGISTER_METHOD
}
PPMInstance::~PPMInstance() {
common::Instance::PostMessage(data->_instance, event.serialize().c_str());
}
-void PPMInstance::checkPermission(const picojson::value& args, picojson::object& out) {
+void PPMInstance::PPMManagerCheckPermission(const picojson::value& args, picojson::object& out) {
ScopeLogger();
const std::string& privilege = args.get("privilege").get<std::string>();
LoggerD("Checking privilege: %s ", privilege.c_str());
ReportSuccess(picojson::value(CheckResultToString(result)), out);
}
-void PPMInstance::checkPermissions(const picojson::value& args, picojson::object& out) {
+void PPMInstance::PPMManagerCheckPermissions(const picojson::value& args, picojson::object& out) {
ScopeLogger();
const picojson::array& privileges = args.get("privileges").get<picojson::array>();
ReportSuccess(result_array, out);
}
-void PPMInstance::requestPermission(const picojson::value& args, picojson::object& out) {
+void PPMInstance::PPMManagerRequestPermission(const picojson::value& args, picojson::object& out) {
ScopeLogger();
const double callback_id = args.get("callbackId").get<double>();
ReportSuccess(out);
}
-void PPMInstance::requestPermissions(const picojson::value& args, picojson::object& out) {
+void PPMInstance::PPMManagerRequestPermissions(const picojson::value& args, picojson::object& out) {
ScopeLogger();
const double callback_id = args.get("callbackId").get<double>();
virtual ~PPMInstance();
private:
- void checkPermission(const picojson::value& args, picojson::object& out);
- void checkPermissions(const picojson::value& args, picojson::object& out);
- void requestPermission(const picojson::value& args, picojson::object& out);
- void requestPermissions(const picojson::value& args, picojson::object& out);
+ void PPMManagerCheckPermission(const picojson::value& args, picojson::object& out);
+ void PPMManagerCheckPermissions(const picojson::value& args, picojson::object& out);
+ void PPMManagerRequestPermission(const picojson::value& args, picojson::object& out);
+ void PPMManagerRequestPermissions(const picojson::value& args, picojson::object& out);
static common::PlatformResult convertError(int err, const std::string& message = "");
static std::string CheckResultToString(ppm_check_result_e result);
}
};
- var result = native_.call('PreferenceManager_getAll', {}, callback);
+ var result = native_.call('PreferenceManagerGetAll', {}, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
{ name: 'value', type: types_.SIMPLE_TYPE }
]);
- var result = native_.callSync('PreferenceManager_setValue', {
+ var result = native_.callSync('PreferenceManagerSetValue', {
key: args.key,
value: args.value
});
PreferenceManager.prototype.getValue = function() {
var args = validator_.validateArgs(arguments, [{ name: 'key', type: types_.STRING }]);
- var result = native_.callSync('PreferenceManager_getValue', { key: args.key });
+ var result = native_.callSync('PreferenceManagerGetValue', { key: args.key });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
PreferenceManager.prototype.remove = function() {
var args = validator_.validateArgs(arguments, [{ name: 'key', type: types_.STRING }]);
- var result = native_.callSync('PreferenceManager_remove', { key: args.key });
+ var result = native_.callSync('PreferenceManagerRemove', { key: args.key });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
};
PreferenceManager.prototype.removeAll = function() {
- var result = native_.callSync('PreferenceManager_removeAll', {});
+ var result = native_.callSync('PreferenceManagerRemoveAll', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
PreferenceManager.prototype.exists = function() {
var args = validator_.validateArgs(arguments, [{ name: 'key', type: types_.STRING }]);
- var result = native_.callSync('PreferenceManager_exists', { key: args.key });
+ var result = native_.callSync('PreferenceManagerExists', { key: args.key });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
{ name: 'listener', type: types_.FUNCTION }
]);
- var result = native_.callSync('PreferenceManager_setChangeListener', {
+ var result = native_.callSync('PreferenceManagerSetChangeListener', {
key: args.key
});
if (native_.isFailure(result)) {
PreferenceManager.prototype.unsetChangeListener = function() {
var args = validator_.validateArgs(arguments, [{ name: 'key', type: types_.STRING }]);
- var result = native_.callSync('PreferenceManager_unsetChangeListener', {
+ var result = native_.callSync('PreferenceManagerUnsetChangeListener', {
key: args.key
});
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER(c, x) RegisterSyncHandler(c, std::bind(&PreferenceInstance::x, this, _1));
- REGISTER("PreferenceManager_setValue", SetValue);
- REGISTER("PreferenceManager_getValue", GetValue);
- REGISTER("PreferenceManager_remove", Remove);
- REGISTER("PreferenceManager_removeAll", RemoveAll);
- REGISTER("PreferenceManager_exists", Exists);
- REGISTER("PreferenceManager_setChangeListener", SetChangeListener);
- REGISTER("PreferenceManager_unsetChangeListener", UnsetChangeListener);
-#undef REGISTER
-#define REGISTER_ASYNC(c, x) RegisterHandler(c, std::bind(&PreferenceInstance::x, this, _1, _2));
- REGISTER_ASYNC("PreferenceManager_getAll", GetAll);
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&PreferenceInstance::M, this, _1))
+ REGISTER_METHOD(PreferenceManagerSetValue);
+ REGISTER_METHOD(PreferenceManagerGetValue);
+ REGISTER_METHOD(PreferenceManagerRemove);
+ REGISTER_METHOD(PreferenceManagerRemoveAll);
+ REGISTER_METHOD(PreferenceManagerExists);
+ REGISTER_METHOD(PreferenceManagerSetChangeListener);
+ REGISTER_METHOD(PreferenceManagerUnsetChangeListener);
+#undef REGISTER_METHOD
+
+#define REGISTER_METHOD(M) RegisterHandler(#M, std::bind(&PreferenceInstance::M, this, _1, _2))
+ REGISTER_METHOD(PreferenceManagerGetAll);
+#undef REGISTER_METHOD
}
PreferenceInstance::~PreferenceInstance() {
ScopeLogger();
}
-common::TizenResult PreferenceInstance::GetAll(const picojson::object& args,
- const common::AsyncToken& token) {
+common::TizenResult PreferenceInstance::PreferenceManagerGetAll(const picojson::object& args,
+ const common::AsyncToken& token) {
ScopeLogger();
return manager_.GetAll(SimplePost(token));
}
-common::TizenResult PreferenceInstance::SetValue(const picojson::object& args) {
+common::TizenResult PreferenceInstance::PreferenceManagerSetValue(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kKey)
return manager_.SetValue(key, value);
}
-common::TizenResult PreferenceInstance::GetValue(const picojson::object& args) {
+common::TizenResult PreferenceInstance::PreferenceManagerGetValue(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kKey)
return manager_.GetValue(key);
}
-common::TizenResult PreferenceInstance::Remove(const picojson::object& args) {
+common::TizenResult PreferenceInstance::PreferenceManagerRemove(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kKey)
return manager_.Remove(key);
}
-common::TizenResult PreferenceInstance::RemoveAll(const picojson::object& args) {
+common::TizenResult PreferenceInstance::PreferenceManagerRemoveAll(const picojson::object& args) {
ScopeLogger();
return manager_.RemoveAll();
}
-common::TizenResult PreferenceInstance::Exists(const picojson::object& args) {
+common::TizenResult PreferenceInstance::PreferenceManagerExists(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kKey)
return manager_.Exists(key);
}
-common::TizenResult PreferenceInstance::SetChangeListener(const picojson::object& args) {
+common::TizenResult PreferenceInstance::PreferenceManagerSetChangeListener(
+ const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kKey)
const auto& key = args.find(kKey)->second.get<std::string>();
return manager_.SetChangeListener(key, callback);
}
-common::TizenResult PreferenceInstance::UnsetChangeListener(const picojson::object& args) {
+common::TizenResult PreferenceInstance::PreferenceManagerUnsetChangeListener(
+ const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kKey)
virtual ~PreferenceInstance();
private:
- common::TizenResult GetAll(const picojson::object& args, const common::AsyncToken& token);
- common::TizenResult SetValue(const picojson::object& args);
- common::TizenResult GetValue(const picojson::object& args);
- common::TizenResult Remove(const picojson::object& args);
- common::TizenResult RemoveAll(const picojson::object& args);
- common::TizenResult Exists(const picojson::object& args);
- common::TizenResult SetChangeListener(const picojson::object& args);
- common::TizenResult UnsetChangeListener(const picojson::object& args);
+ common::TizenResult PreferenceManagerGetAll(const picojson::object& args,
+ const common::AsyncToken& token);
+ common::TizenResult PreferenceManagerSetValue(const picojson::object& args);
+ common::TizenResult PreferenceManagerGetValue(const picojson::object& args);
+ common::TizenResult PreferenceManagerRemove(const picojson::object& args);
+ common::TizenResult PreferenceManagerRemoveAll(const picojson::object& args);
+ common::TizenResult PreferenceManagerExists(const picojson::object& args);
+ common::TizenResult PreferenceManagerSetChangeListener(const picojson::object& args);
+ common::TizenResult PreferenceManagerUnsetChangeListener(const picojson::object& args);
PreferenceManager manager_;
};
}
]);
- var ret = native.call('Push_registerService', {}, function(msg) {
+ var ret = native.call('PushRegisterService', {}, function(msg) {
if (msg.error) {
if (validatorType.isFunction(data.errorCallback)) {
data.errorCallback(native.getErrorObject(msg));
}
]);
- var ret = native.call('Push_registerApplication', {}, function(msg) {
+ var ret = native.call('PushRegisterApplication', {}, function(msg) {
if (msg.error) {
if (validatorType.isFunction(data.errorCallback)) {
data.errorCallback(native.getErrorObject(msg));
nullable: true
}
]);
- var result = native.call('Push_unregisterService', {}, function(msg) {
+ var result = native.call('PushUnregisterService', {}, function(msg) {
if (msg.error) {
if (validatorType.isFunction(data.errorCallback)) {
data.errorCallback(native.getErrorObject(msg));
nullable: true
}
]);
- var result = native.call('Push_unregisterApplication', {}, function(msg) {
+ var result = native.call('PushUnregisterApplication', {}, function(msg) {
if (msg.error) {
if (validatorType.isFunction(data.errorCallback)) {
data.errorCallback(native.getErrorObject(msg));
type: validator.Types.FUNCTION
}
]);
- var ret = native.callSync('Push_connectService', {});
+ var ret = native.callSync('PushConnectService', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
}
nullable: true
}
]);
- var result = native.call('Push_connect', {}, function(msg) {
+ var result = native.call('PushConnect', {}, function(msg) {
// in case of error, call errorCallback
if (msg.error) {
if (validatorType.isFunction(data.errorCallback)) {
PushManager.prototype.disconnectService = function() {
privUtils_.warn(
- 'DEPRECATION WARNING: disconnectService() is deprecated and will be removed ' +
+ 'DEPRECATION WARNING: disconnectService() is deprecated and will be removed' +
'from next release. Use disconnect() instead.'
);
- var ret = native.callSync('Push_disconnectService', {});
+ var ret = native.callSync('PushDisconnectService', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
}
};
PushManager.prototype.disconnect = function() {
- var ret = native.callSync('Push_disconnect', {});
+ var ret = native.callSync('PushDisconnect', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
}
};
PushManager.prototype.getRegistrationId = function() {
- var ret = native.callSync('Push_getRegistrationId', {});
+ var ret = native.callSync('PushGetRegistrationId', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
}
};
PushManager.prototype.getUnreadNotifications = function() {
- var ret = native.callSync('Push_getUnreadNotifications', {});
+ var ret = native.callSync('PushGetUnreadNotifications', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
}
};
PushManager.prototype.getPushMessage = function() {
- var ret = native.callSync('Push_getPushMessage', {});
+ var ret = native.callSync('PushGetPushMessage', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
} else {
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_ASYNC(c, func) RegisterSyncHandler(c, func);
-#define REGISTER_SYNC(c, func) RegisterSyncHandler(c, func);
-
- REGISTER_ASYNC("Push_registerService", std::bind(&PushInstance::registerService, this, _1, _2));
- REGISTER_ASYNC("Push_registerApplication",
- std::bind(&PushInstance::registerApplication, this, _1, _2));
- REGISTER_ASYNC("Push_unregisterService",
- std::bind(&PushInstance::unregisterService, this, _1, _2));
- REGISTER_ASYNC("Push_unregisterApplication",
- std::bind(&PushInstance::unregisterApplication, this, _1, _2));
- REGISTER_SYNC("Push_connectService", std::bind(&PushInstance::connectService, this, _1, _2));
- REGISTER_SYNC("Push_connect", std::bind(&PushInstance::connect, this, _1, _2));
- REGISTER_SYNC("Push_disconnectService",
- std::bind(&PushInstance::disconnectService, this, _1, _2));
- REGISTER_SYNC("Push_disconnect", std::bind(&PushInstance::disconnect, this, _1, _2));
- REGISTER_SYNC("Push_getRegistrationId",
- std::bind(&PushInstance::getRegistrationId, this, _1, _2));
- REGISTER_SYNC("Push_getUnreadNotifications",
- std::bind(&PushInstance::getUnreadNotifications, this, _1, _2));
- REGISTER_SYNC("Push_getPushMessage", std::bind(&PushInstance::getPushMessage, this, _1, _2));
-
-#undef REGISTER_ASYNC
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&PushInstance::M, this, _1, _2))
+ REGISTER_METHOD(PushRegisterService);
+ REGISTER_METHOD(PushRegisterApplication);
+ REGISTER_METHOD(PushUnregisterService);
+ REGISTER_METHOD(PushUnregisterApplication);
+ REGISTER_METHOD(PushConnectService);
+ REGISTER_METHOD(PushConnect);
+ REGISTER_METHOD(PushDisconnectService);
+ REGISTER_METHOD(PushDisconnect);
+ REGISTER_METHOD(PushGetRegistrationId);
+ REGISTER_METHOD(PushGetUnreadNotifications);
+ REGISTER_METHOD(PushGetPushMessage);
+#undef REGISTER_METHOD
impl = new PushManager(this);
}
-void PushInstance::registerService(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushRegisterService(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. "
}
}
-void PushInstance::registerApplication(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushRegisterApplication(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
}
}
-void PushInstance::unregisterService(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushUnregisterService(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: unregisterService() is deprecated and will be removed from next "
}
}
-void PushInstance::unregisterApplication(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushUnregisterApplication(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
}
}
-void PushInstance::connectService(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushConnectService(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: connectService() is deprecated and will be removed from next release. "
}
}
-void PushInstance::connect(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushConnect(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
}
}
-void PushInstance::disconnectService(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushDisconnectService(const picojson::value& args, picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: disconnectService() is deprecated and will be removed from next "
}
}
-void PushInstance::disconnect(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushDisconnect(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
}
}
-void PushInstance::getRegistrationId(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushGetRegistrationId(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
}
}
-void PushInstance::getUnreadNotifications(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushGetUnreadNotifications(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
}
}
-void PushInstance::getPushMessage(const picojson::value& args, picojson::object& out) {
+void PushInstance::PushGetPushMessage(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
virtual void onDeregister(double callbackId, common::PlatformResult result);
private:
- void registerService(const picojson::value& args, picojson::object& out);
- void registerApplication(const picojson::value& args, picojson::object& out);
- void unregisterService(const picojson::value& args, picojson::object& out);
- void unregisterApplication(const picojson::value& args, picojson::object& out);
- void connectService(const picojson::value& args, picojson::object& out);
- void connect(const picojson::value& args, picojson::object& out);
- void disconnectService(const picojson::value& args, picojson::object& out);
- void disconnect(const picojson::value& args, picojson::object& out);
- void getRegistrationId(const picojson::value& args, picojson::object& out);
- void getUnreadNotifications(const picojson::value& args, picojson::object& out);
- void getPushMessage(const picojson::value& args, picojson::object& out);
+ void PushRegisterService(const picojson::value& args, picojson::object& out);
+ void PushRegisterApplication(const picojson::value& args, picojson::object& out);
+ void PushUnregisterService(const picojson::value& args, picojson::object& out);
+ void PushUnregisterApplication(const picojson::value& args, picojson::object& out);
+ void PushConnectService(const picojson::value& args, picojson::object& out);
+ void PushConnect(const picojson::value& args, picojson::object& out);
+ void PushDisconnectService(const picojson::value& args, picojson::object& out);
+ void PushDisconnect(const picojson::value& args, picojson::object& out);
+ void PushGetRegistrationId(const picojson::value& args, picojson::object& out);
+ void PushGetUnreadNotifications(const picojson::value& args, picojson::object& out);
+ void PushGetPushMessage(const picojson::value& args, picojson::object& out);
PushManager* impl;
};
});
function muteGetter() {
- var ret = native_.callSync('FMRadio_MuteGetter');
+ var ret = native_.callSync('FMRadioMuteGetter');
return native_.getResultObject(ret);
}
type: types_.BOOLEAN
}
]);
- native_.callSync('FMRadio_MuteSetter', args);
+ native_.callSync('FMRadioMuteSetter', args);
}
function radioStateGetter() {
- var ret = native_.callSync('FMRadio_RadioStateGetter');
+ var ret = native_.callSync('FMRadioRadioStateGetter');
return native_.getResultObject(ret);
}
function isAntennaConnectedGetter() {
- var ret = native_.callSync('FMRadio_IsAntennaConnectedGetter');
+ var ret = native_.callSync('FMRadioIsAntennaConnectedGetter');
return native_.getResultObject(ret);
}
function signalStrengthGetter() {
- var ret = native_.callSync('FMRadio_SignalStrengthGetter');
+ var ret = native_.callSync('FMRadioSignalStrengthGetter');
return native_.getResultObject(ret);
}
function frequencyGetter() {
- var ret = native_.callSync('FMRadio_FrequencyGetter');
+ var ret = native_.callSync('FMRadioFrequencyGetter');
return native_.getResultObject(ret);
}
}
]);
- native_.call('FMRadio_SeekUp', {}, function(result) {
+ native_.call('FMRadioSeekUp', {}, function(result) {
if (native_.isFailure(result)) {
if (args.errorCallback) args.errorCallback(native_.getErrorObject(result));
} else {
'Frequency out of bounds'
);
}
- var result = native_.callSync('FMRadio_Start', {
+ var result = native_.callSync('FMRadioStart', {
frequency: args.frequency ? args.frequency : this.frequencyLowerBound
});
if (native_.isFailure(result)) {
}
]);
- native_.call('FMRadio_SeekDown', {}, function(result) {
+ native_.call('FMRadioSeekDown', {}, function(result) {
if (native_.isFailure(result)) {
if (args.errorCallback) args.errorCallback(native_.getErrorObject(result));
} else {
scanCBmanager.FMRadioScanSet(args.radioScanCallback.onfrequencyfound);
- native_.call('FMRadio_ScanStart', {}, function(result) {
+ native_.call('FMRadioScanStart', {}, function(result) {
if (native_.isFailure(result)) {
if (args.errorCallback) args.errorCallback(native_.getErrorObject(result));
} else {
};
FMRadioManager.prototype.stop = function() {
- var ret = native_.callSync('FMRadio_Stop');
+ var ret = native_.callSync('FMRadioStop');
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
}
]);
- native_.call('FMRadio_ScanStop', {}, function(result) {
+ native_.call('FMRadioScanStop', {}, function(result) {
if (native_.isFailure(result)) {
if (args.errorCallback) args.errorCallback(native_.getErrorObject(result));
} else {
args.interruptCallback.oninterruptfinished
);
- var ret = native_.callSync('FMRadio_SetFMRadioInterruptedListener');
+ var ret = native_.callSync('SetFMRadioInterruptedListener');
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
FMRadioManager.prototype.unsetFMRadioInterruptedListener = function() {
interruptedCBmanager.FMRadioInterruptedUnset();
- var ret = native_.callSync('FMRadio_UnsetFMRadioInterruptedListener');
+ var ret = native_.callSync('UnsetFMRadioInterruptedListener');
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
]);
antennaCBmanager.FMRadioAntennaChangeSet(args.changeCallback);
- var ret = native_.callSync('FMRadio_SetAntennaChangeListener');
+ var ret = native_.callSync('FMRadioSetAntennaChangeListener');
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
FMRadioManager.prototype.unsetAntennaChangeListener = function() {
antennaCBmanager.FMRadioAntennaUnset();
- var ret = native_.callSync('FMRadio_UnsetAntennaChangeListener');
+ var ret = native_.callSync('FMRadioUnsetAntennaChangeListener');
if (native_.isFailure(ret)) {
throw native_.getErrorObject(ret);
}
*/
#include "radio/radio_instance.h"
-
-#include <functional>
-
#include <radio.h>
-
+#include <functional>
#include "common/logger.h"
namespace extension {
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&RadioInstance::x, this, _1, _2));
-
- REGISTER_SYNC("FMRadio_Start", Start);
- REGISTER_SYNC("FMRadio_Stop", Stop);
- REGISTER_SYNC("FMRadio_SetFMRadioInterruptedListener", SetFMRadioInterruptedListener);
- REGISTER_SYNC("FMRadio_UnsetFMRadioInterruptedListener", UnsetFMRadioInterruptedListener);
- REGISTER_SYNC("FMRadio_SetAntennaChangeListener", SetAntennaChangeListener);
- REGISTER_SYNC("FMRadio_UnsetAntennaChangeListener", UnsetAntennaChangeListener);
- REGISTER_SYNC("FMRadio_FrequencyGetter", FrequencyGetter);
- REGISTER_SYNC("FMRadio_SignalStrengthGetter", SignalStrengthGetter);
- REGISTER_SYNC("FMRadio_IsAntennaConnectedGetter", AntennaGetter);
- REGISTER_SYNC("FMRadio_RadioStateGetter", StateGetter);
- REGISTER_SYNC("FMRadio_MuteSetter", MuteSetter);
- REGISTER_SYNC("FMRadio_MuteGetter", MuteGetter);
-#undef REGISTER_SYNC
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&RadioInstance::x, this, _1, _2));
- REGISTER_ASYNC("FMRadio_SeekUp", SeekUp);
- REGISTER_ASYNC("FMRadio_SeekDown", SeekDown);
- REGISTER_ASYNC("FMRadio_ScanStart", ScanStart);
- REGISTER_ASYNC("FMRadio_ScanStop", ScanStop);
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&RadioInstance::M, this, _1, _2))
+ REGISTER_METHOD(FMRadioStart);
+ REGISTER_METHOD(FMRadioStop);
+ REGISTER_METHOD(SetFMRadioInterruptedListener);
+ REGISTER_METHOD(UnsetFMRadioInterruptedListener);
+ REGISTER_METHOD(FMRadioSetAntennaChangeListener);
+ REGISTER_METHOD(FMRadioUnsetAntennaChangeListener);
+ REGISTER_METHOD(FMRadioFrequencyGetter);
+ REGISTER_METHOD(FMRadioSignalStrengthGetter);
+ REGISTER_METHOD(FMRadioIsAntennaConnectedGetter);
+ REGISTER_METHOD(FMRadioRadioStateGetter);
+ REGISTER_METHOD(FMRadioMuteSetter);
+ REGISTER_METHOD(FMRadioMuteGetter);
+
+ REGISTER_METHOD(FMRadioSeekUp);
+ REGISTER_METHOD(FMRadioSeekDown);
+ REGISTER_METHOD(FMRadioScanStart);
+ REGISTER_METHOD(FMRadioScanStop);
+#undef REGISTER_METHOD
}
RadioInstance::~RadioInstance() {
ScopeLogger();
}
-void RadioInstance::MuteGetter(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioMuteGetter(const picojson::value& args, picojson::object& out) {
ScopeLogger();
ReportSuccess(picojson::value(manager_.IsMuted()), out);
}
-void RadioInstance::MuteSetter(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioMuteSetter(const picojson::value& args, picojson::object& out) {
ScopeLogger();
manager_.SetMute(args.get("mute").get<bool>());
ReportSuccess(out);
}
-void RadioInstance::AntennaGetter(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioIsAntennaConnectedGetter(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
ReportSuccess(picojson::value(manager_.HasAntenna()), out);
}
-void RadioInstance::StateGetter(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioRadioStateGetter(const picojson::value& args, picojson::object& out) {
ScopeLogger();
ReportSuccess(picojson::value(manager_.GetState()), out);
}
-void RadioInstance::FrequencyGetter(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioFrequencyGetter(const picojson::value& args, picojson::object& out) {
ScopeLogger();
ReportSuccess(picojson::value(manager_.GetFrequency()), out);
}
-void RadioInstance::SignalStrengthGetter(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioSignalStrengthGetter(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
ReportSuccess(picojson::value(manager_.GetSignalStrength()), out);
}
-void RadioInstance::SeekUp(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioSeekUp(const picojson::value& args, picojson::object& out) {
ScopeLogger();
manager_.SeekUp(args.get("callbackId").get<double>());
ReportSuccess(out);
}
-void RadioInstance::SeekDown(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioSeekDown(const picojson::value& args, picojson::object& out) {
ScopeLogger();
manager_.SeekDown(args.get("callbackId").get<double>());
ReportSuccess(out);
}
-void RadioInstance::Start(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioStart(const picojson::value& args, picojson::object& out) {
ScopeLogger();
PlatformResult result = manager_.Start(args.get("frequency").get<double>());
}
}
-void RadioInstance::Stop(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioStop(const picojson::value& args, picojson::object& out) {
ScopeLogger();
PlatformResult result = manager_.Stop();
}
}
-void RadioInstance::ScanStart(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioScanStart(const picojson::value& args, picojson::object& out) {
ScopeLogger();
manager_.ScanStart(args.get("callbackId").get<double>());
ReportSuccess(out);
}
-void RadioInstance::ScanStop(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioScanStop(const picojson::value& args, picojson::object& out) {
ScopeLogger();
manager_.ScanStop(args.get("callbackId").get<double>());
ReportSuccess(out);
}
}
-void RadioInstance::SetAntennaChangeListener(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioSetAntennaChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
PlatformResult result = manager_.SetAntennaChangeListener();
}
}
-void RadioInstance::UnsetAntennaChangeListener(const picojson::value& args, picojson::object& out) {
+void RadioInstance::FMRadioUnsetAntennaChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
PlatformResult result = manager_.UnsetAntennaChangeListener();
virtual ~RadioInstance();
private:
- void MuteGetter(const picojson::value& args, picojson::object& out);
- void MuteSetter(const picojson::value& args, picojson::object& out);
- void FrequencyGetter(const picojson::value& args, picojson::object& out);
- void SignalStrengthGetter(const picojson::value& args, picojson::object& out);
- void AntennaGetter(const picojson::value& args, picojson::object& out);
- void StateGetter(const picojson::value& args, picojson::object& out);
- void SeekUp(const picojson::value& args, picojson::object& out);
- void SeekDown(const picojson::value& args, picojson::object& out);
- void ScanStart(const picojson::value& args, picojson::object& out);
- void ScanStop(const picojson::value& args, picojson::object& out);
- void Start(const picojson::value& args, picojson::object& out);
- void Stop(const picojson::value& args, picojson::object& out);
+ void FMRadioMuteGetter(const picojson::value& args, picojson::object& out);
+ void FMRadioMuteSetter(const picojson::value& args, picojson::object& out);
+ void FMRadioFrequencyGetter(const picojson::value& args, picojson::object& out);
+ void FMRadioSignalStrengthGetter(const picojson::value& args, picojson::object& out);
+ void FMRadioIsAntennaConnectedGetter(const picojson::value& args, picojson::object& out);
+ void FMRadioRadioStateGetter(const picojson::value& args, picojson::object& out);
+ void FMRadioSeekUp(const picojson::value& args, picojson::object& out);
+ void FMRadioSeekDown(const picojson::value& args, picojson::object& out);
+ void FMRadioScanStart(const picojson::value& args, picojson::object& out);
+ void FMRadioScanStop(const picojson::value& args, picojson::object& out);
+ void FMRadioStart(const picojson::value& args, picojson::object& out);
+ void FMRadioStop(const picojson::value& args, picojson::object& out);
void SetFMRadioInterruptedListener(const picojson::value& args, picojson::object& out);
void UnsetFMRadioInterruptedListener(const picojson::value& args, picojson::object& out);
- void SetAntennaChangeListener(const picojson::value& args, picojson::object& out);
- void UnsetAntennaChangeListener(const picojson::value& args, picojson::object& out);
+ void FMRadioSetAntennaChangeListener(const picojson::value& args, picojson::object& out);
+ void FMRadioUnsetAntennaChangeListener(const picojson::value& args, picojson::object& out);
FMRadioManager manager_;
};
var id = this.nextId;
if (!this.nativeSet) {
this.native.addListener(this.listenerName, this.onListenerCalled.bind(this));
- var result = this.native.callSync('SEService_registerSEListener');
+ var result = this.native.callSync('SEServiceRegisterSEListener');
if (this.native.isFailure(result)) {
throw this.native.getErrorObject(result);
}
}
if (this.nativeSet && type_utils.isEmptyObject(this.listeners)) {
- var result = this.native.callSync('SEService_unregisterSEListener');
+ var result = this.native.callSync('SEServiceUnregisterSEListener');
if (this.native.isFailure(result)) {
throw this.native.getErrorObject(result);
}
}
};
- var result = native_.call('SEService_getReaders', {}, callback);
+ var result = native_.call('SEServiceGetReaders', {}, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
var SEServiceShutdown = function() {
xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.SECUREELEMENT);
- var result = native_.callSync('SEService_shutdown', {});
+ var result = native_.callSync('SEServiceShutdown', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
set: function() {},
get: function() {
var callArgs = { handle: reader_handle };
- var result = native_.callSync('SEReader_isPresent', callArgs);
+ var result = native_.callSync('SEReaderIsPresent', callArgs);
if (native_.isFailure(result)) {
privUtils_.log(
'SEReader_isPresent error: ' + native_.getErrorObject(result)
Reader.prototype.getName = function() {
var callArgs = { handle: this._handle };
- var result = native_.callSync('SEReader_getName', callArgs);
+ var result = native_.callSync('SEReaderGetName', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
var callArgs = { handle: this._handle };
- var result = native_.call('SEReader_openSession', callArgs, callback);
+ var result = native_.call('SEReaderOpenSession', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
Reader.prototype.closeSessions = function() {
var callArgs = { handle: this._handle };
- var result = native_.callSync('SEReader_closeSessions', callArgs);
+ var result = native_.callSync('SEReaderCloseSessions', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
Channel.prototype.close = function() {
var callArgs = { handle: this._handle };
- var result = native_.callSync('SEChannel_close', callArgs);
+ var result = native_.callSync('SEChannelClose', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
command: args.command
};
- var result = native_.call('SEChannel_transmit', callArgs, callback);
+ var result = native_.call('SEChannelTransmit', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
Channel.prototype.getSelectResponse = function() {
var callArgs = { handle: this._handle };
- var result = native_.callSync('SEChannel_getSelectResponse', callArgs);
+ var result = native_.callSync('SEChannelGetSelectResponse', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
set: function() {},
get: function() {
var callArgs = { handle: session_handle };
- var result = native_.callSync('SESession_isClosed', callArgs);
+ var result = native_.callSync('SESessionIsClosed', callArgs);
if (native_.isFailure(result)) {
privUtils_.log(
'SESession_isClosed error: ' + native_.getErrorObject(result)
aid: args.aid
};
- var result = native_.call('SESession_openBasicChannel', callArgs, callback);
+ var result = native_.call('SESessionOpenBasicChannel', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
aid: args.aid
};
- var result = native_.call('SESession_openLogicalChannel', callArgs, callback);
+ var result = native_.call('SESessionOpenLogicalChannel', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
Session.prototype.getATR = function() {
var callArgs = { handle: this._handle };
- var result = native_.callSync('SESession_getATR', callArgs);
+ var result = native_.callSync('SESessionGetATR', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
} else {
Session.prototype.close = function() {
var callArgs = { handle: this._handle };
- var result = native_.callSync('SESession_close', callArgs);
+ var result = native_.callSync('SESessionClose', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
Session.prototype.closeChannels = function() {
var callArgs = { handle: this._handle };
- var result = native_.callSync('SESession_closeChannels', callArgs);
+ var result = native_.callSync('SESessionCloseChannels', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&SecureElementInstance::x, this, _1));
-
- REGISTER_SYNC("SEService_registerSEListener", RegisterSEListener);
- REGISTER_SYNC("SEService_unregisterSEListener", UnregisterSEListener);
- REGISTER_SYNC("SEService_shutdown", Shutdown);
- REGISTER_SYNC("SEReader_getName", GetName);
- REGISTER_SYNC("SEReader_isPresent", IsPresent);
- REGISTER_SYNC("SEReader_closeSessions", CloseSessions);
- REGISTER_SYNC("SESession_getATR", GetATR);
- REGISTER_SYNC("SESession_isClosed", IsSessionClosed);
- REGISTER_SYNC("SESession_close", CloseSession);
- REGISTER_SYNC("SESession_closeChannels", CloseChannels);
- REGISTER_SYNC("SEChannel_close", CloseChannel);
- REGISTER_SYNC("SEChannel_getSelectResponse", GetSelectResponse);
-#undef REGISTER_SYNC
-
-#define REGISTER(c, x) RegisterHandler(c, std::bind(&SecureElementInstance::x, this, _1, _2));
-
- REGISTER("SEService_getReaders", GetReaders);
- REGISTER("SEReader_openSession", OpenSession);
- REGISTER("SESession_openBasicChannel", OpenBasicChannel);
- REGISTER("SESession_openLogicalChannel", OpenLogicalChannel);
- REGISTER("SEChannel_transmit", Transmit);
-#undef REGISTER
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&SecureElementInstance::M, this, _1))
+ REGISTER_METHOD(SEServiceRegisterSEListener);
+ REGISTER_METHOD(SEServiceUnregisterSEListener);
+ REGISTER_METHOD(SEServiceShutdown);
+ REGISTER_METHOD(SEReaderGetName);
+ REGISTER_METHOD(SEReaderIsPresent);
+ REGISTER_METHOD(SEReaderCloseSessions);
+ REGISTER_METHOD(SESessionGetATR);
+ REGISTER_METHOD(SESessionIsClosed);
+ REGISTER_METHOD(SESessionClose);
+ REGISTER_METHOD(SESessionCloseChannels);
+ REGISTER_METHOD(SEChannelClose);
+ REGISTER_METHOD(SEChannelGetSelectResponse);
+#undef REGISTER_METHOD
+
+#define REGISTER_METHOD(M) RegisterHandler(#M, std::bind(&SecureElementInstance::M, this, _1, _2))
+ REGISTER_METHOD(SEServiceGetReaders);
+ REGISTER_METHOD(SEReaderOpenSession);
+ REGISTER_METHOD(SESessionOpenBasicChannel);
+ REGISTER_METHOD(SESessionOpenLogicalChannel);
+ REGISTER_METHOD(SEChannelTransmit);
+#undef REGISTER_METHOD
if (SMARTCARD_ERROR_NONE == smartcard_initialize()) {
is_initialized_ = true;
}
// Service methods
-TizenResult SecureElementInstance::GetReaders(picojson::object const& args,
- const common::AsyncToken& token) {
+TizenResult SecureElementInstance::SEServiceGetReaders(picojson::object const& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess();
}
-TizenResult SecureElementInstance::RegisterSEListener(picojson::object const& args) {
+TizenResult SecureElementInstance::SEServiceRegisterSEListener(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess();
}
-TizenResult SecureElementInstance::UnregisterSEListener(picojson::object const& args) {
+TizenResult SecureElementInstance::SEServiceUnregisterSEListener(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess();
}
-TizenResult SecureElementInstance::Shutdown(picojson::object const& args) {
+TizenResult SecureElementInstance::SEServiceShutdown(picojson::object const& args) {
ScopeLogger();
UnregisterListener();
}
// Reader methods
-TizenResult SecureElementInstance::GetName(picojson::object const& args) {
+TizenResult SecureElementInstance::SEReaderGetName(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess(picojson::value(name));
}
-TizenResult SecureElementInstance::IsPresent(picojson::object const& args) {
+TizenResult SecureElementInstance::SEReaderIsPresent(picojson::object const& args) {
ScopeLogger();
int reader = static_cast<int>(args.find(kHandle)->second.get<double>());
return TizenSuccess(picojson::value(is_present));
}
-TizenResult SecureElementInstance::OpenSession(picojson::object const& args,
- const common::AsyncToken& token) {
+TizenResult SecureElementInstance::SEReaderOpenSession(picojson::object const& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess();
}
-TizenResult SecureElementInstance::CloseSessions(picojson::object const& args) {
+TizenResult SecureElementInstance::SEReaderCloseSessions(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess(val);
}
-TizenResult SecureElementInstance::OpenBasicChannel(picojson::object const& args,
- const common::AsyncToken& token) {
+TizenResult SecureElementInstance::SESessionOpenBasicChannel(picojson::object const& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess();
}
-TizenResult SecureElementInstance::OpenLogicalChannel(picojson::object const& args,
- const common::AsyncToken& token) {
+TizenResult SecureElementInstance::SESessionOpenLogicalChannel(picojson::object const& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess();
}
-TizenResult SecureElementInstance::GetATR(picojson::object const& args) {
+TizenResult SecureElementInstance::SESessionGetATR(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess(response);
}
-TizenResult SecureElementInstance::IsSessionClosed(picojson::object const& args) {
+TizenResult SecureElementInstance::SESessionIsClosed(picojson::object const& args) {
ScopeLogger();
int session = static_cast<int>(args.find(kHandle)->second.get<double>());
return TizenSuccess(picojson::value(is_closed));
}
-TizenResult SecureElementInstance::CloseSession(picojson::object const& args) {
+TizenResult SecureElementInstance::SESessionClose(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess();
}
-TizenResult SecureElementInstance::CloseChannels(picojson::object const& args) {
+TizenResult SecureElementInstance::SESessionCloseChannels(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
}
// Channel methods
-TizenResult SecureElementInstance::CloseChannel(picojson::object const& args) {
+TizenResult SecureElementInstance::SEChannelClose(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess();
}
-TizenResult SecureElementInstance::Transmit(picojson::object const& args,
- const common::AsyncToken& token) {
+TizenResult SecureElementInstance::SEChannelTransmit(picojson::object const& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
return TizenSuccess();
}
-TizenResult SecureElementInstance::GetSelectResponse(picojson::object const& args) {
+TizenResult SecureElementInstance::SEChannelGetSelectResponse(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeSecureElement);
private:
/* Service methods */
- common::TizenResult GetReaders(picojson::object const& args, const common::AsyncToken& token);
- common::TizenResult RegisterSEListener(picojson::object const& args);
- common::TizenResult UnregisterSEListener(picojson::object const& args);
- common::TizenResult Shutdown(picojson::object const& args);
+ common::TizenResult SEServiceGetReaders(picojson::object const& args,
+ const common::AsyncToken& token);
+ common::TizenResult SEServiceRegisterSEListener(picojson::object const& args);
+ common::TizenResult SEServiceUnregisterSEListener(picojson::object const& args);
+ common::TizenResult SEServiceShutdown(picojson::object const& args);
/* Reader methods */
- common::TizenResult GetName(picojson::object const& args);
- common::TizenResult IsPresent(picojson::object const& args);
- common::TizenResult OpenSession(picojson::object const& args, const common::AsyncToken& token);
- common::TizenResult CloseSessions(picojson::object const& args);
+ common::TizenResult SEReaderGetName(picojson::object const& args);
+ common::TizenResult SEReaderIsPresent(picojson::object const& args);
+ common::TizenResult SEReaderOpenSession(picojson::object const& args,
+ const common::AsyncToken& token);
+ common::TizenResult SEReaderCloseSessions(picojson::object const& args);
/* Session methods */
common::TizenResult IsBasicChannel(int channel, picojson::value& val);
- common::TizenResult OpenBasicChannel(picojson::object const& args,
- const common::AsyncToken& token);
- common::TizenResult OpenLogicalChannel(picojson::object const& args,
- const common::AsyncToken& token);
- common::TizenResult GetATR(picojson::object const& args);
- common::TizenResult IsSessionClosed(picojson::object const& args);
- common::TizenResult CloseSession(picojson::object const& args);
- common::TizenResult CloseChannels(picojson::object const& args);
+ common::TizenResult SESessionOpenBasicChannel(picojson::object const& args,
+ const common::AsyncToken& token);
+ common::TizenResult SESessionOpenLogicalChannel(picojson::object const& args,
+ const common::AsyncToken& token);
+ common::TizenResult SESessionGetATR(picojson::object const& args);
+ common::TizenResult SESessionIsClosed(picojson::object const& args);
+ common::TizenResult SESessionClose(picojson::object const& args);
+ common::TizenResult SESessionCloseChannels(picojson::object const& args);
/* Channel methods */
- common::TizenResult CloseChannel(picojson::object const& args);
- common::TizenResult Transmit(picojson::object const& args, const common::AsyncToken& token);
- common::TizenResult GetSelectResponse(picojson::object const& args);
+ common::TizenResult SEChannelClose(picojson::object const& args);
+ common::TizenResult SEChannelTransmit(picojson::object const& args,
+ const common::AsyncToken& token);
+ common::TizenResult SEChannelGetSelectResponse(picojson::object const& args);
common::TizenResult Deinitialize();
common::TizenResult UnregisterListener();
// sensor not started
this.state = SensorStates.STARTING;
var thisObject = this;
- native_.call('Sensor_start', { sensorType: thisObject.sensorType }, function(
+ native_.call('SensorStart', { sensorType: thisObject.sensorType }, function(
result
) {
if (native_.isFailure(result)) {
SensorListener.prototype.stop = function() {
if (SensorStates.NOT_STARTED != this.state) {
- var result = native_.callSync('Sensor_stop', { sensorType: this.sensorType });
+ var result = native_.callSync('SensorStop', { sensorType: this.sensorType });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
this.callbackBatchLatency != batchLatency
) {
//call platform only if there was no listener registered or parameters changed
- var result = native_.callSync('Sensor_setChangeListener', {
+ var result = native_.callSync('SensorSetChangeListener', {
sensorType: this.sensorType,
interval: interval,
batchLatency: batchLatency
if (this.callback) {
//unregister in platform only if there is callback registered
this.callback = undefined;
- var result = native_.callSync('Sensor_unsetChangeListener', {
+ var result = native_.callSync('SensorUnsetChangeListener', {
sensorType: this.sensorType
});
if (native_.isFailure(result)) {
}
}, 0);
} else {
- native_.call('Sensor_getData', { type: thisObj.sensorType }, function(result) {
+ native_.call('SensorGetData', { type: thisObj.sensorType }, function(result) {
if (native_.isFailure(result)) {
if (!T_.isNullOrUndefined(errorCallback)) {
errorCallback(native_.getErrorObject(result));
native_.addListener(SENSOR_CHANGED_LISTENER, _listener);
function getAvailableSensors() {
- var result = native_.callSync('SensorService_getAvailableSensors', {});
+ var result = native_.callSync('SensorServiceGetAvailableSensors', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
var result = native_.call(
- 'Sensor_getSensorHardwareInfo',
+ 'SensorGetSensorHardwareInfo',
{ type: this.sensorType },
callback
);
// prettier-ignore
GyroscopeRotationVectorSensor.prototype.getGyroscopeRotationVectorSensorData =
- function() {
- var args = validator_.validateArgs(arguments, [
- {
- name: 'successCallback',
- type: types_.FUNCTION
- },
- {
- name: 'errorCallback',
- type: types_.FUNCTION,
- optional: true,
- nullable: true
- }
- ]);
+function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
- _sensorListeners[this.sensorType].getData(
- args.successCallback,
- errorWrapper.bind(args)
- );
- };
+ _sensorListeners[this.sensorType].getData(
+ args.successCallback,
+ errorWrapper.bind(args)
+ );
+};
//// LinearAccelerationSensor
var LinearAccelerationSensor = function(data) {
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&SensorInstance::x, this, _1, _2));
- REGISTER_SYNC("SensorService_getAvailableSensors", GetAvailableSensors);
- REGISTER_SYNC("Sensor_stop", SensorStop);
- REGISTER_SYNC("Sensor_setChangeListener", SensorSetChangeListener);
- REGISTER_SYNC("Sensor_unsetChangeListener", SensorUnsetChangeListener);
-#undef REGISTER_SYNC
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&SensorInstance::x, this, _1, _2));
- REGISTER_ASYNC("Sensor_start", SensorStart);
- REGISTER_ASYNC("Sensor_getData", SensorGetData);
- REGISTER_ASYNC("Sensor_getSensorHardwareInfo", GetSensorHardwareInfo);
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&SensorInstance::M, this, _1, _2))
+ REGISTER_METHOD(SensorServiceGetAvailableSensors);
+ REGISTER_METHOD(SensorStop);
+ REGISTER_METHOD(SensorSetChangeListener);
+ REGISTER_METHOD(SensorUnsetChangeListener);
+ REGISTER_METHOD(SensorStart);
+ REGISTER_METHOD(SensorGetData);
+ REGISTER_METHOD(SensorGetSensorHardwareInfo);
+#undef REGISTER_METHOD
}
SensorInstance::~SensorInstance() {
ScopeLogger();
}
-void SensorInstance::GetAvailableSensors(const picojson::value& args, picojson::object& out) {
+void SensorInstance::SensorServiceGetAvailableSensors(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
service_.GetAvailableSensors(out);
}
service_.GetSensorData(args, out);
}
-void SensorInstance::GetSensorHardwareInfo(const picojson::value& args, picojson::object& out) {
+void SensorInstance::SensorGetSensorHardwareInfo(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
service_.GetSensorHardwareInfo(args, out);
virtual ~SensorInstance();
private:
- void GetAvailableSensors(const picojson::value& args, picojson::object& out);
+ void SensorServiceGetAvailableSensors(const picojson::value& args, picojson::object& out);
void SensorStop(const picojson::value& args, picojson::object& out);
void SensorSetChangeListener(const picojson::value& args, picojson::object& out);
void SensorUnsetChangeListener(const picojson::value& args, picojson::object& out);
void SensorStart(const picojson::value& args, picojson::object& out);
void SensorGetData(const picojson::value& args, picojson::object& out);
- void GetSensorHardwareInfo(const picojson::value& args, picojson::object& out);
+ void SensorGetSensorHardwareInfo(const picojson::value& args, picojson::object& out);
SensorService service_;
};
var id = this.nextId;
if (!this.nativeSet) {
this.native.addListener(this.listenerName, this.onListenerCalled.bind(this));
- this.native.callSync('SoundManager_addDeviceStateChangeListener');
+ this.native.callSync('SoundManagerAddDeviceStateChangeListener');
this.nativeSet = true;
}
delete this.listeners[watchId];
if (this.nativeSet && type_.isEmptyObject(this.listeners)) {
- this.native.callSync('SoundManager_removeDeviceStateChangeListener');
+ this.native.callSync('SoundManagerRemoveDeviceStateChangeListener');
this.native.removeListener(this.listenerName);
this.nativeSet = false;
}
function SoundManager() {}
SoundManager.prototype.getSoundMode = function() {
- var result = native_.callSync('SoundManager_getSoundMode');
+ var result = native_.callSync('SoundManagerGetSoundMode');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
if (args.volume < 0 || args.volume > 1) {
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- var result = native_.callSync('SoundManager_setVolume', args);
+ var result = native_.callSync('SoundManagerSetVolume', args);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
{ name: 'type', type: types_.ENUM, values: Object.keys(SoundType) }
]);
- var result = native_.callSync('SoundManager_getVolume', args);
+ var result = native_.callSync('SoundManagerGetVolume', args);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
_soundModeChangeListener = args.callback;
native_.addListener('SoundModeChangeListener', _soundModeChangeListenerCallback);
- var result = native_.callSync('SoundManager_setSoundModeChangeListener', {});
+ var result = native_.callSync('SoundManagerSetSoundModeChangeListener', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
SoundManager.prototype.unsetSoundModeChangeListener = function() {
native_.removeListener('SoundModeChangeListener', _soundModeChangeListenerCallback);
- var result = native_.callSync('SoundManager_unsetSoundModeChangeListener', {});
+ var result = native_.callSync('SoundManagerUnsetSoundModeChangeListener', {});
_soundModeChangeListener = undefined;
_volumeChangeListener = args.callback;
native_.addListener('VolumeChangeListener', _volumeChangeListenerCallback);
- var result = native_.callSync('SoundManager_setVolumeChangeListener', {});
+ var result = native_.callSync('SoundManagerSetVolumeChangeListener', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
SoundManager.prototype.unsetVolumeChangeListener = function() {
native_.removeListener('VolumeChangeListener', _volumeChangeListenerCallback);
- var result = native_.callSync('SoundManager_unsetVolumeChangeListener', {});
+ var result = native_.callSync('SoundManagerUnsetVolumeChangeListener', {});
_volumeChangeListener = undefined;
};
SoundManager.prototype.getConnectedDeviceList = function() {
- var result = native_.callSync('SoundManager_getConnectedDeviceList', {});
+ var result = native_.callSync('SoundManagerGetConnectedDeviceList', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
SoundManager.prototype.getActivatedDeviceList = function() {
- var result = native_.callSync('SoundManager_getActivatedDeviceList', {});
+ var result = native_.callSync('SoundManagerGetActivatedDeviceList', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&SoundInstance::x, this, _1, _2));
- REGISTER_SYNC("SoundManager_setVolume", SoundManagerSetVolume);
- REGISTER_SYNC("SoundManager_unsetSoundModeChangeListener",
- SoundManagerUnsetSoundModeChangeListener);
- REGISTER_SYNC("SoundManager_getVolume", SoundManagerGetVolume);
- REGISTER_SYNC("SoundManager_unsetVolumeChangeListener", SoundManagerUnsetVolumeChangeListener);
- REGISTER_SYNC("SoundManager_setSoundModeChangeListener", SoundManagerSetSoundModeChangeListener);
- REGISTER_SYNC("SoundManager_setVolumeChangeListener", SoundManagerSetVolumeChangeListener);
- REGISTER_SYNC("SoundManager_getSoundMode", SoundManagerGetSoundMode);
- REGISTER_SYNC("SoundManager_getConnectedDeviceList", SoundManagerGetConnectedDeviceList);
- REGISTER_SYNC("SoundManager_getActivatedDeviceList", SoundManagerGetActivatedDeviceList);
- REGISTER_SYNC("SoundManager_addDeviceStateChangeListener",
- SoundManagerAddDeviceStateChangeListener);
- REGISTER_SYNC("SoundManager_removeDeviceStateChangeListener",
- SoundManagerRemoveDeviceStateChangeListener);
-#undef REGISTER_SYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&SoundInstance::M, this, _1, _2))
+ REGISTER_METHOD(SoundManagerSetVolume);
+ REGISTER_METHOD(SoundManagerUnsetSoundModeChangeListener);
+ REGISTER_METHOD(SoundManagerGetVolume);
+ REGISTER_METHOD(SoundManagerUnsetVolumeChangeListener);
+ REGISTER_METHOD(SoundManagerSetSoundModeChangeListener);
+ REGISTER_METHOD(SoundManagerSetVolumeChangeListener);
+ REGISTER_METHOD(SoundManagerGetSoundMode);
+ REGISTER_METHOD(SoundManagerGetConnectedDeviceList);
+ REGISTER_METHOD(SoundManagerGetActivatedDeviceList);
+ REGISTER_METHOD(SoundManagerAddDeviceStateChangeListener);
+ REGISTER_METHOD(SoundManagerRemoveDeviceStateChangeListener);
+#undef REGISTER_METHOD
}
SoundInstance::~SoundInstance() {
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult SysteminfoUtils::GetServiceCountry(std::string *result) {
+ ScopeLogger();
+
+ char *country_code;
+ country_code = vconf_get_str("db/comss/countrycode");
+ if (nullptr != country_code) {
+ *result = country_code;
+ free(country_code);
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+ return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property SERVICE_COUNTRY is Not Supported");
+}
+
PlatformResult SysteminfoUtils::GetAvailableMemory(long long *result) {
ScopeLogger();
static common::PlatformResult CheckCameraFlashSupport();
static common::PlatformResult CheckIfEthernetNetworkSupported();
static common::PlatformResult GetTotalMemory(long long *result);
+ static common::PlatformResult GetServiceCountry(std::string *result);
static common::PlatformResult GetAvailableMemory(long long *result);
static common::PlatformResult RegisterVconfCallback(const char *in_key, vconf_callback_fn cb,
void *event_ptr);
PERIPHERAL: 'PERIPHERAL',
MEMORY: 'MEMORY',
CAMERA_FLASH: 'CAMERA_FLASH',
- ADS: 'ADS'
+ ADS: 'ADS',
+ SERVICE_COUNTRY: 'SERVICE_COUNTRY'
};
var SystemInfoPropertyIdToFeature = {
enumerable: true,
get: function() {
privUtils_.warn(
- 'DEPRECATION WARNING: SystemInfoStorageUnit.isRemoveable is is ' +
+ 'DEPRECATION WARNING: SystemInfoStorageUnit.isRemoveable is ' +
'deprecated and will be removed from next release. ' +
'Use SystemInfoStorageUnit.isRemovable instead.'
);
function SystemInfoCameraFlash(data) {
var getBrightness = function() {
- var result = native_.callSync('SystemInfo_getBrightness', {});
+ var result = native_.callSync('SystemInfoGetBrightness', {});
if (native_.isSuccess(result)) {
return Converter_.toLong(native_.getResultObject(result)) / this.levels;
}
};
var getLevels = function() {
- var result = native_.callSync('SystemInfo_getMaxBrightness', {});
+ var result = native_.callSync('SystemInfoGetMaxBrightness', {});
if (native_.isSuccess(result)) {
return Converter_.toLong(native_.getResultObject(result));
}
});
}
+function SystemInfoServiceCountry(data) {
+ Object.defineProperties(this, {
+ serviceCountry: { value: data.serviceCountry, writable: false, enumerable: true }
+ });
+}
+
SystemInfoCameraFlash.prototype.setBrightness = function(brightness) {
var args = validator_.validateArgs(arguments, [
{ name: 'brightness', type: types_.DOUBLE }
);
args.brightness = args.brightness * this.levels;
- var result = native_.callSync('SystemInfo_setBrightness', args);
+ var result = native_.callSync('SystemInfoSetBrightness', args);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
'from next release. Use getCapability() instead.'
);
- var result = native_.callSync('SystemInfo_getCapabilities', {});
+ var result = native_.callSync('SystemInfoGetCapabilities', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
]);
- var result = native_.callSync('SystemInfo_getCapability', { key: args.key });
+ var result = native_.callSync('SystemInfoGetCapability', { key: args.key });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
SystemInfo.prototype.getPropertyValue = function() {
- getPropertyFunction('SystemInfo_getPropertyValue', _createProperty).apply(
+ getPropertyFunction('SystemInfoGetPropertyValue', _createProperty).apply(
this,
arguments
);
};
SystemInfo.prototype.getPropertyValueArray = function() {
- getPropertyFunction('SystemInfo_getPropertyValueArray', _createPropertyArray).apply(
+ getPropertyFunction('SystemInfoGetPropertyValueArray', _createPropertyArray).apply(
this,
arguments
);
var _peripheralStr = SystemInfoPropertyId.PERIPHERAL;
var _memoryStr = SystemInfoPropertyId.MEMORY;
var _cameraFlashStr = SystemInfoPropertyId.CAMERA_FLASH;
+var _serviceCountryStr = SystemInfoPropertyId.SERVICE_COUNTRY;
var _nextId = 0;
* According to documentation, the condition should look like this:
*
* (T_.isUndefined(listener.lowThreshold) &&
- * T_.isUndefined(listener.highThreshold)) ||
+ * T_.isUndefined(listener.highThreshold)) ||
* (!T_.isUndefined(listener.lowThreshold) &&
- * !T_.isUndefined(listener.highThreshold) &&
- * (propObj.level <= listener.lowThreshold ||
- * propObj.level >= listener.highThreshold)) ||
+ * !T_.isUndefined(listener.highThreshold) &&
+ * (propObj.level <= listener.lowThreshold ||
+ * propObj.level >= listener.highThreshold)) ||
* (!T_.isUndefined(listener.lowThreshold) &&
- * (propObj.level <= listener.lowThreshold)) ||
+ * (propObj.level <= listener.lowThreshold)) ||
* (!T_.isUndefined(listener.highThreshold) &&
- * (propObj.level >= listener.highThreshold))
+ * (propObj.level >= listener.highThreshold))
*
* but it can be optimized like this:
*/
}
}
+function _systeminfoServiceCountryListenerCallback(eventObj) {
+ var property = _serviceCountryStr;
+ var callbacks = _propertyContainer[property].callbacks;
+
+ for (var watchId in callbacks) {
+ if (callbacks.hasOwnProperty(watchId)) {
+ var listener = callbacks[watchId];
+ var propObj = !listener.isArrayType
+ ? _createProperty(property, eventObj.result.array[0])
+ : _createPropertyArray(property, eventObj.result);
+ callbacks[watchId].callback(propObj);
+ }
+ }
+}
+
var _propertyContainer = {
BATTERY: {
callbacks: {},
constructor: SystemInfoADS,
broadcastFunction: function() {},
signalLabel: ''
+ },
+ SERVICE_COUNTRY: {
+ callbacks: {},
+ constructor: SystemInfoServiceCountry,
+ broadcastFunction: _systeminfoServiceCountryListenerCallback,
+ signalLabel: 'SystemInfoServiceCountryChangeBroadcast'
}
};
var fail = false;
if (T_.isEmptyObject(callbacksMap)) {
//registration in C++ layer
- result = native_.callSync('SystemInfo_addPropertyValueChangeListener', {
+ result = native_.callSync('SystemInfoAddPropertyValueChangeListener', {
property: Converter_.toString(property)
});
fail = native_.isFailure(result);
delete callbacksMap[Number(watchId)];
if (T_.isEmptyObject(callbacksMap)) {
//unregistration in C++ layer
- result = native_.callSync('SystemInfo_removePropertyValueChangeListener', {
+ result = native_.callSync('SystemInfoRemovePropertyValueChangeListener', {
property: Converter_.toString(property)
});
if (native_.isFailure(result)) {
};
SystemInfo.prototype.getTotalMemory = function() {
- var result = native_.callSync('SystemInfo_getTotalMemory', {});
+ var result = native_.callSync('SystemInfoGetTotalMemory', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
SystemInfo.prototype.getAvailableMemory = function() {
- var result = native_.callSync('SystemInfo_getAvailableMemory', {});
+ var result = native_.callSync('SystemInfoGetAvailableMemory', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
]);
- var result = native_.callSync('SystemInfo_getCount', { property: args.property });
+ var result = native_.callSync('SystemInfoGetCount', { property: args.property });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&SysteminfoInstance::x, this, _1, _2));
- REGISTER_SYNC("SystemInfo_getCapabilities", GetCapabilities);
- REGISTER_SYNC("SystemInfo_getCapability", GetCapability);
- REGISTER_SYNC("SystemInfo_addPropertyValueChangeListener", AddPropertyValueChangeListener);
- REGISTER_SYNC("SystemInfo_removePropertyValueChangeListener", RemovePropertyValueChangeListener);
- REGISTER_SYNC("SystemInfo_getTotalMemory", GetTotalMemory);
- REGISTER_SYNC("SystemInfo_getAvailableMemory", GetAvailableMemory);
- REGISTER_SYNC("SystemInfo_getCount", GetCount);
- REGISTER_SYNC("SystemInfo_setBrightness", SetBrightness);
- REGISTER_SYNC("SystemInfo_getBrightness", GetBrightness);
- REGISTER_SYNC("SystemInfo_getMaxBrightness", GetMaxBrightness);
-
-#undef REGISTER_SYNC
-#define REGISTER_ASYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&SysteminfoInstance::x, this, _1, _2));
- REGISTER_ASYNC("SystemInfo_getPropertyValue", GetPropertyValue);
- REGISTER_ASYNC("SystemInfo_getPropertyValueArray", GetPropertyValueArray);
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&SysteminfoInstance::M, this, _1, _2))
+ REGISTER_METHOD(SystemInfoGetCapabilities);
+ REGISTER_METHOD(SystemInfoGetCapability);
+ REGISTER_METHOD(SystemInfoAddPropertyValueChangeListener);
+ REGISTER_METHOD(SystemInfoRemovePropertyValueChangeListener);
+ REGISTER_METHOD(SystemInfoGetTotalMemory);
+ REGISTER_METHOD(SystemInfoGetAvailableMemory);
+ REGISTER_METHOD(SystemInfoGetCount);
+ REGISTER_METHOD(SystemInfoSetBrightness);
+ REGISTER_METHOD(SystemInfoGetBrightness);
+ REGISTER_METHOD(SystemInfoGetMaxBrightness);
+ REGISTER_METHOD(SystemInfoGetPropertyValue);
+ REGISTER_METHOD(SystemInfoGetPropertyValueArray);
+#undef REGISTER_METHOD
}
SysteminfoInstance::~SysteminfoInstance() {
ScopeLogger();
}
-void SysteminfoInstance::GetCapabilities(const picojson::value& args, picojson::object& out) {
+void SysteminfoInstance::SystemInfoGetCapabilities(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: getCapabilities() is deprecated and will be removed from next release. "
manager_.GetCapabilities(args, &out);
}
-void SysteminfoInstance::GetCapability(const picojson::value& args, picojson::object& out) {
+void SysteminfoInstance::SystemInfoGetCapability(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.GetCapability(args, &out);
}
-void SysteminfoInstance::GetPropertyValue(const picojson::value& args, picojson::object& out) {
+void SysteminfoInstance::SystemInfoGetPropertyValue(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.GetPropertyValue(args, &out);
}
-void SysteminfoInstance::GetPropertyValueArray(const picojson::value& args, picojson::object& out) {
+void SysteminfoInstance::SystemInfoGetPropertyValueArray(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.GetPropertyValueArray(args, &out);
}
-void SysteminfoInstance::AddPropertyValueChangeListener(const picojson::value& args,
- picojson::object& out) {
+void SysteminfoInstance::SystemInfoAddPropertyValueChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.AddPropertyValueChangeListener(args, &out);
}
-void SysteminfoInstance::RemovePropertyValueChangeListener(const picojson::value& args,
- picojson::object& out) {
+void SysteminfoInstance::SystemInfoRemovePropertyValueChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.RemovePropertyValueChangeListener(args, &out);
}
-void SysteminfoInstance::GetTotalMemory(const picojson::value& args, picojson::object& out) {
+void SysteminfoInstance::SystemInfoGetTotalMemory(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.GetTotalMemory(args, &out);
}
-void SysteminfoInstance::GetAvailableMemory(const picojson::value& args, picojson::object& out) {
+void SysteminfoInstance::SystemInfoGetAvailableMemory(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
manager_.GetAvailableMemory(args, &out);
}
-void SysteminfoInstance::GetCount(const picojson::value& args, picojson::object& out) {
+void SysteminfoInstance::SystemInfoGetCount(const picojson::value& args, picojson::object& out) {
ScopeLogger();
manager_.GetCount(args, &out);
}
-void SysteminfoInstance::SetBrightness(const picojson::value& args, picojson::object& out) {
+void SysteminfoInstance::SystemInfoSetBrightness(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeLED, &out);
ReportSuccess(out);
}
-void SysteminfoInstance::GetBrightness(const picojson::value& args, picojson::object& out) {
+void SysteminfoInstance::SystemInfoGetBrightness(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeLED, &out);
ReportSuccess(picojson::value(std::to_string(brightness)), out);
}
-void SysteminfoInstance::GetMaxBrightness(const picojson::value& args, picojson::object& out) {
+void SysteminfoInstance::SystemInfoGetMaxBrightness(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeLED, &out);
virtual ~SysteminfoInstance();
private:
- void GetCapabilities(const picojson::value& args, picojson::object& out);
- void GetCapability(const picojson::value& args, picojson::object& out);
- void GetPropertyValue(const picojson::value& args, picojson::object& out);
- void GetPropertyValueArray(const picojson::value& args, picojson::object& out);
- void AddPropertyValueChangeListener(const picojson::value& args, picojson::object& out);
- void RemovePropertyValueChangeListener(const picojson::value& args, picojson::object& out);
- void GetMaxBrightness(const picojson::value& args, picojson::object& out);
- void GetBrightness(const picojson::value& args, picojson::object& out);
- void SetBrightness(const picojson::value& args, picojson::object& out);
- void GetTotalMemory(const picojson::value& args, picojson::object& out);
- void GetAvailableMemory(const picojson::value& args, picojson::object& out);
- void GetCount(const picojson::value& args, picojson::object& out);
+ void SystemInfoGetCapabilities(const picojson::value& args, picojson::object& out);
+ void SystemInfoGetCapability(const picojson::value& args, picojson::object& out);
+ void SystemInfoGetPropertyValue(const picojson::value& args, picojson::object& out);
+ void SystemInfoGetPropertyValueArray(const picojson::value& args, picojson::object& out);
+ void SystemInfoAddPropertyValueChangeListener(const picojson::value& args, picojson::object& out);
+ void SystemInfoRemovePropertyValueChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void SystemInfoGetMaxBrightness(const picojson::value& args, picojson::object& out);
+ void SystemInfoGetBrightness(const picojson::value& args, picojson::object& out);
+ void SystemInfoSetBrightness(const picojson::value& args, picojson::object& out);
+ void SystemInfoGetTotalMemory(const picojson::value& args, picojson::object& out);
+ void SystemInfoGetAvailableMemory(const picojson::value& args, picojson::object& out);
+ void SystemInfoGetCount(const picojson::value& args, picojson::object& out);
SysteminfoManager manager_;
};
const std::string kPropertyIdPeripheral = "PERIPHERAL";
const std::string kPropertyIdMemory = "MEMORY";
const std::string kPropertyIdCameraFlash = "CAMERA_FLASH";
+const std::string kPropertyIdServiceCountry = "SERVICE_COUNTRY";
#define CHECK_EXIST(args, name, out) \
if (!args.contains(name)) { \
manager->SetWifiLevel(rssi_level);
}
+static void OnServiceCountryChangedCb(keynode_t* key, void* user_data) {
+ ScopeLogger();
+ SysteminfoManager* manager = static_cast<SysteminfoManager*>(user_data);
+
+ manager->CallListenerCallback(kPropertyIdServiceCountry);
+}
+
} // namespace
class SysteminfoManager::TapiManager {
ret = RegisterMemoryListener();
} else if (property_name == kPropertyIdCameraFlash) {
ret = RegisterCameraFlashListener();
+ } else if (property_name == kPropertyIdServiceCountry) {
+ ret = RegisterServiceCountryListener();
} else {
ret = LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Not supported property");
}
ret = UnregisterMemoryListener();
} else if (property_name == kPropertyIdCameraFlash) {
ret = UnregisterCameraFlashListener();
+ } else if (property_name == kPropertyIdServiceCountry) {
+ ret = UnregisterServiceCountryListener();
} else {
ret = LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Not supported property");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult SysteminfoManager::RegisterServiceCountryListener() {
+ ScopeLogger();
+
+ int ret = vconf_notify_key_changed("db/comss/countrycode", OnServiceCountryChangedCb, this);
+ if (0 != ret) {
+ return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
+ "SERVICE_COUNTRY is not supported property.",
+ ("vconf_notify_key_changed error"));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SysteminfoManager::UnregisterServiceCountryListener() {
+ ScopeLogger();
+ int ret = vconf_ignore_key_changed("db/comss/countrycode", OnServiceCountryChangedCb);
+ if (0 != ret) {
+ return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
+ "SERVICE_COUNTRY is not supported property.",
+ ("vconf_ignore_key_changed error"));
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
void SysteminfoManager::SetBrightness(const picojson::value& args, picojson::object* out) {
ScopeLogger();
} else {
*count = kDefaultPropertyCount;
}
+ } else if (kPropertyIdServiceCountry == property) {
+ std::string tmp;
+ PlatformResult ret = SysteminfoUtils::GetServiceCountry(&tmp);
+ if (ret.IsError()) {
+ *count = 0;
+ } else {
+ *count = 1;
+ }
} else {
return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
"Property with given id is not supported",
common::PlatformResult UnregisterMemoryListener();
common::PlatformResult RegisterCameraFlashListener();
common::PlatformResult UnregisterCameraFlashListener();
+ common::PlatformResult RegisterServiceCountryListener();
+ common::PlatformResult UnregisterServiceCountryListener();
SysteminfoInstance* instance_;
SysteminfoPropertiesManager prop_manager_;
return ReportCameraFlash(res_obj, index);
} else if ("ADS" == property) {
return ReportAds(res_obj);
+ } else if ("SERVICE_COUNTRY" == property) {
+ return ReportServiceCountry(res_obj);
}
return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
"Property with given id is not supported");
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult SysteminfoPropertiesManager::ReportServiceCountry(picojson::object* out) {
+ ScopeLogger();
+
+ std::string service_country;
+ PlatformResult ret = SysteminfoUtils::GetServiceCountry(&service_country);
+
+ if (ret.IsError()) {
+ return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR);
+ }
+
+ out->insert(std::make_pair("serviceCountry", picojson::value(service_country)));
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
} // namespace systeminfo
} // namespace webapi
common::PlatformResult ReportMemory(picojson::object* out);
common::PlatformResult ReportStorage(picojson::object* out);
common::PlatformResult ReportAds(picojson::object* out);
+ common::PlatformResult ReportServiceCountry(picojson::object* out);
common::PlatformResult FetchIsAutoRotation(bool* result);
common::PlatformResult FetchStatus(std::string* result);
type: args.type
};
- var result = native_.call('SystemSettingManager_getProperty', callArgs, callback);
+ var result = native_.call('SystemSettingManagerGetProperty', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
value: args.value
};
- var result = native_.call('SystemSettingManager_setProperty', callArgs, callback);
+ var result = native_.call('SystemSettingManagerSetProperty', callArgs, callback);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER(c, x) RegisterSyncHandler(c, std::bind(&SystemSettingInstance::x, this, _1, _2));
-
- REGISTER("SystemSettingManager_getProperty", getProperty);
- REGISTER("SystemSettingManager_setProperty", setProperty);
-
-#undef REGISTER
+#define REGISTER_METHOD(M) \
+ RegisterSyncHandler(#M, std::bind(&SystemSettingInstance::M, this, _1, _2))
+ REGISTER_METHOD(SystemSettingManagerGetProperty);
+ REGISTER_METHOD(SystemSettingManagerSetProperty);
+#undef REGISTER_METHOD
}
SystemSettingInstance::~SystemSettingInstance() {
ScopeLogger();
}
-void SystemSettingInstance::getProperty(const picojson::value& args, picojson::object& out) {
+void SystemSettingInstance::SystemSettingManagerGetProperty(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
const double callback_id = args.get("callbackId").get<double>();
}
}
-void SystemSettingInstance::setProperty(const picojson::value& args, picojson::object& out) {
+void SystemSettingInstance::SystemSettingManagerSetProperty(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeSetting, &out);
virtual ~SystemSettingInstance();
private:
- void getProperty(const picojson::value& args, picojson::object& out);
+ void SystemSettingManagerGetProperty(const picojson::value& args, picojson::object& out);
common::PlatformResult getPlatformPropertyValue(const std::string& valueType,
picojson::value* out);
- void setProperty(const picojson::value& args, picojson::object& out);
+ void SystemSettingManagerSetProperty(const picojson::value& args, picojson::object& out);
common::PlatformResult setPlatformPropertyValue(const std::string& settingType,
const std::string& settingValue);
};
timezone: converter_.toString(tzName),
timestamp: converter_.toString(timestamp)
};
- var result = native_.callSync('TZDate_getTimezoneOffset', callArgs);
+ var result = native_.callSync('TZDateGetTimezoneOffset', callArgs);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
tizen.TZDate.prototype.toLocaleDateString = function() {
utils_.log('Entered TZDate.toLocaleDateString');
- var result = native_.callSync('TZDate_toLocaleDateString', {
+ var result = native_.callSync('TZDateToLocaleDateString', {
timezone: String(this._timezoneName),
timestamp: String(this._utcTimestamp)
});
tizen.TZDate.prototype.toLocaleTimeString = function() {
utils_.log('Entered TZDate.toLocaleTimeString');
- var result = native_.callSync('TZDate_toLocaleTimeString', {
+ var result = native_.callSync('TZDateToLocaleTimeString', {
timezone: String(this._timezoneName),
timestamp: String(this._utcTimestamp)
});
tizen.TZDate.prototype.toLocaleString = function() {
utils_.log('Entered TZDate.toLocaleString');
- var result = native_.callSync('TZDate_toLocaleString', {
+ var result = native_.callSync('TZDateToLocaleString', {
timezone: String(this._timezoneName),
timestamp: String(this._utcTimestamp)
});
tizen.TZDate.prototype.toDateString = function() {
utils_.log('Entered TZDate.toDateString');
- var result = native_.callSync('TZDate_toDateString', {
+ var result = native_.callSync('TZDateToDateString', {
timezone: String(this._timezoneName),
timestamp: String(this._utcTimestamp)
});
tizen.TZDate.prototype.toTimeString = function() {
utils_.log('Entered TZDate.toTimeString');
- var result = native_.callSync('TZDate_toTimeString', {
+ var result = native_.callSync('TZDateToTimeString', {
timezone: String(this._timezoneName),
timestamp: String(this._utcTimestamp)
});
tizen.TZDate.prototype.toString = function() {
utils_.log('Entered TZDate.toString');
- var result = native_.callSync('TZDate_toString', {
+ var result = native_.callSync('TZDateToString', {
timezone: String(this._timezoneName),
timestamp: String(this._utcTimestamp)
});
'removed from next release.'
);
- var result = native_.callSync('TZDate_getTimezoneAbbreviation', {
+ var result = native_.callSync('TZDateGetTimezoneAbbreviation', {
timezone: String(this._timezoneName),
timestamp: String(this._utcTimestamp)
});
tizen.TZDate.prototype.isDST = function() {
utils_.log('Entered TZDate.isDST');
- var result = native_.callSync('TZDate_isDST', {
+ var result = native_.callSync('TZDateIsDST', {
timezone: String(this._timezoneName),
timestamp: String(this._utcTimestamp)
});
tizen.TZDate.prototype.getPreviousDSTTransition = function() {
utils_.log('Entered TZDate.getPreviousDSTTransition');
- var result = native_.callSync('TZDate_getPreviousDSTTransition', {
+ var result = native_.callSync('TZDateGetPreviousDSTTransition', {
timezone: String(this._timezoneName),
timestamp: String(this._utcTimestamp)
});
tizen.TZDate.prototype.getNextDSTTransition = function() {
utils_.log('Entered TZDate.getNextDSTTransition');
- var result = native_.callSync('TZDate_getNextDSTTransition', {
+ var result = native_.callSync('TZDateGetNextDSTTransition', {
timezone: String(this._timezoneName),
timestamp: String(this._utcTimestamp)
});
exports.getLocalTimezone = function() {
utils_.log('Entered TimeUtil.getLocalTimezone');
- var result = native_.callSync('TZDate_getLocalTimezone', {});
+ var result = native_.callSync('TZDateGetLocalTimezone', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
exports.getAvailableTimezones = function() {
utils_.log('Entered TimeUtil.getAvailableTimezones');
if (_availableTimezones.length === 0) {
- var result = native_.callSync('TimeUtil_getAvailableTimezones', {});
+ var result = native_.callSync('TimeUtilGetAvailableTimezones', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
args.shortformat = false;
}
- var result = native_.callSync('TimeUtil_getDateFormat', {
+ var result = native_.callSync('TimeUtilGetDateFormat', {
shortformat: args.shortformat
});
if (native_.isFailure(result)) {
exports.getTimeFormat = function() {
utils_.log('Entered TimeUtil.getTimeFormat');
- var result = native_.callSync('TimeUtil_getTimeFormat', {});
+ var result = native_.callSync('TimeUtilGetTimeFormat', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
type: validator_.Types.FUNCTION
}
]);
- var result = native_.callSync('TimeUtil_setDateTimeChangeListener', {});
+ var result = native_.callSync('TimeUtilSetDateTimeChangeListener', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
exports.unsetDateTimeChangeListener = function() {
utils_.log('Entered TimeUtil.unsetDateTimeChangeListener');
- var result = native_.callSync('TimeUtil_unsetDateTimeChangeListener', {});
+ var result = native_.callSync('TimeUtilUnsetDateTimeChangeListener', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
type: validator_.Types.FUNCTION
}
]);
- var result = native_.callSync('TimeUtil_setTimezoneChangeListener', {});
+ var result = native_.callSync('TimeUtilSetTimezoneChangeListener', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
exports.unsetTimezoneChangeListener = function() {
utils_.log('Entered TimeUtil.unsetTimezoneChangeListener');
native_.removeListener('TimezoneChangeListener');
- var result = native_.callSync('TimeUtil_unsetTimezoneChangeListener', {});
+ var result = native_.callSync('TimeUtilUnsetTimezoneChangeListener', {});
_timeUtilTimezoneChangeListener = undefined;
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
using namespace common;
TimeInstance::TimeInstance() : manager_(this) {
+ ScopeLogger();
+
using std::placeholders::_1;
using std::placeholders::_2;
- ScopeLogger();
-
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&TimeInstance::x, this, _1, _2));
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&TimeInstance::x, this, _1, _2));
-
- REGISTER_SYNC("TimeUtil_getAvailableTimezones", TimeUtil_getAvailableTimezones);
- REGISTER_SYNC("TimeUtil_getDateFormat", TimeUtil_getDateFormat);
- REGISTER_SYNC("TimeUtil_getTimeFormat", TimeUtil_getTimeFormat);
- REGISTER_SYNC("TimeUtil_setDateTimeChangeListener", TimeUtil_setDateTimeChangeListener);
- REGISTER_SYNC("TimeUtil_unsetDateTimeChangeListener", TimeUtil_unsetDateTimeChangeListener);
- REGISTER_SYNC("TimeUtil_setTimezoneChangeListener", TimeUtil_setTimezoneChangeListener);
- REGISTER_SYNC("TimeUtil_unsetTimezoneChangeListener", TimeUtil_unsetTimezoneChangeListener);
- REGISTER_SYNC("TZDate_getLocalTimezone", TZDate_getLocalTimezone);
- REGISTER_SYNC("TZDate_getTimezoneOffset", TZDate_GetTimezoneOffset);
- REGISTER_SYNC("TZDate_toLocaleDateString", TZDate_toLocaleDateString);
- REGISTER_SYNC("TZDate_toLocaleTimeString", TZDate_toLocaleTimeString);
- REGISTER_SYNC("TZDate_toLocaleString", TZDate_toLocaleString);
- REGISTER_SYNC("TZDate_toDateString", TZDate_toDateString);
- REGISTER_SYNC("TZDate_toTimeString", TZDate_toTimeString);
- REGISTER_SYNC("TZDate_toString", TZDate_toString);
- REGISTER_SYNC("TZDate_getTimezoneAbbreviation", TZDate_getTimezoneAbbreviation);
- REGISTER_SYNC("TZDate_isDST", TZDate_isDST);
- REGISTER_SYNC("TZDate_getPreviousDSTTransition", TZDate_getPreviousDSTTransition);
- REGISTER_SYNC("TZDate_getNextDSTTransition", TZDate_getNextDSTTransition);
-
-#undef REGISTER_SYNC
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&TimeInstance::M, this, _1, _2))
+ REGISTER_METHOD(TimeUtilGetAvailableTimezones);
+ REGISTER_METHOD(TimeUtilGetDateFormat);
+ REGISTER_METHOD(TimeUtilGetTimeFormat);
+ REGISTER_METHOD(TimeUtilSetDateTimeChangeListener);
+ REGISTER_METHOD(TimeUtilUnsetDateTimeChangeListener);
+ REGISTER_METHOD(TimeUtilSetTimezoneChangeListener);
+ REGISTER_METHOD(TimeUtilUnsetTimezoneChangeListener);
+ REGISTER_METHOD(TZDateGetLocalTimezone);
+ REGISTER_METHOD(TZDateGetTimezoneOffset);
+ REGISTER_METHOD(TZDateToLocaleDateString);
+ REGISTER_METHOD(TZDateToLocaleTimeString);
+ REGISTER_METHOD(TZDateToLocaleString);
+ REGISTER_METHOD(TZDateToDateString);
+ REGISTER_METHOD(TZDateToTimeString);
+ REGISTER_METHOD(TZDateToString);
+ REGISTER_METHOD(TZDateGetTimezoneAbbreviation);
+ REGISTER_METHOD(TZDateIsDST);
+ REGISTER_METHOD(TZDateGetPreviousDSTTransition);
+ REGISTER_METHOD(TZDateGetNextDSTTransition);
+#undef REGISTER_METHOD
}
TimeInstance::~TimeInstance() {
ScopeLogger();
}
-void TimeInstance::TimeUtil_getAvailableTimezones(const picojson::value& /*args*/,
- picojson::object& out) {
+void TimeInstance::TimeUtilGetAvailableTimezones(const picojson::value& /*args*/,
+ picojson::object& out) {
ScopeLogger();
picojson::value result = picojson::value(picojson::object());
picojson::object& result_obj = result.get<picojson::object>();
ReportSuccess(result, out);
}
-void TimeInstance::TimeUtil_getDateFormat(const picojson::value& args, picojson::object& out) {
+void TimeInstance::TimeUtilGetDateFormat(const picojson::value& args, picojson::object& out) {
ScopeLogger();
if (!args.contains("shortformat")) {
LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."),
ReportSuccess(result, out);
}
-void TimeInstance::TimeUtil_getTimeFormat(const picojson::value& /* args */,
- picojson::object& out) {
+void TimeInstance::TimeUtilGetTimeFormat(const picojson::value& /* args */, picojson::object& out) {
ScopeLogger();
std::string format;
PlatformResult res = TimeUtilTools::GetTimeFormat(&format);
ReportSuccess(result, out);
}
-void TimeInstance::TimeUtil_setDateTimeChangeListener(const picojson::value& /*args*/,
- picojson::object& out) {
+void TimeInstance::TimeUtilSetDateTimeChangeListener(const picojson::value& /*args*/,
+ picojson::object& out) {
ScopeLogger();
PlatformResult res = manager_.RegisterVconfCallback(kTimeChange);
if (res.IsError()) {
ReportSuccess(out);
}
-void TimeInstance::TimeUtil_unsetDateTimeChangeListener(const picojson::value& /*args*/,
- picojson::object& out) {
+void TimeInstance::TimeUtilUnsetDateTimeChangeListener(const picojson::value& /*args*/,
+ picojson::object& out) {
ScopeLogger();
PlatformResult res = manager_.UnregisterVconfCallback(kTimeChange);
if (res.IsError()) {
ReportSuccess(out);
}
-void TimeInstance::TimeUtil_setTimezoneChangeListener(const picojson::value& /*args*/,
- picojson::object& out) {
+void TimeInstance::TimeUtilSetTimezoneChangeListener(const picojson::value& /*args*/,
+ picojson::object& out) {
ScopeLogger();
PlatformResult res = manager_.RegisterVconfCallback(kTimezoneChange);
if (res.IsError()) {
ReportSuccess(out);
}
-void TimeInstance::TimeUtil_unsetTimezoneChangeListener(const picojson::value& /*args*/,
- picojson::object& out) {
+void TimeInstance::TimeUtilUnsetTimezoneChangeListener(const picojson::value& /*args*/,
+ picojson::object& out) {
ScopeLogger();
PlatformResult res = manager_.UnregisterVconfCallback(kTimezoneChange);
if (res.IsError()) {
ReportSuccess(out);
}
-void TimeInstance::TZDate_getLocalTimezone(const picojson::value& /*args*/, picojson::object& out) {
+void TimeInstance::TZDateGetLocalTimezone(const picojson::value& /*args*/, picojson::object& out) {
ScopeLogger();
std::string local_timezone = TimeManager::GetDefaultTimezone();
ReportSuccess(result, out);
}
-void TimeInstance::TZDate_GetTimezoneOffset(const picojson::value& args, picojson::object& out) {
+void TimeInstance::TZDateGetTimezoneOffset(const picojson::value& args, picojson::object& out) {
ScopeLogger();
if (!args.contains("timezone") || !args.contains("timestamp")) {
LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."),
ReportSuccess(result, *out);
}
-void TimeInstance::TZDate_toLocaleDateString(const picojson::value& args, picojson::object& out) {
+void TimeInstance::TZDateToLocaleDateString(const picojson::value& args, picojson::object& out) {
ScopeLogger();
ToStringTemplate(args, true, TimeUtilTools::DateTimeFormatType::kDateFormat, &out);
}
-void TimeInstance::TZDate_toLocaleTimeString(const picojson::value& args, picojson::object& out) {
+void TimeInstance::TZDateToLocaleTimeString(const picojson::value& args, picojson::object& out) {
ScopeLogger();
ToStringTemplate(args, true, TimeUtilTools::DateTimeFormatType::kTimeFormat, &out);
}
-void TimeInstance::TZDate_toLocaleString(const picojson::value& args, picojson::object& out) {
+void TimeInstance::TZDateToLocaleString(const picojson::value& args, picojson::object& out) {
ScopeLogger();
ToStringTemplate(args, true, TimeUtilTools::DateTimeFormatType::kDateTimeFormat, &out);
}
-void TimeInstance::TZDate_toDateString(const picojson::value& args, picojson::object& out) {
+void TimeInstance::TZDateToDateString(const picojson::value& args, picojson::object& out) {
ScopeLogger();
ToStringTemplate(args, false, TimeUtilTools::DateTimeFormatType::kDateFormat, &out);
}
-void TimeInstance::TZDate_toTimeString(const picojson::value& args, picojson::object& out) {
+void TimeInstance::TZDateToTimeString(const picojson::value& args, picojson::object& out) {
ScopeLogger();
ToStringTemplate(args, false, TimeUtilTools::DateTimeFormatType::kTimeFormat, &out);
}
-void TimeInstance::TZDate_toString(const picojson::value& args, picojson::object& out) {
+void TimeInstance::TZDateToString(const picojson::value& args, picojson::object& out) {
ScopeLogger();
ToStringTemplate(args, false, TimeUtilTools::DateTimeFormatType::kDateTimeFormat, &out);
}
-void TimeInstance::TZDate_getTimezoneAbbreviation(const picojson::value& args,
- picojson::object& out) {
+void TimeInstance::TZDateGetTimezoneAbbreviation(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
LoggerW(
"DEPRECATION WARNING: getTimezoneAbbreviation() is deprecated and will be removed from next "
ReportSuccess(result, out);
}
-void TimeInstance::TZDate_isDST(const picojson::value& args, picojson::object& out) {
+void TimeInstance::TZDateIsDST(const picojson::value& args, picojson::object& out) {
ScopeLogger();
if (!args.contains("timezone") || !args.contains("timestamp")) {
LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."),
ReportSuccess(result, out);
}
-void TimeInstance::TZDate_getPreviousDSTTransition(const picojson::value& args,
- picojson::object& out) {
+void TimeInstance::TZDateGetPreviousDSTTransition(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
if (!args.contains("timezone") || !args.contains("timestamp")) {
LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."),
ReportSuccess(result, out);
}
-void TimeInstance::TZDate_getNextDSTTransition(const picojson::value& args, picojson::object& out) {
+void TimeInstance::TZDateGetNextDSTTransition(const picojson::value& args, picojson::object& out) {
ScopeLogger();
if (!args.contains("timezone") || !args.contains("timestamp")) {
LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."),
virtual ~TimeInstance();
private:
- void TimeUtil_getAvailableTimezones(const picojson::value& args, picojson::object& out);
- void TimeUtil_getDateFormat(const picojson::value& args, picojson::object& out);
- void TimeUtil_getTimeFormat(const picojson::value& args, picojson::object& out);
- void TimeUtil_setDateTimeChangeListener(const picojson::value& args, picojson::object& out);
- void TimeUtil_unsetDateTimeChangeListener(const picojson::value& args, picojson::object& out);
- void TimeUtil_setTimezoneChangeListener(const picojson::value& args, picojson::object& out);
- void TimeUtil_unsetTimezoneChangeListener(const picojson::value& args, picojson::object& out);
- void TZDate_getLocalTimezone(const picojson::value& args, picojson::object& out);
- void TZDate_GetTimezoneOffset(const picojson::value& args, picojson::object& out);
+ void TimeUtilGetAvailableTimezones(const picojson::value& args, picojson::object& out);
+ void TimeUtilGetDateFormat(const picojson::value& args, picojson::object& out);
+ void TimeUtilGetTimeFormat(const picojson::value& args, picojson::object& out);
+ void TimeUtilSetDateTimeChangeListener(const picojson::value& args, picojson::object& out);
+ void TimeUtilUnsetDateTimeChangeListener(const picojson::value& args, picojson::object& out);
+ void TimeUtilSetTimezoneChangeListener(const picojson::value& args, picojson::object& out);
+ void TimeUtilUnsetTimezoneChangeListener(const picojson::value& args, picojson::object& out);
+ void TZDateGetLocalTimezone(const picojson::value& args, picojson::object& out);
+ void TZDateGetTimezoneOffset(const picojson::value& args, picojson::object& out);
void ToStringTemplate(const picojson::value& args, bool use_locale_fmt,
TimeUtilTools::DateTimeFormatType type, picojson::object* out);
- void TZDate_toLocaleDateString(const picojson::value& args, picojson::object& out);
- void TZDate_toLocaleTimeString(const picojson::value& args, picojson::object& out);
- void TZDate_toLocaleString(const picojson::value& args, picojson::object& out);
- void TZDate_toDateString(const picojson::value& args, picojson::object& out);
- void TZDate_toTimeString(const picojson::value& args, picojson::object& out);
- void TZDate_toString(const picojson::value& args, picojson::object& out);
- void TZDate_getTimezoneAbbreviation(const picojson::value& args, picojson::object& out);
- void TZDate_isDST(const picojson::value& args, picojson::object& out);
- void TZDate_getPreviousDSTTransition(const picojson::value& args, picojson::object& out);
- void TZDate_getNextDSTTransition(const picojson::value& args, picojson::object& out);
+ void TZDateToLocaleDateString(const picojson::value& args, picojson::object& out);
+ void TZDateToLocaleTimeString(const picojson::value& args, picojson::object& out);
+ void TZDateToLocaleString(const picojson::value& args, picojson::object& out);
+ void TZDateToDateString(const picojson::value& args, picojson::object& out);
+ void TZDateToTimeString(const picojson::value& args, picojson::object& out);
+ void TZDateToString(const picojson::value& args, picojson::object& out);
+ void TZDateGetTimezoneAbbreviation(const picojson::value& args, picojson::object& out);
+ void TZDateIsDST(const picojson::value& args, picojson::object& out);
+ void TZDateGetPreviousDSTTransition(const picojson::value& args, picojson::object& out);
+ void TZDateGetNextDSTTransition(const picojson::value& args, picojson::object& out);
TimeManager manager_;
};
],
'conditions': [
[
+ 'tizen_ut_build==1', {
+ 'dependencies': [
+ 'common/common_ut.gyp:*'
+ ]
+ }
+ ],
+ [
'tizen_feature_account_support==1', {
'dependencies': [
'account/account.gyp:*',
--- /dev/null
+mocha.setup('bdd');
+
+describe('default constructor', function() {
+ it('should initialize empty bundle object', function(done) {
+ var bundle = new tizen.Bundle();
+ chai.expect(bundle.data).to.be.empty;
+ done();
+ });
+});
+
+describe('json constructor', function() {
+ it('should properly initialize entries of all types', function(done) {
+ var json = {
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ key3: new Uint8Array([1, 2, 3]),
+ key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
+ key5: [1, 2, 3],
+ key6: [[1, 2, 3], [4, 5, 6]],
+ key7: [],
+ key8: null,
+ key9: {},
+ key10: [1, 2, 300]
+ };
+
+ var bundle = new tizen.Bundle(json);
+ chai.expect(bundle.data.key1).to.equal('value');
+ chai.expect(bundle.data.key2).to.deep.equal(json.key2);
+ chai.expect(bundle.data.key3).to.deep.equal(json.key3);
+ chai.expect(bundle.data.key4).to.deep.equal(json.key4);
+ chai.expect(bundle.data.key5).to.deep.equal(json.key3);
+ chai.expect(bundle.data.key6).to.deep.equal(json.key4);
+ chai.expect(bundle.data.key7).to.be.empty;
+ chai.expect(bundle.data.key8).to.equal('null');
+ chai.expect(bundle.data.key9).to.equal('[object Object]');
+ chai.expect(bundle.data.key10).to.equal('1,2,300');
+ done();
+ });
+});
+
+describe('copy constructor', function() {
+ it('should create deep copy of bundle data', function(done) {
+ var src = new tizen.Bundle({
+ key1: 'value',
+ key2: ['value1', 'value2']
+ });
+ var dest = new tizen.Bundle(src);
+ chai.expect(dest).to.deep.equal(src);
+ done();
+ });
+});
+
+describe('setter and getter', function() {
+ it('should set string entry', function(done) {
+ var bundle = new tizen.Bundle();
+ bundle.set('string', 'hello, world');
+ chai.expect(bundle.get('string')).to.equal('hello, world');
+ chai.expect(bundle.typeOf('string')).to.equal('STRING');
+ done();
+ });
+
+ it('should set string array entry', function(done) {
+ var bundle = new tizen.Bundle();
+ bundle.set('stringArray', ['hello', 'world']);
+ chai.expect(bundle.get('stringArray')).to.deep.equal(['hello', 'world']);
+ chai.expect(bundle.typeOf('stringArray')).to.equal('STRING_ARRAY');
+ done();
+ });
+
+ it('should set byte stream entry', function(done) {
+ var bundle = new tizen.Bundle();
+ bundle.set('bytes', new Uint8Array([1, 2, 3]));
+ chai.expect(bundle.get('bytes')).to.deep.equal(new Uint8Array([1, 2, 3]));
+ chai.expect(bundle.typeOf('bytes')).to.equal('BYTES');
+ done();
+ });
+
+ it('should set byte streams array entry', function(done) {
+ var bundle = new tizen.Bundle();
+ bundle.set('bytesArray', [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]);
+ chai.expect(bundle.get('bytesArray')).to.deep.equal([
+ new Uint8Array([1, 2, 3]),
+ new Uint8Array([4, 5, 6])
+ ]);
+ chai.expect(bundle.typeOf('bytesArray')).to.equal('BYTES_ARRAY');
+ done();
+ });
+
+ it('should convert unsupported types to strings', function(done) {
+ var bundle = new tizen.Bundle();
+
+ bundle.set('other1', function() {});
+ bundle.set('other2', undefined);
+
+ chai.expect(bundle.typeOf('other1')).to.equal('STRING');
+ chai.expect(bundle.get('other1')).to.equal('function () {}');
+
+ chai.expect(bundle.typeOf('other2')).to.equal('STRING');
+ chai.expect(bundle.get('other2')).to.equal('undefined');
+
+ done();
+ });
+
+ it('should throw NotFoundErr if key does not exist - get()', function(done) {
+ var bundle = new tizen.Bundle();
+ try {
+ bundle.get('not-a-key');
+ done(new Error('bundle.get() should fail but it did not'));
+ } catch (error) {
+ chai.expect(error.code).to.equal(WebAPIException.NOT_FOUND_ERR);
+ done();
+ }
+ });
+
+ it('should throw NotFoundErr if key does not exist - typeOf()', function(done) {
+ var bundle = new tizen.Bundle();
+ try {
+ bundle.get('not-a-key');
+ done(new Error('bundle.get() should fail but it did not'));
+ } catch (error) {
+ chai.expect(error.code).to.equal(WebAPIException.NOT_FOUND_ERR);
+ done();
+ }
+ });
+});
+
+describe('forEach', function() {
+ it('should trigger callback for each entry', function(done) {
+ var json = {
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ key3: new Uint8Array([1, 2, 3]),
+ key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]
+ };
+ var bundle = new tizen.Bundle(json);
+ var keys = Object.keys(json);
+ bundle.forEach(function(key, value, type) {
+ var index = keys.indexOf(key);
+ chai.expect(index).to.be.gte(0);
+ keys.splice(index, 1);
+ });
+ chai.expect(keys).to.be.empty;
+ done();
+ });
+});
+
+describe('toJSON', function() {
+ it('should properly convert bundle to json', function(done) {
+ var json = {
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ key3: new Uint8Array([1, 2, 3]),
+ key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]
+ };
+ var result = new tizen.Bundle(json).toJSON();
+ chai.expect(result.key1).to.equal(json.key1);
+ chai.expect(result.key2).to.deep.equal(json.key2);
+ chai.expect(result.key3).to.deep.equal([1, 2, 3]);
+ chai.expect(result.key4).to.deep.equal([[1, 2, 3], [4, 5, 6]]);
+ done();
+ });
+});
+
+describe('toString', function() {
+ it('should properly convert bundle to string', function(done) {
+ var json = {
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ key3: new Uint8Array([1, 2, 3]),
+ key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
+ key5: [1, 2, 3],
+ key6: [[1, 2, 3], [4, 5, 6]]
+ };
+ var bundle = new tizen.Bundle(json);
+ var expected =
+ '{"key1":"value","key2":["value1","value2"],"key3":[1,2,3],' +
+ '"key4":[[1,2,3],[4,5,6]],"key5":[1,2,3],"key6":[[1,2,3],[4,5,6]]}';
+ chai.expect(bundle.toString()).to.equal(expected);
+ done();
+ });
+});
+
+mocha.checkLeaks();
+mocha
+ .run()
+ .on('pass', function(test) {
+ console.log(test.title + ' OK');
+ })
+ .on('fail', function(test, err) {
+ console.error(test.title + ' FAILED');
+ console.error(err);
+ })
+ .on('end', function() {
+ console.log('All done');
+ });
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-/*eslint-disable */
+/* eslint-disable */
// Tizen API Specification:
-//https://developer.tizen.org/dev-guide/2.3.0/org.tizen.mobile.web.device.apireference/tizen/tizen.html
-/*eslint-enable */
+// https://developer.tizen.org/dev-guide/2.3.0/org.tizen.mobile.web.device.apireference/tizen/tizen.html
+/* eslint-enable */
// WebAPIException and WebAPIError definition moved to src/utils/utils_api.js
// for compliance reasons. You can find more info there.
});
};
exports.SimpleCoordinates.prototype.constructor = exports.SimpleCoordinates;
+
+function forEachOwnProperty(obj, callback) {
+ for (var prop in obj) {
+ if (obj.hasOwnProperty(prop)) {
+ callback(prop, obj[prop]);
+ }
+ }
+}
+
+var BundleValueType = {
+ STRING: 'STRING',
+ STRING_ARRAY: 'STRING_ARRAY',
+ BYTES: 'BYTES',
+ BYTES_ARRAY: 'BYTES_ARRAY'
+};
+exports.BundleValueType = BundleValueType;
+
+function getValueType(value) {
+ if (xwalk.utils.type.isString(value)) {
+ return BundleValueType.STRING;
+ }
+ if (xwalk.utils.type.isStringArray(value)) {
+ return BundleValueType.STRING_ARRAY;
+ }
+ if (
+ xwalk.utils.type.isByteStream(value) ||
+ xwalk.utils.type.isLegacyByteStream(value)
+ ) {
+ return BundleValueType.BYTES;
+ }
+ if (
+ xwalk.utils.type.isByteStreamArray(value) ||
+ xwalk.utils.type.isLegacyByteStreamArray(value)
+ ) {
+ return BundleValueType.BYTES_ARRAY;
+ }
+}
+
+function Bundle(arg) {
+ xwalk.utils.validator.isConstructorCall(this, exports.Bundle);
+ this.data = {};
+ var json = {};
+
+ // copy constructor
+ if (arg instanceof tizen.Bundle) {
+ json = JSON.parse(arg.toString());
+ }
+ // json to bundle conversion
+ else if (xwalk.utils.type.isObject(arg)) {
+ json = arg;
+ }
+
+ forEachOwnProperty(
+ json,
+ function(key, value) {
+ this.set(key, value);
+ }.bind(this)
+ );
+}
+exports.Bundle = Bundle;
+exports.Bundle.prototype.constructor = exports.Bundle;
+
+exports.Bundle.prototype.set = function(key, value) {
+ this.data[key] = convertToBundleValue(value);
+};
+
+function convertToBundleValue(value) {
+ var converted = value;
+ switch (getValueType(value)) {
+ case undefined:
+ converted = xwalk.utils.converter.toString(value);
+ break;
+ case BundleValueType.BYTES:
+ converted = new Uint8Array(value);
+ break;
+ case BundleValueType.BYTES_ARRAY:
+ converted = [];
+ value.forEach(
+ function(stream) {
+ converted.push(new Uint8Array(stream));
+ }.bind(this)
+ );
+ break;
+ }
+ return converted;
+}
+
+exports.Bundle.prototype.get = function(key) {
+ if (!this.data.hasOwnProperty(key)) {
+ throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
+ }
+ return this.data[key];
+};
+
+exports.Bundle.prototype.typeOf = function(key) {
+ if (!this.data.hasOwnProperty(key)) {
+ throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
+ }
+ return getValueType(this.data[key]);
+};
+
+exports.Bundle.prototype.forEach = function(callback) {
+ forEachOwnProperty(
+ this.data,
+ function(key, value) {
+ callback(key, value, this.typeOf(key));
+ }.bind(this)
+ );
+};
+
+exports.Bundle.prototype.toJSON = function() {
+ var json = {};
+ this.forEach(function(key, value, type) {
+ if (type == BundleValueType.BYTES) {
+ json[key] = [].slice.call(value);
+ } else if (type == BundleValueType.BYTES_ARRAY) {
+ json[key] = [];
+ value.forEach(function(stream) {
+ json[key].push([].slice.call(stream));
+ });
+ } else {
+ json[key] = value;
+ }
+ });
+ return json;
+};
+
+exports.Bundle.prototype.toString = function() {
+ return JSON.stringify(this);
+};
}
/**
- * This class provides access to the API functionalities through
- * the tizen.tvinputdevice interface.
+ * This class provides access to the API functionalities through the
+ * tizen.tvinputdevice interface.
* @constructor
*/
function TVInputDeviceManager() {
--- /dev/null
+/*
+MIT License
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.chai = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
+module.exports = require('./lib/chai');
+
+},{"./lib/chai":2}],2:[function(require,module,exports){
+/*!
+ * chai
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+var used = [];
+
+/*!
+ * Chai version
+ */
+
+exports.version = '4.1.2';
+
+/*!
+ * Assertion Error
+ */
+
+exports.AssertionError = require('assertion-error');
+
+/*!
+ * Utils for plugins (not exported)
+ */
+
+var util = require('./chai/utils');
+
+/**
+ * # .use(function)
+ *
+ * Provides a way to extend the internals of Chai.
+ *
+ * @param {Function}
+ * @returns {this} for chaining
+ * @api public
+ */
+
+exports.use = function (fn) {
+ if (!~used.indexOf(fn)) {
+ fn(exports, util);
+ used.push(fn);
+ }
+
+ return exports;
+};
+
+/*!
+ * Utility Functions
+ */
+
+exports.util = util;
+
+/*!
+ * Configuration
+ */
+
+var config = require('./chai/config');
+exports.config = config;
+
+/*!
+ * Primary `Assertion` prototype
+ */
+
+var assertion = require('./chai/assertion');
+exports.use(assertion);
+
+/*!
+ * Core Assertions
+ */
+
+var core = require('./chai/core/assertions');
+exports.use(core);
+
+/*!
+ * Expect interface
+ */
+
+var expect = require('./chai/interface/expect');
+exports.use(expect);
+
+/*!
+ * Should interface
+ */
+
+var should = require('./chai/interface/should');
+exports.use(should);
+
+/*!
+ * Assert interface
+ */
+
+var assert = require('./chai/interface/assert');
+exports.use(assert);
+
+},{"./chai/assertion":3,"./chai/config":4,"./chai/core/assertions":5,"./chai/interface/assert":6,"./chai/interface/expect":7,"./chai/interface/should":8,"./chai/utils":22,"assertion-error":33}],3:[function(require,module,exports){
+/*!
+ * chai
+ * http://chaijs.com
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+var config = require('./config');
+
+module.exports = function (_chai, util) {
+ /*!
+ * Module dependencies.
+ */
+
+ var AssertionError = _chai.AssertionError
+ , flag = util.flag;
+
+ /*!
+ * Module export.
+ */
+
+ _chai.Assertion = Assertion;
+
+ /*!
+ * Assertion Constructor
+ *
+ * Creates object for chaining.
+ *
+ * `Assertion` objects contain metadata in the form of flags. Three flags can
+ * be assigned during instantiation by passing arguments to this constructor:
+ *
+ * - `object`: This flag contains the target of the assertion. For example, in
+ * the assertion `expect(numKittens).to.equal(7);`, the `object` flag will
+ * contain `numKittens` so that the `equal` assertion can reference it when
+ * needed.
+ *
+ * - `message`: This flag contains an optional custom error message to be
+ * prepended to the error message that's generated by the assertion when it
+ * fails.
+ *
+ * - `ssfi`: This flag stands for "start stack function indicator". It
+ * contains a function reference that serves as the starting point for
+ * removing frames from the stack trace of the error that's created by the
+ * assertion when it fails. The goal is to provide a cleaner stack trace to
+ * end users by removing Chai's internal functions. Note that it only works
+ * in environments that support `Error.captureStackTrace`, and only when
+ * `Chai.config.includeStack` hasn't been set to `false`.
+ *
+ * - `lockSsfi`: This flag controls whether or not the given `ssfi` flag
+ * should retain its current value, even as assertions are chained off of
+ * this object. This is usually set to `true` when creating a new assertion
+ * from within another assertion. It's also temporarily set to `true` before
+ * an overwritten assertion gets called by the overwriting assertion.
+ *
+ * @param {Mixed} obj target of the assertion
+ * @param {String} msg (optional) custom error message
+ * @param {Function} ssfi (optional) starting point for removing stack frames
+ * @param {Boolean} lockSsfi (optional) whether or not the ssfi flag is locked
+ * @api private
+ */
+
+ function Assertion (obj, msg, ssfi, lockSsfi) {
+ flag(this, 'ssfi', ssfi || Assertion);
+ flag(this, 'lockSsfi', lockSsfi);
+ flag(this, 'object', obj);
+ flag(this, 'message', msg);
+
+ return util.proxify(this);
+ }
+
+ Object.defineProperty(Assertion, 'includeStack', {
+ get: function() {
+ console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
+ return config.includeStack;
+ },
+ set: function(value) {
+ console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
+ config.includeStack = value;
+ }
+ });
+
+ Object.defineProperty(Assertion, 'showDiff', {
+ get: function() {
+ console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
+ return config.showDiff;
+ },
+ set: function(value) {
+ console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
+ config.showDiff = value;
+ }
+ });
+
+ Assertion.addProperty = function (name, fn) {
+ util.addProperty(this.prototype, name, fn);
+ };
+
+ Assertion.addMethod = function (name, fn) {
+ util.addMethod(this.prototype, name, fn);
+ };
+
+ Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
+ util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
+ };
+
+ Assertion.overwriteProperty = function (name, fn) {
+ util.overwriteProperty(this.prototype, name, fn);
+ };
+
+ Assertion.overwriteMethod = function (name, fn) {
+ util.overwriteMethod(this.prototype, name, fn);
+ };
+
+ Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
+ util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
+ };
+
+ /**
+ * ### .assert(expression, message, negateMessage, expected, actual, showDiff)
+ *
+ * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
+ *
+ * @name assert
+ * @param {Philosophical} expression to be tested
+ * @param {String|Function} message or function that returns message to display if expression fails
+ * @param {String|Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
+ * @param {Mixed} expected value (remember to check for negation)
+ * @param {Mixed} actual (optional) will default to `this.obj`
+ * @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
+ * @api private
+ */
+
+ Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
+ var ok = util.test(this, arguments);
+ if (false !== showDiff) showDiff = true;
+ if (undefined === expected && undefined === _actual) showDiff = false;
+ if (true !== config.showDiff) showDiff = false;
+
+ if (!ok) {
+ msg = util.getMessage(this, arguments);
+ var actual = util.getActual(this, arguments);
+ throw new AssertionError(msg, {
+ actual: actual
+ , expected: expected
+ , showDiff: showDiff
+ }, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
+ }
+ };
+
+ /*!
+ * ### ._obj
+ *
+ * Quick reference to stored `actual` value for plugin developers.
+ *
+ * @api private
+ */
+
+ Object.defineProperty(Assertion.prototype, '_obj',
+ { get: function () {
+ return flag(this, 'object');
+ }
+ , set: function (val) {
+ flag(this, 'object', val);
+ }
+ });
+};
+
+},{"./config":4}],4:[function(require,module,exports){
+module.exports = {
+
+ /**
+ * ### config.includeStack
+ *
+ * User configurable property, influences whether stack trace
+ * is included in Assertion error message. Default of false
+ * suppresses stack trace in the error message.
+ *
+ * chai.config.includeStack = true; // enable stack on error
+ *
+ * @param {Boolean}
+ * @api public
+ */
+
+ includeStack: false,
+
+ /**
+ * ### config.showDiff
+ *
+ * User configurable property, influences whether or not
+ * the `showDiff` flag should be included in the thrown
+ * AssertionErrors. `false` will always be `false`; `true`
+ * will be true when the assertion has requested a diff
+ * be shown.
+ *
+ * @param {Boolean}
+ * @api public
+ */
+
+ showDiff: true,
+
+ /**
+ * ### config.truncateThreshold
+ *
+ * User configurable property, sets length threshold for actual and
+ * expected values in assertion errors. If this threshold is exceeded, for
+ * example for large data structures, the value is replaced with something
+ * like `[ Array(3) ]` or `{ Object (prop1, prop2) }`.
+ *
+ * Set it to zero if you want to disable truncating altogether.
+ *
+ * This is especially userful when doing assertions on arrays: having this
+ * set to a reasonable large value makes the failure messages readily
+ * inspectable.
+ *
+ * chai.config.truncateThreshold = 0; // disable truncating
+ *
+ * @param {Number}
+ * @api public
+ */
+
+ truncateThreshold: 40,
+
+ /**
+ * ### config.useProxy
+ *
+ * User configurable property, defines if chai will use a Proxy to throw
+ * an error when a non-existent property is read, which protects users
+ * from typos when using property-based assertions.
+ *
+ * Set it to false if you want to disable this feature.
+ *
+ * chai.config.useProxy = false; // disable use of Proxy
+ *
+ * This feature is automatically disabled regardless of this config value
+ * in environments that don't support proxies.
+ *
+ * @param {Boolean}
+ * @api public
+ */
+
+ useProxy: true,
+
+ /**
+ * ### config.proxyExcludedKeys
+ *
+ * User configurable property, defines which properties should be ignored
+ * instead of throwing an error if they do not exist on the assertion.
+ * This is only applied if the environment Chai is running in supports proxies and
+ * if the `useProxy` configuration setting is enabled.
+ * By default, `then` and `inspect` will not throw an error if they do not exist on the
+ * assertion object because the `.inspect` property is read by `util.inspect` (for example, when
+ * using `console.log` on the assertion object) and `.then` is necessary for promise type-checking.
+ *
+ * // By default these keys will not throw an error if they do not exist on the assertion object
+ * chai.config.proxyExcludedKeys = ['then', 'inspect'];
+ *
+ * @param {Array}
+ * @api public
+ */
+
+ proxyExcludedKeys: ['then', 'inspect', 'toJSON']
+};
+
+},{}],5:[function(require,module,exports){
+/*!
+ * chai
+ * http://chaijs.com
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+module.exports = function (chai, _) {
+ var Assertion = chai.Assertion
+ , AssertionError = chai.AssertionError
+ , flag = _.flag;
+
+ /**
+ * ### Language Chains
+ *
+ * The following are provided as chainable getters to improve the readability
+ * of your assertions.
+ *
+ * **Chains**
+ *
+ * - to
+ * - be
+ * - been
+ * - is
+ * - that
+ * - which
+ * - and
+ * - has
+ * - have
+ * - with
+ * - at
+ * - of
+ * - same
+ * - but
+ * - does
+ *
+ * @name language chains
+ * @namespace BDD
+ * @api public
+ */
+
+ [ 'to', 'be', 'been'
+ , 'is', 'and', 'has', 'have'
+ , 'with', 'that', 'which', 'at'
+ , 'of', 'same', 'but', 'does' ].forEach(function (chain) {
+ Assertion.addProperty(chain);
+ });
+
+ /**
+ * ### .not
+ *
+ * Negates all assertions that follow in the chain.
+ *
+ * expect(function () {}).to.not.throw();
+ * expect({a: 1}).to.not.have.property('b');
+ * expect([1, 2]).to.be.an('array').that.does.not.include(3);
+ *
+ * Just because you can negate any assertion with `.not` doesn't mean you
+ * should. With great power comes great responsibility. It's often best to
+ * assert that the one expected output was produced, rather than asserting
+ * that one of countless unexpected outputs wasn't produced. See individual
+ * assertions for specific guidance.
+ *
+ * expect(2).to.equal(2); // Recommended
+ * expect(2).to.not.equal(1); // Not recommended
+ *
+ * @name not
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('not', function () {
+ flag(this, 'negate', true);
+ });
+
+ /**
+ * ### .deep
+ *
+ * Causes all `.equal`, `.include`, `.members`, `.keys`, and `.property`
+ * assertions that follow in the chain to use deep equality instead of strict
+ * (`===`) equality. See the `deep-eql` project page for info on the deep
+ * equality algorithm: https://github.com/chaijs/deep-eql.
+ *
+ * // Target object deeply (but not strictly) equals `{a: 1}`
+ * expect({a: 1}).to.deep.equal({a: 1});
+ * expect({a: 1}).to.not.equal({a: 1});
+ *
+ * // Target array deeply (but not strictly) includes `{a: 1}`
+ * expect([{a: 1}]).to.deep.include({a: 1});
+ * expect([{a: 1}]).to.not.include({a: 1});
+ *
+ * // Target object deeply (but not strictly) includes `x: {a: 1}`
+ * expect({x: {a: 1}}).to.deep.include({x: {a: 1}});
+ * expect({x: {a: 1}}).to.not.include({x: {a: 1}});
+ *
+ * // Target array deeply (but not strictly) has member `{a: 1}`
+ * expect([{a: 1}]).to.have.deep.members([{a: 1}]);
+ * expect([{a: 1}]).to.not.have.members([{a: 1}]);
+ *
+ * // Target set deeply (but not strictly) has key `{a: 1}`
+ * expect(new Set([{a: 1}])).to.have.deep.keys([{a: 1}]);
+ * expect(new Set([{a: 1}])).to.not.have.keys([{a: 1}]);
+ *
+ * // Target object deeply (but not strictly) has property `x: {a: 1}`
+ * expect({x: {a: 1}}).to.have.deep.property('x', {a: 1});
+ * expect({x: {a: 1}}).to.not.have.property('x', {a: 1});
+ *
+ * @name deep
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('deep', function () {
+ flag(this, 'deep', true);
+ });
+
+ /**
+ * ### .nested
+ *
+ * Enables dot- and bracket-notation in all `.property` and `.include`
+ * assertions that follow in the chain.
+ *
+ * expect({a: {b: ['x', 'y']}}).to.have.nested.property('a.b[1]');
+ * expect({a: {b: ['x', 'y']}}).to.nested.include({'a.b[1]': 'y'});
+ *
+ * If `.` or `[]` are part of an actual property name, they can be escaped by
+ * adding two backslashes before them.
+ *
+ * expect({'.a': {'[b]': 'x'}}).to.have.nested.property('\\.a.\\[b\\]');
+ * expect({'.a': {'[b]': 'x'}}).to.nested.include({'\\.a.\\[b\\]': 'x'});
+ *
+ * `.nested` cannot be combined with `.own`.
+ *
+ * @name nested
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('nested', function () {
+ flag(this, 'nested', true);
+ });
+
+ /**
+ * ### .own
+ *
+ * Causes all `.property` and `.include` assertions that follow in the chain
+ * to ignore inherited properties.
+ *
+ * Object.prototype.b = 2;
+ *
+ * expect({a: 1}).to.have.own.property('a');
+ * expect({a: 1}).to.have.property('b').but.not.own.property('b');
+ *
+ * expect({a: 1}).to.own.include({a: 1});
+ * expect({a: 1}).to.include({b: 2}).but.not.own.include({b: 2});
+ *
+ * `.own` cannot be combined with `.nested`.
+ *
+ * @name own
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('own', function () {
+ flag(this, 'own', true);
+ });
+
+ /**
+ * ### .ordered
+ *
+ * Causes all `.members` assertions that follow in the chain to require that
+ * members be in the same order.
+ *
+ * expect([1, 2]).to.have.ordered.members([1, 2])
+ * .but.not.have.ordered.members([2, 1]);
+ *
+ * When `.include` and `.ordered` are combined, the ordering begins at the
+ * start of both arrays.
+ *
+ * expect([1, 2, 3]).to.include.ordered.members([1, 2])
+ * .but.not.include.ordered.members([2, 3]);
+ *
+ * @name ordered
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('ordered', function () {
+ flag(this, 'ordered', true);
+ });
+
+ /**
+ * ### .any
+ *
+ * Causes all `.keys` assertions that follow in the chain to only require that
+ * the target have at least one of the given keys. This is the opposite of
+ * `.all`, which requires that the target have all of the given keys.
+ *
+ * expect({a: 1, b: 2}).to.not.have.any.keys('c', 'd');
+ *
+ * See the `.keys` doc for guidance on when to use `.any` or `.all`.
+ *
+ * @name any
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('any', function () {
+ flag(this, 'any', true);
+ flag(this, 'all', false);
+ });
+
+
+ /**
+ * ### .all
+ *
+ * Causes all `.keys` assertions that follow in the chain to require that the
+ * target have all of the given keys. This is the opposite of `.any`, which
+ * only requires that the target have at least one of the given keys.
+ *
+ * expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
+ *
+ * Note that `.all` is used by default when neither `.all` nor `.any` are
+ * added earlier in the chain. However, it's often best to add `.all` anyway
+ * because it improves readability.
+ *
+ * See the `.keys` doc for guidance on when to use `.any` or `.all`.
+ *
+ * @name all
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('all', function () {
+ flag(this, 'all', true);
+ flag(this, 'any', false);
+ });
+
+ /**
+ * ### .a(type[, msg])
+ *
+ * Asserts that the target's type is equal to the given string `type`. Types
+ * are case insensitive. See the `type-detect` project page for info on the
+ * type detection algorithm: https://github.com/chaijs/type-detect.
+ *
+ * expect('foo').to.be.a('string');
+ * expect({a: 1}).to.be.an('object');
+ * expect(null).to.be.a('null');
+ * expect(undefined).to.be.an('undefined');
+ * expect(new Error).to.be.an('error');
+ * expect(Promise.resolve()).to.be.a('promise');
+ * expect(new Float32Array).to.be.a('float32array');
+ * expect(Symbol()).to.be.a('symbol');
+ *
+ * `.a` supports objects that have a custom type set via `Symbol.toStringTag`.
+ *
+ * var myObj = {
+ * [Symbol.toStringTag]: 'myCustomType'
+ * };
+ *
+ * expect(myObj).to.be.a('myCustomType').but.not.an('object');
+ *
+ * It's often best to use `.a` to check a target's type before making more
+ * assertions on the same target. That way, you avoid unexpected behavior from
+ * any assertion that does different things based on the target's type.
+ *
+ * expect([1, 2, 3]).to.be.an('array').that.includes(2);
+ * expect([]).to.be.an('array').that.is.empty;
+ *
+ * Add `.not` earlier in the chain to negate `.a`. However, it's often best to
+ * assert that the target is the expected type, rather than asserting that it
+ * isn't one of many unexpected types.
+ *
+ * expect('foo').to.be.a('string'); // Recommended
+ * expect('foo').to.not.be.an('array'); // Not recommended
+ *
+ * `.a` accepts an optional `msg` argument which is a custom error message to
+ * show when the assertion fails. The message can also be given as the second
+ * argument to `expect`.
+ *
+ * expect(1).to.be.a('string', 'nooo why fail??');
+ * expect(1, 'nooo why fail??').to.be.a('string');
+ *
+ * `.a` can also be used as a language chain to improve the readability of
+ * your assertions.
+ *
+ * expect({b: 2}).to.have.a.property('b');
+ *
+ * The alias `.an` can be used interchangeably with `.a`.
+ *
+ * @name a
+ * @alias an
+ * @param {String} type
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function an (type, msg) {
+ if (msg) flag(this, 'message', msg);
+ type = type.toLowerCase();
+ var obj = flag(this, 'object')
+ , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
+
+ this.assert(
+ type === _.type(obj).toLowerCase()
+ , 'expected #{this} to be ' + article + type
+ , 'expected #{this} not to be ' + article + type
+ );
+ }
+
+ Assertion.addChainableMethod('an', an);
+ Assertion.addChainableMethod('a', an);
+
+ /**
+ * ### .include(val[, msg])
+ *
+ * When the target is a string, `.include` asserts that the given string `val`
+ * is a substring of the target.
+ *
+ * expect('foobar').to.include('foo');
+ *
+ * When the target is an array, `.include` asserts that the given `val` is a
+ * member of the target.
+ *
+ * expect([1, 2, 3]).to.include(2);
+ *
+ * When the target is an object, `.include` asserts that the given object
+ * `val`'s properties are a subset of the target's properties.
+ *
+ * expect({a: 1, b: 2, c: 3}).to.include({a: 1, b: 2});
+ *
+ * When the target is a Set or WeakSet, `.include` asserts that the given `val` is a
+ * member of the target. SameValueZero equality algorithm is used.
+ *
+ * expect(new Set([1, 2])).to.include(2);
+ *
+ * When the target is a Map, `.include` asserts that the given `val` is one of
+ * the values of the target. SameValueZero equality algorithm is used.
+ *
+ * expect(new Map([['a', 1], ['b', 2]])).to.include(2);
+ *
+ * Because `.include` does different things based on the target's type, it's
+ * important to check the target's type before using `.include`. See the `.a`
+ * doc for info on testing a target's type.
+ *
+ * expect([1, 2, 3]).to.be.an('array').that.includes(2);
+ *
+ * By default, strict (`===`) equality is used to compare array members and
+ * object properties. Add `.deep` earlier in the chain to use deep equality
+ * instead (WeakSet targets are not supported). See the `deep-eql` project
+ * page for info on the deep equality algorithm: https://github.com/chaijs/deep-eql.
+ *
+ * // Target array deeply (but not strictly) includes `{a: 1}`
+ * expect([{a: 1}]).to.deep.include({a: 1});
+ * expect([{a: 1}]).to.not.include({a: 1});
+ *
+ * // Target object deeply (but not strictly) includes `x: {a: 1}`
+ * expect({x: {a: 1}}).to.deep.include({x: {a: 1}});
+ * expect({x: {a: 1}}).to.not.include({x: {a: 1}});
+ *
+ * By default, all of the target's properties are searched when working with
+ * objects. This includes properties that are inherited and/or non-enumerable.
+ * Add `.own` earlier in the chain to exclude the target's inherited
+ * properties from the search.
+ *
+ * Object.prototype.b = 2;
+ *
+ * expect({a: 1}).to.own.include({a: 1});
+ * expect({a: 1}).to.include({b: 2}).but.not.own.include({b: 2});
+ *
+ * Note that a target object is always only searched for `val`'s own
+ * enumerable properties.
+ *
+ * `.deep` and `.own` can be combined.
+ *
+ * expect({a: {b: 2}}).to.deep.own.include({a: {b: 2}});
+ *
+ * Add `.nested` earlier in the chain to enable dot- and bracket-notation when
+ * referencing nested properties.
+ *
+ * expect({a: {b: ['x', 'y']}}).to.nested.include({'a.b[1]': 'y'});
+ *
+ * If `.` or `[]` are part of an actual property name, they can be escaped by
+ * adding two backslashes before them.
+ *
+ * expect({'.a': {'[b]': 2}}).to.nested.include({'\\.a.\\[b\\]': 2});
+ *
+ * `.deep` and `.nested` can be combined.
+ *
+ * expect({a: {b: [{c: 3}]}}).to.deep.nested.include({'a.b[0]': {c: 3}});
+ *
+ * `.own` and `.nested` cannot be combined.
+ *
+ * Add `.not` earlier in the chain to negate `.include`.
+ *
+ * expect('foobar').to.not.include('taco');
+ * expect([1, 2, 3]).to.not.include(4);
+ *
+ * However, it's dangerous to negate `.include` when the target is an object.
+ * The problem is that it creates uncertain expectations by asserting that the
+ * target object doesn't have all of `val`'s key/value pairs but may or may
+ * not have some of them. It's often best to identify the exact output that's
+ * expected, and then write an assertion that only accepts that exact output.
+ *
+ * When the target object isn't even expected to have `val`'s keys, it's
+ * often best to assert exactly that.
+ *
+ * expect({c: 3}).to.not.have.any.keys('a', 'b'); // Recommended
+ * expect({c: 3}).to.not.include({a: 1, b: 2}); // Not recommended
+ *
+ * When the target object is expected to have `val`'s keys, it's often best to
+ * assert that each of the properties has its expected value, rather than
+ * asserting that each property doesn't have one of many unexpected values.
+ *
+ * expect({a: 3, b: 4}).to.include({a: 3, b: 4}); // Recommended
+ * expect({a: 3, b: 4}).to.not.include({a: 1, b: 2}); // Not recommended
+ *
+ * `.include` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`.
+ *
+ * expect([1, 2, 3]).to.include(4, 'nooo why fail??');
+ * expect([1, 2, 3], 'nooo why fail??').to.include(4);
+ *
+ * `.include` can also be used as a language chain, causing all `.members` and
+ * `.keys` assertions that follow in the chain to require the target to be a
+ * superset of the expected set, rather than an identical set. Note that
+ * `.members` ignores duplicates in the subset when `.include` is added.
+ *
+ * // Target object's keys are a superset of ['a', 'b'] but not identical
+ * expect({a: 1, b: 2, c: 3}).to.include.all.keys('a', 'b');
+ * expect({a: 1, b: 2, c: 3}).to.not.have.all.keys('a', 'b');
+ *
+ * // Target array is a superset of [1, 2] but not identical
+ * expect([1, 2, 3]).to.include.members([1, 2]);
+ * expect([1, 2, 3]).to.not.have.members([1, 2]);
+ *
+ * // Duplicates in the subset are ignored
+ * expect([1, 2, 3]).to.include.members([1, 2, 2, 2]);
+ *
+ * Note that adding `.any` earlier in the chain causes the `.keys` assertion
+ * to ignore `.include`.
+ *
+ * // Both assertions are identical
+ * expect({a: 1}).to.include.any.keys('a', 'b');
+ * expect({a: 1}).to.have.any.keys('a', 'b');
+ *
+ * The aliases `.includes`, `.contain`, and `.contains` can be used
+ * interchangeably with `.include`.
+ *
+ * @name include
+ * @alias contain
+ * @alias includes
+ * @alias contains
+ * @param {Mixed} val
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function SameValueZero(a, b) {
+ return (_.isNaN(a) && _.isNaN(b)) || a === b;
+ }
+
+ function includeChainingBehavior () {
+ flag(this, 'contains', true);
+ }
+
+ function include (val, msg) {
+ if (msg) flag(this, 'message', msg);
+
+ var obj = flag(this, 'object')
+ , objType = _.type(obj).toLowerCase()
+ , flagMsg = flag(this, 'message')
+ , negate = flag(this, 'negate')
+ , ssfi = flag(this, 'ssfi')
+ , isDeep = flag(this, 'deep')
+ , descriptor = isDeep ? 'deep ' : '';
+
+ flagMsg = flagMsg ? flagMsg + ': ' : '';
+
+ var included = false;
+
+ switch (objType) {
+ case 'string':
+ included = obj.indexOf(val) !== -1;
+ break;
+
+ case 'weakset':
+ if (isDeep) {
+ throw new AssertionError(
+ flagMsg + 'unable to use .deep.include with WeakSet',
+ undefined,
+ ssfi
+ );
+ }
+
+ included = obj.has(val);
+ break;
+
+ case 'map':
+ var isEql = isDeep ? _.eql : SameValueZero;
+ obj.forEach(function (item) {
+ included = included || isEql(item, val);
+ });
+ break;
+
+ case 'set':
+ if (isDeep) {
+ obj.forEach(function (item) {
+ included = included || _.eql(item, val);
+ });
+ } else {
+ included = obj.has(val);
+ }
+ break;
+
+ case 'array':
+ if (isDeep) {
+ included = obj.some(function (item) {
+ return _.eql(item, val);
+ })
+ } else {
+ included = obj.indexOf(val) !== -1;
+ }
+ break;
+
+ default:
+ // This block is for asserting a subset of properties in an object.
+ // `_.expectTypes` isn't used here because `.include` should work with
+ // objects with a custom `@@toStringTag`.
+ if (val !== Object(val)) {
+ throw new AssertionError(
+ flagMsg + 'object tested must be an array, a map, an object,'
+ + ' a set, a string, or a weakset, but ' + objType + ' given',
+ undefined,
+ ssfi
+ );
+ }
+
+ var props = Object.keys(val)
+ , firstErr = null
+ , numErrs = 0;
+
+ props.forEach(function (prop) {
+ var propAssertion = new Assertion(obj);
+ _.transferFlags(this, propAssertion, true);
+ flag(propAssertion, 'lockSsfi', true);
+
+ if (!negate || props.length === 1) {
+ propAssertion.property(prop, val[prop]);
+ return;
+ }
+
+ try {
+ propAssertion.property(prop, val[prop]);
+ } catch (err) {
+ if (!_.checkError.compatibleConstructor(err, AssertionError)) {
+ throw err;
+ }
+ if (firstErr === null) firstErr = err;
+ numErrs++;
+ }
+ }, this);
+
+ // When validating .not.include with multiple properties, we only want
+ // to throw an assertion error if all of the properties are included,
+ // in which case we throw the first property assertion error that we
+ // encountered.
+ if (negate && props.length > 1 && numErrs === props.length) {
+ throw firstErr;
+ }
+ return;
+ }
+
+ // Assert inclusion in collection or substring in a string.
+ this.assert(
+ included
+ , 'expected #{this} to ' + descriptor + 'include ' + _.inspect(val)
+ , 'expected #{this} to not ' + descriptor + 'include ' + _.inspect(val));
+ }
+
+ Assertion.addChainableMethod('include', include, includeChainingBehavior);
+ Assertion.addChainableMethod('contain', include, includeChainingBehavior);
+ Assertion.addChainableMethod('contains', include, includeChainingBehavior);
+ Assertion.addChainableMethod('includes', include, includeChainingBehavior);
+
+ /**
+ * ### .ok
+ *
+ * Asserts that the target is loosely (`==`) equal to `true`. However, it's
+ * often best to assert that the target is strictly (`===`) or deeply equal to
+ * its expected value.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.be.ok; // Not recommended
+ *
+ * expect(true).to.be.true; // Recommended
+ * expect(true).to.be.ok; // Not recommended
+ *
+ * Add `.not` earlier in the chain to negate `.ok`.
+ *
+ * expect(0).to.equal(0); // Recommended
+ * expect(0).to.not.be.ok; // Not recommended
+ *
+ * expect(false).to.be.false; // Recommended
+ * expect(false).to.not.be.ok; // Not recommended
+ *
+ * expect(null).to.be.null; // Recommended
+ * expect(null).to.not.be.ok; // Not recommended
+ *
+ * expect(undefined).to.be.undefined; // Recommended
+ * expect(undefined).to.not.be.ok; // Not recommended
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect(false, 'nooo why fail??').to.be.ok;
+ *
+ * @name ok
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('ok', function () {
+ this.assert(
+ flag(this, 'object')
+ , 'expected #{this} to be truthy'
+ , 'expected #{this} to be falsy');
+ });
+
+ /**
+ * ### .true
+ *
+ * Asserts that the target is strictly (`===`) equal to `true`.
+ *
+ * expect(true).to.be.true;
+ *
+ * Add `.not` earlier in the chain to negate `.true`. However, it's often best
+ * to assert that the target is equal to its expected value, rather than not
+ * equal to `true`.
+ *
+ * expect(false).to.be.false; // Recommended
+ * expect(false).to.not.be.true; // Not recommended
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.not.be.true; // Not recommended
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect(false, 'nooo why fail??').to.be.true;
+ *
+ * @name true
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('true', function () {
+ this.assert(
+ true === flag(this, 'object')
+ , 'expected #{this} to be true'
+ , 'expected #{this} to be false'
+ , flag(this, 'negate') ? false : true
+ );
+ });
+
+ /**
+ * ### .false
+ *
+ * Asserts that the target is strictly (`===`) equal to `false`.
+ *
+ * expect(false).to.be.false;
+ *
+ * Add `.not` earlier in the chain to negate `.false`. However, it's often
+ * best to assert that the target is equal to its expected value, rather than
+ * not equal to `false`.
+ *
+ * expect(true).to.be.true; // Recommended
+ * expect(true).to.not.be.false; // Not recommended
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.not.be.false; // Not recommended
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect(true, 'nooo why fail??').to.be.false;
+ *
+ * @name false
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('false', function () {
+ this.assert(
+ false === flag(this, 'object')
+ , 'expected #{this} to be false'
+ , 'expected #{this} to be true'
+ , flag(this, 'negate') ? true : false
+ );
+ });
+
+ /**
+ * ### .null
+ *
+ * Asserts that the target is strictly (`===`) equal to `null`.
+ *
+ * expect(null).to.be.null;
+ *
+ * Add `.not` earlier in the chain to negate `.null`. However, it's often best
+ * to assert that the target is equal to its expected value, rather than not
+ * equal to `null`.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.not.be.null; // Not recommended
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect(42, 'nooo why fail??').to.be.null;
+ *
+ * @name null
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('null', function () {
+ this.assert(
+ null === flag(this, 'object')
+ , 'expected #{this} to be null'
+ , 'expected #{this} not to be null'
+ );
+ });
+
+ /**
+ * ### .undefined
+ *
+ * Asserts that the target is strictly (`===`) equal to `undefined`.
+ *
+ * expect(undefined).to.be.undefined;
+ *
+ * Add `.not` earlier in the chain to negate `.undefined`. However, it's often
+ * best to assert that the target is equal to its expected value, rather than
+ * not equal to `undefined`.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.not.be.undefined; // Not recommended
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect(42, 'nooo why fail??').to.be.undefined;
+ *
+ * @name undefined
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('undefined', function () {
+ this.assert(
+ undefined === flag(this, 'object')
+ , 'expected #{this} to be undefined'
+ , 'expected #{this} not to be undefined'
+ );
+ });
+
+ /**
+ * ### .NaN
+ *
+ * Asserts that the target is exactly `NaN`.
+ *
+ * expect(NaN).to.be.NaN;
+ *
+ * Add `.not` earlier in the chain to negate `.NaN`. However, it's often best
+ * to assert that the target is equal to its expected value, rather than not
+ * equal to `NaN`.
+ *
+ * expect('foo').to.equal('foo'); // Recommended
+ * expect('foo').to.not.be.NaN; // Not recommended
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect(42, 'nooo why fail??').to.be.NaN;
+ *
+ * @name NaN
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('NaN', function () {
+ this.assert(
+ _.isNaN(flag(this, 'object'))
+ , 'expected #{this} to be NaN'
+ , 'expected #{this} not to be NaN'
+ );
+ });
+
+ /**
+ * ### .exist
+ *
+ * Asserts that the target is not strictly (`===`) equal to either `null` or
+ * `undefined`. However, it's often best to assert that the target is equal to
+ * its expected value.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.exist; // Not recommended
+ *
+ * expect(0).to.equal(0); // Recommended
+ * expect(0).to.exist; // Not recommended
+ *
+ * Add `.not` earlier in the chain to negate `.exist`.
+ *
+ * expect(null).to.be.null; // Recommended
+ * expect(null).to.not.exist; // Not recommended
+ *
+ * expect(undefined).to.be.undefined; // Recommended
+ * expect(undefined).to.not.exist; // Not recommended
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect(null, 'nooo why fail??').to.exist;
+ *
+ * @name exist
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('exist', function () {
+ var val = flag(this, 'object');
+ this.assert(
+ val !== null && val !== undefined
+ , 'expected #{this} to exist'
+ , 'expected #{this} to not exist'
+ );
+ });
+
+ /**
+ * ### .empty
+ *
+ * When the target is a string or array, `.empty` asserts that the target's
+ * `length` property is strictly (`===`) equal to `0`.
+ *
+ * expect([]).to.be.empty;
+ * expect('').to.be.empty;
+ *
+ * When the target is a map or set, `.empty` asserts that the target's `size`
+ * property is strictly equal to `0`.
+ *
+ * expect(new Set()).to.be.empty;
+ * expect(new Map()).to.be.empty;
+ *
+ * When the target is a non-function object, `.empty` asserts that the target
+ * doesn't have any own enumerable properties. Properties with Symbol-based
+ * keys are excluded from the count.
+ *
+ * expect({}).to.be.empty;
+ *
+ * Because `.empty` does different things based on the target's type, it's
+ * important to check the target's type before using `.empty`. See the `.a`
+ * doc for info on testing a target's type.
+ *
+ * expect([]).to.be.an('array').that.is.empty;
+ *
+ * Add `.not` earlier in the chain to negate `.empty`. However, it's often
+ * best to assert that the target contains its expected number of values,
+ * rather than asserting that it's not empty.
+ *
+ * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
+ * expect([1, 2, 3]).to.not.be.empty; // Not recommended
+ *
+ * expect(new Set([1, 2, 3])).to.have.property('size', 3); // Recommended
+ * expect(new Set([1, 2, 3])).to.not.be.empty; // Not recommended
+ *
+ * expect(Object.keys({a: 1})).to.have.lengthOf(1); // Recommended
+ * expect({a: 1}).to.not.be.empty; // Not recommended
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect([1, 2, 3], 'nooo why fail??').to.be.empty;
+ *
+ * @name empty
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('empty', function () {
+ var val = flag(this, 'object')
+ , ssfi = flag(this, 'ssfi')
+ , flagMsg = flag(this, 'message')
+ , itemsCount;
+
+ flagMsg = flagMsg ? flagMsg + ': ' : '';
+
+ switch (_.type(val).toLowerCase()) {
+ case 'array':
+ case 'string':
+ itemsCount = val.length;
+ break;
+ case 'map':
+ case 'set':
+ itemsCount = val.size;
+ break;
+ case 'weakmap':
+ case 'weakset':
+ throw new AssertionError(
+ flagMsg + '.empty was passed a weak collection',
+ undefined,
+ ssfi
+ );
+ case 'function':
+ var msg = flagMsg + '.empty was passed a function ' + _.getName(val);
+ throw new AssertionError(msg.trim(), undefined, ssfi);
+ default:
+ if (val !== Object(val)) {
+ throw new AssertionError(
+ flagMsg + '.empty was passed non-string primitive ' + _.inspect(val),
+ undefined,
+ ssfi
+ );
+ }
+ itemsCount = Object.keys(val).length;
+ }
+
+ this.assert(
+ 0 === itemsCount
+ , 'expected #{this} to be empty'
+ , 'expected #{this} not to be empty'
+ );
+ });
+
+ /**
+ * ### .arguments
+ *
+ * Asserts that the target is an `arguments` object.
+ *
+ * function test () {
+ * expect(arguments).to.be.arguments;
+ * }
+ *
+ * test();
+ *
+ * Add `.not` earlier in the chain to negate `.arguments`. However, it's often
+ * best to assert which type the target is expected to be, rather than
+ * asserting that its not an `arguments` object.
+ *
+ * expect('foo').to.be.a('string'); // Recommended
+ * expect('foo').to.not.be.arguments; // Not recommended
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect({}, 'nooo why fail??').to.be.arguments;
+ *
+ * The alias `.Arguments` can be used interchangeably with `.arguments`.
+ *
+ * @name arguments
+ * @alias Arguments
+ * @namespace BDD
+ * @api public
+ */
+
+ function checkArguments () {
+ var obj = flag(this, 'object')
+ , type = _.type(obj);
+ this.assert(
+ 'Arguments' === type
+ , 'expected #{this} to be arguments but got ' + type
+ , 'expected #{this} to not be arguments'
+ );
+ }
+
+ Assertion.addProperty('arguments', checkArguments);
+ Assertion.addProperty('Arguments', checkArguments);
+
+ /**
+ * ### .equal(val[, msg])
+ *
+ * Asserts that the target is strictly (`===`) equal to the given `val`.
+ *
+ * expect(1).to.equal(1);
+ * expect('foo').to.equal('foo');
+ *
+ * Add `.deep` earlier in the chain to use deep equality instead. See the
+ * `deep-eql` project page for info on the deep equality algorithm:
+ * https://github.com/chaijs/deep-eql.
+ *
+ * // Target object deeply (but not strictly) equals `{a: 1}`
+ * expect({a: 1}).to.deep.equal({a: 1});
+ * expect({a: 1}).to.not.equal({a: 1});
+ *
+ * // Target array deeply (but not strictly) equals `[1, 2]`
+ * expect([1, 2]).to.deep.equal([1, 2]);
+ * expect([1, 2]).to.not.equal([1, 2]);
+ *
+ * Add `.not` earlier in the chain to negate `.equal`. However, it's often
+ * best to assert that the target is equal to its expected value, rather than
+ * not equal to one of countless unexpected values.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.not.equal(2); // Not recommended
+ *
+ * `.equal` accepts an optional `msg` argument which is a custom error message
+ * to show when the assertion fails. The message can also be given as the
+ * second argument to `expect`.
+ *
+ * expect(1).to.equal(2, 'nooo why fail??');
+ * expect(1, 'nooo why fail??').to.equal(2);
+ *
+ * The aliases `.equals` and `eq` can be used interchangeably with `.equal`.
+ *
+ * @name equal
+ * @alias equals
+ * @alias eq
+ * @param {Mixed} val
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertEqual (val, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object');
+ if (flag(this, 'deep')) {
+ return this.eql(val);
+ } else {
+ this.assert(
+ val === obj
+ , 'expected #{this} to equal #{exp}'
+ , 'expected #{this} to not equal #{exp}'
+ , val
+ , this._obj
+ , true
+ );
+ }
+ }
+
+ Assertion.addMethod('equal', assertEqual);
+ Assertion.addMethod('equals', assertEqual);
+ Assertion.addMethod('eq', assertEqual);
+
+ /**
+ * ### .eql(obj[, msg])
+ *
+ * Asserts that the target is deeply equal to the given `obj`. See the
+ * `deep-eql` project page for info on the deep equality algorithm:
+ * https://github.com/chaijs/deep-eql.
+ *
+ * // Target object is deeply (but not strictly) equal to {a: 1}
+ * expect({a: 1}).to.eql({a: 1}).but.not.equal({a: 1});
+ *
+ * // Target array is deeply (but not strictly) equal to [1, 2]
+ * expect([1, 2]).to.eql([1, 2]).but.not.equal([1, 2]);
+ *
+ * Add `.not` earlier in the chain to negate `.eql`. However, it's often best
+ * to assert that the target is deeply equal to its expected value, rather
+ * than not deeply equal to one of countless unexpected values.
+ *
+ * expect({a: 1}).to.eql({a: 1}); // Recommended
+ * expect({a: 1}).to.not.eql({b: 2}); // Not recommended
+ *
+ * `.eql` accepts an optional `msg` argument which is a custom error message
+ * to show when the assertion fails. The message can also be given as the
+ * second argument to `expect`.
+ *
+ * expect({a: 1}).to.eql({b: 2}, 'nooo why fail??');
+ * expect({a: 1}, 'nooo why fail??').to.eql({b: 2});
+ *
+ * The alias `.eqls` can be used interchangeably with `.eql`.
+ *
+ * The `.deep.equal` assertion is almost identical to `.eql` but with one
+ * difference: `.deep.equal` causes deep equality comparisons to also be used
+ * for any other assertions that follow in the chain.
+ *
+ * @name eql
+ * @alias eqls
+ * @param {Mixed} obj
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertEql(obj, msg) {
+ if (msg) flag(this, 'message', msg);
+ this.assert(
+ _.eql(obj, flag(this, 'object'))
+ , 'expected #{this} to deeply equal #{exp}'
+ , 'expected #{this} to not deeply equal #{exp}'
+ , obj
+ , this._obj
+ , true
+ );
+ }
+
+ Assertion.addMethod('eql', assertEql);
+ Assertion.addMethod('eqls', assertEql);
+
+ /**
+ * ### .above(n[, msg])
+ *
+ * Asserts that the target is a number or a date greater than the given number or date `n` respectively.
+ * However, it's often best to assert that the target is equal to its expected
+ * value.
+ *
+ * expect(2).to.equal(2); // Recommended
+ * expect(2).to.be.above(1); // Not recommended
+ *
+ * Add `.lengthOf` earlier in the chain to assert that the value of the
+ * target's `length` property is greater than the given number `n`.
+ *
+ * expect('foo').to.have.lengthOf(3); // Recommended
+ * expect('foo').to.have.lengthOf.above(2); // Not recommended
+ *
+ * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
+ * expect([1, 2, 3]).to.have.lengthOf.above(2); // Not recommended
+ *
+ * Add `.not` earlier in the chain to negate `.above`.
+ *
+ * expect(2).to.equal(2); // Recommended
+ * expect(1).to.not.be.above(2); // Not recommended
+ *
+ * `.above` accepts an optional `msg` argument which is a custom error message
+ * to show when the assertion fails. The message can also be given as the
+ * second argument to `expect`.
+ *
+ * expect(1).to.be.above(2, 'nooo why fail??');
+ * expect(1, 'nooo why fail??').to.be.above(2);
+ *
+ * The aliases `.gt` and `.greaterThan` can be used interchangeably with
+ * `.above`.
+ *
+ * @name above
+ * @alias gt
+ * @alias greaterThan
+ * @param {Number} n
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertAbove (n, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , doLength = flag(this, 'doLength')
+ , flagMsg = flag(this, 'message')
+ , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
+ , ssfi = flag(this, 'ssfi')
+ , objType = _.type(obj).toLowerCase()
+ , nType = _.type(n).toLowerCase()
+ , shouldThrow = true;
+
+ if (doLength) {
+ new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
+ }
+
+ if (!doLength && (objType === 'date' && nType !== 'date')) {
+ errorMessage = msgPrefix + 'the argument to above must be a date';
+ } else if (nType !== 'number' && (doLength || objType === 'number')) {
+ errorMessage = msgPrefix + 'the argument to above must be a number';
+ } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
+ var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
+ errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
+ } else {
+ shouldThrow = false;
+ }
+
+ if (shouldThrow) {
+ throw new AssertionError(errorMessage, undefined, ssfi);
+ }
+
+ if (doLength) {
+ var len = obj.length;
+ this.assert(
+ len > n
+ , 'expected #{this} to have a length above #{exp} but got #{act}'
+ , 'expected #{this} to not have a length above #{exp}'
+ , n
+ , len
+ );
+ } else {
+ this.assert(
+ obj > n
+ , 'expected #{this} to be above #{exp}'
+ , 'expected #{this} to be at most #{exp}'
+ , n
+ );
+ }
+ }
+
+ Assertion.addMethod('above', assertAbove);
+ Assertion.addMethod('gt', assertAbove);
+ Assertion.addMethod('greaterThan', assertAbove);
+
+ /**
+ * ### .least(n[, msg])
+ *
+ * Asserts that the target is a number or a date greater than or equal to the given
+ * number or date `n` respectively. However, it's often best to assert that the target is equal to
+ * its expected value.
+ *
+ * expect(2).to.equal(2); // Recommended
+ * expect(2).to.be.at.least(1); // Not recommended
+ * expect(2).to.be.at.least(2); // Not recommended
+ *
+ * Add `.lengthOf` earlier in the chain to assert that the value of the
+ * target's `length` property is greater than or equal to the given number
+ * `n`.
+ *
+ * expect('foo').to.have.lengthOf(3); // Recommended
+ * expect('foo').to.have.lengthOf.at.least(2); // Not recommended
+ *
+ * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
+ * expect([1, 2, 3]).to.have.lengthOf.at.least(2); // Not recommended
+ *
+ * Add `.not` earlier in the chain to negate `.least`.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.not.be.at.least(2); // Not recommended
+ *
+ * `.least` accepts an optional `msg` argument which is a custom error message
+ * to show when the assertion fails. The message can also be given as the
+ * second argument to `expect`.
+ *
+ * expect(1).to.be.at.least(2, 'nooo why fail??');
+ * expect(1, 'nooo why fail??').to.be.at.least(2);
+ *
+ * The alias `.gte` can be used interchangeably with `.least`.
+ *
+ * @name least
+ * @alias gte
+ * @param {Number} n
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertLeast (n, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , doLength = flag(this, 'doLength')
+ , flagMsg = flag(this, 'message')
+ , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
+ , ssfi = flag(this, 'ssfi')
+ , objType = _.type(obj).toLowerCase()
+ , nType = _.type(n).toLowerCase()
+ , shouldThrow = true;
+
+ if (doLength) {
+ new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
+ }
+
+ if (!doLength && (objType === 'date' && nType !== 'date')) {
+ errorMessage = msgPrefix + 'the argument to least must be a date';
+ } else if (nType !== 'number' && (doLength || objType === 'number')) {
+ errorMessage = msgPrefix + 'the argument to least must be a number';
+ } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
+ var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
+ errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
+ } else {
+ shouldThrow = false;
+ }
+
+ if (shouldThrow) {
+ throw new AssertionError(errorMessage, undefined, ssfi);
+ }
+
+ if (doLength) {
+ var len = obj.length;
+ this.assert(
+ len >= n
+ , 'expected #{this} to have a length at least #{exp} but got #{act}'
+ , 'expected #{this} to have a length below #{exp}'
+ , n
+ , len
+ );
+ } else {
+ this.assert(
+ obj >= n
+ , 'expected #{this} to be at least #{exp}'
+ , 'expected #{this} to be below #{exp}'
+ , n
+ );
+ }
+ }
+
+ Assertion.addMethod('least', assertLeast);
+ Assertion.addMethod('gte', assertLeast);
+
+ /**
+ * ### .below(n[, msg])
+ *
+ * Asserts that the target is a number or a date less than the given number or date `n` respectively.
+ * However, it's often best to assert that the target is equal to its expected
+ * value.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.be.below(2); // Not recommended
+ *
+ * Add `.lengthOf` earlier in the chain to assert that the value of the
+ * target's `length` property is less than the given number `n`.
+ *
+ * expect('foo').to.have.lengthOf(3); // Recommended
+ * expect('foo').to.have.lengthOf.below(4); // Not recommended
+ *
+ * expect([1, 2, 3]).to.have.length(3); // Recommended
+ * expect([1, 2, 3]).to.have.lengthOf.below(4); // Not recommended
+ *
+ * Add `.not` earlier in the chain to negate `.below`.
+ *
+ * expect(2).to.equal(2); // Recommended
+ * expect(2).to.not.be.below(1); // Not recommended
+ *
+ * `.below` accepts an optional `msg` argument which is a custom error message
+ * to show when the assertion fails. The message can also be given as the
+ * second argument to `expect`.
+ *
+ * expect(2).to.be.below(1, 'nooo why fail??');
+ * expect(2, 'nooo why fail??').to.be.below(1);
+ *
+ * The aliases `.lt` and `.lessThan` can be used interchangeably with
+ * `.below`.
+ *
+ * @name below
+ * @alias lt
+ * @alias lessThan
+ * @param {Number} n
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertBelow (n, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , doLength = flag(this, 'doLength')
+ , flagMsg = flag(this, 'message')
+ , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
+ , ssfi = flag(this, 'ssfi')
+ , objType = _.type(obj).toLowerCase()
+ , nType = _.type(n).toLowerCase()
+ , shouldThrow = true;
+
+ if (doLength) {
+ new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
+ }
+
+ if (!doLength && (objType === 'date' && nType !== 'date')) {
+ errorMessage = msgPrefix + 'the argument to below must be a date';
+ } else if (nType !== 'number' && (doLength || objType === 'number')) {
+ errorMessage = msgPrefix + 'the argument to below must be a number';
+ } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
+ var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
+ errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
+ } else {
+ shouldThrow = false;
+ }
+
+ if (shouldThrow) {
+ throw new AssertionError(errorMessage, undefined, ssfi);
+ }
+
+ if (doLength) {
+ var len = obj.length;
+ this.assert(
+ len < n
+ , 'expected #{this} to have a length below #{exp} but got #{act}'
+ , 'expected #{this} to not have a length below #{exp}'
+ , n
+ , len
+ );
+ } else {
+ this.assert(
+ obj < n
+ , 'expected #{this} to be below #{exp}'
+ , 'expected #{this} to be at least #{exp}'
+ , n
+ );
+ }
+ }
+
+ Assertion.addMethod('below', assertBelow);
+ Assertion.addMethod('lt', assertBelow);
+ Assertion.addMethod('lessThan', assertBelow);
+
+ /**
+ * ### .most(n[, msg])
+ *
+ * Asserts that the target is a number or a date less than or equal to the given number
+ * or date `n` respectively. However, it's often best to assert that the target is equal to its
+ * expected value.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.be.at.most(2); // Not recommended
+ * expect(1).to.be.at.most(1); // Not recommended
+ *
+ * Add `.lengthOf` earlier in the chain to assert that the value of the
+ * target's `length` property is less than or equal to the given number `n`.
+ *
+ * expect('foo').to.have.lengthOf(3); // Recommended
+ * expect('foo').to.have.lengthOf.at.most(4); // Not recommended
+ *
+ * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
+ * expect([1, 2, 3]).to.have.lengthOf.at.most(4); // Not recommended
+ *
+ * Add `.not` earlier in the chain to negate `.most`.
+ *
+ * expect(2).to.equal(2); // Recommended
+ * expect(2).to.not.be.at.most(1); // Not recommended
+ *
+ * `.most` accepts an optional `msg` argument which is a custom error message
+ * to show when the assertion fails. The message can also be given as the
+ * second argument to `expect`.
+ *
+ * expect(2).to.be.at.most(1, 'nooo why fail??');
+ * expect(2, 'nooo why fail??').to.be.at.most(1);
+ *
+ * The alias `.lte` can be used interchangeably with `.most`.
+ *
+ * @name most
+ * @alias lte
+ * @param {Number} n
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertMost (n, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , doLength = flag(this, 'doLength')
+ , flagMsg = flag(this, 'message')
+ , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
+ , ssfi = flag(this, 'ssfi')
+ , objType = _.type(obj).toLowerCase()
+ , nType = _.type(n).toLowerCase()
+ , shouldThrow = true;
+
+ if (doLength) {
+ new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
+ }
+
+ if (!doLength && (objType === 'date' && nType !== 'date')) {
+ errorMessage = msgPrefix + 'the argument to most must be a date';
+ } else if (nType !== 'number' && (doLength || objType === 'number')) {
+ errorMessage = msgPrefix + 'the argument to most must be a number';
+ } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
+ var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
+ errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
+ } else {
+ shouldThrow = false;
+ }
+
+ if (shouldThrow) {
+ throw new AssertionError(errorMessage, undefined, ssfi);
+ }
+
+ if (doLength) {
+ var len = obj.length;
+ this.assert(
+ len <= n
+ , 'expected #{this} to have a length at most #{exp} but got #{act}'
+ , 'expected #{this} to have a length above #{exp}'
+ , n
+ , len
+ );
+ } else {
+ this.assert(
+ obj <= n
+ , 'expected #{this} to be at most #{exp}'
+ , 'expected #{this} to be above #{exp}'
+ , n
+ );
+ }
+ }
+
+ Assertion.addMethod('most', assertMost);
+ Assertion.addMethod('lte', assertMost);
+
+ /**
+ * ### .within(start, finish[, msg])
+ *
+ * Asserts that the target is a number or a date greater than or equal to the given
+ * number or date `start`, and less than or equal to the given number or date `finish` respectively.
+ * However, it's often best to assert that the target is equal to its expected
+ * value.
+ *
+ * expect(2).to.equal(2); // Recommended
+ * expect(2).to.be.within(1, 3); // Not recommended
+ * expect(2).to.be.within(2, 3); // Not recommended
+ * expect(2).to.be.within(1, 2); // Not recommended
+ *
+ * Add `.lengthOf` earlier in the chain to assert that the value of the
+ * target's `length` property is greater than or equal to the given number
+ * `start`, and less than or equal to the given number `finish`.
+ *
+ * expect('foo').to.have.lengthOf(3); // Recommended
+ * expect('foo').to.have.lengthOf.within(2, 4); // Not recommended
+ *
+ * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
+ * expect([1, 2, 3]).to.have.lengthOf.within(2, 4); // Not recommended
+ *
+ * Add `.not` earlier in the chain to negate `.within`.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.not.be.within(2, 4); // Not recommended
+ *
+ * `.within` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`.
+ *
+ * expect(4).to.be.within(1, 3, 'nooo why fail??');
+ * expect(4, 'nooo why fail??').to.be.within(1, 3);
+ *
+ * @name within
+ * @param {Number} start lower bound inclusive
+ * @param {Number} finish upper bound inclusive
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addMethod('within', function (start, finish, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , doLength = flag(this, 'doLength')
+ , flagMsg = flag(this, 'message')
+ , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
+ , ssfi = flag(this, 'ssfi')
+ , objType = _.type(obj).toLowerCase()
+ , startType = _.type(start).toLowerCase()
+ , finishType = _.type(finish).toLowerCase()
+ , shouldThrow = true
+ , range = (startType === 'date' && finishType === 'date')
+ ? start.toUTCString() + '..' + finish.toUTCString()
+ : start + '..' + finish;
+
+ if (doLength) {
+ new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
+ }
+
+ if (!doLength && (objType === 'date' && (startType !== 'date' || finishType !== 'date'))) {
+ errorMessage = msgPrefix + 'the arguments to within must be dates';
+ } else if ((startType !== 'number' || finishType !== 'number') && (doLength || objType === 'number')) {
+ errorMessage = msgPrefix + 'the arguments to within must be numbers';
+ } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
+ var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
+ errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
+ } else {
+ shouldThrow = false;
+ }
+
+ if (shouldThrow) {
+ throw new AssertionError(errorMessage, undefined, ssfi);
+ }
+
+ if (doLength) {
+ var len = obj.length;
+ this.assert(
+ len >= start && len <= finish
+ , 'expected #{this} to have a length within ' + range
+ , 'expected #{this} to not have a length within ' + range
+ );
+ } else {
+ this.assert(
+ obj >= start && obj <= finish
+ , 'expected #{this} to be within ' + range
+ , 'expected #{this} to not be within ' + range
+ );
+ }
+ });
+
+ /**
+ * ### .instanceof(constructor[, msg])
+ *
+ * Asserts that the target is an instance of the given `constructor`.
+ *
+ * function Cat () { }
+ *
+ * expect(new Cat()).to.be.an.instanceof(Cat);
+ * expect([1, 2]).to.be.an.instanceof(Array);
+ *
+ * Add `.not` earlier in the chain to negate `.instanceof`.
+ *
+ * expect({a: 1}).to.not.be.an.instanceof(Array);
+ *
+ * `.instanceof` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`.
+ *
+ * expect(1).to.be.an.instanceof(Array, 'nooo why fail??');
+ * expect(1, 'nooo why fail??').to.be.an.instanceof(Array);
+ *
+ * Due to limitations in ES5, `.instanceof` may not always work as expected
+ * when using a transpiler such as Babel or TypeScript. In particular, it may
+ * produce unexpected results when subclassing built-in object such as
+ * `Array`, `Error`, and `Map`. See your transpiler's docs for details:
+ *
+ * - ([Babel](https://babeljs.io/docs/usage/caveats/#classes))
+ * - ([TypeScript](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work))
+ *
+ * The alias `.instanceOf` can be used interchangeably with `.instanceof`.
+ *
+ * @name instanceof
+ * @param {Constructor} constructor
+ * @param {String} msg _optional_
+ * @alias instanceOf
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertInstanceOf (constructor, msg) {
+ if (msg) flag(this, 'message', msg);
+
+ var target = flag(this, 'object')
+ var ssfi = flag(this, 'ssfi');
+ var flagMsg = flag(this, 'message');
+
+ try {
+ var isInstanceOf = target instanceof constructor;
+ } catch (err) {
+ if (err instanceof TypeError) {
+ flagMsg = flagMsg ? flagMsg + ': ' : '';
+ throw new AssertionError(
+ flagMsg + 'The instanceof assertion needs a constructor but '
+ + _.type(constructor) + ' was given.',
+ undefined,
+ ssfi
+ );
+ }
+ throw err;
+ }
+
+ var name = _.getName(constructor);
+ if (name === null) {
+ name = 'an unnamed constructor';
+ }
+
+ this.assert(
+ isInstanceOf
+ , 'expected #{this} to be an instance of ' + name
+ , 'expected #{this} to not be an instance of ' + name
+ );
+ };
+
+ Assertion.addMethod('instanceof', assertInstanceOf);
+ Assertion.addMethod('instanceOf', assertInstanceOf);
+
+ /**
+ * ### .property(name[, val[, msg]])
+ *
+ * Asserts that the target has a property with the given key `name`.
+ *
+ * expect({a: 1}).to.have.property('a');
+ *
+ * When `val` is provided, `.property` also asserts that the property's value
+ * is equal to the given `val`.
+ *
+ * expect({a: 1}).to.have.property('a', 1);
+ *
+ * By default, strict (`===`) equality is used. Add `.deep` earlier in the
+ * chain to use deep equality instead. See the `deep-eql` project page for
+ * info on the deep equality algorithm: https://github.com/chaijs/deep-eql.
+ *
+ * // Target object deeply (but not strictly) has property `x: {a: 1}`
+ * expect({x: {a: 1}}).to.have.deep.property('x', {a: 1});
+ * expect({x: {a: 1}}).to.not.have.property('x', {a: 1});
+ *
+ * The target's enumerable and non-enumerable properties are always included
+ * in the search. By default, both own and inherited properties are included.
+ * Add `.own` earlier in the chain to exclude inherited properties from the
+ * search.
+ *
+ * Object.prototype.b = 2;
+ *
+ * expect({a: 1}).to.have.own.property('a');
+ * expect({a: 1}).to.have.own.property('a', 1);
+ * expect({a: 1}).to.have.property('b').but.not.own.property('b');
+ *
+ * `.deep` and `.own` can be combined.
+ *
+ * expect({x: {a: 1}}).to.have.deep.own.property('x', {a: 1});
+ *
+ * Add `.nested` earlier in the chain to enable dot- and bracket-notation when
+ * referencing nested properties.
+ *
+ * expect({a: {b: ['x', 'y']}}).to.have.nested.property('a.b[1]');
+ * expect({a: {b: ['x', 'y']}}).to.have.nested.property('a.b[1]', 'y');
+ *
+ * If `.` or `[]` are part of an actual property name, they can be escaped by
+ * adding two backslashes before them.
+ *
+ * expect({'.a': {'[b]': 'x'}}).to.have.nested.property('\\.a.\\[b\\]');
+ *
+ * `.deep` and `.nested` can be combined.
+ *
+ * expect({a: {b: [{c: 3}]}})
+ * .to.have.deep.nested.property('a.b[0]', {c: 3});
+ *
+ * `.own` and `.nested` cannot be combined.
+ *
+ * Add `.not` earlier in the chain to negate `.property`.
+ *
+ * expect({a: 1}).to.not.have.property('b');
+ *
+ * However, it's dangerous to negate `.property` when providing `val`. The
+ * problem is that it creates uncertain expectations by asserting that the
+ * target either doesn't have a property with the given key `name`, or that it
+ * does have a property with the given key `name` but its value isn't equal to
+ * the given `val`. It's often best to identify the exact output that's
+ * expected, and then write an assertion that only accepts that exact output.
+ *
+ * When the target isn't expected to have a property with the given key
+ * `name`, it's often best to assert exactly that.
+ *
+ * expect({b: 2}).to.not.have.property('a'); // Recommended
+ * expect({b: 2}).to.not.have.property('a', 1); // Not recommended
+ *
+ * When the target is expected to have a property with the given key `name`,
+ * it's often best to assert that the property has its expected value, rather
+ * than asserting that it doesn't have one of many unexpected values.
+ *
+ * expect({a: 3}).to.have.property('a', 3); // Recommended
+ * expect({a: 3}).to.not.have.property('a', 1); // Not recommended
+ *
+ * `.property` changes the target of any assertions that follow in the chain
+ * to be the value of the property from the original target object.
+ *
+ * expect({a: 1}).to.have.property('a').that.is.a('number');
+ *
+ * `.property` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`. When not providing `val`, only use the
+ * second form.
+ *
+ * // Recommended
+ * expect({a: 1}).to.have.property('a', 2, 'nooo why fail??');
+ * expect({a: 1}, 'nooo why fail??').to.have.property('a', 2);
+ * expect({a: 1}, 'nooo why fail??').to.have.property('b');
+ *
+ * // Not recommended
+ * expect({a: 1}).to.have.property('b', undefined, 'nooo why fail??');
+ *
+ * The above assertion isn't the same thing as not providing `val`. Instead,
+ * it's asserting that the target object has a `b` property that's equal to
+ * `undefined`.
+ *
+ * The assertions `.ownProperty` and `.haveOwnProperty` can be used
+ * interchangeably with `.own.property`.
+ *
+ * @name property
+ * @param {String} name
+ * @param {Mixed} val (optional)
+ * @param {String} msg _optional_
+ * @returns value of property for chaining
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertProperty (name, val, msg) {
+ if (msg) flag(this, 'message', msg);
+
+ var isNested = flag(this, 'nested')
+ , isOwn = flag(this, 'own')
+ , flagMsg = flag(this, 'message')
+ , obj = flag(this, 'object')
+ , ssfi = flag(this, 'ssfi');
+
+ if (isNested && isOwn) {
+ flagMsg = flagMsg ? flagMsg + ': ' : '';
+ throw new AssertionError(
+ flagMsg + 'The "nested" and "own" flags cannot be combined.',
+ undefined,
+ ssfi
+ );
+ }
+
+ if (obj === null || obj === undefined) {
+ flagMsg = flagMsg ? flagMsg + ': ' : '';
+ throw new AssertionError(
+ flagMsg + 'Target cannot be null or undefined.',
+ undefined,
+ ssfi
+ );
+ }
+
+ var isDeep = flag(this, 'deep')
+ , negate = flag(this, 'negate')
+ , pathInfo = isNested ? _.getPathInfo(obj, name) : null
+ , value = isNested ? pathInfo.value : obj[name];
+
+ var descriptor = '';
+ if (isDeep) descriptor += 'deep ';
+ if (isOwn) descriptor += 'own ';
+ if (isNested) descriptor += 'nested ';
+ descriptor += 'property ';
+
+ var hasProperty;
+ if (isOwn) hasProperty = Object.prototype.hasOwnProperty.call(obj, name);
+ else if (isNested) hasProperty = pathInfo.exists;
+ else hasProperty = _.hasProperty(obj, name);
+
+ // When performing a negated assertion for both name and val, merely having
+ // a property with the given name isn't enough to cause the assertion to
+ // fail. It must both have a property with the given name, and the value of
+ // that property must equal the given val. Therefore, skip this assertion in
+ // favor of the next.
+ if (!negate || arguments.length === 1) {
+ this.assert(
+ hasProperty
+ , 'expected #{this} to have ' + descriptor + _.inspect(name)
+ , 'expected #{this} to not have ' + descriptor + _.inspect(name));
+ }
+
+ if (arguments.length > 1) {
+ this.assert(
+ hasProperty && (isDeep ? _.eql(val, value) : val === value)
+ , 'expected #{this} to have ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
+ , 'expected #{this} to not have ' + descriptor + _.inspect(name) + ' of #{act}'
+ , val
+ , value
+ );
+ }
+
+ flag(this, 'object', value);
+ }
+
+ Assertion.addMethod('property', assertProperty);
+
+ function assertOwnProperty (name, value, msg) {
+ flag(this, 'own', true);
+ assertProperty.apply(this, arguments);
+ }
+
+ Assertion.addMethod('ownProperty', assertOwnProperty);
+ Assertion.addMethod('haveOwnProperty', assertOwnProperty);
+
+ /**
+ * ### .ownPropertyDescriptor(name[, descriptor[, msg]])
+ *
+ * Asserts that the target has its own property descriptor with the given key
+ * `name`. Enumerable and non-enumerable properties are included in the
+ * search.
+ *
+ * expect({a: 1}).to.have.ownPropertyDescriptor('a');
+ *
+ * When `descriptor` is provided, `.ownPropertyDescriptor` also asserts that
+ * the property's descriptor is deeply equal to the given `descriptor`. See
+ * the `deep-eql` project page for info on the deep equality algorithm:
+ * https://github.com/chaijs/deep-eql.
+ *
+ * expect({a: 1}).to.have.ownPropertyDescriptor('a', {
+ * configurable: true,
+ * enumerable: true,
+ * writable: true,
+ * value: 1,
+ * });
+ *
+ * Add `.not` earlier in the chain to negate `.ownPropertyDescriptor`.
+ *
+ * expect({a: 1}).to.not.have.ownPropertyDescriptor('b');
+ *
+ * However, it's dangerous to negate `.ownPropertyDescriptor` when providing
+ * a `descriptor`. The problem is that it creates uncertain expectations by
+ * asserting that the target either doesn't have a property descriptor with
+ * the given key `name`, or that it does have a property descriptor with the
+ * given key `name` but its not deeply equal to the given `descriptor`. It's
+ * often best to identify the exact output that's expected, and then write an
+ * assertion that only accepts that exact output.
+ *
+ * When the target isn't expected to have a property descriptor with the given
+ * key `name`, it's often best to assert exactly that.
+ *
+ * // Recommended
+ * expect({b: 2}).to.not.have.ownPropertyDescriptor('a');
+ *
+ * // Not recommended
+ * expect({b: 2}).to.not.have.ownPropertyDescriptor('a', {
+ * configurable: true,
+ * enumerable: true,
+ * writable: true,
+ * value: 1,
+ * });
+ *
+ * When the target is expected to have a property descriptor with the given
+ * key `name`, it's often best to assert that the property has its expected
+ * descriptor, rather than asserting that it doesn't have one of many
+ * unexpected descriptors.
+ *
+ * // Recommended
+ * expect({a: 3}).to.have.ownPropertyDescriptor('a', {
+ * configurable: true,
+ * enumerable: true,
+ * writable: true,
+ * value: 3,
+ * });
+ *
+ * // Not recommended
+ * expect({a: 3}).to.not.have.ownPropertyDescriptor('a', {
+ * configurable: true,
+ * enumerable: true,
+ * writable: true,
+ * value: 1,
+ * });
+ *
+ * `.ownPropertyDescriptor` changes the target of any assertions that follow
+ * in the chain to be the value of the property descriptor from the original
+ * target object.
+ *
+ * expect({a: 1}).to.have.ownPropertyDescriptor('a')
+ * .that.has.property('enumerable', true);
+ *
+ * `.ownPropertyDescriptor` accepts an optional `msg` argument which is a
+ * custom error message to show when the assertion fails. The message can also
+ * be given as the second argument to `expect`. When not providing
+ * `descriptor`, only use the second form.
+ *
+ * // Recommended
+ * expect({a: 1}).to.have.ownPropertyDescriptor('a', {
+ * configurable: true,
+ * enumerable: true,
+ * writable: true,
+ * value: 2,
+ * }, 'nooo why fail??');
+ *
+ * // Recommended
+ * expect({a: 1}, 'nooo why fail??').to.have.ownPropertyDescriptor('a', {
+ * configurable: true,
+ * enumerable: true,
+ * writable: true,
+ * value: 2,
+ * });
+ *
+ * // Recommended
+ * expect({a: 1}, 'nooo why fail??').to.have.ownPropertyDescriptor('b');
+ *
+ * // Not recommended
+ * expect({a: 1})
+ * .to.have.ownPropertyDescriptor('b', undefined, 'nooo why fail??');
+ *
+ * The above assertion isn't the same thing as not providing `descriptor`.
+ * Instead, it's asserting that the target object has a `b` property
+ * descriptor that's deeply equal to `undefined`.
+ *
+ * The alias `.haveOwnPropertyDescriptor` can be used interchangeably with
+ * `.ownPropertyDescriptor`.
+ *
+ * @name ownPropertyDescriptor
+ * @alias haveOwnPropertyDescriptor
+ * @param {String} name
+ * @param {Object} descriptor _optional_
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertOwnPropertyDescriptor (name, descriptor, msg) {
+ if (typeof descriptor === 'string') {
+ msg = descriptor;
+ descriptor = null;
+ }
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object');
+ var actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
+ if (actualDescriptor && descriptor) {
+ this.assert(
+ _.eql(descriptor, actualDescriptor)
+ , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor)
+ , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor)
+ , descriptor
+ , actualDescriptor
+ , true
+ );
+ } else {
+ this.assert(
+ actualDescriptor
+ , 'expected #{this} to have an own property descriptor for ' + _.inspect(name)
+ , 'expected #{this} to not have an own property descriptor for ' + _.inspect(name)
+ );
+ }
+ flag(this, 'object', actualDescriptor);
+ }
+
+ Assertion.addMethod('ownPropertyDescriptor', assertOwnPropertyDescriptor);
+ Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor);
+
+ /**
+ * ### .lengthOf(n[, msg])
+ *
+ * Asserts that the target's `length` property is equal to the given number
+ * `n`.
+ *
+ * expect([1, 2, 3]).to.have.lengthOf(3);
+ * expect('foo').to.have.lengthOf(3);
+ *
+ * Add `.not` earlier in the chain to negate `.lengthOf`. However, it's often
+ * best to assert that the target's `length` property is equal to its expected
+ * value, rather than not equal to one of many unexpected values.
+ *
+ * expect('foo').to.have.lengthOf(3); // Recommended
+ * expect('foo').to.not.have.lengthOf(4); // Not recommended
+ *
+ * `.lengthOf` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`.
+ *
+ * expect([1, 2, 3]).to.have.lengthOf(2, 'nooo why fail??');
+ * expect([1, 2, 3], 'nooo why fail??').to.have.lengthOf(2);
+ *
+ * `.lengthOf` can also be used as a language chain, causing all `.above`,
+ * `.below`, `.least`, `.most`, and `.within` assertions that follow in the
+ * chain to use the target's `length` property as the target. However, it's
+ * often best to assert that the target's `length` property is equal to its
+ * expected length, rather than asserting that its `length` property falls
+ * within some range of values.
+ *
+ * // Recommended
+ * expect([1, 2, 3]).to.have.lengthOf(3);
+ *
+ * // Not recommended
+ * expect([1, 2, 3]).to.have.lengthOf.above(2);
+ * expect([1, 2, 3]).to.have.lengthOf.below(4);
+ * expect([1, 2, 3]).to.have.lengthOf.at.least(3);
+ * expect([1, 2, 3]).to.have.lengthOf.at.most(3);
+ * expect([1, 2, 3]).to.have.lengthOf.within(2,4);
+ *
+ * Due to a compatibility issue, the alias `.length` can't be chained directly
+ * off of an uninvoked method such as `.a`. Therefore, `.length` can't be used
+ * interchangeably with `.lengthOf` in every situation. It's recommended to
+ * always use `.lengthOf` instead of `.length`.
+ *
+ * expect([1, 2, 3]).to.have.a.length(3); // incompatible; throws error
+ * expect([1, 2, 3]).to.have.a.lengthOf(3); // passes as expected
+ *
+ * @name lengthOf
+ * @alias length
+ * @param {Number} n
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertLengthChain () {
+ flag(this, 'doLength', true);
+ }
+
+ function assertLength (n, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , flagMsg = flag(this, 'message')
+ , ssfi = flag(this, 'ssfi');
+ new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
+ var len = obj.length;
+
+ this.assert(
+ len == n
+ , 'expected #{this} to have a length of #{exp} but got #{act}'
+ , 'expected #{this} to not have a length of #{act}'
+ , n
+ , len
+ );
+ }
+
+ Assertion.addChainableMethod('length', assertLength, assertLengthChain);
+ Assertion.addChainableMethod('lengthOf', assertLength, assertLengthChain);
+
+ /**
+ * ### .match(re[, msg])
+ *
+ * Asserts that the target matches the given regular expression `re`.
+ *
+ * expect('foobar').to.match(/^foo/);
+ *
+ * Add `.not` earlier in the chain to negate `.match`.
+ *
+ * expect('foobar').to.not.match(/taco/);
+ *
+ * `.match` accepts an optional `msg` argument which is a custom error message
+ * to show when the assertion fails. The message can also be given as the
+ * second argument to `expect`.
+ *
+ * expect('foobar').to.match(/taco/, 'nooo why fail??');
+ * expect('foobar', 'nooo why fail??').to.match(/taco/);
+ *
+ * The alias `.matches` can be used interchangeably with `.match`.
+ *
+ * @name match
+ * @alias matches
+ * @param {RegExp} re
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+ function assertMatch(re, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object');
+ this.assert(
+ re.exec(obj)
+ , 'expected #{this} to match ' + re
+ , 'expected #{this} not to match ' + re
+ );
+ }
+
+ Assertion.addMethod('match', assertMatch);
+ Assertion.addMethod('matches', assertMatch);
+
+ /**
+ * ### .string(str[, msg])
+ *
+ * Asserts that the target string contains the given substring `str`.
+ *
+ * expect('foobar').to.have.string('bar');
+ *
+ * Add `.not` earlier in the chain to negate `.string`.
+ *
+ * expect('foobar').to.not.have.string('taco');
+ *
+ * `.string` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`.
+ *
+ * expect('foobar').to.have.string(/taco/, 'nooo why fail??');
+ * expect('foobar', 'nooo why fail??').to.have.string(/taco/);
+ *
+ * @name string
+ * @param {String} str
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addMethod('string', function (str, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , flagMsg = flag(this, 'message')
+ , ssfi = flag(this, 'ssfi');
+ new Assertion(obj, flagMsg, ssfi, true).is.a('string');
+
+ this.assert(
+ ~obj.indexOf(str)
+ , 'expected #{this} to contain ' + _.inspect(str)
+ , 'expected #{this} to not contain ' + _.inspect(str)
+ );
+ });
+
+ /**
+ * ### .keys(key1[, key2[, ...]])
+ *
+ * Asserts that the target object, array, map, or set has the given keys. Only
+ * the target's own inherited properties are included in the search.
+ *
+ * When the target is an object or array, keys can be provided as one or more
+ * string arguments, a single array argument, or a single object argument. In
+ * the latter case, only the keys in the given object matter; the values are
+ * ignored.
+ *
+ * expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
+ * expect(['x', 'y']).to.have.all.keys(0, 1);
+ *
+ * expect({a: 1, b: 2}).to.have.all.keys(['a', 'b']);
+ * expect(['x', 'y']).to.have.all.keys([0, 1]);
+ *
+ * expect({a: 1, b: 2}).to.have.all.keys({a: 4, b: 5}); // ignore 4 and 5
+ * expect(['x', 'y']).to.have.all.keys({0: 4, 1: 5}); // ignore 4 and 5
+ *
+ * When the target is a map or set, each key must be provided as a separate
+ * argument.
+ *
+ * expect(new Map([['a', 1], ['b', 2]])).to.have.all.keys('a', 'b');
+ * expect(new Set(['a', 'b'])).to.have.all.keys('a', 'b');
+ *
+ * Because `.keys` does different things based on the target's type, it's
+ * important to check the target's type before using `.keys`. See the `.a` doc
+ * for info on testing a target's type.
+ *
+ * expect({a: 1, b: 2}).to.be.an('object').that.has.all.keys('a', 'b');
+ *
+ * By default, strict (`===`) equality is used to compare keys of maps and
+ * sets. Add `.deep` earlier in the chain to use deep equality instead. See
+ * the `deep-eql` project page for info on the deep equality algorithm:
+ * https://github.com/chaijs/deep-eql.
+ *
+ * // Target set deeply (but not strictly) has key `{a: 1}`
+ * expect(new Set([{a: 1}])).to.have.all.deep.keys([{a: 1}]);
+ * expect(new Set([{a: 1}])).to.not.have.all.keys([{a: 1}]);
+ *
+ * By default, the target must have all of the given keys and no more. Add
+ * `.any` earlier in the chain to only require that the target have at least
+ * one of the given keys. Also, add `.not` earlier in the chain to negate
+ * `.keys`. It's often best to add `.any` when negating `.keys`, and to use
+ * `.all` when asserting `.keys` without negation.
+ *
+ * When negating `.keys`, `.any` is preferred because `.not.any.keys` asserts
+ * exactly what's expected of the output, whereas `.not.all.keys` creates
+ * uncertain expectations.
+ *
+ * // Recommended; asserts that target doesn't have any of the given keys
+ * expect({a: 1, b: 2}).to.not.have.any.keys('c', 'd');
+ *
+ * // Not recommended; asserts that target doesn't have all of the given
+ * // keys but may or may not have some of them
+ * expect({a: 1, b: 2}).to.not.have.all.keys('c', 'd');
+ *
+ * When asserting `.keys` without negation, `.all` is preferred because
+ * `.all.keys` asserts exactly what's expected of the output, whereas
+ * `.any.keys` creates uncertain expectations.
+ *
+ * // Recommended; asserts that target has all the given keys
+ * expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
+ *
+ * // Not recommended; asserts that target has at least one of the given
+ * // keys but may or may not have more of them
+ * expect({a: 1, b: 2}).to.have.any.keys('a', 'b');
+ *
+ * Note that `.all` is used by default when neither `.all` nor `.any` appear
+ * earlier in the chain. However, it's often best to add `.all` anyway because
+ * it improves readability.
+ *
+ * // Both assertions are identical
+ * expect({a: 1, b: 2}).to.have.all.keys('a', 'b'); // Recommended
+ * expect({a: 1, b: 2}).to.have.keys('a', 'b'); // Not recommended
+ *
+ * Add `.include` earlier in the chain to require that the target's keys be a
+ * superset of the expected keys, rather than identical sets.
+ *
+ * // Target object's keys are a superset of ['a', 'b'] but not identical
+ * expect({a: 1, b: 2, c: 3}).to.include.all.keys('a', 'b');
+ * expect({a: 1, b: 2, c: 3}).to.not.have.all.keys('a', 'b');
+ *
+ * However, if `.any` and `.include` are combined, only the `.any` takes
+ * effect. The `.include` is ignored in this case.
+ *
+ * // Both assertions are identical
+ * expect({a: 1}).to.have.any.keys('a', 'b');
+ * expect({a: 1}).to.include.any.keys('a', 'b');
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect({a: 1}, 'nooo why fail??').to.have.key('b');
+ *
+ * The alias `.key` can be used interchangeably with `.keys`.
+ *
+ * @name keys
+ * @alias key
+ * @param {...String|Array|Object} keys
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertKeys (keys) {
+ var obj = flag(this, 'object')
+ , objType = _.type(obj)
+ , keysType = _.type(keys)
+ , ssfi = flag(this, 'ssfi')
+ , isDeep = flag(this, 'deep')
+ , str
+ , deepStr = ''
+ , ok = true
+ , flagMsg = flag(this, 'message');
+
+ flagMsg = flagMsg ? flagMsg + ': ' : '';
+ var mixedArgsMsg = flagMsg + 'when testing keys against an object or an array you must give a single Array|Object|String argument or multiple String arguments';
+
+ if (objType === 'Map' || objType === 'Set') {
+ deepStr = isDeep ? 'deeply ' : '';
+ actual = [];
+
+ // Map and Set '.keys' aren't supported in IE 11. Therefore, use .forEach.
+ obj.forEach(function (val, key) { actual.push(key) });
+
+ if (keysType !== 'Array') {
+ keys = Array.prototype.slice.call(arguments);
+ }
+
+ } else {
+ actual = _.getOwnEnumerableProperties(obj);
+
+ switch (keysType) {
+ case 'Array':
+ if (arguments.length > 1) {
+ throw new AssertionError(mixedArgsMsg, undefined, ssfi);
+ }
+ break;
+ case 'Object':
+ if (arguments.length > 1) {
+ throw new AssertionError(mixedArgsMsg, undefined, ssfi);
+ }
+ keys = Object.keys(keys);
+ break;
+ default:
+ keys = Array.prototype.slice.call(arguments);
+ }
+
+ // Only stringify non-Symbols because Symbols would become "Symbol()"
+ keys = keys.map(function (val) {
+ return typeof val === 'symbol' ? val : String(val);
+ });
+ }
+
+ if (!keys.length) {
+ throw new AssertionError(flagMsg + 'keys required', undefined, ssfi);
+ }
+
+ var len = keys.length
+ , any = flag(this, 'any')
+ , all = flag(this, 'all')
+ , expected = keys
+ , actual;
+
+ if (!any && !all) {
+ all = true;
+ }
+
+ // Has any
+ if (any) {
+ ok = expected.some(function(expectedKey) {
+ return actual.some(function(actualKey) {
+ if (isDeep) {
+ return _.eql(expectedKey, actualKey);
+ } else {
+ return expectedKey === actualKey;
+ }
+ });
+ });
+ }
+
+ // Has all
+ if (all) {
+ ok = expected.every(function(expectedKey) {
+ return actual.some(function(actualKey) {
+ if (isDeep) {
+ return _.eql(expectedKey, actualKey);
+ } else {
+ return expectedKey === actualKey;
+ }
+ });
+ });
+
+ if (!flag(this, 'contains')) {
+ ok = ok && keys.length == actual.length;
+ }
+ }
+
+ // Key string
+ if (len > 1) {
+ keys = keys.map(function(key) {
+ return _.inspect(key);
+ });
+ var last = keys.pop();
+ if (all) {
+ str = keys.join(', ') + ', and ' + last;
+ }
+ if (any) {
+ str = keys.join(', ') + ', or ' + last;
+ }
+ } else {
+ str = _.inspect(keys[0]);
+ }
+
+ // Form
+ str = (len > 1 ? 'keys ' : 'key ') + str;
+
+ // Have / include
+ str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
+
+ // Assertion
+ this.assert(
+ ok
+ , 'expected #{this} to ' + deepStr + str
+ , 'expected #{this} to not ' + deepStr + str
+ , expected.slice(0).sort(_.compareByInspect)
+ , actual.sort(_.compareByInspect)
+ , true
+ );
+ }
+
+ Assertion.addMethod('keys', assertKeys);
+ Assertion.addMethod('key', assertKeys);
+
+ /**
+ * ### .throw([errorLike], [errMsgMatcher], [msg])
+ *
+ * When no arguments are provided, `.throw` invokes the target function and
+ * asserts that an error is thrown.
+ *
+ * var badFn = function () { throw new TypeError('Illegal salmon!'); };
+ *
+ * expect(badFn).to.throw();
+ *
+ * When one argument is provided, and it's an error constructor, `.throw`
+ * invokes the target function and asserts that an error is thrown that's an
+ * instance of that error constructor.
+ *
+ * var badFn = function () { throw new TypeError('Illegal salmon!'); };
+ *
+ * expect(badFn).to.throw(TypeError);
+ *
+ * When one argument is provided, and it's an error instance, `.throw` invokes
+ * the target function and asserts that an error is thrown that's strictly
+ * (`===`) equal to that error instance.
+ *
+ * var err = new TypeError('Illegal salmon!');
+ * var badFn = function () { throw err; };
+ *
+ * expect(badFn).to.throw(err);
+ *
+ * When one argument is provided, and it's a string, `.throw` invokes the
+ * target function and asserts that an error is thrown with a message that
+ * contains that string.
+ *
+ * var badFn = function () { throw new TypeError('Illegal salmon!'); };
+ *
+ * expect(badFn).to.throw('salmon');
+ *
+ * When one argument is provided, and it's a regular expression, `.throw`
+ * invokes the target function and asserts that an error is thrown with a
+ * message that matches that regular expression.
+ *
+ * var badFn = function () { throw new TypeError('Illegal salmon!'); };
+ *
+ * expect(badFn).to.throw(/salmon/);
+ *
+ * When two arguments are provided, and the first is an error instance or
+ * constructor, and the second is a string or regular expression, `.throw`
+ * invokes the function and asserts that an error is thrown that fulfills both
+ * conditions as described above.
+ *
+ * var err = new TypeError('Illegal salmon!');
+ * var badFn = function () { throw err; };
+ *
+ * expect(badFn).to.throw(TypeError, 'salmon');
+ * expect(badFn).to.throw(TypeError, /salmon/);
+ * expect(badFn).to.throw(err, 'salmon');
+ * expect(badFn).to.throw(err, /salmon/);
+ *
+ * Add `.not` earlier in the chain to negate `.throw`.
+ *
+ * var goodFn = function () {};
+ *
+ * expect(goodFn).to.not.throw();
+ *
+ * However, it's dangerous to negate `.throw` when providing any arguments.
+ * The problem is that it creates uncertain expectations by asserting that the
+ * target either doesn't throw an error, or that it throws an error but of a
+ * different type than the given type, or that it throws an error of the given
+ * type but with a message that doesn't include the given string. It's often
+ * best to identify the exact output that's expected, and then write an
+ * assertion that only accepts that exact output.
+ *
+ * When the target isn't expected to throw an error, it's often best to assert
+ * exactly that.
+ *
+ * var goodFn = function () {};
+ *
+ * expect(goodFn).to.not.throw(); // Recommended
+ * expect(goodFn).to.not.throw(ReferenceError, 'x'); // Not recommended
+ *
+ * When the target is expected to throw an error, it's often best to assert
+ * that the error is of its expected type, and has a message that includes an
+ * expected string, rather than asserting that it doesn't have one of many
+ * unexpected types, and doesn't have a message that includes some string.
+ *
+ * var badFn = function () { throw new TypeError('Illegal salmon!'); };
+ *
+ * expect(badFn).to.throw(TypeError, 'salmon'); // Recommended
+ * expect(badFn).to.not.throw(ReferenceError, 'x'); // Not recommended
+ *
+ * `.throw` changes the target of any assertions that follow in the chain to
+ * be the error object that's thrown.
+ *
+ * var err = new TypeError('Illegal salmon!');
+ * err.code = 42;
+ * var badFn = function () { throw err; };
+ *
+ * expect(badFn).to.throw(TypeError).with.property('code', 42);
+ *
+ * `.throw` accepts an optional `msg` argument which is a custom error message
+ * to show when the assertion fails. The message can also be given as the
+ * second argument to `expect`. When not providing two arguments, always use
+ * the second form.
+ *
+ * var goodFn = function () {};
+ *
+ * expect(goodFn).to.throw(TypeError, 'x', 'nooo why fail??');
+ * expect(goodFn, 'nooo why fail??').to.throw();
+ *
+ * Due to limitations in ES5, `.throw` may not always work as expected when
+ * using a transpiler such as Babel or TypeScript. In particular, it may
+ * produce unexpected results when subclassing the built-in `Error` object and
+ * then passing the subclassed constructor to `.throw`. See your transpiler's
+ * docs for details:
+ *
+ * - ([Babel](https://babeljs.io/docs/usage/caveats/#classes))
+ * - ([TypeScript](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work))
+ *
+ * Beware of some common mistakes when using the `throw` assertion. One common
+ * mistake is to accidentally invoke the function yourself instead of letting
+ * the `throw` assertion invoke the function for you. For example, when
+ * testing if a function named `fn` throws, provide `fn` instead of `fn()` as
+ * the target for the assertion.
+ *
+ * expect(fn).to.throw(); // Good! Tests `fn` as desired
+ * expect(fn()).to.throw(); // Bad! Tests result of `fn()`, not `fn`
+ *
+ * If you need to assert that your function `fn` throws when passed certain
+ * arguments, then wrap a call to `fn` inside of another function.
+ *
+ * expect(function () { fn(42); }).to.throw(); // Function expression
+ * expect(() => fn(42)).to.throw(); // ES6 arrow function
+ *
+ * Another common mistake is to provide an object method (or any stand-alone
+ * function that relies on `this`) as the target of the assertion. Doing so is
+ * problematic because the `this` context will be lost when the function is
+ * invoked by `.throw`; there's no way for it to know what `this` is supposed
+ * to be. There are two ways around this problem. One solution is to wrap the
+ * method or function call inside of another function. Another solution is to
+ * use `bind`.
+ *
+ * expect(function () { cat.meow(); }).to.throw(); // Function expression
+ * expect(() => cat.meow()).to.throw(); // ES6 arrow function
+ * expect(cat.meow.bind(cat)).to.throw(); // Bind
+ *
+ * Finally, it's worth mentioning that it's a best practice in JavaScript to
+ * only throw `Error` and derivatives of `Error` such as `ReferenceError`,
+ * `TypeError`, and user-defined objects that extend `Error`. No other type of
+ * value will generate a stack trace when initialized. With that said, the
+ * `throw` assertion does technically support any type of value being thrown,
+ * not just `Error` and its derivatives.
+ *
+ * The aliases `.throws` and `.Throw` can be used interchangeably with
+ * `.throw`.
+ *
+ * @name throw
+ * @alias throws
+ * @alias Throw
+ * @param {Error|ErrorConstructor} errorLike
+ * @param {String|RegExp} errMsgMatcher error message
+ * @param {String} msg _optional_
+ * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
+ * @returns error for chaining (null if no error)
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertThrows (errorLike, errMsgMatcher, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , ssfi = flag(this, 'ssfi')
+ , flagMsg = flag(this, 'message')
+ , negate = flag(this, 'negate') || false;
+ new Assertion(obj, flagMsg, ssfi, true).is.a('function');
+
+ if (errorLike instanceof RegExp || typeof errorLike === 'string') {
+ errMsgMatcher = errorLike;
+ errorLike = null;
+ }
+
+ var caughtErr;
+ try {
+ obj();
+ } catch (err) {
+ caughtErr = err;
+ }
+
+ // If we have the negate flag enabled and at least one valid argument it means we do expect an error
+ // but we want it to match a given set of criteria
+ var everyArgIsUndefined = errorLike === undefined && errMsgMatcher === undefined;
+
+ // If we've got the negate flag enabled and both args, we should only fail if both aren't compatible
+ // See Issue #551 and PR #683@GitHub
+ var everyArgIsDefined = Boolean(errorLike && errMsgMatcher);
+ var errorLikeFail = false;
+ var errMsgMatcherFail = false;
+
+ // Checking if error was thrown
+ if (everyArgIsUndefined || !everyArgIsUndefined && !negate) {
+ // We need this to display results correctly according to their types
+ var errorLikeString = 'an error';
+ if (errorLike instanceof Error) {
+ errorLikeString = '#{exp}';
+ } else if (errorLike) {
+ errorLikeString = _.checkError.getConstructorName(errorLike);
+ }
+
+ this.assert(
+ caughtErr
+ , 'expected #{this} to throw ' + errorLikeString
+ , 'expected #{this} to not throw an error but #{act} was thrown'
+ , errorLike && errorLike.toString()
+ , (caughtErr instanceof Error ?
+ caughtErr.toString() : (typeof caughtErr === 'string' ? caughtErr : caughtErr &&
+ _.checkError.getConstructorName(caughtErr)))
+ );
+ }
+
+ if (errorLike && caughtErr) {
+ // We should compare instances only if `errorLike` is an instance of `Error`
+ if (errorLike instanceof Error) {
+ var isCompatibleInstance = _.checkError.compatibleInstance(caughtErr, errorLike);
+
+ if (isCompatibleInstance === negate) {
+ // These checks were created to ensure we won't fail too soon when we've got both args and a negate
+ // See Issue #551 and PR #683@GitHub
+ if (everyArgIsDefined && negate) {
+ errorLikeFail = true;
+ } else {
+ this.assert(
+ negate
+ , 'expected #{this} to throw #{exp} but #{act} was thrown'
+ , 'expected #{this} to not throw #{exp}' + (caughtErr && !negate ? ' but #{act} was thrown' : '')
+ , errorLike.toString()
+ , caughtErr.toString()
+ );
+ }
+ }
+ }
+
+ var isCompatibleConstructor = _.checkError.compatibleConstructor(caughtErr, errorLike);
+ if (isCompatibleConstructor === negate) {
+ if (everyArgIsDefined && negate) {
+ errorLikeFail = true;
+ } else {
+ this.assert(
+ negate
+ , 'expected #{this} to throw #{exp} but #{act} was thrown'
+ , 'expected #{this} to not throw #{exp}' + (caughtErr ? ' but #{act} was thrown' : '')
+ , (errorLike instanceof Error ? errorLike.toString() : errorLike && _.checkError.getConstructorName(errorLike))
+ , (caughtErr instanceof Error ? caughtErr.toString() : caughtErr && _.checkError.getConstructorName(caughtErr))
+ );
+ }
+ }
+ }
+
+ if (caughtErr && errMsgMatcher !== undefined && errMsgMatcher !== null) {
+ // Here we check compatible messages
+ var placeholder = 'including';
+ if (errMsgMatcher instanceof RegExp) {
+ placeholder = 'matching'
+ }
+
+ var isCompatibleMessage = _.checkError.compatibleMessage(caughtErr, errMsgMatcher);
+ if (isCompatibleMessage === negate) {
+ if (everyArgIsDefined && negate) {
+ errMsgMatcherFail = true;
+ } else {
+ this.assert(
+ negate
+ , 'expected #{this} to throw error ' + placeholder + ' #{exp} but got #{act}'
+ , 'expected #{this} to throw error not ' + placeholder + ' #{exp}'
+ , errMsgMatcher
+ , _.checkError.getMessage(caughtErr)
+ );
+ }
+ }
+ }
+
+ // If both assertions failed and both should've matched we throw an error
+ if (errorLikeFail && errMsgMatcherFail) {
+ this.assert(
+ negate
+ , 'expected #{this} to throw #{exp} but #{act} was thrown'
+ , 'expected #{this} to not throw #{exp}' + (caughtErr ? ' but #{act} was thrown' : '')
+ , (errorLike instanceof Error ? errorLike.toString() : errorLike && _.checkError.getConstructorName(errorLike))
+ , (caughtErr instanceof Error ? caughtErr.toString() : caughtErr && _.checkError.getConstructorName(caughtErr))
+ );
+ }
+
+ flag(this, 'object', caughtErr);
+ };
+
+ Assertion.addMethod('throw', assertThrows);
+ Assertion.addMethod('throws', assertThrows);
+ Assertion.addMethod('Throw', assertThrows);
+
+ /**
+ * ### .respondTo(method[, msg])
+ *
+ * When the target is a non-function object, `.respondTo` asserts that the
+ * target has a method with the given name `method`. The method can be own or
+ * inherited, and it can be enumerable or non-enumerable.
+ *
+ * function Cat () {}
+ * Cat.prototype.meow = function () {};
+ *
+ * expect(new Cat()).to.respondTo('meow');
+ *
+ * When the target is a function, `.respondTo` asserts that the target's
+ * `prototype` property has a method with the given name `method`. Again, the
+ * method can be own or inherited, and it can be enumerable or non-enumerable.
+ *
+ * function Cat () {}
+ * Cat.prototype.meow = function () {};
+ *
+ * expect(Cat).to.respondTo('meow');
+ *
+ * Add `.itself` earlier in the chain to force `.respondTo` to treat the
+ * target as a non-function object, even if it's a function. Thus, it asserts
+ * that the target has a method with the given name `method`, rather than
+ * asserting that the target's `prototype` property has a method with the
+ * given name `method`.
+ *
+ * function Cat () {}
+ * Cat.prototype.meow = function () {};
+ * Cat.hiss = function () {};
+ *
+ * expect(Cat).itself.to.respondTo('hiss').but.not.respondTo('meow');
+ *
+ * When not adding `.itself`, it's important to check the target's type before
+ * using `.respondTo`. See the `.a` doc for info on checking a target's type.
+ *
+ * function Cat () {}
+ * Cat.prototype.meow = function () {};
+ *
+ * expect(new Cat()).to.be.an('object').that.respondsTo('meow');
+ *
+ * Add `.not` earlier in the chain to negate `.respondTo`.
+ *
+ * function Dog () {}
+ * Dog.prototype.bark = function () {};
+ *
+ * expect(new Dog()).to.not.respondTo('meow');
+ *
+ * `.respondTo` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`.
+ *
+ * expect({}).to.respondTo('meow', 'nooo why fail??');
+ * expect({}, 'nooo why fail??').to.respondTo('meow');
+ *
+ * The alias `.respondsTo` can be used interchangeably with `.respondTo`.
+ *
+ * @name respondTo
+ * @alias respondsTo
+ * @param {String} method
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function respondTo (method, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , itself = flag(this, 'itself')
+ , context = ('function' === typeof obj && !itself)
+ ? obj.prototype[method]
+ : obj[method];
+
+ this.assert(
+ 'function' === typeof context
+ , 'expected #{this} to respond to ' + _.inspect(method)
+ , 'expected #{this} to not respond to ' + _.inspect(method)
+ );
+ }
+
+ Assertion.addMethod('respondTo', respondTo);
+ Assertion.addMethod('respondsTo', respondTo);
+
+ /**
+ * ### .itself
+ *
+ * Forces all `.respondTo` assertions that follow in the chain to behave as if
+ * the target is a non-function object, even if it's a function. Thus, it
+ * causes `.respondTo` to assert that the target has a method with the given
+ * name, rather than asserting that the target's `prototype` property has a
+ * method with the given name.
+ *
+ * function Cat () {}
+ * Cat.prototype.meow = function () {};
+ * Cat.hiss = function () {};
+ *
+ * expect(Cat).itself.to.respondTo('hiss').but.not.respondTo('meow');
+ *
+ * @name itself
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('itself', function () {
+ flag(this, 'itself', true);
+ });
+
+ /**
+ * ### .satisfy(matcher[, msg])
+ *
+ * Invokes the given `matcher` function with the target being passed as the
+ * first argument, and asserts that the value returned is truthy.
+ *
+ * expect(1).to.satisfy(function(num) {
+ * return num > 0;
+ * });
+ *
+ * Add `.not` earlier in the chain to negate `.satisfy`.
+ *
+ * expect(1).to.not.satisfy(function(num) {
+ * return num > 2;
+ * });
+ *
+ * `.satisfy` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`.
+ *
+ * expect(1).to.satisfy(function(num) {
+ * return num > 2;
+ * }, 'nooo why fail??');
+ *
+ * expect(1, 'nooo why fail??').to.satisfy(function(num) {
+ * return num > 2;
+ * });
+ *
+ * The alias `.satisfies` can be used interchangeably with `.satisfy`.
+ *
+ * @name satisfy
+ * @alias satisfies
+ * @param {Function} matcher
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function satisfy (matcher, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object');
+ var result = matcher(obj);
+ this.assert(
+ result
+ , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
+ , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
+ , flag(this, 'negate') ? false : true
+ , result
+ );
+ }
+
+ Assertion.addMethod('satisfy', satisfy);
+ Assertion.addMethod('satisfies', satisfy);
+
+ /**
+ * ### .closeTo(expected, delta[, msg])
+ *
+ * Asserts that the target is a number that's within a given +/- `delta` range
+ * of the given number `expected`. However, it's often best to assert that the
+ * target is equal to its expected value.
+ *
+ * // Recommended
+ * expect(1.5).to.equal(1.5);
+ *
+ * // Not recommended
+ * expect(1.5).to.be.closeTo(1, 0.5);
+ * expect(1.5).to.be.closeTo(2, 0.5);
+ * expect(1.5).to.be.closeTo(1, 1);
+ *
+ * Add `.not` earlier in the chain to negate `.closeTo`.
+ *
+ * expect(1.5).to.equal(1.5); // Recommended
+ * expect(1.5).to.not.be.closeTo(3, 1); // Not recommended
+ *
+ * `.closeTo` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`.
+ *
+ * expect(1.5).to.be.closeTo(3, 1, 'nooo why fail??');
+ * expect(1.5, 'nooo why fail??').to.be.closeTo(3, 1);
+ *
+ * The alias `.approximately` can be used interchangeably with `.closeTo`.
+ *
+ * @name closeTo
+ * @alias approximately
+ * @param {Number} expected
+ * @param {Number} delta
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function closeTo(expected, delta, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , flagMsg = flag(this, 'message')
+ , ssfi = flag(this, 'ssfi');
+
+ new Assertion(obj, flagMsg, ssfi, true).is.a('number');
+ if (typeof expected !== 'number' || typeof delta !== 'number') {
+ flagMsg = flagMsg ? flagMsg + ': ' : '';
+ throw new AssertionError(
+ flagMsg + 'the arguments to closeTo or approximately must be numbers',
+ undefined,
+ ssfi
+ );
+ }
+
+ this.assert(
+ Math.abs(obj - expected) <= delta
+ , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
+ , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
+ );
+ }
+
+ Assertion.addMethod('closeTo', closeTo);
+ Assertion.addMethod('approximately', closeTo);
+
+ // Note: Duplicates are ignored if testing for inclusion instead of sameness.
+ function isSubsetOf(subset, superset, cmp, contains, ordered) {
+ if (!contains) {
+ if (subset.length !== superset.length) return false;
+ superset = superset.slice();
+ }
+
+ return subset.every(function(elem, idx) {
+ if (ordered) return cmp ? cmp(elem, superset[idx]) : elem === superset[idx];
+
+ if (!cmp) {
+ var matchIdx = superset.indexOf(elem);
+ if (matchIdx === -1) return false;
+
+ // Remove match from superset so not counted twice if duplicate in subset.
+ if (!contains) superset.splice(matchIdx, 1);
+ return true;
+ }
+
+ return superset.some(function(elem2, matchIdx) {
+ if (!cmp(elem, elem2)) return false;
+
+ // Remove match from superset so not counted twice if duplicate in subset.
+ if (!contains) superset.splice(matchIdx, 1);
+ return true;
+ });
+ });
+ }
+
+ /**
+ * ### .members(set[, msg])
+ *
+ * Asserts that the target array has the same members as the given array
+ * `set`.
+ *
+ * expect([1, 2, 3]).to.have.members([2, 1, 3]);
+ * expect([1, 2, 2]).to.have.members([2, 1, 2]);
+ *
+ * By default, members are compared using strict (`===`) equality. Add `.deep`
+ * earlier in the chain to use deep equality instead. See the `deep-eql`
+ * project page for info on the deep equality algorithm:
+ * https://github.com/chaijs/deep-eql.
+ *
+ * // Target array deeply (but not strictly) has member `{a: 1}`
+ * expect([{a: 1}]).to.have.deep.members([{a: 1}]);
+ * expect([{a: 1}]).to.not.have.members([{a: 1}]);
+ *
+ * By default, order doesn't matter. Add `.ordered` earlier in the chain to
+ * require that members appear in the same order.
+ *
+ * expect([1, 2, 3]).to.have.ordered.members([1, 2, 3]);
+ * expect([1, 2, 3]).to.have.members([2, 1, 3])
+ * .but.not.ordered.members([2, 1, 3]);
+ *
+ * By default, both arrays must be the same size. Add `.include` earlier in
+ * the chain to require that the target's members be a superset of the
+ * expected members. Note that duplicates are ignored in the subset when
+ * `.include` is added.
+ *
+ * // Target array is a superset of [1, 2] but not identical
+ * expect([1, 2, 3]).to.include.members([1, 2]);
+ * expect([1, 2, 3]).to.not.have.members([1, 2]);
+ *
+ * // Duplicates in the subset are ignored
+ * expect([1, 2, 3]).to.include.members([1, 2, 2, 2]);
+ *
+ * `.deep`, `.ordered`, and `.include` can all be combined. However, if
+ * `.include` and `.ordered` are combined, the ordering begins at the start of
+ * both arrays.
+ *
+ * expect([{a: 1}, {b: 2}, {c: 3}])
+ * .to.include.deep.ordered.members([{a: 1}, {b: 2}])
+ * .but.not.include.deep.ordered.members([{b: 2}, {c: 3}]);
+ *
+ * Add `.not` earlier in the chain to negate `.members`. However, it's
+ * dangerous to do so. The problem is that it creates uncertain expectations
+ * by asserting that the target array doesn't have all of the same members as
+ * the given array `set` but may or may not have some of them. It's often best
+ * to identify the exact output that's expected, and then write an assertion
+ * that only accepts that exact output.
+ *
+ * expect([1, 2]).to.not.include(3).and.not.include(4); // Recommended
+ * expect([1, 2]).to.not.have.members([3, 4]); // Not recommended
+ *
+ * `.members` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`.
+ *
+ * expect([1, 2]).to.have.members([1, 2, 3], 'nooo why fail??');
+ * expect([1, 2], 'nooo why fail??').to.have.members([1, 2, 3]);
+ *
+ * @name members
+ * @param {Array} set
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addMethod('members', function (subset, msg) {
+ if (msg) flag(this, 'message', msg);
+ var obj = flag(this, 'object')
+ , flagMsg = flag(this, 'message')
+ , ssfi = flag(this, 'ssfi');
+
+ new Assertion(obj, flagMsg, ssfi, true).to.be.an('array');
+ new Assertion(subset, flagMsg, ssfi, true).to.be.an('array');
+
+ var contains = flag(this, 'contains');
+ var ordered = flag(this, 'ordered');
+
+ var subject, failMsg, failNegateMsg, lengthCheck;
+
+ if (contains) {
+ subject = ordered ? 'an ordered superset' : 'a superset';
+ failMsg = 'expected #{this} to be ' + subject + ' of #{exp}';
+ failNegateMsg = 'expected #{this} to not be ' + subject + ' of #{exp}';
+ } else {
+ subject = ordered ? 'ordered members' : 'members';
+ failMsg = 'expected #{this} to have the same ' + subject + ' as #{exp}';
+ failNegateMsg = 'expected #{this} to not have the same ' + subject + ' as #{exp}';
+ }
+
+ var cmp = flag(this, 'deep') ? _.eql : undefined;
+
+ this.assert(
+ isSubsetOf(subset, obj, cmp, contains, ordered)
+ , failMsg
+ , failNegateMsg
+ , subset
+ , obj
+ , true
+ );
+ });
+
+ /**
+ * ### .oneOf(list[, msg])
+ *
+ * Asserts that the target is a member of the given array `list`. However,
+ * it's often best to assert that the target is equal to its expected value.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.be.oneOf([1, 2, 3]); // Not recommended
+ *
+ * Comparisons are performed using strict (`===`) equality.
+ *
+ * Add `.not` earlier in the chain to negate `.oneOf`.
+ *
+ * expect(1).to.equal(1); // Recommended
+ * expect(1).to.not.be.oneOf([2, 3, 4]); // Not recommended
+ *
+ * `.oneOf` accepts an optional `msg` argument which is a custom error message
+ * to show when the assertion fails. The message can also be given as the
+ * second argument to `expect`.
+ *
+ * expect(1).to.be.oneOf([2, 3, 4], 'nooo why fail??');
+ * expect(1, 'nooo why fail??').to.be.oneOf([2, 3, 4]);
+ *
+ * @name oneOf
+ * @param {Array<*>} list
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function oneOf (list, msg) {
+ if (msg) flag(this, 'message', msg);
+ var expected = flag(this, 'object')
+ , flagMsg = flag(this, 'message')
+ , ssfi = flag(this, 'ssfi');
+ new Assertion(list, flagMsg, ssfi, true).to.be.an('array');
+
+ this.assert(
+ list.indexOf(expected) > -1
+ , 'expected #{this} to be one of #{exp}'
+ , 'expected #{this} to not be one of #{exp}'
+ , list
+ , expected
+ );
+ }
+
+ Assertion.addMethod('oneOf', oneOf);
+
+
+ /**
+ * ### .change(subject[, prop[, msg]])
+ *
+ * When one argument is provided, `.change` asserts that the given function
+ * `subject` returns a different value when it's invoked before the target
+ * function compared to when it's invoked afterward. However, it's often best
+ * to assert that `subject` is equal to its expected value.
+ *
+ * var dots = ''
+ * , addDot = function () { dots += '.'; }
+ * , getDots = function () { return dots; };
+ *
+ * // Recommended
+ * expect(getDots()).to.equal('');
+ * addDot();
+ * expect(getDots()).to.equal('.');
+ *
+ * // Not recommended
+ * expect(addDot).to.change(getDots);
+ *
+ * When two arguments are provided, `.change` asserts that the value of the
+ * given object `subject`'s `prop` property is different before invoking the
+ * target function compared to afterward.
+ *
+ * var myObj = {dots: ''}
+ * , addDot = function () { myObj.dots += '.'; };
+ *
+ * // Recommended
+ * expect(myObj).to.have.property('dots', '');
+ * addDot();
+ * expect(myObj).to.have.property('dots', '.');
+ *
+ * // Not recommended
+ * expect(addDot).to.change(myObj, 'dots');
+ *
+ * Strict (`===`) equality is used to compare before and after values.
+ *
+ * Add `.not` earlier in the chain to negate `.change`.
+ *
+ * var dots = ''
+ * , noop = function () {}
+ * , getDots = function () { return dots; };
+ *
+ * expect(noop).to.not.change(getDots);
+ *
+ * var myObj = {dots: ''}
+ * , noop = function () {};
+ *
+ * expect(noop).to.not.change(myObj, 'dots');
+ *
+ * `.change` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`. When not providing two arguments, always
+ * use the second form.
+ *
+ * var myObj = {dots: ''}
+ * , addDot = function () { myObj.dots += '.'; };
+ *
+ * expect(addDot).to.not.change(myObj, 'dots', 'nooo why fail??');
+ *
+ * var dots = ''
+ * , addDot = function () { dots += '.'; }
+ * , getDots = function () { return dots; };
+ *
+ * expect(addDot, 'nooo why fail??').to.not.change(getDots);
+ *
+ * `.change` also causes all `.by` assertions that follow in the chain to
+ * assert how much a numeric subject was increased or decreased by. However,
+ * it's dangerous to use `.change.by`. The problem is that it creates
+ * uncertain expectations by asserting that the subject either increases by
+ * the given delta, or that it decreases by the given delta. It's often best
+ * to identify the exact output that's expected, and then write an assertion
+ * that only accepts that exact output.
+ *
+ * var myObj = {val: 1}
+ * , addTwo = function () { myObj.val += 2; }
+ * , subtractTwo = function () { myObj.val -= 2; };
+ *
+ * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
+ * expect(addTwo).to.change(myObj, 'val').by(2); // Not recommended
+ *
+ * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
+ * expect(subtractTwo).to.change(myObj, 'val').by(2); // Not recommended
+ *
+ * The alias `.changes` can be used interchangeably with `.change`.
+ *
+ * @name change
+ * @alias changes
+ * @param {String} subject
+ * @param {String} prop name _optional_
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertChanges (subject, prop, msg) {
+ if (msg) flag(this, 'message', msg);
+ var fn = flag(this, 'object')
+ , flagMsg = flag(this, 'message')
+ , ssfi = flag(this, 'ssfi');
+ new Assertion(fn, flagMsg, ssfi, true).is.a('function');
+
+ var initial;
+ if (!prop) {
+ new Assertion(subject, flagMsg, ssfi, true).is.a('function');
+ initial = subject();
+ } else {
+ new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
+ initial = subject[prop];
+ }
+
+ fn();
+
+ var final = prop === undefined || prop === null ? subject() : subject[prop];
+ var msgObj = prop === undefined || prop === null ? initial : '.' + prop;
+
+ // This gets flagged because of the .by(delta) assertion
+ flag(this, 'deltaMsgObj', msgObj);
+ flag(this, 'initialDeltaValue', initial);
+ flag(this, 'finalDeltaValue', final);
+ flag(this, 'deltaBehavior', 'change');
+ flag(this, 'realDelta', final !== initial);
+
+ this.assert(
+ initial !== final
+ , 'expected ' + msgObj + ' to change'
+ , 'expected ' + msgObj + ' to not change'
+ );
+ }
+
+ Assertion.addMethod('change', assertChanges);
+ Assertion.addMethod('changes', assertChanges);
+
+ /**
+ * ### .increase(subject[, prop[, msg]])
+ *
+ * When one argument is provided, `.increase` asserts that the given function
+ * `subject` returns a greater number when it's invoked after invoking the
+ * target function compared to when it's invoked beforehand. `.increase` also
+ * causes all `.by` assertions that follow in the chain to assert how much
+ * greater of a number is returned. It's often best to assert that the return
+ * value increased by the expected amount, rather than asserting it increased
+ * by any amount.
+ *
+ * var val = 1
+ * , addTwo = function () { val += 2; }
+ * , getVal = function () { return val; };
+ *
+ * expect(addTwo).to.increase(getVal).by(2); // Recommended
+ * expect(addTwo).to.increase(getVal); // Not recommended
+ *
+ * When two arguments are provided, `.increase` asserts that the value of the
+ * given object `subject`'s `prop` property is greater after invoking the
+ * target function compared to beforehand.
+ *
+ * var myObj = {val: 1}
+ * , addTwo = function () { myObj.val += 2; };
+ *
+ * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
+ * expect(addTwo).to.increase(myObj, 'val'); // Not recommended
+ *
+ * Add `.not` earlier in the chain to negate `.increase`. However, it's
+ * dangerous to do so. The problem is that it creates uncertain expectations
+ * by asserting that the subject either decreases, or that it stays the same.
+ * It's often best to identify the exact output that's expected, and then
+ * write an assertion that only accepts that exact output.
+ *
+ * When the subject is expected to decrease, it's often best to assert that it
+ * decreased by the expected amount.
+ *
+ * var myObj = {val: 1}
+ * , subtractTwo = function () { myObj.val -= 2; };
+ *
+ * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
+ * expect(subtractTwo).to.not.increase(myObj, 'val'); // Not recommended
+ *
+ * When the subject is expected to stay the same, it's often best to assert
+ * exactly that.
+ *
+ * var myObj = {val: 1}
+ * , noop = function () {};
+ *
+ * expect(noop).to.not.change(myObj, 'val'); // Recommended
+ * expect(noop).to.not.increase(myObj, 'val'); // Not recommended
+ *
+ * `.increase` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`. When not providing two arguments, always
+ * use the second form.
+ *
+ * var myObj = {val: 1}
+ * , noop = function () {};
+ *
+ * expect(noop).to.increase(myObj, 'val', 'nooo why fail??');
+ *
+ * var val = 1
+ * , noop = function () {}
+ * , getVal = function () { return val; };
+ *
+ * expect(noop, 'nooo why fail??').to.increase(getVal);
+ *
+ * The alias `.increases` can be used interchangeably with `.increase`.
+ *
+ * @name increase
+ * @alias increases
+ * @param {String|Function} subject
+ * @param {String} prop name _optional_
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertIncreases (subject, prop, msg) {
+ if (msg) flag(this, 'message', msg);
+ var fn = flag(this, 'object')
+ , flagMsg = flag(this, 'message')
+ , ssfi = flag(this, 'ssfi');
+ new Assertion(fn, flagMsg, ssfi, true).is.a('function');
+
+ var initial;
+ if (!prop) {
+ new Assertion(subject, flagMsg, ssfi, true).is.a('function');
+ initial = subject();
+ } else {
+ new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
+ initial = subject[prop];
+ }
+
+ // Make sure that the target is a number
+ new Assertion(initial, flagMsg, ssfi, true).is.a('number');
+
+ fn();
+
+ var final = prop === undefined || prop === null ? subject() : subject[prop];
+ var msgObj = prop === undefined || prop === null ? initial : '.' + prop;
+
+ flag(this, 'deltaMsgObj', msgObj);
+ flag(this, 'initialDeltaValue', initial);
+ flag(this, 'finalDeltaValue', final);
+ flag(this, 'deltaBehavior', 'increase');
+ flag(this, 'realDelta', final - initial);
+
+ this.assert(
+ final - initial > 0
+ , 'expected ' + msgObj + ' to increase'
+ , 'expected ' + msgObj + ' to not increase'
+ );
+ }
+
+ Assertion.addMethod('increase', assertIncreases);
+ Assertion.addMethod('increases', assertIncreases);
+
+ /**
+ * ### .decrease(subject[, prop[, msg]])
+ *
+ * When one argument is provided, `.decrease` asserts that the given function
+ * `subject` returns a lesser number when it's invoked after invoking the
+ * target function compared to when it's invoked beforehand. `.decrease` also
+ * causes all `.by` assertions that follow in the chain to assert how much
+ * lesser of a number is returned. It's often best to assert that the return
+ * value decreased by the expected amount, rather than asserting it decreased
+ * by any amount.
+ *
+ * var val = 1
+ * , subtractTwo = function () { val -= 2; }
+ * , getVal = function () { return val; };
+ *
+ * expect(subtractTwo).to.decrease(getVal).by(2); // Recommended
+ * expect(subtractTwo).to.decrease(getVal); // Not recommended
+ *
+ * When two arguments are provided, `.decrease` asserts that the value of the
+ * given object `subject`'s `prop` property is lesser after invoking the
+ * target function compared to beforehand.
+ *
+ * var myObj = {val: 1}
+ * , subtractTwo = function () { myObj.val -= 2; };
+ *
+ * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
+ * expect(subtractTwo).to.decrease(myObj, 'val'); // Not recommended
+ *
+ * Add `.not` earlier in the chain to negate `.decrease`. However, it's
+ * dangerous to do so. The problem is that it creates uncertain expectations
+ * by asserting that the subject either increases, or that it stays the same.
+ * It's often best to identify the exact output that's expected, and then
+ * write an assertion that only accepts that exact output.
+ *
+ * When the subject is expected to increase, it's often best to assert that it
+ * increased by the expected amount.
+ *
+ * var myObj = {val: 1}
+ * , addTwo = function () { myObj.val += 2; };
+ *
+ * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
+ * expect(addTwo).to.not.decrease(myObj, 'val'); // Not recommended
+ *
+ * When the subject is expected to stay the same, it's often best to assert
+ * exactly that.
+ *
+ * var myObj = {val: 1}
+ * , noop = function () {};
+ *
+ * expect(noop).to.not.change(myObj, 'val'); // Recommended
+ * expect(noop).to.not.decrease(myObj, 'val'); // Not recommended
+ *
+ * `.decrease` accepts an optional `msg` argument which is a custom error
+ * message to show when the assertion fails. The message can also be given as
+ * the second argument to `expect`. When not providing two arguments, always
+ * use the second form.
+ *
+ * var myObj = {val: 1}
+ * , noop = function () {};
+ *
+ * expect(noop).to.decrease(myObj, 'val', 'nooo why fail??');
+ *
+ * var val = 1
+ * , noop = function () {}
+ * , getVal = function () { return val; };
+ *
+ * expect(noop, 'nooo why fail??').to.decrease(getVal);
+ *
+ * The alias `.decreases` can be used interchangeably with `.decrease`.
+ *
+ * @name decrease
+ * @alias decreases
+ * @param {String|Function} subject
+ * @param {String} prop name _optional_
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertDecreases (subject, prop, msg) {
+ if (msg) flag(this, 'message', msg);
+ var fn = flag(this, 'object')
+ , flagMsg = flag(this, 'message')
+ , ssfi = flag(this, 'ssfi');
+ new Assertion(fn, flagMsg, ssfi, true).is.a('function');
+
+ var initial;
+ if (!prop) {
+ new Assertion(subject, flagMsg, ssfi, true).is.a('function');
+ initial = subject();
+ } else {
+ new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
+ initial = subject[prop];
+ }
+
+ // Make sure that the target is a number
+ new Assertion(initial, flagMsg, ssfi, true).is.a('number');
+
+ fn();
+
+ var final = prop === undefined || prop === null ? subject() : subject[prop];
+ var msgObj = prop === undefined || prop === null ? initial : '.' + prop;
+
+ flag(this, 'deltaMsgObj', msgObj);
+ flag(this, 'initialDeltaValue', initial);
+ flag(this, 'finalDeltaValue', final);
+ flag(this, 'deltaBehavior', 'decrease');
+ flag(this, 'realDelta', initial - final);
+
+ this.assert(
+ final - initial < 0
+ , 'expected ' + msgObj + ' to decrease'
+ , 'expected ' + msgObj + ' to not decrease'
+ );
+ }
+
+ Assertion.addMethod('decrease', assertDecreases);
+ Assertion.addMethod('decreases', assertDecreases);
+
+ /**
+ * ### .by(delta[, msg])
+ *
+ * When following an `.increase` assertion in the chain, `.by` asserts that
+ * the subject of the `.increase` assertion increased by the given `delta`.
+ *
+ * var myObj = {val: 1}
+ * , addTwo = function () { myObj.val += 2; };
+ *
+ * expect(addTwo).to.increase(myObj, 'val').by(2);
+ *
+ * When following a `.decrease` assertion in the chain, `.by` asserts that the
+ * subject of the `.decrease` assertion decreased by the given `delta`.
+ *
+ * var myObj = {val: 1}
+ * , subtractTwo = function () { myObj.val -= 2; };
+ *
+ * expect(subtractTwo).to.decrease(myObj, 'val').by(2);
+ *
+ * When following a `.change` assertion in the chain, `.by` asserts that the
+ * subject of the `.change` assertion either increased or decreased by the
+ * given `delta`. However, it's dangerous to use `.change.by`. The problem is
+ * that it creates uncertain expectations. It's often best to identify the
+ * exact output that's expected, and then write an assertion that only accepts
+ * that exact output.
+ *
+ * var myObj = {val: 1}
+ * , addTwo = function () { myObj.val += 2; }
+ * , subtractTwo = function () { myObj.val -= 2; };
+ *
+ * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
+ * expect(addTwo).to.change(myObj, 'val').by(2); // Not recommended
+ *
+ * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
+ * expect(subtractTwo).to.change(myObj, 'val').by(2); // Not recommended
+ *
+ * Add `.not` earlier in the chain to negate `.by`. However, it's often best
+ * to assert that the subject changed by its expected delta, rather than
+ * asserting that it didn't change by one of countless unexpected deltas.
+ *
+ * var myObj = {val: 1}
+ * , addTwo = function () { myObj.val += 2; };
+ *
+ * // Recommended
+ * expect(addTwo).to.increase(myObj, 'val').by(2);
+ *
+ * // Not recommended
+ * expect(addTwo).to.increase(myObj, 'val').but.not.by(3);
+ *
+ * `.by` accepts an optional `msg` argument which is a custom error message to
+ * show when the assertion fails. The message can also be given as the second
+ * argument to `expect`.
+ *
+ * var myObj = {val: 1}
+ * , addTwo = function () { myObj.val += 2; };
+ *
+ * expect(addTwo).to.increase(myObj, 'val').by(3, 'nooo why fail??');
+ * expect(addTwo, 'nooo why fail??').to.increase(myObj, 'val').by(3);
+ *
+ * @name by
+ * @param {Number} delta
+ * @param {String} msg _optional_
+ * @namespace BDD
+ * @api public
+ */
+
+ function assertDelta(delta, msg) {
+ if (msg) flag(this, 'message', msg);
+
+ var msgObj = flag(this, 'deltaMsgObj');
+ var initial = flag(this, 'initialDeltaValue');
+ var final = flag(this, 'finalDeltaValue');
+ var behavior = flag(this, 'deltaBehavior');
+ var realDelta = flag(this, 'realDelta');
+
+ var expression;
+ if (behavior === 'change') {
+ expression = Math.abs(final - initial) === Math.abs(delta);
+ } else {
+ expression = realDelta === Math.abs(delta);
+ }
+
+ this.assert(
+ expression
+ , 'expected ' + msgObj + ' to ' + behavior + ' by ' + delta
+ , 'expected ' + msgObj + ' to not ' + behavior + ' by ' + delta
+ );
+ }
+
+ Assertion.addMethod('by', assertDelta);
+
+ /**
+ * ### .extensible
+ *
+ * Asserts that the target is extensible, which means that new properties can
+ * be added to it. Primitives are never extensible.
+ *
+ * expect({a: 1}).to.be.extensible;
+ *
+ * Add `.not` earlier in the chain to negate `.extensible`.
+ *
+ * var nonExtensibleObject = Object.preventExtensions({})
+ * , sealedObject = Object.seal({})
+ * , frozenObject = Object.freeze({});
+ *
+ * expect(nonExtensibleObject).to.not.be.extensible;
+ * expect(sealedObject).to.not.be.extensible;
+ * expect(frozenObject).to.not.be.extensible;
+ * expect(1).to.not.be.extensible;
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect(1, 'nooo why fail??').to.be.extensible;
+ *
+ * @name extensible
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('extensible', function() {
+ var obj = flag(this, 'object');
+
+ // In ES5, if the argument to this method is a primitive, then it will cause a TypeError.
+ // In ES6, a non-object argument will be treated as if it was a non-extensible ordinary object, simply return false.
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible
+ // The following provides ES6 behavior for ES5 environments.
+
+ var isExtensible = obj === Object(obj) && Object.isExtensible(obj);
+
+ this.assert(
+ isExtensible
+ , 'expected #{this} to be extensible'
+ , 'expected #{this} to not be extensible'
+ );
+ });
+
+ /**
+ * ### .sealed
+ *
+ * Asserts that the target is sealed, which means that new properties can't be
+ * added to it, and its existing properties can't be reconfigured or deleted.
+ * However, it's possible that its existing properties can still be reassigned
+ * to different values. Primitives are always sealed.
+ *
+ * var sealedObject = Object.seal({});
+ * var frozenObject = Object.freeze({});
+ *
+ * expect(sealedObject).to.be.sealed;
+ * expect(frozenObject).to.be.sealed;
+ * expect(1).to.be.sealed;
+ *
+ * Add `.not` earlier in the chain to negate `.sealed`.
+ *
+ * expect({a: 1}).to.not.be.sealed;
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect({a: 1}, 'nooo why fail??').to.be.sealed;
+ *
+ * @name sealed
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('sealed', function() {
+ var obj = flag(this, 'object');
+
+ // In ES5, if the argument to this method is a primitive, then it will cause a TypeError.
+ // In ES6, a non-object argument will be treated as if it was a sealed ordinary object, simply return true.
+ // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
+ // The following provides ES6 behavior for ES5 environments.
+
+ var isSealed = obj === Object(obj) ? Object.isSealed(obj) : true;
+
+ this.assert(
+ isSealed
+ , 'expected #{this} to be sealed'
+ , 'expected #{this} to not be sealed'
+ );
+ });
+
+ /**
+ * ### .frozen
+ *
+ * Asserts that the target is frozen, which means that new properties can't be
+ * added to it, and its existing properties can't be reassigned to different
+ * values, reconfigured, or deleted. Primitives are always frozen.
+ *
+ * var frozenObject = Object.freeze({});
+ *
+ * expect(frozenObject).to.be.frozen;
+ * expect(1).to.be.frozen;
+ *
+ * Add `.not` earlier in the chain to negate `.frozen`.
+ *
+ * expect({a: 1}).to.not.be.frozen;
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect({a: 1}, 'nooo why fail??').to.be.frozen;
+ *
+ * @name frozen
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('frozen', function() {
+ var obj = flag(this, 'object');
+
+ // In ES5, if the argument to this method is a primitive, then it will cause a TypeError.
+ // In ES6, a non-object argument will be treated as if it was a frozen ordinary object, simply return true.
+ // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
+ // The following provides ES6 behavior for ES5 environments.
+
+ var isFrozen = obj === Object(obj) ? Object.isFrozen(obj) : true;
+
+ this.assert(
+ isFrozen
+ , 'expected #{this} to be frozen'
+ , 'expected #{this} to not be frozen'
+ );
+ });
+
+ /**
+ * ### .finite
+ *
+ * Asserts that the target is a number, and isn't `NaN` or positive/negative
+ * `Infinity`.
+ *
+ * expect(1).to.be.finite;
+ *
+ * Add `.not` earlier in the chain to negate `.finite`. However, it's
+ * dangerous to do so. The problem is that it creates uncertain expectations
+ * by asserting that the subject either isn't a number, or that it's `NaN`, or
+ * that it's positive `Infinity`, or that it's negative `Infinity`. It's often
+ * best to identify the exact output that's expected, and then write an
+ * assertion that only accepts that exact output.
+ *
+ * When the target isn't expected to be a number, it's often best to assert
+ * that it's the expected type, rather than asserting that it isn't one of
+ * many unexpected types.
+ *
+ * expect('foo').to.be.a('string'); // Recommended
+ * expect('foo').to.not.be.finite; // Not recommended
+ *
+ * When the target is expected to be `NaN`, it's often best to assert exactly
+ * that.
+ *
+ * expect(NaN).to.be.NaN; // Recommended
+ * expect(NaN).to.not.be.finite; // Not recommended
+ *
+ * When the target is expected to be positive infinity, it's often best to
+ * assert exactly that.
+ *
+ * expect(Infinity).to.equal(Infinity); // Recommended
+ * expect(Infinity).to.not.be.finite; // Not recommended
+ *
+ * When the target is expected to be negative infinity, it's often best to
+ * assert exactly that.
+ *
+ * expect(-Infinity).to.equal(-Infinity); // Recommended
+ * expect(-Infinity).to.not.be.finite; // Not recommended
+ *
+ * A custom error message can be given as the second argument to `expect`.
+ *
+ * expect('foo', 'nooo why fail??').to.be.finite;
+ *
+ * @name finite
+ * @namespace BDD
+ * @api public
+ */
+
+ Assertion.addProperty('finite', function(msg) {
+ var obj = flag(this, 'object');
+
+ this.assert(
+ typeof obj === "number" && isFinite(obj)
+ , 'expected #{this} to be a finite number'
+ , 'expected #{this} to not be a finite number'
+ );
+ });
+};
+
+},{}],6:[function(require,module,exports){
+/*!
+ * chai
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+
+module.exports = function (chai, util) {
+
+ /*!
+ * Chai dependencies.
+ */
+
+ var Assertion = chai.Assertion
+ , flag = util.flag;
+
+ /*!
+ * Module export.
+ */
+
+ /**
+ * ### assert(expression, message)
+ *
+ * Write your own test expressions.
+ *
+ * assert('foo' !== 'bar', 'foo is not bar');
+ * assert(Array.isArray([]), 'empty arrays are arrays');
+ *
+ * @param {Mixed} expression to test for truthiness
+ * @param {String} message to display on error
+ * @name assert
+ * @namespace Assert
+ * @api public
+ */
+
+ var assert = chai.assert = function (express, errmsg) {
+ var test = new Assertion(null, null, chai.assert, true);
+ test.assert(
+ express
+ , errmsg
+ , '[ negation message unavailable ]'
+ );
+ };
+
+ /**
+ * ### .fail(actual, expected, [message], [operator])
+ *
+ * Throw a failure. Node.js `assert` module-compatible.
+ *
+ * @name fail
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @param {String} operator
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.fail = function (actual, expected, message, operator) {
+ message = message || 'assert.fail()';
+ throw new chai.AssertionError(message, {
+ actual: actual
+ , expected: expected
+ , operator: operator
+ }, assert.fail);
+ };
+
+ /**
+ * ### .isOk(object, [message])
+ *
+ * Asserts that `object` is truthy.
+ *
+ * assert.isOk('everything', 'everything is ok');
+ * assert.isOk(false, 'this will fail');
+ *
+ * @name isOk
+ * @alias ok
+ * @param {Mixed} object to test
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isOk = function (val, msg) {
+ new Assertion(val, msg, assert.isOk, true).is.ok;
+ };
+
+ /**
+ * ### .isNotOk(object, [message])
+ *
+ * Asserts that `object` is falsy.
+ *
+ * assert.isNotOk('everything', 'this will fail');
+ * assert.isNotOk(false, 'this will pass');
+ *
+ * @name isNotOk
+ * @alias notOk
+ * @param {Mixed} object to test
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotOk = function (val, msg) {
+ new Assertion(val, msg, assert.isNotOk, true).is.not.ok;
+ };
+
+ /**
+ * ### .equal(actual, expected, [message])
+ *
+ * Asserts non-strict equality (`==`) of `actual` and `expected`.
+ *
+ * assert.equal(3, '3', '== coerces values to strings');
+ *
+ * @name equal
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.equal = function (act, exp, msg) {
+ var test = new Assertion(act, msg, assert.equal, true);
+
+ test.assert(
+ exp == flag(test, 'object')
+ , 'expected #{this} to equal #{exp}'
+ , 'expected #{this} to not equal #{act}'
+ , exp
+ , act
+ , true
+ );
+ };
+
+ /**
+ * ### .notEqual(actual, expected, [message])
+ *
+ * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
+ *
+ * assert.notEqual(3, 4, 'these numbers are not equal');
+ *
+ * @name notEqual
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notEqual = function (act, exp, msg) {
+ var test = new Assertion(act, msg, assert.notEqual, true);
+
+ test.assert(
+ exp != flag(test, 'object')
+ , 'expected #{this} to not equal #{exp}'
+ , 'expected #{this} to equal #{act}'
+ , exp
+ , act
+ , true
+ );
+ };
+
+ /**
+ * ### .strictEqual(actual, expected, [message])
+ *
+ * Asserts strict equality (`===`) of `actual` and `expected`.
+ *
+ * assert.strictEqual(true, true, 'these booleans are strictly equal');
+ *
+ * @name strictEqual
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.strictEqual = function (act, exp, msg) {
+ new Assertion(act, msg, assert.strictEqual, true).to.equal(exp);
+ };
+
+ /**
+ * ### .notStrictEqual(actual, expected, [message])
+ *
+ * Asserts strict inequality (`!==`) of `actual` and `expected`.
+ *
+ * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
+ *
+ * @name notStrictEqual
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notStrictEqual = function (act, exp, msg) {
+ new Assertion(act, msg, assert.notStrictEqual, true).to.not.equal(exp);
+ };
+
+ /**
+ * ### .deepEqual(actual, expected, [message])
+ *
+ * Asserts that `actual` is deeply equal to `expected`.
+ *
+ * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
+ *
+ * @name deepEqual
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @alias deepStrictEqual
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.deepEqual = assert.deepStrictEqual = function (act, exp, msg) {
+ new Assertion(act, msg, assert.deepEqual, true).to.eql(exp);
+ };
+
+ /**
+ * ### .notDeepEqual(actual, expected, [message])
+ *
+ * Assert that `actual` is not deeply equal to `expected`.
+ *
+ * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
+ *
+ * @name notDeepEqual
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notDeepEqual = function (act, exp, msg) {
+ new Assertion(act, msg, assert.notDeepEqual, true).to.not.eql(exp);
+ };
+
+ /**
+ * ### .isAbove(valueToCheck, valueToBeAbove, [message])
+ *
+ * Asserts `valueToCheck` is strictly greater than (>) `valueToBeAbove`.
+ *
+ * assert.isAbove(5, 2, '5 is strictly greater than 2');
+ *
+ * @name isAbove
+ * @param {Mixed} valueToCheck
+ * @param {Mixed} valueToBeAbove
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isAbove = function (val, abv, msg) {
+ new Assertion(val, msg, assert.isAbove, true).to.be.above(abv);
+ };
+
+ /**
+ * ### .isAtLeast(valueToCheck, valueToBeAtLeast, [message])
+ *
+ * Asserts `valueToCheck` is greater than or equal to (>=) `valueToBeAtLeast`.
+ *
+ * assert.isAtLeast(5, 2, '5 is greater or equal to 2');
+ * assert.isAtLeast(3, 3, '3 is greater or equal to 3');
+ *
+ * @name isAtLeast
+ * @param {Mixed} valueToCheck
+ * @param {Mixed} valueToBeAtLeast
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isAtLeast = function (val, atlst, msg) {
+ new Assertion(val, msg, assert.isAtLeast, true).to.be.least(atlst);
+ };
+
+ /**
+ * ### .isBelow(valueToCheck, valueToBeBelow, [message])
+ *
+ * Asserts `valueToCheck` is strictly less than (<) `valueToBeBelow`.
+ *
+ * assert.isBelow(3, 6, '3 is strictly less than 6');
+ *
+ * @name isBelow
+ * @param {Mixed} valueToCheck
+ * @param {Mixed} valueToBeBelow
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isBelow = function (val, blw, msg) {
+ new Assertion(val, msg, assert.isBelow, true).to.be.below(blw);
+ };
+
+ /**
+ * ### .isAtMost(valueToCheck, valueToBeAtMost, [message])
+ *
+ * Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`.
+ *
+ * assert.isAtMost(3, 6, '3 is less than or equal to 6');
+ * assert.isAtMost(4, 4, '4 is less than or equal to 4');
+ *
+ * @name isAtMost
+ * @param {Mixed} valueToCheck
+ * @param {Mixed} valueToBeAtMost
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isAtMost = function (val, atmst, msg) {
+ new Assertion(val, msg, assert.isAtMost, true).to.be.most(atmst);
+ };
+
+ /**
+ * ### .isTrue(value, [message])
+ *
+ * Asserts that `value` is true.
+ *
+ * var teaServed = true;
+ * assert.isTrue(teaServed, 'the tea has been served');
+ *
+ * @name isTrue
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isTrue = function (val, msg) {
+ new Assertion(val, msg, assert.isTrue, true).is['true'];
+ };
+
+ /**
+ * ### .isNotTrue(value, [message])
+ *
+ * Asserts that `value` is not true.
+ *
+ * var tea = 'tasty chai';
+ * assert.isNotTrue(tea, 'great, time for tea!');
+ *
+ * @name isNotTrue
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotTrue = function (val, msg) {
+ new Assertion(val, msg, assert.isNotTrue, true).to.not.equal(true);
+ };
+
+ /**
+ * ### .isFalse(value, [message])
+ *
+ * Asserts that `value` is false.
+ *
+ * var teaServed = false;
+ * assert.isFalse(teaServed, 'no tea yet? hmm...');
+ *
+ * @name isFalse
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isFalse = function (val, msg) {
+ new Assertion(val, msg, assert.isFalse, true).is['false'];
+ };
+
+ /**
+ * ### .isNotFalse(value, [message])
+ *
+ * Asserts that `value` is not false.
+ *
+ * var tea = 'tasty chai';
+ * assert.isNotFalse(tea, 'great, time for tea!');
+ *
+ * @name isNotFalse
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotFalse = function (val, msg) {
+ new Assertion(val, msg, assert.isNotFalse, true).to.not.equal(false);
+ };
+
+ /**
+ * ### .isNull(value, [message])
+ *
+ * Asserts that `value` is null.
+ *
+ * assert.isNull(err, 'there was no error');
+ *
+ * @name isNull
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNull = function (val, msg) {
+ new Assertion(val, msg, assert.isNull, true).to.equal(null);
+ };
+
+ /**
+ * ### .isNotNull(value, [message])
+ *
+ * Asserts that `value` is not null.
+ *
+ * var tea = 'tasty chai';
+ * assert.isNotNull(tea, 'great, time for tea!');
+ *
+ * @name isNotNull
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotNull = function (val, msg) {
+ new Assertion(val, msg, assert.isNotNull, true).to.not.equal(null);
+ };
+
+ /**
+ * ### .isNaN
+ *
+ * Asserts that value is NaN.
+ *
+ * assert.isNaN(NaN, 'NaN is NaN');
+ *
+ * @name isNaN
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNaN = function (val, msg) {
+ new Assertion(val, msg, assert.isNaN, true).to.be.NaN;
+ };
+
+ /**
+ * ### .isNotNaN
+ *
+ * Asserts that value is not NaN.
+ *
+ * assert.isNotNaN(4, '4 is not NaN');
+ *
+ * @name isNotNaN
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+ assert.isNotNaN = function (val, msg) {
+ new Assertion(val, msg, assert.isNotNaN, true).not.to.be.NaN;
+ };
+
+ /**
+ * ### .exists
+ *
+ * Asserts that the target is neither `null` nor `undefined`.
+ *
+ * var foo = 'hi';
+ *
+ * assert.exists(foo, 'foo is neither `null` nor `undefined`');
+ *
+ * @name exists
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.exists = function (val, msg) {
+ new Assertion(val, msg, assert.exists, true).to.exist;
+ };
+
+ /**
+ * ### .notExists
+ *
+ * Asserts that the target is either `null` or `undefined`.
+ *
+ * var bar = null
+ * , baz;
+ *
+ * assert.notExists(bar);
+ * assert.notExists(baz, 'baz is either null or undefined');
+ *
+ * @name notExists
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notExists = function (val, msg) {
+ new Assertion(val, msg, assert.notExists, true).to.not.exist;
+ };
+
+ /**
+ * ### .isUndefined(value, [message])
+ *
+ * Asserts that `value` is `undefined`.
+ *
+ * var tea;
+ * assert.isUndefined(tea, 'no tea defined');
+ *
+ * @name isUndefined
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isUndefined = function (val, msg) {
+ new Assertion(val, msg, assert.isUndefined, true).to.equal(undefined);
+ };
+
+ /**
+ * ### .isDefined(value, [message])
+ *
+ * Asserts that `value` is not `undefined`.
+ *
+ * var tea = 'cup of chai';
+ * assert.isDefined(tea, 'tea has been defined');
+ *
+ * @name isDefined
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isDefined = function (val, msg) {
+ new Assertion(val, msg, assert.isDefined, true).to.not.equal(undefined);
+ };
+
+ /**
+ * ### .isFunction(value, [message])
+ *
+ * Asserts that `value` is a function.
+ *
+ * function serveTea() { return 'cup of tea'; };
+ * assert.isFunction(serveTea, 'great, we can have tea now');
+ *
+ * @name isFunction
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isFunction = function (val, msg) {
+ new Assertion(val, msg, assert.isFunction, true).to.be.a('function');
+ };
+
+ /**
+ * ### .isNotFunction(value, [message])
+ *
+ * Asserts that `value` is _not_ a function.
+ *
+ * var serveTea = [ 'heat', 'pour', 'sip' ];
+ * assert.isNotFunction(serveTea, 'great, we have listed the steps');
+ *
+ * @name isNotFunction
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotFunction = function (val, msg) {
+ new Assertion(val, msg, assert.isNotFunction, true).to.not.be.a('function');
+ };
+
+ /**
+ * ### .isObject(value, [message])
+ *
+ * Asserts that `value` is an object of type 'Object' (as revealed by `Object.prototype.toString`).
+ * _The assertion does not match subclassed objects._
+ *
+ * var selection = { name: 'Chai', serve: 'with spices' };
+ * assert.isObject(selection, 'tea selection is an object');
+ *
+ * @name isObject
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isObject = function (val, msg) {
+ new Assertion(val, msg, assert.isObject, true).to.be.a('object');
+ };
+
+ /**
+ * ### .isNotObject(value, [message])
+ *
+ * Asserts that `value` is _not_ an object of type 'Object' (as revealed by `Object.prototype.toString`).
+ *
+ * var selection = 'chai'
+ * assert.isNotObject(selection, 'tea selection is not an object');
+ * assert.isNotObject(null, 'null is not an object');
+ *
+ * @name isNotObject
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotObject = function (val, msg) {
+ new Assertion(val, msg, assert.isNotObject, true).to.not.be.a('object');
+ };
+
+ /**
+ * ### .isArray(value, [message])
+ *
+ * Asserts that `value` is an array.
+ *
+ * var menu = [ 'green', 'chai', 'oolong' ];
+ * assert.isArray(menu, 'what kind of tea do we want?');
+ *
+ * @name isArray
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isArray = function (val, msg) {
+ new Assertion(val, msg, assert.isArray, true).to.be.an('array');
+ };
+
+ /**
+ * ### .isNotArray(value, [message])
+ *
+ * Asserts that `value` is _not_ an array.
+ *
+ * var menu = 'green|chai|oolong';
+ * assert.isNotArray(menu, 'what kind of tea do we want?');
+ *
+ * @name isNotArray
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotArray = function (val, msg) {
+ new Assertion(val, msg, assert.isNotArray, true).to.not.be.an('array');
+ };
+
+ /**
+ * ### .isString(value, [message])
+ *
+ * Asserts that `value` is a string.
+ *
+ * var teaOrder = 'chai';
+ * assert.isString(teaOrder, 'order placed');
+ *
+ * @name isString
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isString = function (val, msg) {
+ new Assertion(val, msg, assert.isString, true).to.be.a('string');
+ };
+
+ /**
+ * ### .isNotString(value, [message])
+ *
+ * Asserts that `value` is _not_ a string.
+ *
+ * var teaOrder = 4;
+ * assert.isNotString(teaOrder, 'order placed');
+ *
+ * @name isNotString
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotString = function (val, msg) {
+ new Assertion(val, msg, assert.isNotString, true).to.not.be.a('string');
+ };
+
+ /**
+ * ### .isNumber(value, [message])
+ *
+ * Asserts that `value` is a number.
+ *
+ * var cups = 2;
+ * assert.isNumber(cups, 'how many cups');
+ *
+ * @name isNumber
+ * @param {Number} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNumber = function (val, msg) {
+ new Assertion(val, msg, assert.isNumber, true).to.be.a('number');
+ };
+
+ /**
+ * ### .isNotNumber(value, [message])
+ *
+ * Asserts that `value` is _not_ a number.
+ *
+ * var cups = '2 cups please';
+ * assert.isNotNumber(cups, 'how many cups');
+ *
+ * @name isNotNumber
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotNumber = function (val, msg) {
+ new Assertion(val, msg, assert.isNotNumber, true).to.not.be.a('number');
+ };
+
+ /**
+ * ### .isFinite(value, [message])
+ *
+ * Asserts that `value` is a finite number. Unlike `.isNumber`, this will fail for `NaN` and `Infinity`.
+ *
+ * var cups = 2;
+ * assert.isFinite(cups, 'how many cups');
+ *
+ * assert.isFinite(NaN); // throws
+ *
+ * @name isFinite
+ * @param {Number} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isFinite = function (val, msg) {
+ new Assertion(val, msg, assert.isFinite, true).to.be.finite;
+ };
+
+ /**
+ * ### .isBoolean(value, [message])
+ *
+ * Asserts that `value` is a boolean.
+ *
+ * var teaReady = true
+ * , teaServed = false;
+ *
+ * assert.isBoolean(teaReady, 'is the tea ready');
+ * assert.isBoolean(teaServed, 'has tea been served');
+ *
+ * @name isBoolean
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isBoolean = function (val, msg) {
+ new Assertion(val, msg, assert.isBoolean, true).to.be.a('boolean');
+ };
+
+ /**
+ * ### .isNotBoolean(value, [message])
+ *
+ * Asserts that `value` is _not_ a boolean.
+ *
+ * var teaReady = 'yep'
+ * , teaServed = 'nope';
+ *
+ * assert.isNotBoolean(teaReady, 'is the tea ready');
+ * assert.isNotBoolean(teaServed, 'has tea been served');
+ *
+ * @name isNotBoolean
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotBoolean = function (val, msg) {
+ new Assertion(val, msg, assert.isNotBoolean, true).to.not.be.a('boolean');
+ };
+
+ /**
+ * ### .typeOf(value, name, [message])
+ *
+ * Asserts that `value`'s type is `name`, as determined by
+ * `Object.prototype.toString`.
+ *
+ * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
+ * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
+ * assert.typeOf('tea', 'string', 'we have a string');
+ * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
+ * assert.typeOf(null, 'null', 'we have a null');
+ * assert.typeOf(undefined, 'undefined', 'we have an undefined');
+ *
+ * @name typeOf
+ * @param {Mixed} value
+ * @param {String} name
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.typeOf = function (val, type, msg) {
+ new Assertion(val, msg, assert.typeOf, true).to.be.a(type);
+ };
+
+ /**
+ * ### .notTypeOf(value, name, [message])
+ *
+ * Asserts that `value`'s type is _not_ `name`, as determined by
+ * `Object.prototype.toString`.
+ *
+ * assert.notTypeOf('tea', 'number', 'strings are not numbers');
+ *
+ * @name notTypeOf
+ * @param {Mixed} value
+ * @param {String} typeof name
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notTypeOf = function (val, type, msg) {
+ new Assertion(val, msg, assert.notTypeOf, true).to.not.be.a(type);
+ };
+
+ /**
+ * ### .instanceOf(object, constructor, [message])
+ *
+ * Asserts that `value` is an instance of `constructor`.
+ *
+ * var Tea = function (name) { this.name = name; }
+ * , chai = new Tea('chai');
+ *
+ * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
+ *
+ * @name instanceOf
+ * @param {Object} object
+ * @param {Constructor} constructor
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.instanceOf = function (val, type, msg) {
+ new Assertion(val, msg, assert.instanceOf, true).to.be.instanceOf(type);
+ };
+
+ /**
+ * ### .notInstanceOf(object, constructor, [message])
+ *
+ * Asserts `value` is not an instance of `constructor`.
+ *
+ * var Tea = function (name) { this.name = name; }
+ * , chai = new String('chai');
+ *
+ * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
+ *
+ * @name notInstanceOf
+ * @param {Object} object
+ * @param {Constructor} constructor
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notInstanceOf = function (val, type, msg) {
+ new Assertion(val, msg, assert.notInstanceOf, true)
+ .to.not.be.instanceOf(type);
+ };
+
+ /**
+ * ### .include(haystack, needle, [message])
+ *
+ * Asserts that `haystack` includes `needle`. Can be used to assert the
+ * inclusion of a value in an array, a substring in a string, or a subset of
+ * properties in an object.
+ *
+ * assert.include([1,2,3], 2, 'array contains value');
+ * assert.include('foobar', 'foo', 'string contains substring');
+ * assert.include({ foo: 'bar', hello: 'universe' }, { foo: 'bar' }, 'object contains property');
+ *
+ * Strict equality (===) is used. When asserting the inclusion of a value in
+ * an array, the array is searched for an element that's strictly equal to the
+ * given value. When asserting a subset of properties in an object, the object
+ * is searched for the given property keys, checking that each one is present
+ * and stricty equal to the given property value. For instance:
+ *
+ * var obj1 = {a: 1}
+ * , obj2 = {b: 2};
+ * assert.include([obj1, obj2], obj1);
+ * assert.include({foo: obj1, bar: obj2}, {foo: obj1});
+ * assert.include({foo: obj1, bar: obj2}, {foo: obj1, bar: obj2});
+ *
+ * @name include
+ * @param {Array|String} haystack
+ * @param {Mixed} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.include = function (exp, inc, msg) {
+ new Assertion(exp, msg, assert.include, true).include(inc);
+ };
+
+ /**
+ * ### .notInclude(haystack, needle, [message])
+ *
+ * Asserts that `haystack` does not include `needle`. Can be used to assert
+ * the absence of a value in an array, a substring in a string, or a subset of
+ * properties in an object.
+ *
+ * assert.notInclude([1,2,3], 4, 'array doesn't contain value');
+ * assert.notInclude('foobar', 'baz', 'string doesn't contain substring');
+ * assert.notInclude({ foo: 'bar', hello: 'universe' }, { foo: 'baz' }, 'object doesn't contain property');
+ *
+ * Strict equality (===) is used. When asserting the absence of a value in an
+ * array, the array is searched to confirm the absence of an element that's
+ * strictly equal to the given value. When asserting a subset of properties in
+ * an object, the object is searched to confirm that at least one of the given
+ * property keys is either not present or not strictly equal to the given
+ * property value. For instance:
+ *
+ * var obj1 = {a: 1}
+ * , obj2 = {b: 2};
+ * assert.notInclude([obj1, obj2], {a: 1});
+ * assert.notInclude({foo: obj1, bar: obj2}, {foo: {a: 1}});
+ * assert.notInclude({foo: obj1, bar: obj2}, {foo: obj1, bar: {b: 2}});
+ *
+ * @name notInclude
+ * @param {Array|String} haystack
+ * @param {Mixed} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notInclude = function (exp, inc, msg) {
+ new Assertion(exp, msg, assert.notInclude, true).not.include(inc);
+ };
+
+ /**
+ * ### .deepInclude(haystack, needle, [message])
+ *
+ * Asserts that `haystack` includes `needle`. Can be used to assert the
+ * inclusion of a value in an array or a subset of properties in an object.
+ * Deep equality is used.
+ *
+ * var obj1 = {a: 1}
+ * , obj2 = {b: 2};
+ * assert.deepInclude([obj1, obj2], {a: 1});
+ * assert.deepInclude({foo: obj1, bar: obj2}, {foo: {a: 1}});
+ * assert.deepInclude({foo: obj1, bar: obj2}, {foo: {a: 1}, bar: {b: 2}});
+ *
+ * @name deepInclude
+ * @param {Array|String} haystack
+ * @param {Mixed} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.deepInclude = function (exp, inc, msg) {
+ new Assertion(exp, msg, assert.deepInclude, true).deep.include(inc);
+ };
+
+ /**
+ * ### .notDeepInclude(haystack, needle, [message])
+ *
+ * Asserts that `haystack` does not include `needle`. Can be used to assert
+ * the absence of a value in an array or a subset of properties in an object.
+ * Deep equality is used.
+ *
+ * var obj1 = {a: 1}
+ * , obj2 = {b: 2};
+ * assert.notDeepInclude([obj1, obj2], {a: 9});
+ * assert.notDeepInclude({foo: obj1, bar: obj2}, {foo: {a: 9}});
+ * assert.notDeepInclude({foo: obj1, bar: obj2}, {foo: {a: 1}, bar: {b: 9}});
+ *
+ * @name notDeepInclude
+ * @param {Array|String} haystack
+ * @param {Mixed} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notDeepInclude = function (exp, inc, msg) {
+ new Assertion(exp, msg, assert.notDeepInclude, true).not.deep.include(inc);
+ };
+
+ /**
+ * ### .nestedInclude(haystack, needle, [message])
+ *
+ * Asserts that 'haystack' includes 'needle'.
+ * Can be used to assert the inclusion of a subset of properties in an
+ * object.
+ * Enables the use of dot- and bracket-notation for referencing nested
+ * properties.
+ * '[]' and '.' in property names can be escaped using double backslashes.
+ *
+ * assert.nestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'x'});
+ * assert.nestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'x'});
+ *
+ * @name nestedInclude
+ * @param {Object} haystack
+ * @param {Object} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.nestedInclude = function (exp, inc, msg) {
+ new Assertion(exp, msg, assert.nestedInclude, true).nested.include(inc);
+ };
+
+ /**
+ * ### .notNestedInclude(haystack, needle, [message])
+ *
+ * Asserts that 'haystack' does not include 'needle'.
+ * Can be used to assert the absence of a subset of properties in an
+ * object.
+ * Enables the use of dot- and bracket-notation for referencing nested
+ * properties.
+ * '[]' and '.' in property names can be escaped using double backslashes.
+ *
+ * assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.b': 'y'});
+ * assert.notNestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'y'});
+ *
+ * @name notNestedInclude
+ * @param {Object} haystack
+ * @param {Object} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notNestedInclude = function (exp, inc, msg) {
+ new Assertion(exp, msg, assert.notNestedInclude, true)
+ .not.nested.include(inc);
+ };
+
+ /**
+ * ### .deepNestedInclude(haystack, needle, [message])
+ *
+ * Asserts that 'haystack' includes 'needle'.
+ * Can be used to assert the inclusion of a subset of properties in an
+ * object while checking for deep equality.
+ * Enables the use of dot- and bracket-notation for referencing nested
+ * properties.
+ * '[]' and '.' in property names can be escaped using double backslashes.
+ *
+ * assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}});
+ * assert.deepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {x: 1}});
+ *
+ * @name deepNestedInclude
+ * @param {Object} haystack
+ * @param {Object} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.deepNestedInclude = function(exp, inc, msg) {
+ new Assertion(exp, msg, assert.deepNestedInclude, true)
+ .deep.nested.include(inc);
+ };
+
+ /**
+ * ### .notDeepNestedInclude(haystack, needle, [message])
+ *
+ * Asserts that 'haystack' does not include 'needle'.
+ * Can be used to assert the absence of a subset of properties in an
+ * object while checking for deep equality.
+ * Enables the use of dot- and bracket-notation for referencing nested
+ * properties.
+ * '[]' and '.' in property names can be escaped using double backslashes.
+ *
+ * assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 1}})
+ * assert.notDeepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {y: 2}});
+ *
+ * @name notDeepNestedInclude
+ * @param {Object} haystack
+ * @param {Object} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notDeepNestedInclude = function(exp, inc, msg) {
+ new Assertion(exp, msg, assert.notDeepNestedInclude, true)
+ .not.deep.nested.include(inc);
+ };
+
+ /**
+ * ### .ownInclude(haystack, needle, [message])
+ *
+ * Asserts that 'haystack' includes 'needle'.
+ * Can be used to assert the inclusion of a subset of properties in an
+ * object while ignoring inherited properties.
+ *
+ * assert.ownInclude({ a: 1 }, { a: 1 });
+ *
+ * @name ownInclude
+ * @param {Object} haystack
+ * @param {Object} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.ownInclude = function(exp, inc, msg) {
+ new Assertion(exp, msg, assert.ownInclude, true).own.include(inc);
+ };
+
+ /**
+ * ### .notOwnInclude(haystack, needle, [message])
+ *
+ * Asserts that 'haystack' includes 'needle'.
+ * Can be used to assert the absence of a subset of properties in an
+ * object while ignoring inherited properties.
+ *
+ * Object.prototype.b = 2;
+ *
+ * assert.notOwnInclude({ a: 1 }, { b: 2 });
+ *
+ * @name notOwnInclude
+ * @param {Object} haystack
+ * @param {Object} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notOwnInclude = function(exp, inc, msg) {
+ new Assertion(exp, msg, assert.notOwnInclude, true).not.own.include(inc);
+ };
+
+ /**
+ * ### .deepOwnInclude(haystack, needle, [message])
+ *
+ * Asserts that 'haystack' includes 'needle'.
+ * Can be used to assert the inclusion of a subset of properties in an
+ * object while ignoring inherited properties and checking for deep equality.
+ *
+ * assert.deepOwnInclude({a: {b: 2}}, {a: {b: 2}});
+ *
+ * @name deepOwnInclude
+ * @param {Object} haystack
+ * @param {Object} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.deepOwnInclude = function(exp, inc, msg) {
+ new Assertion(exp, msg, assert.deepOwnInclude, true)
+ .deep.own.include(inc);
+ };
+
+ /**
+ * ### .notDeepOwnInclude(haystack, needle, [message])
+ *
+ * Asserts that 'haystack' includes 'needle'.
+ * Can be used to assert the absence of a subset of properties in an
+ * object while ignoring inherited properties and checking for deep equality.
+ *
+ * assert.notDeepOwnInclude({a: {b: 2}}, {a: {c: 3}});
+ *
+ * @name notDeepOwnInclude
+ * @param {Object} haystack
+ * @param {Object} needle
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notDeepOwnInclude = function(exp, inc, msg) {
+ new Assertion(exp, msg, assert.notDeepOwnInclude, true)
+ .not.deep.own.include(inc);
+ };
+
+ /**
+ * ### .match(value, regexp, [message])
+ *
+ * Asserts that `value` matches the regular expression `regexp`.
+ *
+ * assert.match('foobar', /^foo/, 'regexp matches');
+ *
+ * @name match
+ * @param {Mixed} value
+ * @param {RegExp} regexp
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.match = function (exp, re, msg) {
+ new Assertion(exp, msg, assert.match, true).to.match(re);
+ };
+
+ /**
+ * ### .notMatch(value, regexp, [message])
+ *
+ * Asserts that `value` does not match the regular expression `regexp`.
+ *
+ * assert.notMatch('foobar', /^foo/, 'regexp does not match');
+ *
+ * @name notMatch
+ * @param {Mixed} value
+ * @param {RegExp} regexp
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notMatch = function (exp, re, msg) {
+ new Assertion(exp, msg, assert.notMatch, true).to.not.match(re);
+ };
+
+ /**
+ * ### .property(object, property, [message])
+ *
+ * Asserts that `object` has a direct or inherited property named by
+ * `property`.
+ *
+ * assert.property({ tea: { green: 'matcha' }}, 'tea');
+ * assert.property({ tea: { green: 'matcha' }}, 'toString');
+ *
+ * @name property
+ * @param {Object} object
+ * @param {String} property
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.property = function (obj, prop, msg) {
+ new Assertion(obj, msg, assert.property, true).to.have.property(prop);
+ };
+
+ /**
+ * ### .notProperty(object, property, [message])
+ *
+ * Asserts that `object` does _not_ have a direct or inherited property named
+ * by `property`.
+ *
+ * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
+ *
+ * @name notProperty
+ * @param {Object} object
+ * @param {String} property
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notProperty = function (obj, prop, msg) {
+ new Assertion(obj, msg, assert.notProperty, true)
+ .to.not.have.property(prop);
+ };
+
+ /**
+ * ### .propertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` has a direct or inherited property named by
+ * `property` with a value given by `value`. Uses a strict equality check
+ * (===).
+ *
+ * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
+ *
+ * @name propertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.propertyVal = function (obj, prop, val, msg) {
+ new Assertion(obj, msg, assert.propertyVal, true)
+ .to.have.property(prop, val);
+ };
+
+ /**
+ * ### .notPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` does _not_ have a direct or inherited property named
+ * by `property` with value given by `value`. Uses a strict equality check
+ * (===).
+ *
+ * assert.notPropertyVal({ tea: 'is good' }, 'tea', 'is bad');
+ * assert.notPropertyVal({ tea: 'is good' }, 'coffee', 'is good');
+ *
+ * @name notPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notPropertyVal = function (obj, prop, val, msg) {
+ new Assertion(obj, msg, assert.notPropertyVal, true)
+ .to.not.have.property(prop, val);
+ };
+
+ /**
+ * ### .deepPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` has a direct or inherited property named by
+ * `property` with a value given by `value`. Uses a deep equality check.
+ *
+ * assert.deepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'matcha' });
+ *
+ * @name deepPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.deepPropertyVal = function (obj, prop, val, msg) {
+ new Assertion(obj, msg, assert.deepPropertyVal, true)
+ .to.have.deep.property(prop, val);
+ };
+
+ /**
+ * ### .notDeepPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` does _not_ have a direct or inherited property named
+ * by `property` with value given by `value`. Uses a deep equality check.
+ *
+ * assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { black: 'matcha' });
+ * assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'oolong' });
+ * assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'coffee', { green: 'matcha' });
+ *
+ * @name notDeepPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notDeepPropertyVal = function (obj, prop, val, msg) {
+ new Assertion(obj, msg, assert.notDeepPropertyVal, true)
+ .to.not.have.deep.property(prop, val);
+ };
+
+ /**
+ * ### .ownProperty(object, property, [message])
+ *
+ * Asserts that `object` has a direct property named by `property`. Inherited
+ * properties aren't checked.
+ *
+ * assert.ownProperty({ tea: { green: 'matcha' }}, 'tea');
+ *
+ * @name ownProperty
+ * @param {Object} object
+ * @param {String} property
+ * @param {String} message
+ * @api public
+ */
+
+ assert.ownProperty = function (obj, prop, msg) {
+ new Assertion(obj, msg, assert.ownProperty, true)
+ .to.have.own.property(prop);
+ };
+
+ /**
+ * ### .notOwnProperty(object, property, [message])
+ *
+ * Asserts that `object` does _not_ have a direct property named by
+ * `property`. Inherited properties aren't checked.
+ *
+ * assert.notOwnProperty({ tea: { green: 'matcha' }}, 'coffee');
+ * assert.notOwnProperty({}, 'toString');
+ *
+ * @name notOwnProperty
+ * @param {Object} object
+ * @param {String} property
+ * @param {String} message
+ * @api public
+ */
+
+ assert.notOwnProperty = function (obj, prop, msg) {
+ new Assertion(obj, msg, assert.notOwnProperty, true)
+ .to.not.have.own.property(prop);
+ };
+
+ /**
+ * ### .ownPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` has a direct property named by `property` and a value
+ * equal to the provided `value`. Uses a strict equality check (===).
+ * Inherited properties aren't checked.
+ *
+ * assert.ownPropertyVal({ coffee: 'is good'}, 'coffee', 'is good');
+ *
+ * @name ownPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @api public
+ */
+
+ assert.ownPropertyVal = function (obj, prop, value, msg) {
+ new Assertion(obj, msg, assert.ownPropertyVal, true)
+ .to.have.own.property(prop, value);
+ };
+
+ /**
+ * ### .notOwnPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` does _not_ have a direct property named by `property`
+ * with a value equal to the provided `value`. Uses a strict equality check
+ * (===). Inherited properties aren't checked.
+ *
+ * assert.notOwnPropertyVal({ tea: 'is better'}, 'tea', 'is worse');
+ * assert.notOwnPropertyVal({}, 'toString', Object.prototype.toString);
+ *
+ * @name notOwnPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @api public
+ */
+
+ assert.notOwnPropertyVal = function (obj, prop, value, msg) {
+ new Assertion(obj, msg, assert.notOwnPropertyVal, true)
+ .to.not.have.own.property(prop, value);
+ };
+
+ /**
+ * ### .deepOwnPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` has a direct property named by `property` and a value
+ * equal to the provided `value`. Uses a deep equality check. Inherited
+ * properties aren't checked.
+ *
+ * assert.deepOwnPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'matcha' });
+ *
+ * @name deepOwnPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @api public
+ */
+
+ assert.deepOwnPropertyVal = function (obj, prop, value, msg) {
+ new Assertion(obj, msg, assert.deepOwnPropertyVal, true)
+ .to.have.deep.own.property(prop, value);
+ };
+
+ /**
+ * ### .notDeepOwnPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` does _not_ have a direct property named by `property`
+ * with a value equal to the provided `value`. Uses a deep equality check.
+ * Inherited properties aren't checked.
+ *
+ * assert.notDeepOwnPropertyVal({ tea: { green: 'matcha' } }, 'tea', { black: 'matcha' });
+ * assert.notDeepOwnPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'oolong' });
+ * assert.notDeepOwnPropertyVal({ tea: { green: 'matcha' } }, 'coffee', { green: 'matcha' });
+ * assert.notDeepOwnPropertyVal({}, 'toString', Object.prototype.toString);
+ *
+ * @name notDeepOwnPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @api public
+ */
+
+ assert.notDeepOwnPropertyVal = function (obj, prop, value, msg) {
+ new Assertion(obj, msg, assert.notDeepOwnPropertyVal, true)
+ .to.not.have.deep.own.property(prop, value);
+ };
+
+ /**
+ * ### .nestedProperty(object, property, [message])
+ *
+ * Asserts that `object` has a direct or inherited property named by
+ * `property`, which can be a string using dot- and bracket-notation for
+ * nested reference.
+ *
+ * assert.nestedProperty({ tea: { green: 'matcha' }}, 'tea.green');
+ *
+ * @name nestedProperty
+ * @param {Object} object
+ * @param {String} property
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.nestedProperty = function (obj, prop, msg) {
+ new Assertion(obj, msg, assert.nestedProperty, true)
+ .to.have.nested.property(prop);
+ };
+
+ /**
+ * ### .notNestedProperty(object, property, [message])
+ *
+ * Asserts that `object` does _not_ have a property named by `property`, which
+ * can be a string using dot- and bracket-notation for nested reference. The
+ * property cannot exist on the object nor anywhere in its prototype chain.
+ *
+ * assert.notNestedProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
+ *
+ * @name notNestedProperty
+ * @param {Object} object
+ * @param {String} property
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notNestedProperty = function (obj, prop, msg) {
+ new Assertion(obj, msg, assert.notNestedProperty, true)
+ .to.not.have.nested.property(prop);
+ };
+
+ /**
+ * ### .nestedPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` has a property named by `property` with value given
+ * by `value`. `property` can use dot- and bracket-notation for nested
+ * reference. Uses a strict equality check (===).
+ *
+ * assert.nestedPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
+ *
+ * @name nestedPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.nestedPropertyVal = function (obj, prop, val, msg) {
+ new Assertion(obj, msg, assert.nestedPropertyVal, true)
+ .to.have.nested.property(prop, val);
+ };
+
+ /**
+ * ### .notNestedPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` does _not_ have a property named by `property` with
+ * value given by `value`. `property` can use dot- and bracket-notation for
+ * nested reference. Uses a strict equality check (===).
+ *
+ * assert.notNestedPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
+ * assert.notNestedPropertyVal({ tea: { green: 'matcha' }}, 'coffee.green', 'matcha');
+ *
+ * @name notNestedPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notNestedPropertyVal = function (obj, prop, val, msg) {
+ new Assertion(obj, msg, assert.notNestedPropertyVal, true)
+ .to.not.have.nested.property(prop, val);
+ };
+
+ /**
+ * ### .deepNestedPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` has a property named by `property` with a value given
+ * by `value`. `property` can use dot- and bracket-notation for nested
+ * reference. Uses a deep equality check.
+ *
+ * assert.deepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { matcha: 'yum' });
+ *
+ * @name deepNestedPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.deepNestedPropertyVal = function (obj, prop, val, msg) {
+ new Assertion(obj, msg, assert.deepNestedPropertyVal, true)
+ .to.have.deep.nested.property(prop, val);
+ };
+
+ /**
+ * ### .notDeepNestedPropertyVal(object, property, value, [message])
+ *
+ * Asserts that `object` does _not_ have a property named by `property` with
+ * value given by `value`. `property` can use dot- and bracket-notation for
+ * nested reference. Uses a deep equality check.
+ *
+ * assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { oolong: 'yum' });
+ * assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { matcha: 'yuck' });
+ * assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.black', { matcha: 'yum' });
+ *
+ * @name notDeepNestedPropertyVal
+ * @param {Object} object
+ * @param {String} property
+ * @param {Mixed} value
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notDeepNestedPropertyVal = function (obj, prop, val, msg) {
+ new Assertion(obj, msg, assert.notDeepNestedPropertyVal, true)
+ .to.not.have.deep.nested.property(prop, val);
+ }
+
+ /**
+ * ### .lengthOf(object, length, [message])
+ *
+ * Asserts that `object` has a `length` property with the expected value.
+ *
+ * assert.lengthOf([1,2,3], 3, 'array has length of 3');
+ * assert.lengthOf('foobar', 6, 'string has length of 6');
+ *
+ * @name lengthOf
+ * @param {Mixed} object
+ * @param {Number} length
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.lengthOf = function (exp, len, msg) {
+ new Assertion(exp, msg, assert.lengthOf, true).to.have.lengthOf(len);
+ };
+
+ /**
+ * ### .hasAnyKeys(object, [keys], [message])
+ *
+ * Asserts that `object` has at least one of the `keys` provided.
+ * You can also provide a single object instead of a `keys` array and its keys
+ * will be used as the expected set of keys.
+ *
+ * assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'iDontExist', 'baz']);
+ * assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, iDontExist: 99, baz: 1337});
+ * assert.hasAnyKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
+ * assert.hasAnyKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']);
+ *
+ * @name hasAnyKeys
+ * @param {Mixed} object
+ * @param {Array|Object} keys
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.hasAnyKeys = function (obj, keys, msg) {
+ new Assertion(obj, msg, assert.hasAnyKeys, true).to.have.any.keys(keys);
+ }
+
+ /**
+ * ### .hasAllKeys(object, [keys], [message])
+ *
+ * Asserts that `object` has all and only all of the `keys` provided.
+ * You can also provide a single object instead of a `keys` array and its keys
+ * will be used as the expected set of keys.
+ *
+ * assert.hasAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'bar', 'baz']);
+ * assert.hasAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, bar: 99, baz: 1337]);
+ * assert.hasAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
+ * assert.hasAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}, 'anotherKey']);
+ *
+ * @name hasAllKeys
+ * @param {Mixed} object
+ * @param {String[]} keys
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.hasAllKeys = function (obj, keys, msg) {
+ new Assertion(obj, msg, assert.hasAllKeys, true).to.have.all.keys(keys);
+ }
+
+ /**
+ * ### .containsAllKeys(object, [keys], [message])
+ *
+ * Asserts that `object` has all of the `keys` provided but may have more keys not listed.
+ * You can also provide a single object instead of a `keys` array and its keys
+ * will be used as the expected set of keys.
+ *
+ * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'baz']);
+ * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'bar', 'baz']);
+ * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, baz: 1337});
+ * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, bar: 99, baz: 1337});
+ * assert.containsAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}]);
+ * assert.containsAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
+ * assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}]);
+ * assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}, 'anotherKey']);
+ *
+ * @name containsAllKeys
+ * @param {Mixed} object
+ * @param {String[]} keys
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.containsAllKeys = function (obj, keys, msg) {
+ new Assertion(obj, msg, assert.containsAllKeys, true)
+ .to.contain.all.keys(keys);
+ }
+
+ /**
+ * ### .doesNotHaveAnyKeys(object, [keys], [message])
+ *
+ * Asserts that `object` has none of the `keys` provided.
+ * You can also provide a single object instead of a `keys` array and its keys
+ * will be used as the expected set of keys.
+ *
+ * assert.doesNotHaveAnyKeys({foo: 1, bar: 2, baz: 3}, ['one', 'two', 'example']);
+ * assert.doesNotHaveAnyKeys({foo: 1, bar: 2, baz: 3}, {one: 1, two: 2, example: 'foo'});
+ * assert.doesNotHaveAnyKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{one: 'two'}, 'example']);
+ * assert.doesNotHaveAnyKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{one: 'two'}, 'example']);
+ *
+ * @name doesNotHaveAnyKeys
+ * @param {Mixed} object
+ * @param {String[]} keys
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.doesNotHaveAnyKeys = function (obj, keys, msg) {
+ new Assertion(obj, msg, assert.doesNotHaveAnyKeys, true)
+ .to.not.have.any.keys(keys);
+ }
+
+ /**
+ * ### .doesNotHaveAllKeys(object, [keys], [message])
+ *
+ * Asserts that `object` does not have at least one of the `keys` provided.
+ * You can also provide a single object instead of a `keys` array and its keys
+ * will be used as the expected set of keys.
+ *
+ * assert.doesNotHaveAllKeys({foo: 1, bar: 2, baz: 3}, ['one', 'two', 'example']);
+ * assert.doesNotHaveAllKeys({foo: 1, bar: 2, baz: 3}, {one: 1, two: 2, example: 'foo'});
+ * assert.doesNotHaveAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{one: 'two'}, 'example']);
+ * assert.doesNotHaveAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{one: 'two'}, 'example']);
+ *
+ * @name doesNotHaveAllKeys
+ * @param {Mixed} object
+ * @param {String[]} keys
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.doesNotHaveAllKeys = function (obj, keys, msg) {
+ new Assertion(obj, msg, assert.doesNotHaveAllKeys, true)
+ .to.not.have.all.keys(keys);
+ }
+
+ /**
+ * ### .hasAnyDeepKeys(object, [keys], [message])
+ *
+ * Asserts that `object` has at least one of the `keys` provided.
+ * Since Sets and Maps can have objects as keys you can use this assertion to perform
+ * a deep comparison.
+ * You can also provide a single object instead of a `keys` array and its keys
+ * will be used as the expected set of keys.
+ *
+ * assert.hasAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {one: 'one'});
+ * assert.hasAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), [{one: 'one'}, {two: 'two'}]);
+ * assert.hasAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
+ * assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {one: 'one'});
+ * assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {three: 'three'}]);
+ * assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
+ *
+ * @name doesNotHaveAllKeys
+ * @param {Mixed} object
+ * @param {Array|Object} keys
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.hasAnyDeepKeys = function (obj, keys, msg) {
+ new Assertion(obj, msg, assert.hasAnyDeepKeys, true)
+ .to.have.any.deep.keys(keys);
+ }
+
+ /**
+ * ### .hasAllDeepKeys(object, [keys], [message])
+ *
+ * Asserts that `object` has all and only all of the `keys` provided.
+ * Since Sets and Maps can have objects as keys you can use this assertion to perform
+ * a deep comparison.
+ * You can also provide a single object instead of a `keys` array and its keys
+ * will be used as the expected set of keys.
+ *
+ * assert.hasAllDeepKeys(new Map([[{one: 'one'}, 'valueOne']]), {one: 'one'});
+ * assert.hasAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
+ * assert.hasAllDeepKeys(new Set([{one: 'one'}]), {one: 'one'});
+ * assert.hasAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
+ *
+ * @name hasAllDeepKeys
+ * @param {Mixed} object
+ * @param {Array|Object} keys
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.hasAllDeepKeys = function (obj, keys, msg) {
+ new Assertion(obj, msg, assert.hasAllDeepKeys, true)
+ .to.have.all.deep.keys(keys);
+ }
+
+ /**
+ * ### .containsAllDeepKeys(object, [keys], [message])
+ *
+ * Asserts that `object` contains all of the `keys` provided.
+ * Since Sets and Maps can have objects as keys you can use this assertion to perform
+ * a deep comparison.
+ * You can also provide a single object instead of a `keys` array and its keys
+ * will be used as the expected set of keys.
+ *
+ * assert.containsAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {one: 'one'});
+ * assert.containsAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
+ * assert.containsAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {one: 'one'});
+ * assert.containsAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
+ *
+ * @name containsAllDeepKeys
+ * @param {Mixed} object
+ * @param {Array|Object} keys
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.containsAllDeepKeys = function (obj, keys, msg) {
+ new Assertion(obj, msg, assert.containsAllDeepKeys, true)
+ .to.contain.all.deep.keys(keys);
+ }
+
+ /**
+ * ### .doesNotHaveAnyDeepKeys(object, [keys], [message])
+ *
+ * Asserts that `object` has none of the `keys` provided.
+ * Since Sets and Maps can have objects as keys you can use this assertion to perform
+ * a deep comparison.
+ * You can also provide a single object instead of a `keys` array and its keys
+ * will be used as the expected set of keys.
+ *
+ * assert.doesNotHaveAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {thisDoesNot: 'exist'});
+ * assert.doesNotHaveAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{twenty: 'twenty'}, {fifty: 'fifty'}]);
+ * assert.doesNotHaveAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {twenty: 'twenty'});
+ * assert.doesNotHaveAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{twenty: 'twenty'}, {fifty: 'fifty'}]);
+ *
+ * @name doesNotHaveAnyDeepKeys
+ * @param {Mixed} object
+ * @param {Array|Object} keys
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.doesNotHaveAnyDeepKeys = function (obj, keys, msg) {
+ new Assertion(obj, msg, assert.doesNotHaveAnyDeepKeys, true)
+ .to.not.have.any.deep.keys(keys);
+ }
+
+ /**
+ * ### .doesNotHaveAllDeepKeys(object, [keys], [message])
+ *
+ * Asserts that `object` does not have at least one of the `keys` provided.
+ * Since Sets and Maps can have objects as keys you can use this assertion to perform
+ * a deep comparison.
+ * You can also provide a single object instead of a `keys` array and its keys
+ * will be used as the expected set of keys.
+ *
+ * assert.doesNotHaveAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {thisDoesNot: 'exist'});
+ * assert.doesNotHaveAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{twenty: 'twenty'}, {one: 'one'}]);
+ * assert.doesNotHaveAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {twenty: 'twenty'});
+ * assert.doesNotHaveAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {fifty: 'fifty'}]);
+ *
+ * @name doesNotHaveAllDeepKeys
+ * @param {Mixed} object
+ * @param {Array|Object} keys
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.doesNotHaveAllDeepKeys = function (obj, keys, msg) {
+ new Assertion(obj, msg, assert.doesNotHaveAllDeepKeys, true)
+ .to.not.have.all.deep.keys(keys);
+ }
+
+ /**
+ * ### .throws(fn, [errorLike/string/regexp], [string/regexp], [message])
+ *
+ * If `errorLike` is an `Error` constructor, asserts that `fn` will throw an error that is an
+ * instance of `errorLike`.
+ * If `errorLike` is an `Error` instance, asserts that the error thrown is the same
+ * instance as `errorLike`.
+ * If `errMsgMatcher` is provided, it also asserts that the error thrown will have a
+ * message matching `errMsgMatcher`.
+ *
+ * assert.throws(fn, 'function throws a reference error');
+ * assert.throws(fn, /function throws a reference error/);
+ * assert.throws(fn, ReferenceError);
+ * assert.throws(fn, errorInstance);
+ * assert.throws(fn, ReferenceError, 'Error thrown must be a ReferenceError and have this msg');
+ * assert.throws(fn, errorInstance, 'Error thrown must be the same errorInstance and have this msg');
+ * assert.throws(fn, ReferenceError, /Error thrown must be a ReferenceError and match this/);
+ * assert.throws(fn, errorInstance, /Error thrown must be the same errorInstance and match this/);
+ *
+ * @name throws
+ * @alias throw
+ * @alias Throw
+ * @param {Function} fn
+ * @param {ErrorConstructor|Error} errorLike
+ * @param {RegExp|String} errMsgMatcher
+ * @param {String} message
+ * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.throws = function (fn, errorLike, errMsgMatcher, msg) {
+ if ('string' === typeof errorLike || errorLike instanceof RegExp) {
+ errMsgMatcher = errorLike;
+ errorLike = null;
+ }
+
+ var assertErr = new Assertion(fn, msg, assert.throws, true)
+ .to.throw(errorLike, errMsgMatcher);
+ return flag(assertErr, 'object');
+ };
+
+ /**
+ * ### .doesNotThrow(fn, [errorLike/string/regexp], [string/regexp], [message])
+ *
+ * If `errorLike` is an `Error` constructor, asserts that `fn` will _not_ throw an error that is an
+ * instance of `errorLike`.
+ * If `errorLike` is an `Error` instance, asserts that the error thrown is _not_ the same
+ * instance as `errorLike`.
+ * If `errMsgMatcher` is provided, it also asserts that the error thrown will _not_ have a
+ * message matching `errMsgMatcher`.
+ *
+ * assert.doesNotThrow(fn, 'Any Error thrown must not have this message');
+ * assert.doesNotThrow(fn, /Any Error thrown must not match this/);
+ * assert.doesNotThrow(fn, Error);
+ * assert.doesNotThrow(fn, errorInstance);
+ * assert.doesNotThrow(fn, Error, 'Error must not have this message');
+ * assert.doesNotThrow(fn, errorInstance, 'Error must not have this message');
+ * assert.doesNotThrow(fn, Error, /Error must not match this/);
+ * assert.doesNotThrow(fn, errorInstance, /Error must not match this/);
+ *
+ * @name doesNotThrow
+ * @param {Function} fn
+ * @param {ErrorConstructor} errorLike
+ * @param {RegExp|String} errMsgMatcher
+ * @param {String} message
+ * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.doesNotThrow = function (fn, errorLike, errMsgMatcher, msg) {
+ if ('string' === typeof errorLike || errorLike instanceof RegExp) {
+ errMsgMatcher = errorLike;
+ errorLike = null;
+ }
+
+ new Assertion(fn, msg, assert.doesNotThrow, true)
+ .to.not.throw(errorLike, errMsgMatcher);
+ };
+
+ /**
+ * ### .operator(val1, operator, val2, [message])
+ *
+ * Compares two values using `operator`.
+ *
+ * assert.operator(1, '<', 2, 'everything is ok');
+ * assert.operator(1, '>', 2, 'this will fail');
+ *
+ * @name operator
+ * @param {Mixed} val1
+ * @param {String} operator
+ * @param {Mixed} val2
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.operator = function (val, operator, val2, msg) {
+ var ok;
+ switch(operator) {
+ case '==':
+ ok = val == val2;
+ break;
+ case '===':
+ ok = val === val2;
+ break;
+ case '>':
+ ok = val > val2;
+ break;
+ case '>=':
+ ok = val >= val2;
+ break;
+ case '<':
+ ok = val < val2;
+ break;
+ case '<=':
+ ok = val <= val2;
+ break;
+ case '!=':
+ ok = val != val2;
+ break;
+ case '!==':
+ ok = val !== val2;
+ break;
+ default:
+ msg = msg ? msg + ': ' : msg;
+ throw new chai.AssertionError(
+ msg + 'Invalid operator "' + operator + '"',
+ undefined,
+ assert.operator
+ );
+ }
+ var test = new Assertion(ok, msg, assert.operator, true);
+ test.assert(
+ true === flag(test, 'object')
+ , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
+ , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
+ };
+
+ /**
+ * ### .closeTo(actual, expected, delta, [message])
+ *
+ * Asserts that the target is equal `expected`, to within a +/- `delta` range.
+ *
+ * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
+ *
+ * @name closeTo
+ * @param {Number} actual
+ * @param {Number} expected
+ * @param {Number} delta
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.closeTo = function (act, exp, delta, msg) {
+ new Assertion(act, msg, assert.closeTo, true).to.be.closeTo(exp, delta);
+ };
+
+ /**
+ * ### .approximately(actual, expected, delta, [message])
+ *
+ * Asserts that the target is equal `expected`, to within a +/- `delta` range.
+ *
+ * assert.approximately(1.5, 1, 0.5, 'numbers are close');
+ *
+ * @name approximately
+ * @param {Number} actual
+ * @param {Number} expected
+ * @param {Number} delta
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.approximately = function (act, exp, delta, msg) {
+ new Assertion(act, msg, assert.approximately, true)
+ .to.be.approximately(exp, delta);
+ };
+
+ /**
+ * ### .sameMembers(set1, set2, [message])
+ *
+ * Asserts that `set1` and `set2` have the same members in any order. Uses a
+ * strict equality check (===).
+ *
+ * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
+ *
+ * @name sameMembers
+ * @param {Array} set1
+ * @param {Array} set2
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.sameMembers = function (set1, set2, msg) {
+ new Assertion(set1, msg, assert.sameMembers, true)
+ .to.have.same.members(set2);
+ }
+
+ /**
+ * ### .notSameMembers(set1, set2, [message])
+ *
+ * Asserts that `set1` and `set2` don't have the same members in any order.
+ * Uses a strict equality check (===).
+ *
+ * assert.notSameMembers([ 1, 2, 3 ], [ 5, 1, 3 ], 'not same members');
+ *
+ * @name notSameMembers
+ * @param {Array} set1
+ * @param {Array} set2
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notSameMembers = function (set1, set2, msg) {
+ new Assertion(set1, msg, assert.notSameMembers, true)
+ .to.not.have.same.members(set2);
+ }
+
+ /**
+ * ### .sameDeepMembers(set1, set2, [message])
+ *
+ * Asserts that `set1` and `set2` have the same members in any order. Uses a
+ * deep equality check.
+ *
+ * assert.sameDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [{ b: 2 }, { a: 1 }, { c: 3 }], 'same deep members');
+ *
+ * @name sameDeepMembers
+ * @param {Array} set1
+ * @param {Array} set2
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.sameDeepMembers = function (set1, set2, msg) {
+ new Assertion(set1, msg, assert.sameDeepMembers, true)
+ .to.have.same.deep.members(set2);
+ }
+
+ /**
+ * ### .notSameDeepMembers(set1, set2, [message])
+ *
+ * Asserts that `set1` and `set2` don't have the same members in any order.
+ * Uses a deep equality check.
+ *
+ * assert.notSameDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [{ b: 2 }, { a: 1 }, { f: 5 }], 'not same deep members');
+ *
+ * @name notSameDeepMembers
+ * @param {Array} set1
+ * @param {Array} set2
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notSameDeepMembers = function (set1, set2, msg) {
+ new Assertion(set1, msg, assert.notSameDeepMembers, true)
+ .to.not.have.same.deep.members(set2);
+ }
+
+ /**
+ * ### .sameOrderedMembers(set1, set2, [message])
+ *
+ * Asserts that `set1` and `set2` have the same members in the same order.
+ * Uses a strict equality check (===).
+ *
+ * assert.sameOrderedMembers([ 1, 2, 3 ], [ 1, 2, 3 ], 'same ordered members');
+ *
+ * @name sameOrderedMembers
+ * @param {Array} set1
+ * @param {Array} set2
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.sameOrderedMembers = function (set1, set2, msg) {
+ new Assertion(set1, msg, assert.sameOrderedMembers, true)
+ .to.have.same.ordered.members(set2);
+ }
+
+ /**
+ * ### .notSameOrderedMembers(set1, set2, [message])
+ *
+ * Asserts that `set1` and `set2` don't have the same members in the same
+ * order. Uses a strict equality check (===).
+ *
+ * assert.notSameOrderedMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'not same ordered members');
+ *
+ * @name notSameOrderedMembers
+ * @param {Array} set1
+ * @param {Array} set2
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notSameOrderedMembers = function (set1, set2, msg) {
+ new Assertion(set1, msg, assert.notSameOrderedMembers, true)
+ .to.not.have.same.ordered.members(set2);
+ }
+
+ /**
+ * ### .sameDeepOrderedMembers(set1, set2, [message])
+ *
+ * Asserts that `set1` and `set2` have the same members in the same order.
+ * Uses a deep equality check.
+ *
+ * assert.sameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 }, { c: 3 } ], 'same deep ordered members');
+ *
+ * @name sameDeepOrderedMembers
+ * @param {Array} set1
+ * @param {Array} set2
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.sameDeepOrderedMembers = function (set1, set2, msg) {
+ new Assertion(set1, msg, assert.sameDeepOrderedMembers, true)
+ .to.have.same.deep.ordered.members(set2);
+ }
+
+ /**
+ * ### .notSameDeepOrderedMembers(set1, set2, [message])
+ *
+ * Asserts that `set1` and `set2` don't have the same members in the same
+ * order. Uses a deep equality check.
+ *
+ * assert.notSameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 }, { z: 5 } ], 'not same deep ordered members');
+ * assert.notSameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 }, { c: 3 } ], 'not same deep ordered members');
+ *
+ * @name notSameDeepOrderedMembers
+ * @param {Array} set1
+ * @param {Array} set2
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notSameDeepOrderedMembers = function (set1, set2, msg) {
+ new Assertion(set1, msg, assert.notSameDeepOrderedMembers, true)
+ .to.not.have.same.deep.ordered.members(set2);
+ }
+
+ /**
+ * ### .includeMembers(superset, subset, [message])
+ *
+ * Asserts that `subset` is included in `superset` in any order. Uses a
+ * strict equality check (===). Duplicates are ignored.
+ *
+ * assert.includeMembers([ 1, 2, 3 ], [ 2, 1, 2 ], 'include members');
+ *
+ * @name includeMembers
+ * @param {Array} superset
+ * @param {Array} subset
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.includeMembers = function (superset, subset, msg) {
+ new Assertion(superset, msg, assert.includeMembers, true)
+ .to.include.members(subset);
+ }
+
+ /**
+ * ### .notIncludeMembers(superset, subset, [message])
+ *
+ * Asserts that `subset` isn't included in `superset` in any order. Uses a
+ * strict equality check (===). Duplicates are ignored.
+ *
+ * assert.notIncludeMembers([ 1, 2, 3 ], [ 5, 1 ], 'not include members');
+ *
+ * @name notIncludeMembers
+ * @param {Array} superset
+ * @param {Array} subset
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notIncludeMembers = function (superset, subset, msg) {
+ new Assertion(superset, msg, assert.notIncludeMembers, true)
+ .to.not.include.members(subset);
+ }
+
+ /**
+ * ### .includeDeepMembers(superset, subset, [message])
+ *
+ * Asserts that `subset` is included in `superset` in any order. Uses a deep
+ * equality check. Duplicates are ignored.
+ *
+ * assert.includeDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 }, { b: 2 } ], 'include deep members');
+ *
+ * @name includeDeepMembers
+ * @param {Array} superset
+ * @param {Array} subset
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.includeDeepMembers = function (superset, subset, msg) {
+ new Assertion(superset, msg, assert.includeDeepMembers, true)
+ .to.include.deep.members(subset);
+ }
+
+ /**
+ * ### .notIncludeDeepMembers(superset, subset, [message])
+ *
+ * Asserts that `subset` isn't included in `superset` in any order. Uses a
+ * deep equality check. Duplicates are ignored.
+ *
+ * assert.notIncludeDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { f: 5 } ], 'not include deep members');
+ *
+ * @name notIncludeDeepMembers
+ * @param {Array} superset
+ * @param {Array} subset
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notIncludeDeepMembers = function (superset, subset, msg) {
+ new Assertion(superset, msg, assert.notIncludeDeepMembers, true)
+ .to.not.include.deep.members(subset);
+ }
+
+ /**
+ * ### .includeOrderedMembers(superset, subset, [message])
+ *
+ * Asserts that `subset` is included in `superset` in the same order
+ * beginning with the first element in `superset`. Uses a strict equality
+ * check (===).
+ *
+ * assert.includeOrderedMembers([ 1, 2, 3 ], [ 1, 2 ], 'include ordered members');
+ *
+ * @name includeOrderedMembers
+ * @param {Array} superset
+ * @param {Array} subset
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.includeOrderedMembers = function (superset, subset, msg) {
+ new Assertion(superset, msg, assert.includeOrderedMembers, true)
+ .to.include.ordered.members(subset);
+ }
+
+ /**
+ * ### .notIncludeOrderedMembers(superset, subset, [message])
+ *
+ * Asserts that `subset` isn't included in `superset` in the same order
+ * beginning with the first element in `superset`. Uses a strict equality
+ * check (===).
+ *
+ * assert.notIncludeOrderedMembers([ 1, 2, 3 ], [ 2, 1 ], 'not include ordered members');
+ * assert.notIncludeOrderedMembers([ 1, 2, 3 ], [ 2, 3 ], 'not include ordered members');
+ *
+ * @name notIncludeOrderedMembers
+ * @param {Array} superset
+ * @param {Array} subset
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notIncludeOrderedMembers = function (superset, subset, msg) {
+ new Assertion(superset, msg, assert.notIncludeOrderedMembers, true)
+ .to.not.include.ordered.members(subset);
+ }
+
+ /**
+ * ### .includeDeepOrderedMembers(superset, subset, [message])
+ *
+ * Asserts that `subset` is included in `superset` in the same order
+ * beginning with the first element in `superset`. Uses a deep equality
+ * check.
+ *
+ * assert.includeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 } ], 'include deep ordered members');
+ *
+ * @name includeDeepOrderedMembers
+ * @param {Array} superset
+ * @param {Array} subset
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.includeDeepOrderedMembers = function (superset, subset, msg) {
+ new Assertion(superset, msg, assert.includeDeepOrderedMembers, true)
+ .to.include.deep.ordered.members(subset);
+ }
+
+ /**
+ * ### .notIncludeDeepOrderedMembers(superset, subset, [message])
+ *
+ * Asserts that `subset` isn't included in `superset` in the same order
+ * beginning with the first element in `superset`. Uses a deep equality
+ * check.
+ *
+ * assert.notIncludeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { f: 5 } ], 'not include deep ordered members');
+ * assert.notIncludeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 } ], 'not include deep ordered members');
+ * assert.notIncludeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { c: 3 } ], 'not include deep ordered members');
+ *
+ * @name notIncludeDeepOrderedMembers
+ * @param {Array} superset
+ * @param {Array} subset
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.notIncludeDeepOrderedMembers = function (superset, subset, msg) {
+ new Assertion(superset, msg, assert.notIncludeDeepOrderedMembers, true)
+ .to.not.include.deep.ordered.members(subset);
+ }
+
+ /**
+ * ### .oneOf(inList, list, [message])
+ *
+ * Asserts that non-object, non-array value `inList` appears in the flat array `list`.
+ *
+ * assert.oneOf(1, [ 2, 1 ], 'Not found in list');
+ *
+ * @name oneOf
+ * @param {*} inList
+ * @param {Array<*>} list
+ * @param {String} message
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.oneOf = function (inList, list, msg) {
+ new Assertion(inList, msg, assert.oneOf, true).to.be.oneOf(list);
+ }
+
+ /**
+ * ### .changes(function, object, property, [message])
+ *
+ * Asserts that a function changes the value of a property.
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val = 22 };
+ * assert.changes(fn, obj, 'val');
+ *
+ * @name changes
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.changes = function (fn, obj, prop, msg) {
+ if (arguments.length === 3 && typeof obj === 'function') {
+ msg = prop;
+ prop = null;
+ }
+
+ new Assertion(fn, msg, assert.changes, true).to.change(obj, prop);
+ }
+
+ /**
+ * ### .changesBy(function, object, property, delta, [message])
+ *
+ * Asserts that a function changes the value of a property by an amount (delta).
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val += 2 };
+ * assert.changesBy(fn, obj, 'val', 2);
+ *
+ * @name changesBy
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {Number} change amount (delta)
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.changesBy = function (fn, obj, prop, delta, msg) {
+ if (arguments.length === 4 && typeof obj === 'function') {
+ var tmpMsg = delta;
+ delta = prop;
+ msg = tmpMsg;
+ } else if (arguments.length === 3) {
+ delta = prop;
+ prop = null;
+ }
+
+ new Assertion(fn, msg, assert.changesBy, true)
+ .to.change(obj, prop).by(delta);
+ }
+
+ /**
+ * ### .doesNotChange(function, object, property, [message])
+ *
+ * Asserts that a function does not change the value of a property.
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { console.log('foo'); };
+ * assert.doesNotChange(fn, obj, 'val');
+ *
+ * @name doesNotChange
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.doesNotChange = function (fn, obj, prop, msg) {
+ if (arguments.length === 3 && typeof obj === 'function') {
+ msg = prop;
+ prop = null;
+ }
+
+ return new Assertion(fn, msg, assert.doesNotChange, true)
+ .to.not.change(obj, prop);
+ }
+
+ /**
+ * ### .changesButNotBy(function, object, property, delta, [message])
+ *
+ * Asserts that a function does not change the value of a property or of a function's return value by an amount (delta)
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val += 10 };
+ * assert.changesButNotBy(fn, obj, 'val', 5);
+ *
+ * @name changesButNotBy
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {Number} change amount (delta)
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.changesButNotBy = function (fn, obj, prop, delta, msg) {
+ if (arguments.length === 4 && typeof obj === 'function') {
+ var tmpMsg = delta;
+ delta = prop;
+ msg = tmpMsg;
+ } else if (arguments.length === 3) {
+ delta = prop;
+ prop = null;
+ }
+
+ new Assertion(fn, msg, assert.changesButNotBy, true)
+ .to.change(obj, prop).but.not.by(delta);
+ }
+
+ /**
+ * ### .increases(function, object, property, [message])
+ *
+ * Asserts that a function increases a numeric object property.
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val = 13 };
+ * assert.increases(fn, obj, 'val');
+ *
+ * @name increases
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.increases = function (fn, obj, prop, msg) {
+ if (arguments.length === 3 && typeof obj === 'function') {
+ msg = prop;
+ prop = null;
+ }
+
+ return new Assertion(fn, msg, assert.increases, true)
+ .to.increase(obj, prop);
+ }
+
+ /**
+ * ### .increasesBy(function, object, property, delta, [message])
+ *
+ * Asserts that a function increases a numeric object property or a function's return value by an amount (delta).
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val += 10 };
+ * assert.increasesBy(fn, obj, 'val', 10);
+ *
+ * @name increasesBy
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {Number} change amount (delta)
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.increasesBy = function (fn, obj, prop, delta, msg) {
+ if (arguments.length === 4 && typeof obj === 'function') {
+ var tmpMsg = delta;
+ delta = prop;
+ msg = tmpMsg;
+ } else if (arguments.length === 3) {
+ delta = prop;
+ prop = null;
+ }
+
+ new Assertion(fn, msg, assert.increasesBy, true)
+ .to.increase(obj, prop).by(delta);
+ }
+
+ /**
+ * ### .doesNotIncrease(function, object, property, [message])
+ *
+ * Asserts that a function does not increase a numeric object property.
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val = 8 };
+ * assert.doesNotIncrease(fn, obj, 'val');
+ *
+ * @name doesNotIncrease
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.doesNotIncrease = function (fn, obj, prop, msg) {
+ if (arguments.length === 3 && typeof obj === 'function') {
+ msg = prop;
+ prop = null;
+ }
+
+ return new Assertion(fn, msg, assert.doesNotIncrease, true)
+ .to.not.increase(obj, prop);
+ }
+
+ /**
+ * ### .increasesButNotBy(function, object, property, [message])
+ *
+ * Asserts that a function does not increase a numeric object property or function's return value by an amount (delta).
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val = 15 };
+ * assert.increasesButNotBy(fn, obj, 'val', 10);
+ *
+ * @name increasesButNotBy
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {Number} change amount (delta)
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.increasesButNotBy = function (fn, obj, prop, delta, msg) {
+ if (arguments.length === 4 && typeof obj === 'function') {
+ var tmpMsg = delta;
+ delta = prop;
+ msg = tmpMsg;
+ } else if (arguments.length === 3) {
+ delta = prop;
+ prop = null;
+ }
+
+ new Assertion(fn, msg, assert.increasesButNotBy, true)
+ .to.increase(obj, prop).but.not.by(delta);
+ }
+
+ /**
+ * ### .decreases(function, object, property, [message])
+ *
+ * Asserts that a function decreases a numeric object property.
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val = 5 };
+ * assert.decreases(fn, obj, 'val');
+ *
+ * @name decreases
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.decreases = function (fn, obj, prop, msg) {
+ if (arguments.length === 3 && typeof obj === 'function') {
+ msg = prop;
+ prop = null;
+ }
+
+ return new Assertion(fn, msg, assert.decreases, true)
+ .to.decrease(obj, prop);
+ }
+
+ /**
+ * ### .decreasesBy(function, object, property, delta, [message])
+ *
+ * Asserts that a function decreases a numeric object property or a function's return value by an amount (delta)
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val -= 5 };
+ * assert.decreasesBy(fn, obj, 'val', 5);
+ *
+ * @name decreasesBy
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {Number} change amount (delta)
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.decreasesBy = function (fn, obj, prop, delta, msg) {
+ if (arguments.length === 4 && typeof obj === 'function') {
+ var tmpMsg = delta;
+ delta = prop;
+ msg = tmpMsg;
+ } else if (arguments.length === 3) {
+ delta = prop;
+ prop = null;
+ }
+
+ new Assertion(fn, msg, assert.decreasesBy, true)
+ .to.decrease(obj, prop).by(delta);
+ }
+
+ /**
+ * ### .doesNotDecrease(function, object, property, [message])
+ *
+ * Asserts that a function does not decreases a numeric object property.
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val = 15 };
+ * assert.doesNotDecrease(fn, obj, 'val');
+ *
+ * @name doesNotDecrease
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.doesNotDecrease = function (fn, obj, prop, msg) {
+ if (arguments.length === 3 && typeof obj === 'function') {
+ msg = prop;
+ prop = null;
+ }
+
+ return new Assertion(fn, msg, assert.doesNotDecrease, true)
+ .to.not.decrease(obj, prop);
+ }
+
+ /**
+ * ### .doesNotDecreaseBy(function, object, property, delta, [message])
+ *
+ * Asserts that a function does not decreases a numeric object property or a function's return value by an amount (delta)
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val = 5 };
+ * assert.doesNotDecreaseBy(fn, obj, 'val', 1);
+ *
+ * @name doesNotDecrease
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {Number} change amount (delta)
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.doesNotDecreaseBy = function (fn, obj, prop, delta, msg) {
+ if (arguments.length === 4 && typeof obj === 'function') {
+ var tmpMsg = delta;
+ delta = prop;
+ msg = tmpMsg;
+ } else if (arguments.length === 3) {
+ delta = prop;
+ prop = null;
+ }
+
+ return new Assertion(fn, msg, assert.doesNotDecreaseBy, true)
+ .to.not.decrease(obj, prop).by(delta);
+ }
+
+ /**
+ * ### .decreasesButNotBy(function, object, property, delta, [message])
+ *
+ * Asserts that a function does not decreases a numeric object property or a function's return value by an amount (delta)
+ *
+ * var obj = { val: 10 };
+ * var fn = function() { obj.val = 5 };
+ * assert.decreasesButNotBy(fn, obj, 'val', 1);
+ *
+ * @name decreasesButNotBy
+ * @param {Function} modifier function
+ * @param {Object} object or getter function
+ * @param {String} property name _optional_
+ * @param {Number} change amount (delta)
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) {
+ if (arguments.length === 4 && typeof obj === 'function') {
+ var tmpMsg = delta;
+ delta = prop;
+ msg = tmpMsg;
+ } else if (arguments.length === 3) {
+ delta = prop;
+ prop = null;
+ }
+
+ new Assertion(fn, msg, assert.decreasesButNotBy, true)
+ .to.decrease(obj, prop).but.not.by(delta);
+ }
+
+ /*!
+ * ### .ifError(object)
+ *
+ * Asserts if value is not a false value, and throws if it is a true value.
+ * This is added to allow for chai to be a drop-in replacement for Node's
+ * assert class.
+ *
+ * var err = new Error('I am a custom error');
+ * assert.ifError(err); // Rethrows err!
+ *
+ * @name ifError
+ * @param {Object} object
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.ifError = function (val) {
+ if (val) {
+ throw(val);
+ }
+ };
+
+ /**
+ * ### .isExtensible(object)
+ *
+ * Asserts that `object` is extensible (can have new properties added to it).
+ *
+ * assert.isExtensible({});
+ *
+ * @name isExtensible
+ * @alias extensible
+ * @param {Object} object
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isExtensible = function (obj, msg) {
+ new Assertion(obj, msg, assert.isExtensible, true).to.be.extensible;
+ };
+
+ /**
+ * ### .isNotExtensible(object)
+ *
+ * Asserts that `object` is _not_ extensible.
+ *
+ * var nonExtensibleObject = Object.preventExtensions({});
+ * var sealedObject = Object.seal({});
+ * var frozenObject = Object.freeze({});
+ *
+ * assert.isNotExtensible(nonExtensibleObject);
+ * assert.isNotExtensible(sealedObject);
+ * assert.isNotExtensible(frozenObject);
+ *
+ * @name isNotExtensible
+ * @alias notExtensible
+ * @param {Object} object
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotExtensible = function (obj, msg) {
+ new Assertion(obj, msg, assert.isNotExtensible, true).to.not.be.extensible;
+ };
+
+ /**
+ * ### .isSealed(object)
+ *
+ * Asserts that `object` is sealed (cannot have new properties added to it
+ * and its existing properties cannot be removed).
+ *
+ * var sealedObject = Object.seal({});
+ * var frozenObject = Object.seal({});
+ *
+ * assert.isSealed(sealedObject);
+ * assert.isSealed(frozenObject);
+ *
+ * @name isSealed
+ * @alias sealed
+ * @param {Object} object
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isSealed = function (obj, msg) {
+ new Assertion(obj, msg, assert.isSealed, true).to.be.sealed;
+ };
+
+ /**
+ * ### .isNotSealed(object)
+ *
+ * Asserts that `object` is _not_ sealed.
+ *
+ * assert.isNotSealed({});
+ *
+ * @name isNotSealed
+ * @alias notSealed
+ * @param {Object} object
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotSealed = function (obj, msg) {
+ new Assertion(obj, msg, assert.isNotSealed, true).to.not.be.sealed;
+ };
+
+ /**
+ * ### .isFrozen(object)
+ *
+ * Asserts that `object` is frozen (cannot have new properties added to it
+ * and its existing properties cannot be modified).
+ *
+ * var frozenObject = Object.freeze({});
+ * assert.frozen(frozenObject);
+ *
+ * @name isFrozen
+ * @alias frozen
+ * @param {Object} object
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isFrozen = function (obj, msg) {
+ new Assertion(obj, msg, assert.isFrozen, true).to.be.frozen;
+ };
+
+ /**
+ * ### .isNotFrozen(object)
+ *
+ * Asserts that `object` is _not_ frozen.
+ *
+ * assert.isNotFrozen({});
+ *
+ * @name isNotFrozen
+ * @alias notFrozen
+ * @param {Object} object
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotFrozen = function (obj, msg) {
+ new Assertion(obj, msg, assert.isNotFrozen, true).to.not.be.frozen;
+ };
+
+ /**
+ * ### .isEmpty(target)
+ *
+ * Asserts that the target does not contain any values.
+ * For arrays and strings, it checks the `length` property.
+ * For `Map` and `Set` instances, it checks the `size` property.
+ * For non-function objects, it gets the count of own
+ * enumerable string keys.
+ *
+ * assert.isEmpty([]);
+ * assert.isEmpty('');
+ * assert.isEmpty(new Map);
+ * assert.isEmpty({});
+ *
+ * @name isEmpty
+ * @alias empty
+ * @param {Object|Array|String|Map|Set} target
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isEmpty = function(val, msg) {
+ new Assertion(val, msg, assert.isEmpty, true).to.be.empty;
+ };
+
+ /**
+ * ### .isNotEmpty(target)
+ *
+ * Asserts that the target contains values.
+ * For arrays and strings, it checks the `length` property.
+ * For `Map` and `Set` instances, it checks the `size` property.
+ * For non-function objects, it gets the count of own
+ * enumerable string keys.
+ *
+ * assert.isNotEmpty([1, 2]);
+ * assert.isNotEmpty('34');
+ * assert.isNotEmpty(new Set([5, 6]));
+ * assert.isNotEmpty({ key: 7 });
+ *
+ * @name isNotEmpty
+ * @alias notEmpty
+ * @param {Object|Array|String|Map|Set} target
+ * @param {String} message _optional_
+ * @namespace Assert
+ * @api public
+ */
+
+ assert.isNotEmpty = function(val, msg) {
+ new Assertion(val, msg, assert.isNotEmpty, true).to.not.be.empty;
+ };
+
+ /*!
+ * Aliases.
+ */
+
+ (function alias(name, as){
+ assert[as] = assert[name];
+ return alias;
+ })
+ ('isOk', 'ok')
+ ('isNotOk', 'notOk')
+ ('throws', 'throw')
+ ('throws', 'Throw')
+ ('isExtensible', 'extensible')
+ ('isNotExtensible', 'notExtensible')
+ ('isSealed', 'sealed')
+ ('isNotSealed', 'notSealed')
+ ('isFrozen', 'frozen')
+ ('isNotFrozen', 'notFrozen')
+ ('isEmpty', 'empty')
+ ('isNotEmpty', 'notEmpty');
+};
+
+},{}],7:[function(require,module,exports){
+/*!
+ * chai
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+module.exports = function (chai, util) {
+ chai.expect = function (val, message) {
+ return new chai.Assertion(val, message);
+ };
+
+ /**
+ * ### .fail(actual, expected, [message], [operator])
+ *
+ * Throw a failure.
+ *
+ * @name fail
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @param {String} operator
+ * @namespace BDD
+ * @api public
+ */
+
+ chai.expect.fail = function (actual, expected, message, operator) {
+ message = message || 'expect.fail()';
+ throw new chai.AssertionError(message, {
+ actual: actual
+ , expected: expected
+ , operator: operator
+ }, chai.expect.fail);
+ };
+};
+
+},{}],8:[function(require,module,exports){
+/*!
+ * chai
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+module.exports = function (chai, util) {
+ var Assertion = chai.Assertion;
+
+ function loadShould () {
+ // explicitly define this method as function as to have it's name to include as `ssfi`
+ function shouldGetter() {
+ if (this instanceof String
+ || this instanceof Number
+ || this instanceof Boolean
+ || typeof Symbol === 'function' && this instanceof Symbol) {
+ return new Assertion(this.valueOf(), null, shouldGetter);
+ }
+ return new Assertion(this, null, shouldGetter);
+ }
+ function shouldSetter(value) {
+ // See https://github.com/chaijs/chai/issues/86: this makes
+ // `whatever.should = someValue` actually set `someValue`, which is
+ // especially useful for `global.should = require('chai').should()`.
+ //
+ // Note that we have to use [[DefineProperty]] instead of [[Put]]
+ // since otherwise we would trigger this very setter!
+ Object.defineProperty(this, 'should', {
+ value: value,
+ enumerable: true,
+ configurable: true,
+ writable: true
+ });
+ }
+ // modify Object.prototype to have `should`
+ Object.defineProperty(Object.prototype, 'should', {
+ set: shouldSetter
+ , get: shouldGetter
+ , configurable: true
+ });
+
+ var should = {};
+
+ /**
+ * ### .fail(actual, expected, [message], [operator])
+ *
+ * Throw a failure.
+ *
+ * @name fail
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @param {String} operator
+ * @namespace BDD
+ * @api public
+ */
+
+ should.fail = function (actual, expected, message, operator) {
+ message = message || 'should.fail()';
+ throw new chai.AssertionError(message, {
+ actual: actual
+ , expected: expected
+ , operator: operator
+ }, should.fail);
+ };
+
+ /**
+ * ### .equal(actual, expected, [message])
+ *
+ * Asserts non-strict equality (`==`) of `actual` and `expected`.
+ *
+ * should.equal(3, '3', '== coerces values to strings');
+ *
+ * @name equal
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @namespace Should
+ * @api public
+ */
+
+ should.equal = function (val1, val2, msg) {
+ new Assertion(val1, msg).to.equal(val2);
+ };
+
+ /**
+ * ### .throw(function, [constructor/string/regexp], [string/regexp], [message])
+ *
+ * Asserts that `function` will throw an error that is an instance of
+ * `constructor`, or alternately that it will throw an error with message
+ * matching `regexp`.
+ *
+ * should.throw(fn, 'function throws a reference error');
+ * should.throw(fn, /function throws a reference error/);
+ * should.throw(fn, ReferenceError);
+ * should.throw(fn, ReferenceError, 'function throws a reference error');
+ * should.throw(fn, ReferenceError, /function throws a reference error/);
+ *
+ * @name throw
+ * @alias Throw
+ * @param {Function} function
+ * @param {ErrorConstructor} constructor
+ * @param {RegExp} regexp
+ * @param {String} message
+ * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
+ * @namespace Should
+ * @api public
+ */
+
+ should.Throw = function (fn, errt, errs, msg) {
+ new Assertion(fn, msg).to.Throw(errt, errs);
+ };
+
+ /**
+ * ### .exist
+ *
+ * Asserts that the target is neither `null` nor `undefined`.
+ *
+ * var foo = 'hi';
+ *
+ * should.exist(foo, 'foo exists');
+ *
+ * @name exist
+ * @namespace Should
+ * @api public
+ */
+
+ should.exist = function (val, msg) {
+ new Assertion(val, msg).to.exist;
+ }
+
+ // negation
+ should.not = {}
+
+ /**
+ * ### .not.equal(actual, expected, [message])
+ *
+ * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
+ *
+ * should.not.equal(3, 4, 'these numbers are not equal');
+ *
+ * @name not.equal
+ * @param {Mixed} actual
+ * @param {Mixed} expected
+ * @param {String} message
+ * @namespace Should
+ * @api public
+ */
+
+ should.not.equal = function (val1, val2, msg) {
+ new Assertion(val1, msg).to.not.equal(val2);
+ };
+
+ /**
+ * ### .throw(function, [constructor/regexp], [message])
+ *
+ * Asserts that `function` will _not_ throw an error that is an instance of
+ * `constructor`, or alternately that it will not throw an error with message
+ * matching `regexp`.
+ *
+ * should.not.throw(fn, Error, 'function does not throw');
+ *
+ * @name not.throw
+ * @alias not.Throw
+ * @param {Function} function
+ * @param {ErrorConstructor} constructor
+ * @param {RegExp} regexp
+ * @param {String} message
+ * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
+ * @namespace Should
+ * @api public
+ */
+
+ should.not.Throw = function (fn, errt, errs, msg) {
+ new Assertion(fn, msg).to.not.Throw(errt, errs);
+ };
+
+ /**
+ * ### .not.exist
+ *
+ * Asserts that the target is neither `null` nor `undefined`.
+ *
+ * var bar = null;
+ *
+ * should.not.exist(bar, 'bar does not exist');
+ *
+ * @name not.exist
+ * @namespace Should
+ * @api public
+ */
+
+ should.not.exist = function (val, msg) {
+ new Assertion(val, msg).to.not.exist;
+ }
+
+ should['throw'] = should['Throw'];
+ should.not['throw'] = should.not['Throw'];
+
+ return should;
+ };
+
+ chai.should = loadShould;
+ chai.Should = loadShould;
+};
+
+},{}],9:[function(require,module,exports){
+/*!
+ * Chai - addChainingMethod utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/*!
+ * Module dependencies
+ */
+
+var addLengthGuard = require('./addLengthGuard');
+var chai = require('../../chai');
+var flag = require('./flag');
+var proxify = require('./proxify');
+var transferFlags = require('./transferFlags');
+
+/*!
+ * Module variables
+ */
+
+// Check whether `Object.setPrototypeOf` is supported
+var canSetPrototype = typeof Object.setPrototypeOf === 'function';
+
+// Without `Object.setPrototypeOf` support, this module will need to add properties to a function.
+// However, some of functions' own props are not configurable and should be skipped.
+var testFn = function() {};
+var excludeNames = Object.getOwnPropertyNames(testFn).filter(function(name) {
+ var propDesc = Object.getOwnPropertyDescriptor(testFn, name);
+
+ // Note: PhantomJS 1.x includes `callee` as one of `testFn`'s own properties,
+ // but then returns `undefined` as the property descriptor for `callee`. As a
+ // workaround, we perform an otherwise unnecessary type-check for `propDesc`,
+ // and then filter it out if it's not an object as it should be.
+ if (typeof propDesc !== 'object')
+ return true;
+
+ return !propDesc.configurable;
+});
+
+// Cache `Function` properties
+var call = Function.prototype.call,
+ apply = Function.prototype.apply;
+
+/**
+ * ### .addChainableMethod(ctx, name, method, chainingBehavior)
+ *
+ * Adds a method to an object, such that the method can also be chained.
+ *
+ * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
+ * var obj = utils.flag(this, 'object');
+ * new chai.Assertion(obj).to.be.equal(str);
+ * });
+ *
+ * Can also be accessed directly from `chai.Assertion`.
+ *
+ * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
+ *
+ * The result can then be used as both a method assertion, executing both `method` and
+ * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
+ *
+ * expect(fooStr).to.be.foo('bar');
+ * expect(fooStr).to.be.foo.equal('foo');
+ *
+ * @param {Object} ctx object to which the method is added
+ * @param {String} name of method to add
+ * @param {Function} method function to be used for `name`, when called
+ * @param {Function} chainingBehavior function to be called every time the property is accessed
+ * @namespace Utils
+ * @name addChainableMethod
+ * @api public
+ */
+
+module.exports = function addChainableMethod(ctx, name, method, chainingBehavior) {
+ if (typeof chainingBehavior !== 'function') {
+ chainingBehavior = function () { };
+ }
+
+ var chainableBehavior = {
+ method: method
+ , chainingBehavior: chainingBehavior
+ };
+
+ // save the methods so we can overwrite them later, if we need to.
+ if (!ctx.__methods) {
+ ctx.__methods = {};
+ }
+ ctx.__methods[name] = chainableBehavior;
+
+ Object.defineProperty(ctx, name,
+ { get: function chainableMethodGetter() {
+ chainableBehavior.chainingBehavior.call(this);
+
+ var chainableMethodWrapper = function () {
+ // Setting the `ssfi` flag to `chainableMethodWrapper` causes this
+ // function to be the starting point for removing implementation
+ // frames from the stack trace of a failed assertion.
+ //
+ // However, we only want to use this function as the starting point if
+ // the `lockSsfi` flag isn't set.
+ //
+ // If the `lockSsfi` flag is set, then this assertion is being
+ // invoked from inside of another assertion. In this case, the `ssfi`
+ // flag has already been set by the outer assertion.
+ //
+ // Note that overwriting a chainable method merely replaces the saved
+ // methods in `ctx.__methods` instead of completely replacing the
+ // overwritten assertion. Therefore, an overwriting assertion won't
+ // set the `ssfi` or `lockSsfi` flags.
+ if (!flag(this, 'lockSsfi')) {
+ flag(this, 'ssfi', chainableMethodWrapper);
+ }
+
+ var result = chainableBehavior.method.apply(this, arguments);
+ if (result !== undefined) {
+ return result;
+ }
+
+ var newAssertion = new chai.Assertion();
+ transferFlags(this, newAssertion);
+ return newAssertion;
+ };
+
+ addLengthGuard(chainableMethodWrapper, name, true);
+
+ // Use `Object.setPrototypeOf` if available
+ if (canSetPrototype) {
+ // Inherit all properties from the object by replacing the `Function` prototype
+ var prototype = Object.create(this);
+ // Restore the `call` and `apply` methods from `Function`
+ prototype.call = call;
+ prototype.apply = apply;
+ Object.setPrototypeOf(chainableMethodWrapper, prototype);
+ }
+ // Otherwise, redefine all properties (slow!)
+ else {
+ var asserterNames = Object.getOwnPropertyNames(ctx);
+ asserterNames.forEach(function (asserterName) {
+ if (excludeNames.indexOf(asserterName) !== -1) {
+ return;
+ }
+
+ var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
+ Object.defineProperty(chainableMethodWrapper, asserterName, pd);
+ });
+ }
+
+ transferFlags(this, chainableMethodWrapper);
+ return proxify(chainableMethodWrapper);
+ }
+ , configurable: true
+ });
+};
+
+},{"../../chai":2,"./addLengthGuard":10,"./flag":15,"./proxify":30,"./transferFlags":32}],10:[function(require,module,exports){
+var config = require('../config');
+
+var fnLengthDesc = Object.getOwnPropertyDescriptor(function () {}, 'length');
+
+/*!
+ * Chai - addLengthGuard utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .addLengthGuard(fn, assertionName, isChainable)
+ *
+ * Define `length` as a getter on the given uninvoked method assertion. The
+ * getter acts as a guard against chaining `length` directly off of an uninvoked
+ * method assertion, which is a problem because it references `function`'s
+ * built-in `length` property instead of Chai's `length` assertion. When the
+ * getter catches the user making this mistake, it throws an error with a
+ * helpful message.
+ *
+ * There are two ways in which this mistake can be made. The first way is by
+ * chaining the `length` assertion directly off of an uninvoked chainable
+ * method. In this case, Chai suggests that the user use `lengthOf` instead. The
+ * second way is by chaining the `length` assertion directly off of an uninvoked
+ * non-chainable method. Non-chainable methods must be invoked prior to
+ * chaining. In this case, Chai suggests that the user consult the docs for the
+ * given assertion.
+ *
+ * If the `length` property of functions is unconfigurable, then return `fn`
+ * without modification.
+ *
+ * Note that in ES6, the function's `length` property is configurable, so once
+ * support for legacy environments is dropped, Chai's `length` property can
+ * replace the built-in function's `length` property, and this length guard will
+ * no longer be necessary. In the mean time, maintaining consistency across all
+ * environments is the priority.
+ *
+ * @param {Function} fn
+ * @param {String} assertionName
+ * @param {Boolean} isChainable
+ * @namespace Utils
+ * @name addLengthGuard
+ */
+
+module.exports = function addLengthGuard (fn, assertionName, isChainable) {
+ if (!fnLengthDesc.configurable) return fn;
+
+ Object.defineProperty(fn, 'length', {
+ get: function () {
+ if (isChainable) {
+ throw Error('Invalid Chai property: ' + assertionName + '.length. Due' +
+ ' to a compatibility issue, "length" cannot directly follow "' +
+ assertionName + '". Use "' + assertionName + '.lengthOf" instead.');
+ }
+
+ throw Error('Invalid Chai property: ' + assertionName + '.length. See' +
+ ' docs for proper usage of "' + assertionName + '".');
+ }
+ });
+
+ return fn;
+};
+
+},{"../config":4}],11:[function(require,module,exports){
+/*!
+ * Chai - addMethod utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+var addLengthGuard = require('./addLengthGuard');
+var chai = require('../../chai');
+var flag = require('./flag');
+var proxify = require('./proxify');
+var transferFlags = require('./transferFlags');
+
+/**
+ * ### .addMethod(ctx, name, method)
+ *
+ * Adds a method to the prototype of an object.
+ *
+ * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
+ * var obj = utils.flag(this, 'object');
+ * new chai.Assertion(obj).to.be.equal(str);
+ * });
+ *
+ * Can also be accessed directly from `chai.Assertion`.
+ *
+ * chai.Assertion.addMethod('foo', fn);
+ *
+ * Then can be used as any other assertion.
+ *
+ * expect(fooStr).to.be.foo('bar');
+ *
+ * @param {Object} ctx object to which the method is added
+ * @param {String} name of method to add
+ * @param {Function} method function to be used for name
+ * @namespace Utils
+ * @name addMethod
+ * @api public
+ */
+
+module.exports = function addMethod(ctx, name, method) {
+ var methodWrapper = function () {
+ // Setting the `ssfi` flag to `methodWrapper` causes this function to be the
+ // starting point for removing implementation frames from the stack trace of
+ // a failed assertion.
+ //
+ // However, we only want to use this function as the starting point if the
+ // `lockSsfi` flag isn't set.
+ //
+ // If the `lockSsfi` flag is set, then either this assertion has been
+ // overwritten by another assertion, or this assertion is being invoked from
+ // inside of another assertion. In the first case, the `ssfi` flag has
+ // already been set by the overwriting assertion. In the second case, the
+ // `ssfi` flag has already been set by the outer assertion.
+ if (!flag(this, 'lockSsfi')) {
+ flag(this, 'ssfi', methodWrapper);
+ }
+
+ var result = method.apply(this, arguments);
+ if (result !== undefined)
+ return result;
+
+ var newAssertion = new chai.Assertion();
+ transferFlags(this, newAssertion);
+ return newAssertion;
+ };
+
+ addLengthGuard(methodWrapper, name, false);
+ ctx[name] = proxify(methodWrapper, name);
+};
+
+},{"../../chai":2,"./addLengthGuard":10,"./flag":15,"./proxify":30,"./transferFlags":32}],12:[function(require,module,exports){
+/*!
+ * Chai - addProperty utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+var chai = require('../../chai');
+var flag = require('./flag');
+var isProxyEnabled = require('./isProxyEnabled');
+var transferFlags = require('./transferFlags');
+
+/**
+ * ### .addProperty(ctx, name, getter)
+ *
+ * Adds a property to the prototype of an object.
+ *
+ * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
+ * var obj = utils.flag(this, 'object');
+ * new chai.Assertion(obj).to.be.instanceof(Foo);
+ * });
+ *
+ * Can also be accessed directly from `chai.Assertion`.
+ *
+ * chai.Assertion.addProperty('foo', fn);
+ *
+ * Then can be used as any other assertion.
+ *
+ * expect(myFoo).to.be.foo;
+ *
+ * @param {Object} ctx object to which the property is added
+ * @param {String} name of property to add
+ * @param {Function} getter function to be used for name
+ * @namespace Utils
+ * @name addProperty
+ * @api public
+ */
+
+module.exports = function addProperty(ctx, name, getter) {
+ getter = getter === undefined ? function () {} : getter;
+
+ Object.defineProperty(ctx, name,
+ { get: function propertyGetter() {
+ // Setting the `ssfi` flag to `propertyGetter` causes this function to
+ // be the starting point for removing implementation frames from the
+ // stack trace of a failed assertion.
+ //
+ // However, we only want to use this function as the starting point if
+ // the `lockSsfi` flag isn't set and proxy protection is disabled.
+ //
+ // If the `lockSsfi` flag is set, then either this assertion has been
+ // overwritten by another assertion, or this assertion is being invoked
+ // from inside of another assertion. In the first case, the `ssfi` flag
+ // has already been set by the overwriting assertion. In the second
+ // case, the `ssfi` flag has already been set by the outer assertion.
+ //
+ // If proxy protection is enabled, then the `ssfi` flag has already been
+ // set by the proxy getter.
+ if (!isProxyEnabled() && !flag(this, 'lockSsfi')) {
+ flag(this, 'ssfi', propertyGetter);
+ }
+
+ var result = getter.call(this);
+ if (result !== undefined)
+ return result;
+
+ var newAssertion = new chai.Assertion();
+ transferFlags(this, newAssertion);
+ return newAssertion;
+ }
+ , configurable: true
+ });
+};
+
+},{"../../chai":2,"./flag":15,"./isProxyEnabled":25,"./transferFlags":32}],13:[function(require,module,exports){
+/*!
+ * Chai - compareByInspect utility
+ * Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/*!
+ * Module dependancies
+ */
+
+var inspect = require('./inspect');
+
+/**
+ * ### .compareByInspect(mixed, mixed)
+ *
+ * To be used as a compareFunction with Array.prototype.sort. Compares elements
+ * using inspect instead of default behavior of using toString so that Symbols
+ * and objects with irregular/missing toString can still be sorted without a
+ * TypeError.
+ *
+ * @param {Mixed} first element to compare
+ * @param {Mixed} second element to compare
+ * @returns {Number} -1 if 'a' should come before 'b'; otherwise 1
+ * @name compareByInspect
+ * @namespace Utils
+ * @api public
+ */
+
+module.exports = function compareByInspect(a, b) {
+ return inspect(a) < inspect(b) ? -1 : 1;
+};
+
+},{"./inspect":23}],14:[function(require,module,exports){
+/*!
+ * Chai - expectTypes utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .expectTypes(obj, types)
+ *
+ * Ensures that the object being tested against is of a valid type.
+ *
+ * utils.expectTypes(this, ['array', 'object', 'string']);
+ *
+ * @param {Mixed} obj constructed Assertion
+ * @param {Array} type A list of allowed types for this assertion
+ * @namespace Utils
+ * @name expectTypes
+ * @api public
+ */
+
+var AssertionError = require('assertion-error');
+var flag = require('./flag');
+var type = require('type-detect');
+
+module.exports = function expectTypes(obj, types) {
+ var flagMsg = flag(obj, 'message');
+ var ssfi = flag(obj, 'ssfi');
+
+ flagMsg = flagMsg ? flagMsg + ': ' : '';
+
+ obj = flag(obj, 'object');
+ types = types.map(function (t) { return t.toLowerCase(); });
+ types.sort();
+
+ // Transforms ['lorem', 'ipsum'] into 'a lorem, or an ipsum'
+ var str = types.map(function (t, index) {
+ var art = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(t.charAt(0)) ? 'an' : 'a';
+ var or = types.length > 1 && index === types.length - 1 ? 'or ' : '';
+ return or + art + ' ' + t;
+ }).join(', ');
+
+ var objType = type(obj).toLowerCase();
+
+ if (!types.some(function (expected) { return objType === expected; })) {
+ throw new AssertionError(
+ flagMsg + 'object tested must be ' + str + ', but ' + objType + ' given',
+ undefined,
+ ssfi
+ );
+ }
+};
+
+},{"./flag":15,"assertion-error":33,"type-detect":38}],15:[function(require,module,exports){
+/*!
+ * Chai - flag utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .flag(object, key, [value])
+ *
+ * Get or set a flag value on an object. If a
+ * value is provided it will be set, else it will
+ * return the currently set value or `undefined` if
+ * the value is not set.
+ *
+ * utils.flag(this, 'foo', 'bar'); // setter
+ * utils.flag(this, 'foo'); // getter, returns `bar`
+ *
+ * @param {Object} object constructed Assertion
+ * @param {String} key
+ * @param {Mixed} value (optional)
+ * @namespace Utils
+ * @name flag
+ * @api private
+ */
+
+module.exports = function flag(obj, key, value) {
+ var flags = obj.__flags || (obj.__flags = Object.create(null));
+ if (arguments.length === 3) {
+ flags[key] = value;
+ } else {
+ return flags[key];
+ }
+};
+
+},{}],16:[function(require,module,exports){
+/*!
+ * Chai - getActual utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .getActual(object, [actual])
+ *
+ * Returns the `actual` value for an Assertion.
+ *
+ * @param {Object} object (constructed Assertion)
+ * @param {Arguments} chai.Assertion.prototype.assert arguments
+ * @namespace Utils
+ * @name getActual
+ */
+
+module.exports = function getActual(obj, args) {
+ return args.length > 4 ? args[4] : obj._obj;
+};
+
+},{}],17:[function(require,module,exports){
+/*!
+ * Chai - getEnumerableProperties utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .getEnumerableProperties(object)
+ *
+ * This allows the retrieval of enumerable property names of an object,
+ * inherited or not.
+ *
+ * @param {Object} object
+ * @returns {Array}
+ * @namespace Utils
+ * @name getEnumerableProperties
+ * @api public
+ */
+
+module.exports = function getEnumerableProperties(object) {
+ var result = [];
+ for (var name in object) {
+ result.push(name);
+ }
+ return result;
+};
+
+},{}],18:[function(require,module,exports){
+/*!
+ * Chai - message composition utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/*!
+ * Module dependancies
+ */
+
+var flag = require('./flag')
+ , getActual = require('./getActual')
+ , inspect = require('./inspect')
+ , objDisplay = require('./objDisplay');
+
+/**
+ * ### .getMessage(object, message, negateMessage)
+ *
+ * Construct the error message based on flags
+ * and template tags. Template tags will return
+ * a stringified inspection of the object referenced.
+ *
+ * Message template tags:
+ * - `#{this}` current asserted object
+ * - `#{act}` actual value
+ * - `#{exp}` expected value
+ *
+ * @param {Object} object (constructed Assertion)
+ * @param {Arguments} chai.Assertion.prototype.assert arguments
+ * @namespace Utils
+ * @name getMessage
+ * @api public
+ */
+
+module.exports = function getMessage(obj, args) {
+ var negate = flag(obj, 'negate')
+ , val = flag(obj, 'object')
+ , expected = args[3]
+ , actual = getActual(obj, args)
+ , msg = negate ? args[2] : args[1]
+ , flagMsg = flag(obj, 'message');
+
+ if(typeof msg === "function") msg = msg();
+ msg = msg || '';
+ msg = msg
+ .replace(/#\{this\}/g, function () { return objDisplay(val); })
+ .replace(/#\{act\}/g, function () { return objDisplay(actual); })
+ .replace(/#\{exp\}/g, function () { return objDisplay(expected); });
+
+ return flagMsg ? flagMsg + ': ' + msg : msg;
+};
+
+},{"./flag":15,"./getActual":16,"./inspect":23,"./objDisplay":26}],19:[function(require,module,exports){
+/*!
+ * Chai - getOwnEnumerableProperties utility
+ * Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/*!
+ * Module dependancies
+ */
+
+var getOwnEnumerablePropertySymbols = require('./getOwnEnumerablePropertySymbols');
+
+/**
+ * ### .getOwnEnumerableProperties(object)
+ *
+ * This allows the retrieval of directly-owned enumerable property names and
+ * symbols of an object. This function is necessary because Object.keys only
+ * returns enumerable property names, not enumerable property symbols.
+ *
+ * @param {Object} object
+ * @returns {Array}
+ * @namespace Utils
+ * @name getOwnEnumerableProperties
+ * @api public
+ */
+
+module.exports = function getOwnEnumerableProperties(obj) {
+ return Object.keys(obj).concat(getOwnEnumerablePropertySymbols(obj));
+};
+
+},{"./getOwnEnumerablePropertySymbols":20}],20:[function(require,module,exports){
+/*!
+ * Chai - getOwnEnumerablePropertySymbols utility
+ * Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .getOwnEnumerablePropertySymbols(object)
+ *
+ * This allows the retrieval of directly-owned enumerable property symbols of an
+ * object. This function is necessary because Object.getOwnPropertySymbols
+ * returns both enumerable and non-enumerable property symbols.
+ *
+ * @param {Object} object
+ * @returns {Array}
+ * @namespace Utils
+ * @name getOwnEnumerablePropertySymbols
+ * @api public
+ */
+
+module.exports = function getOwnEnumerablePropertySymbols(obj) {
+ if (typeof Object.getOwnPropertySymbols !== 'function') return [];
+
+ return Object.getOwnPropertySymbols(obj).filter(function (sym) {
+ return Object.getOwnPropertyDescriptor(obj, sym).enumerable;
+ });
+};
+
+},{}],21:[function(require,module,exports){
+/*!
+ * Chai - getProperties utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .getProperties(object)
+ *
+ * This allows the retrieval of property names of an object, enumerable or not,
+ * inherited or not.
+ *
+ * @param {Object} object
+ * @returns {Array}
+ * @namespace Utils
+ * @name getProperties
+ * @api public
+ */
+
+module.exports = function getProperties(object) {
+ var result = Object.getOwnPropertyNames(object);
+
+ function addProperty(property) {
+ if (result.indexOf(property) === -1) {
+ result.push(property);
+ }
+ }
+
+ var proto = Object.getPrototypeOf(object);
+ while (proto !== null) {
+ Object.getOwnPropertyNames(proto).forEach(addProperty);
+ proto = Object.getPrototypeOf(proto);
+ }
+
+ return result;
+};
+
+},{}],22:[function(require,module,exports){
+/*!
+ * chai
+ * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/*!
+ * Dependencies that are used for multiple exports are required here only once
+ */
+
+var pathval = require('pathval');
+
+/*!
+ * test utility
+ */
+
+exports.test = require('./test');
+
+/*!
+ * type utility
+ */
+
+exports.type = require('type-detect');
+
+/*!
+ * expectTypes utility
+ */
+exports.expectTypes = require('./expectTypes');
+
+/*!
+ * message utility
+ */
+
+exports.getMessage = require('./getMessage');
+
+/*!
+ * actual utility
+ */
+
+exports.getActual = require('./getActual');
+
+/*!
+ * Inspect util
+ */
+
+exports.inspect = require('./inspect');
+
+/*!
+ * Object Display util
+ */
+
+exports.objDisplay = require('./objDisplay');
+
+/*!
+ * Flag utility
+ */
+
+exports.flag = require('./flag');
+
+/*!
+ * Flag transferring utility
+ */
+
+exports.transferFlags = require('./transferFlags');
+
+/*!
+ * Deep equal utility
+ */
+
+exports.eql = require('deep-eql');
+
+/*!
+ * Deep path info
+ */
+
+exports.getPathInfo = pathval.getPathInfo;
+
+/*!
+ * Check if a property exists
+ */
+
+exports.hasProperty = pathval.hasProperty;
+
+/*!
+ * Function name
+ */
+
+exports.getName = require('get-func-name');
+
+/*!
+ * add Property
+ */
+
+exports.addProperty = require('./addProperty');
+
+/*!
+ * add Method
+ */
+
+exports.addMethod = require('./addMethod');
+
+/*!
+ * overwrite Property
+ */
+
+exports.overwriteProperty = require('./overwriteProperty');
+
+/*!
+ * overwrite Method
+ */
+
+exports.overwriteMethod = require('./overwriteMethod');
+
+/*!
+ * Add a chainable method
+ */
+
+exports.addChainableMethod = require('./addChainableMethod');
+
+/*!
+ * Overwrite chainable method
+ */
+
+exports.overwriteChainableMethod = require('./overwriteChainableMethod');
+
+/*!
+ * Compare by inspect method
+ */
+
+exports.compareByInspect = require('./compareByInspect');
+
+/*!
+ * Get own enumerable property symbols method
+ */
+
+exports.getOwnEnumerablePropertySymbols = require('./getOwnEnumerablePropertySymbols');
+
+/*!
+ * Get own enumerable properties method
+ */
+
+exports.getOwnEnumerableProperties = require('./getOwnEnumerableProperties');
+
+/*!
+ * Checks error against a given set of criteria
+ */
+
+exports.checkError = require('check-error');
+
+/*!
+ * Proxify util
+ */
+
+exports.proxify = require('./proxify');
+
+/*!
+ * addLengthGuard util
+ */
+
+exports.addLengthGuard = require('./addLengthGuard');
+
+/*!
+ * isProxyEnabled helper
+ */
+
+exports.isProxyEnabled = require('./isProxyEnabled');
+
+/*!
+ * isNaN method
+ */
+
+exports.isNaN = require('./isNaN');
+
+},{"./addChainableMethod":9,"./addLengthGuard":10,"./addMethod":11,"./addProperty":12,"./compareByInspect":13,"./expectTypes":14,"./flag":15,"./getActual":16,"./getMessage":18,"./getOwnEnumerableProperties":19,"./getOwnEnumerablePropertySymbols":20,"./inspect":23,"./isNaN":24,"./isProxyEnabled":25,"./objDisplay":26,"./overwriteChainableMethod":27,"./overwriteMethod":28,"./overwriteProperty":29,"./proxify":30,"./test":31,"./transferFlags":32,"check-error":34,"deep-eql":35,"get-func-name":36,"pathval":37,"type-detect":38}],23:[function(require,module,exports){
+// This is (almost) directly from Node.js utils
+// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
+
+var getName = require('get-func-name');
+var getProperties = require('./getProperties');
+var getEnumerableProperties = require('./getEnumerableProperties');
+var config = require('../config');
+
+module.exports = inspect;
+
+/**
+ * ### .inspect(obj, [showHidden], [depth], [colors])
+ *
+ * Echoes the value of a value. Tries to print the value out
+ * in the best way possible given the different types.
+ *
+ * @param {Object} obj The object to print out.
+ * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
+ * properties of objects. Default is false.
+ * @param {Number} depth Depth in which to descend in object. Default is 2.
+ * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
+ * output. Default is false (no coloring).
+ * @namespace Utils
+ * @name inspect
+ */
+function inspect(obj, showHidden, depth, colors) {
+ var ctx = {
+ showHidden: showHidden,
+ seen: [],
+ stylize: function (str) { return str; }
+ };
+ return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
+}
+
+// Returns true if object is a DOM element.
+var isDOMElement = function (object) {
+ if (typeof HTMLElement === 'object') {
+ return object instanceof HTMLElement;
+ } else {
+ return object &&
+ typeof object === 'object' &&
+ 'nodeType' in object &&
+ object.nodeType === 1 &&
+ typeof object.nodeName === 'string';
+ }
+};
+
+function formatValue(ctx, value, recurseTimes) {
+ // Provide a hook for user-specified inspect functions.
+ // Check that value is an object with an inspect function on it
+ if (value && typeof value.inspect === 'function' &&
+ // Filter out the util module, it's inspect function is special
+ value.inspect !== exports.inspect &&
+ // Also filter out any prototype objects using the circular check.
+ !(value.constructor && value.constructor.prototype === value)) {
+ var ret = value.inspect(recurseTimes, ctx);
+ if (typeof ret !== 'string') {
+ ret = formatValue(ctx, ret, recurseTimes);
+ }
+ return ret;
+ }
+
+ // Primitive types cannot have properties
+ var primitive = formatPrimitive(ctx, value);
+ if (primitive) {
+ return primitive;
+ }
+
+ // If this is a DOM element, try to get the outer HTML.
+ if (isDOMElement(value)) {
+ if ('outerHTML' in value) {
+ return value.outerHTML;
+ // This value does not have an outerHTML attribute,
+ // it could still be an XML element
+ } else {
+ // Attempt to serialize it
+ try {
+ if (document.xmlVersion) {
+ var xmlSerializer = new XMLSerializer();
+ return xmlSerializer.serializeToString(value);
+ } else {
+ // Firefox 11- do not support outerHTML
+ // It does, however, support innerHTML
+ // Use the following to render the element
+ var ns = "http://www.w3.org/1999/xhtml";
+ var container = document.createElementNS(ns, '_');
+
+ container.appendChild(value.cloneNode(false));
+ var html = container.innerHTML
+ .replace('><', '>' + value.innerHTML + '<');
+ container.innerHTML = '';
+ return html;
+ }
+ } catch (err) {
+ // This could be a non-native DOM implementation,
+ // continue with the normal flow:
+ // printing the element as if it is an object.
+ }
+ }
+ }
+
+ // Look up the keys of the object.
+ var visibleKeys = getEnumerableProperties(value);
+ var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
+
+ var name, nameSuffix;
+
+ // Some type of object without properties can be shortcutted.
+ // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
+ // a `stack` plus `description` property; ignore those for consistency.
+ if (keys.length === 0 || (isError(value) && (
+ (keys.length === 1 && keys[0] === 'stack') ||
+ (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
+ ))) {
+ if (typeof value === 'function') {
+ name = getName(value);
+ nameSuffix = name ? ': ' + name : '';
+ return ctx.stylize('[Function' + nameSuffix + ']', 'special');
+ }
+ if (isRegExp(value)) {
+ return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
+ }
+ if (isDate(value)) {
+ return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
+ }
+ if (isError(value)) {
+ return formatError(value);
+ }
+ }
+
+ var base = ''
+ , array = false
+ , typedArray = false
+ , braces = ['{', '}'];
+
+ if (isTypedArray(value)) {
+ typedArray = true;
+ braces = ['[', ']'];
+ }
+
+ // Make Array say that they are Array
+ if (isArray(value)) {
+ array = true;
+ braces = ['[', ']'];
+ }
+
+ // Make functions say that they are functions
+ if (typeof value === 'function') {
+ name = getName(value);
+ nameSuffix = name ? ': ' + name : '';
+ base = ' [Function' + nameSuffix + ']';
+ }
+
+ // Make RegExps say that they are RegExps
+ if (isRegExp(value)) {
+ base = ' ' + RegExp.prototype.toString.call(value);
+ }
+
+ // Make dates with properties first say the date
+ if (isDate(value)) {
+ base = ' ' + Date.prototype.toUTCString.call(value);
+ }
+
+ // Make error with message first say the error
+ if (isError(value)) {
+ return formatError(value);
+ }
+
+ if (keys.length === 0 && (!array || value.length == 0)) {
+ return braces[0] + base + braces[1];
+ }
+
+ if (recurseTimes < 0) {
+ if (isRegExp(value)) {
+ return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
+ } else {
+ return ctx.stylize('[Object]', 'special');
+ }
+ }
+
+ ctx.seen.push(value);
+
+ var output;
+ if (array) {
+ output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
+ } else if (typedArray) {
+ return formatTypedArray(value);
+ } else {
+ output = keys.map(function(key) {
+ return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
+ });
+ }
+
+ ctx.seen.pop();
+
+ return reduceToSingleString(output, base, braces);
+}
+
+
+function formatPrimitive(ctx, value) {
+ switch (typeof value) {
+ case 'undefined':
+ return ctx.stylize('undefined', 'undefined');
+
+ case 'string':
+ var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
+ .replace(/'/g, "\\'")
+ .replace(/\\"/g, '"') + '\'';
+ return ctx.stylize(simple, 'string');
+
+ case 'number':
+ if (value === 0 && (1/value) === -Infinity) {
+ return ctx.stylize('-0', 'number');
+ }
+ return ctx.stylize('' + value, 'number');
+
+ case 'boolean':
+ return ctx.stylize('' + value, 'boolean');
+
+ case 'symbol':
+ return ctx.stylize(value.toString(), 'symbol');
+ }
+ // For some reason typeof null is "object", so special case here.
+ if (value === null) {
+ return ctx.stylize('null', 'null');
+ }
+}
+
+
+function formatError(value) {
+ return '[' + Error.prototype.toString.call(value) + ']';
+}
+
+
+function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
+ var output = [];
+ for (var i = 0, l = value.length; i < l; ++i) {
+ if (Object.prototype.hasOwnProperty.call(value, String(i))) {
+ output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
+ String(i), true));
+ } else {
+ output.push('');
+ }
+ }
+
+ keys.forEach(function(key) {
+ if (!key.match(/^\d+$/)) {
+ output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
+ key, true));
+ }
+ });
+ return output;
+}
+
+function formatTypedArray(value) {
+ var str = '[ ';
+
+ for (var i = 0; i < value.length; ++i) {
+ if (str.length >= config.truncateThreshold - 7) {
+ str += '...';
+ break;
+ }
+ str += value[i] + ', ';
+ }
+ str += ' ]';
+
+ // Removing trailing `, ` if the array was not truncated
+ if (str.indexOf(', ]') !== -1) {
+ str = str.replace(', ]', ' ]');
+ }
+
+ return str;
+}
+
+function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
+ var name;
+ var propDescriptor = Object.getOwnPropertyDescriptor(value, key);
+ var str;
+
+ if (propDescriptor) {
+ if (propDescriptor.get) {
+ if (propDescriptor.set) {
+ str = ctx.stylize('[Getter/Setter]', 'special');
+ } else {
+ str = ctx.stylize('[Getter]', 'special');
+ }
+ } else {
+ if (propDescriptor.set) {
+ str = ctx.stylize('[Setter]', 'special');
+ }
+ }
+ }
+ if (visibleKeys.indexOf(key) < 0) {
+ name = '[' + key + ']';
+ }
+ if (!str) {
+ if (ctx.seen.indexOf(value[key]) < 0) {
+ if (recurseTimes === null) {
+ str = formatValue(ctx, value[key], null);
+ } else {
+ str = formatValue(ctx, value[key], recurseTimes - 1);
+ }
+ if (str.indexOf('\n') > -1) {
+ if (array) {
+ str = str.split('\n').map(function(line) {
+ return ' ' + line;
+ }).join('\n').substr(2);
+ } else {
+ str = '\n' + str.split('\n').map(function(line) {
+ return ' ' + line;
+ }).join('\n');
+ }
+ }
+ } else {
+ str = ctx.stylize('[Circular]', 'special');
+ }
+ }
+ if (typeof name === 'undefined') {
+ if (array && key.match(/^\d+$/)) {
+ return str;
+ }
+ name = JSON.stringify('' + key);
+ if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
+ name = name.substr(1, name.length - 2);
+ name = ctx.stylize(name, 'name');
+ } else {
+ name = name.replace(/'/g, "\\'")
+ .replace(/\\"/g, '"')
+ .replace(/(^"|"$)/g, "'");
+ name = ctx.stylize(name, 'string');
+ }
+ }
+
+ return name + ': ' + str;
+}
+
+
+function reduceToSingleString(output, base, braces) {
+ var numLinesEst = 0;
+ var length = output.reduce(function(prev, cur) {
+ numLinesEst++;
+ if (cur.indexOf('\n') >= 0) numLinesEst++;
+ return prev + cur.length + 1;
+ }, 0);
+
+ if (length > 60) {
+ return braces[0] +
+ (base === '' ? '' : base + '\n ') +
+ ' ' +
+ output.join(',\n ') +
+ ' ' +
+ braces[1];
+ }
+
+ return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
+}
+
+function isTypedArray(ar) {
+ // Unfortunately there's no way to check if an object is a TypedArray
+ // We have to check if it's one of these types
+ return (typeof ar === 'object' && /\w+Array]$/.test(objectToString(ar)));
+}
+
+function isArray(ar) {
+ return Array.isArray(ar) ||
+ (typeof ar === 'object' && objectToString(ar) === '[object Array]');
+}
+
+function isRegExp(re) {
+ return typeof re === 'object' && objectToString(re) === '[object RegExp]';
+}
+
+function isDate(d) {
+ return typeof d === 'object' && objectToString(d) === '[object Date]';
+}
+
+function isError(e) {
+ return typeof e === 'object' && objectToString(e) === '[object Error]';
+}
+
+function objectToString(o) {
+ return Object.prototype.toString.call(o);
+}
+
+},{"../config":4,"./getEnumerableProperties":17,"./getProperties":21,"get-func-name":36}],24:[function(require,module,exports){
+/*!
+ * Chai - isNaN utility
+ * Copyright(c) 2012-2015 Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .isNaN(value)
+ *
+ * Checks if the given value is NaN or not.
+ *
+ * utils.isNaN(NaN); // true
+ *
+ * @param {Value} The value which has to be checked if it is NaN
+ * @name isNaN
+ * @api private
+ */
+
+function isNaN(value) {
+ // Refer http://www.ecma-international.org/ecma-262/6.0/#sec-isnan-number
+ // section's NOTE.
+ return value !== value;
+}
+
+// If ECMAScript 6's Number.isNaN is present, prefer that.
+module.exports = Number.isNaN || isNaN;
+
+},{}],25:[function(require,module,exports){
+var config = require('../config');
+
+/*!
+ * Chai - isProxyEnabled helper
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .isProxyEnabled()
+ *
+ * Helper function to check if Chai's proxy protection feature is enabled. If
+ * proxies are unsupported or disabled via the user's Chai config, then return
+ * false. Otherwise, return true.
+ *
+ * @namespace Utils
+ * @name isProxyEnabled
+ */
+
+module.exports = function isProxyEnabled() {
+ return config.useProxy &&
+ typeof Proxy !== 'undefined' &&
+ typeof Reflect !== 'undefined';
+};
+
+},{"../config":4}],26:[function(require,module,exports){
+/*!
+ * Chai - flag utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/*!
+ * Module dependancies
+ */
+
+var inspect = require('./inspect');
+var config = require('../config');
+
+/**
+ * ### .objDisplay(object)
+ *
+ * Determines if an object or an array matches
+ * criteria to be inspected in-line for error
+ * messages or should be truncated.
+ *
+ * @param {Mixed} javascript object to inspect
+ * @name objDisplay
+ * @namespace Utils
+ * @api public
+ */
+
+module.exports = function objDisplay(obj) {
+ var str = inspect(obj)
+ , type = Object.prototype.toString.call(obj);
+
+ if (config.truncateThreshold && str.length >= config.truncateThreshold) {
+ if (type === '[object Function]') {
+ return !obj.name || obj.name === ''
+ ? '[Function]'
+ : '[Function: ' + obj.name + ']';
+ } else if (type === '[object Array]') {
+ return '[ Array(' + obj.length + ') ]';
+ } else if (type === '[object Object]') {
+ var keys = Object.keys(obj)
+ , kstr = keys.length > 2
+ ? keys.splice(0, 2).join(', ') + ', ...'
+ : keys.join(', ');
+ return '{ Object (' + kstr + ') }';
+ } else {
+ return str;
+ }
+ } else {
+ return str;
+ }
+};
+
+},{"../config":4,"./inspect":23}],27:[function(require,module,exports){
+/*!
+ * Chai - overwriteChainableMethod utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+var chai = require('../../chai');
+var transferFlags = require('./transferFlags');
+
+/**
+ * ### .overwriteChainableMethod(ctx, name, method, chainingBehavior)
+ *
+ * Overwites an already existing chainable method
+ * and provides access to the previous function or
+ * property. Must return functions to be used for
+ * name.
+ *
+ * utils.overwriteChainableMethod(chai.Assertion.prototype, 'lengthOf',
+ * function (_super) {
+ * }
+ * , function (_super) {
+ * }
+ * );
+ *
+ * Can also be accessed directly from `chai.Assertion`.
+ *
+ * chai.Assertion.overwriteChainableMethod('foo', fn, fn);
+ *
+ * Then can be used as any other assertion.
+ *
+ * expect(myFoo).to.have.lengthOf(3);
+ * expect(myFoo).to.have.lengthOf.above(3);
+ *
+ * @param {Object} ctx object whose method / property is to be overwritten
+ * @param {String} name of method / property to overwrite
+ * @param {Function} method function that returns a function to be used for name
+ * @param {Function} chainingBehavior function that returns a function to be used for property
+ * @namespace Utils
+ * @name overwriteChainableMethod
+ * @api public
+ */
+
+module.exports = function overwriteChainableMethod(ctx, name, method, chainingBehavior) {
+ var chainableBehavior = ctx.__methods[name];
+
+ var _chainingBehavior = chainableBehavior.chainingBehavior;
+ chainableBehavior.chainingBehavior = function overwritingChainableMethodGetter() {
+ var result = chainingBehavior(_chainingBehavior).call(this);
+ if (result !== undefined) {
+ return result;
+ }
+
+ var newAssertion = new chai.Assertion();
+ transferFlags(this, newAssertion);
+ return newAssertion;
+ };
+
+ var _method = chainableBehavior.method;
+ chainableBehavior.method = function overwritingChainableMethodWrapper() {
+ var result = method(_method).apply(this, arguments);
+ if (result !== undefined) {
+ return result;
+ }
+
+ var newAssertion = new chai.Assertion();
+ transferFlags(this, newAssertion);
+ return newAssertion;
+ };
+};
+
+},{"../../chai":2,"./transferFlags":32}],28:[function(require,module,exports){
+/*!
+ * Chai - overwriteMethod utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+var addLengthGuard = require('./addLengthGuard');
+var chai = require('../../chai');
+var flag = require('./flag');
+var proxify = require('./proxify');
+var transferFlags = require('./transferFlags');
+
+/**
+ * ### .overwriteMethod(ctx, name, fn)
+ *
+ * Overwites an already existing method and provides
+ * access to previous function. Must return function
+ * to be used for name.
+ *
+ * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
+ * return function (str) {
+ * var obj = utils.flag(this, 'object');
+ * if (obj instanceof Foo) {
+ * new chai.Assertion(obj.value).to.equal(str);
+ * } else {
+ * _super.apply(this, arguments);
+ * }
+ * }
+ * });
+ *
+ * Can also be accessed directly from `chai.Assertion`.
+ *
+ * chai.Assertion.overwriteMethod('foo', fn);
+ *
+ * Then can be used as any other assertion.
+ *
+ * expect(myFoo).to.equal('bar');
+ *
+ * @param {Object} ctx object whose method is to be overwritten
+ * @param {String} name of method to overwrite
+ * @param {Function} method function that returns a function to be used for name
+ * @namespace Utils
+ * @name overwriteMethod
+ * @api public
+ */
+
+module.exports = function overwriteMethod(ctx, name, method) {
+ var _method = ctx[name]
+ , _super = function () {
+ throw new Error(name + ' is not a function');
+ };
+
+ if (_method && 'function' === typeof _method)
+ _super = _method;
+
+ var overwritingMethodWrapper = function () {
+ // Setting the `ssfi` flag to `overwritingMethodWrapper` causes this
+ // function to be the starting point for removing implementation frames from
+ // the stack trace of a failed assertion.
+ //
+ // However, we only want to use this function as the starting point if the
+ // `lockSsfi` flag isn't set.
+ //
+ // If the `lockSsfi` flag is set, then either this assertion has been
+ // overwritten by another assertion, or this assertion is being invoked from
+ // inside of another assertion. In the first case, the `ssfi` flag has
+ // already been set by the overwriting assertion. In the second case, the
+ // `ssfi` flag has already been set by the outer assertion.
+ if (!flag(this, 'lockSsfi')) {
+ flag(this, 'ssfi', overwritingMethodWrapper);
+ }
+
+ // Setting the `lockSsfi` flag to `true` prevents the overwritten assertion
+ // from changing the `ssfi` flag. By this point, the `ssfi` flag is already
+ // set to the correct starting point for this assertion.
+ var origLockSsfi = flag(this, 'lockSsfi');
+ flag(this, 'lockSsfi', true);
+ var result = method(_super).apply(this, arguments);
+ flag(this, 'lockSsfi', origLockSsfi);
+
+ if (result !== undefined) {
+ return result;
+ }
+
+ var newAssertion = new chai.Assertion();
+ transferFlags(this, newAssertion);
+ return newAssertion;
+ }
+
+ addLengthGuard(overwritingMethodWrapper, name, false);
+ ctx[name] = proxify(overwritingMethodWrapper, name);
+};
+
+},{"../../chai":2,"./addLengthGuard":10,"./flag":15,"./proxify":30,"./transferFlags":32}],29:[function(require,module,exports){
+/*!
+ * Chai - overwriteProperty utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+var chai = require('../../chai');
+var flag = require('./flag');
+var isProxyEnabled = require('./isProxyEnabled');
+var transferFlags = require('./transferFlags');
+
+/**
+ * ### .overwriteProperty(ctx, name, fn)
+ *
+ * Overwites an already existing property getter and provides
+ * access to previous value. Must return function to use as getter.
+ *
+ * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
+ * return function () {
+ * var obj = utils.flag(this, 'object');
+ * if (obj instanceof Foo) {
+ * new chai.Assertion(obj.name).to.equal('bar');
+ * } else {
+ * _super.call(this);
+ * }
+ * }
+ * });
+ *
+ *
+ * Can also be accessed directly from `chai.Assertion`.
+ *
+ * chai.Assertion.overwriteProperty('foo', fn);
+ *
+ * Then can be used as any other assertion.
+ *
+ * expect(myFoo).to.be.ok;
+ *
+ * @param {Object} ctx object whose property is to be overwritten
+ * @param {String} name of property to overwrite
+ * @param {Function} getter function that returns a getter function to be used for name
+ * @namespace Utils
+ * @name overwriteProperty
+ * @api public
+ */
+
+module.exports = function overwriteProperty(ctx, name, getter) {
+ var _get = Object.getOwnPropertyDescriptor(ctx, name)
+ , _super = function () {};
+
+ if (_get && 'function' === typeof _get.get)
+ _super = _get.get
+
+ Object.defineProperty(ctx, name,
+ { get: function overwritingPropertyGetter() {
+ // Setting the `ssfi` flag to `overwritingPropertyGetter` causes this
+ // function to be the starting point for removing implementation frames
+ // from the stack trace of a failed assertion.
+ //
+ // However, we only want to use this function as the starting point if
+ // the `lockSsfi` flag isn't set and proxy protection is disabled.
+ //
+ // If the `lockSsfi` flag is set, then either this assertion has been
+ // overwritten by another assertion, or this assertion is being invoked
+ // from inside of another assertion. In the first case, the `ssfi` flag
+ // has already been set by the overwriting assertion. In the second
+ // case, the `ssfi` flag has already been set by the outer assertion.
+ //
+ // If proxy protection is enabled, then the `ssfi` flag has already been
+ // set by the proxy getter.
+ if (!isProxyEnabled() && !flag(this, 'lockSsfi')) {
+ flag(this, 'ssfi', overwritingPropertyGetter);
+ }
+
+ // Setting the `lockSsfi` flag to `true` prevents the overwritten
+ // assertion from changing the `ssfi` flag. By this point, the `ssfi`
+ // flag is already set to the correct starting point for this assertion.
+ var origLockSsfi = flag(this, 'lockSsfi');
+ flag(this, 'lockSsfi', true);
+ var result = getter(_super).call(this);
+ flag(this, 'lockSsfi', origLockSsfi);
+
+ if (result !== undefined) {
+ return result;
+ }
+
+ var newAssertion = new chai.Assertion();
+ transferFlags(this, newAssertion);
+ return newAssertion;
+ }
+ , configurable: true
+ });
+};
+
+},{"../../chai":2,"./flag":15,"./isProxyEnabled":25,"./transferFlags":32}],30:[function(require,module,exports){
+var config = require('../config');
+var flag = require('./flag');
+var getProperties = require('./getProperties');
+var isProxyEnabled = require('./isProxyEnabled');
+
+/*!
+ * Chai - proxify utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .proxify(object)
+ *
+ * Return a proxy of given object that throws an error when a non-existent
+ * property is read. By default, the root cause is assumed to be a misspelled
+ * property, and thus an attempt is made to offer a reasonable suggestion from
+ * the list of existing properties. However, if a nonChainableMethodName is
+ * provided, then the root cause is instead a failure to invoke a non-chainable
+ * method prior to reading the non-existent property.
+ *
+ * If proxies are unsupported or disabled via the user's Chai config, then
+ * return object without modification.
+ *
+ * @param {Object} obj
+ * @param {String} nonChainableMethodName
+ * @namespace Utils
+ * @name proxify
+ */
+
+var builtins = ['__flags', '__methods', '_obj', 'assert'];
+
+module.exports = function proxify(obj, nonChainableMethodName) {
+ if (!isProxyEnabled()) return obj;
+
+ return new Proxy(obj, {
+ get: function proxyGetter(target, property) {
+ // This check is here because we should not throw errors on Symbol properties
+ // such as `Symbol.toStringTag`.
+ // The values for which an error should be thrown can be configured using
+ // the `config.proxyExcludedKeys` setting.
+ if (typeof property === 'string' &&
+ config.proxyExcludedKeys.indexOf(property) === -1 &&
+ !Reflect.has(target, property)) {
+ // Special message for invalid property access of non-chainable methods.
+ if (nonChainableMethodName) {
+ throw Error('Invalid Chai property: ' + nonChainableMethodName + '.' +
+ property + '. See docs for proper usage of "' +
+ nonChainableMethodName + '".');
+ }
+
+ var orderedProperties = getProperties(target).filter(function(property) {
+ return !Object.prototype.hasOwnProperty(property) &&
+ builtins.indexOf(property) === -1;
+ }).sort(function(a, b) {
+ return stringDistance(property, a) - stringDistance(property, b);
+ });
+
+ if (orderedProperties.length &&
+ stringDistance(orderedProperties[0], property) < 4) {
+ // If the property is reasonably close to an existing Chai property,
+ // suggest that property to the user.
+ throw Error('Invalid Chai property: ' + property +
+ '. Did you mean "' + orderedProperties[0] + '"?');
+ } else {
+ throw Error('Invalid Chai property: ' + property);
+ }
+ }
+
+ // Use this proxy getter as the starting point for removing implementation
+ // frames from the stack trace of a failed assertion. For property
+ // assertions, this prevents the proxy getter from showing up in the stack
+ // trace since it's invoked before the property getter. For method and
+ // chainable method assertions, this flag will end up getting changed to
+ // the method wrapper, which is good since this frame will no longer be in
+ // the stack once the method is invoked. Note that Chai builtin assertion
+ // properties such as `__flags` are skipped since this is only meant to
+ // capture the starting point of an assertion. This step is also skipped
+ // if the `lockSsfi` flag is set, thus indicating that this assertion is
+ // being called from within another assertion. In that case, the `ssfi`
+ // flag is already set to the outer assertion's starting point.
+ if (builtins.indexOf(property) === -1 && !flag(target, 'lockSsfi')) {
+ flag(target, 'ssfi', proxyGetter);
+ }
+
+ return Reflect.get(target, property);
+ }
+ });
+};
+
+/**
+ * # stringDistance(strA, strB)
+ * Return the Levenshtein distance between two strings.
+ * @param {string} strA
+ * @param {string} strB
+ * @return {number} the string distance between strA and strB
+ * @api private
+ */
+
+function stringDistance(strA, strB, memo) {
+ if (!memo) {
+ // `memo` is a two-dimensional array containing a cache of distances
+ // memo[i][j] is the distance between strA.slice(0, i) and
+ // strB.slice(0, j).
+ memo = [];
+ for (var i = 0; i <= strA.length; i++) {
+ memo[i] = [];
+ }
+ }
+
+ if (!memo[strA.length] || !memo[strA.length][strB.length]) {
+ if (strA.length === 0 || strB.length === 0) {
+ memo[strA.length][strB.length] = Math.max(strA.length, strB.length);
+ } else {
+ memo[strA.length][strB.length] = Math.min(
+ stringDistance(strA.slice(0, -1), strB, memo) + 1,
+ stringDistance(strA, strB.slice(0, -1), memo) + 1,
+ stringDistance(strA.slice(0, -1), strB.slice(0, -1), memo) +
+ (strA.slice(-1) === strB.slice(-1) ? 0 : 1)
+ );
+ }
+ }
+
+ return memo[strA.length][strB.length];
+}
+
+},{"../config":4,"./flag":15,"./getProperties":21,"./isProxyEnabled":25}],31:[function(require,module,exports){
+/*!
+ * Chai - test utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/*!
+ * Module dependancies
+ */
+
+var flag = require('./flag');
+
+/**
+ * ### .test(object, expression)
+ *
+ * Test and object for expression.
+ *
+ * @param {Object} object (constructed Assertion)
+ * @param {Arguments} chai.Assertion.prototype.assert arguments
+ * @namespace Utils
+ * @name test
+ */
+
+module.exports = function test(obj, args) {
+ var negate = flag(obj, 'negate')
+ , expr = args[0];
+ return negate ? !expr : expr;
+};
+
+},{"./flag":15}],32:[function(require,module,exports){
+/*!
+ * Chai - transferFlags utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .transferFlags(assertion, object, includeAll = true)
+ *
+ * Transfer all the flags for `assertion` to `object`. If
+ * `includeAll` is set to `false`, then the base Chai
+ * assertion flags (namely `object`, `ssfi`, `lockSsfi`,
+ * and `message`) will not be transferred.
+ *
+ *
+ * var newAssertion = new Assertion();
+ * utils.transferFlags(assertion, newAssertion);
+ *
+ * var anotherAsseriton = new Assertion(myObj);
+ * utils.transferFlags(assertion, anotherAssertion, false);
+ *
+ * @param {Assertion} assertion the assertion to transfer the flags from
+ * @param {Object} object the object to transfer the flags to; usually a new assertion
+ * @param {Boolean} includeAll
+ * @namespace Utils
+ * @name transferFlags
+ * @api private
+ */
+
+module.exports = function transferFlags(assertion, object, includeAll) {
+ var flags = assertion.__flags || (assertion.__flags = Object.create(null));
+
+ if (!object.__flags) {
+ object.__flags = Object.create(null);
+ }
+
+ includeAll = arguments.length === 3 ? includeAll : true;
+
+ for (var flag in flags) {
+ if (includeAll ||
+ (flag !== 'object' && flag !== 'ssfi' && flag !== 'lockSsfi' && flag != 'message')) {
+ object.__flags[flag] = flags[flag];
+ }
+ }
+};
+
+},{}],33:[function(require,module,exports){
+/*!
+ * assertion-error
+ * Copyright(c) 2013 Jake Luer <jake@qualiancy.com>
+ * MIT Licensed
+ */
+
+/*!
+ * Return a function that will copy properties from
+ * one object to another excluding any originally
+ * listed. Returned function will create a new `{}`.
+ *
+ * @param {String} excluded properties ...
+ * @return {Function}
+ */
+
+function exclude () {
+ var excludes = [].slice.call(arguments);
+
+ function excludeProps (res, obj) {
+ Object.keys(obj).forEach(function (key) {
+ if (!~excludes.indexOf(key)) res[key] = obj[key];
+ });
+ }
+
+ return function extendExclude () {
+ var args = [].slice.call(arguments)
+ , i = 0
+ , res = {};
+
+ for (; i < args.length; i++) {
+ excludeProps(res, args[i]);
+ }
+
+ return res;
+ };
+};
+
+/*!
+ * Primary Exports
+ */
+
+module.exports = AssertionError;
+
+/**
+ * ### AssertionError
+ *
+ * An extension of the JavaScript `Error` constructor for
+ * assertion and validation scenarios.
+ *
+ * @param {String} message
+ * @param {Object} properties to include (optional)
+ * @param {callee} start stack function (optional)
+ */
+
+function AssertionError (message, _props, ssf) {
+ var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
+ , props = extend(_props || {});
+
+ // default values
+ this.message = message || 'Unspecified AssertionError';
+ this.showDiff = false;
+
+ // copy from properties
+ for (var key in props) {
+ this[key] = props[key];
+ }
+
+ // capture stack trace
+ ssf = ssf || arguments.callee;
+ if (ssf && Error.captureStackTrace) {
+ Error.captureStackTrace(this, ssf);
+ } else {
+ try {
+ throw new Error();
+ } catch(e) {
+ this.stack = e.stack;
+ }
+ }
+}
+
+/*!
+ * Inherit from Error.prototype
+ */
+
+AssertionError.prototype = Object.create(Error.prototype);
+
+/*!
+ * Statically set name
+ */
+
+AssertionError.prototype.name = 'AssertionError';
+
+/*!
+ * Ensure correct constructor
+ */
+
+AssertionError.prototype.constructor = AssertionError;
+
+/**
+ * Allow errors to be converted to JSON for static transfer.
+ *
+ * @param {Boolean} include stack (default: `true`)
+ * @return {Object} object that can be `JSON.stringify`
+ */
+
+AssertionError.prototype.toJSON = function (stack) {
+ var extend = exclude('constructor', 'toJSON', 'stack')
+ , props = extend({ name: this.name }, this);
+
+ // include stack if exists and not turned off
+ if (false !== stack && this.stack) {
+ props.stack = this.stack;
+ }
+
+ return props;
+};
+
+},{}],34:[function(require,module,exports){
+'use strict';
+
+/* !
+ * Chai - checkError utility
+ * Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .checkError
+ *
+ * Checks that an error conforms to a given set of criteria and/or retrieves information about it.
+ *
+ * @api public
+ */
+
+/**
+ * ### .compatibleInstance(thrown, errorLike)
+ *
+ * Checks if two instances are compatible (strict equal).
+ * Returns false if errorLike is not an instance of Error, because instances
+ * can only be compatible if they're both error instances.
+ *
+ * @name compatibleInstance
+ * @param {Error} thrown error
+ * @param {Error|ErrorConstructor} errorLike object to compare against
+ * @namespace Utils
+ * @api public
+ */
+
+function compatibleInstance(thrown, errorLike) {
+ return errorLike instanceof Error && thrown === errorLike;
+}
+
+/**
+ * ### .compatibleConstructor(thrown, errorLike)
+ *
+ * Checks if two constructors are compatible.
+ * This function can receive either an error constructor or
+ * an error instance as the `errorLike` argument.
+ * Constructors are compatible if they're the same or if one is
+ * an instance of another.
+ *
+ * @name compatibleConstructor
+ * @param {Error} thrown error
+ * @param {Error|ErrorConstructor} errorLike object to compare against
+ * @namespace Utils
+ * @api public
+ */
+
+function compatibleConstructor(thrown, errorLike) {
+ if (errorLike instanceof Error) {
+ // If `errorLike` is an instance of any error we compare their constructors
+ return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
+ } else if (errorLike.prototype instanceof Error || errorLike === Error) {
+ // If `errorLike` is a constructor that inherits from Error, we compare `thrown` to `errorLike` directly
+ return thrown.constructor === errorLike || thrown instanceof errorLike;
+ }
+
+ return false;
+}
+
+/**
+ * ### .compatibleMessage(thrown, errMatcher)
+ *
+ * Checks if an error's message is compatible with a matcher (String or RegExp).
+ * If the message contains the String or passes the RegExp test,
+ * it is considered compatible.
+ *
+ * @name compatibleMessage
+ * @param {Error} thrown error
+ * @param {String|RegExp} errMatcher to look for into the message
+ * @namespace Utils
+ * @api public
+ */
+
+function compatibleMessage(thrown, errMatcher) {
+ var comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
+ if (errMatcher instanceof RegExp) {
+ return errMatcher.test(comparisonString);
+ } else if (typeof errMatcher === 'string') {
+ return comparisonString.indexOf(errMatcher) !== -1; // eslint-disable-line no-magic-numbers
+ }
+
+ return false;
+}
+
+/**
+ * ### .getFunctionName(constructorFn)
+ *
+ * Returns the name of a function.
+ * This also includes a polyfill function if `constructorFn.name` is not defined.
+ *
+ * @name getFunctionName
+ * @param {Function} constructorFn
+ * @namespace Utils
+ * @api private
+ */
+
+var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\(\/]+)/;
+function getFunctionName(constructorFn) {
+ var name = '';
+ if (typeof constructorFn.name === 'undefined') {
+ // Here we run a polyfill if constructorFn.name is not defined
+ var match = String(constructorFn).match(functionNameMatch);
+ if (match) {
+ name = match[1];
+ }
+ } else {
+ name = constructorFn.name;
+ }
+
+ return name;
+}
+
+/**
+ * ### .getConstructorName(errorLike)
+ *
+ * Gets the constructor name for an Error instance or constructor itself.
+ *
+ * @name getConstructorName
+ * @param {Error|ErrorConstructor} errorLike
+ * @namespace Utils
+ * @api public
+ */
+
+function getConstructorName(errorLike) {
+ var constructorName = errorLike;
+ if (errorLike instanceof Error) {
+ constructorName = getFunctionName(errorLike.constructor);
+ } else if (typeof errorLike === 'function') {
+ // If `err` is not an instance of Error it is an error constructor itself or another function.
+ // If we've got a common function we get its name, otherwise we may need to create a new instance
+ // of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
+ constructorName = getFunctionName(errorLike).trim() ||
+ getFunctionName(new errorLike()); // eslint-disable-line new-cap
+ }
+
+ return constructorName;
+}
+
+/**
+ * ### .getMessage(errorLike)
+ *
+ * Gets the error message from an error.
+ * If `err` is a String itself, we return it.
+ * If the error has no message, we return an empty string.
+ *
+ * @name getMessage
+ * @param {Error|String} errorLike
+ * @namespace Utils
+ * @api public
+ */
+
+function getMessage(errorLike) {
+ var msg = '';
+ if (errorLike && errorLike.message) {
+ msg = errorLike.message;
+ } else if (typeof errorLike === 'string') {
+ msg = errorLike;
+ }
+
+ return msg;
+}
+
+module.exports = {
+ compatibleInstance: compatibleInstance,
+ compatibleConstructor: compatibleConstructor,
+ compatibleMessage: compatibleMessage,
+ getMessage: getMessage,
+ getConstructorName: getConstructorName,
+};
+
+},{}],35:[function(require,module,exports){
+'use strict';
+/* globals Symbol: false, Uint8Array: false, WeakMap: false */
+/*!
+ * deep-eql
+ * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+var type = require('type-detect');
+function FakeMap() {
+ this._key = 'chai/deep-eql__' + Math.random() + Date.now();
+}
+
+FakeMap.prototype = {
+ get: function getMap(key) {
+ return key[this._key];
+ },
+ set: function setMap(key, value) {
+ if (!Object.isFrozen(key)) {
+ Object.defineProperty(key, this._key, {
+ value: value,
+ configurable: true,
+ });
+ }
+ },
+};
+
+var MemoizeMap = typeof WeakMap === 'function' ? WeakMap : FakeMap;
+/*!
+ * Check to see if the MemoizeMap has recorded a result of the two operands
+ *
+ * @param {Mixed} leftHandOperand
+ * @param {Mixed} rightHandOperand
+ * @param {MemoizeMap} memoizeMap
+ * @returns {Boolean|null} result
+*/
+function memoizeCompare(leftHandOperand, rightHandOperand, memoizeMap) {
+ // Technically, WeakMap keys can *only* be objects, not primitives.
+ if (!memoizeMap || isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
+ return null;
+ }
+ var leftHandMap = memoizeMap.get(leftHandOperand);
+ if (leftHandMap) {
+ var result = leftHandMap.get(rightHandOperand);
+ if (typeof result === 'boolean') {
+ return result;
+ }
+ }
+ return null;
+}
+
+/*!
+ * Set the result of the equality into the MemoizeMap
+ *
+ * @param {Mixed} leftHandOperand
+ * @param {Mixed} rightHandOperand
+ * @param {MemoizeMap} memoizeMap
+ * @param {Boolean} result
+*/
+function memoizeSet(leftHandOperand, rightHandOperand, memoizeMap, result) {
+ // Technically, WeakMap keys can *only* be objects, not primitives.
+ if (!memoizeMap || isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
+ return;
+ }
+ var leftHandMap = memoizeMap.get(leftHandOperand);
+ if (leftHandMap) {
+ leftHandMap.set(rightHandOperand, result);
+ } else {
+ leftHandMap = new MemoizeMap();
+ leftHandMap.set(rightHandOperand, result);
+ memoizeMap.set(leftHandOperand, leftHandMap);
+ }
+}
+
+/*!
+ * Primary Export
+ */
+
+module.exports = deepEqual;
+module.exports.MemoizeMap = MemoizeMap;
+
+/**
+ * Assert deeply nested sameValue equality between two objects of any type.
+ *
+ * @param {Mixed} leftHandOperand
+ * @param {Mixed} rightHandOperand
+ * @param {Object} [options] (optional) Additional options
+ * @param {Array} [options.comparator] (optional) Override default algorithm, determining custom equality.
+ * @param {Array} [options.memoize] (optional) Provide a custom memoization object which will cache the results of
+ complex objects for a speed boost. By passing `false` you can disable memoization, but this will cause circular
+ references to blow the stack.
+ * @return {Boolean} equal match
+ */
+function deepEqual(leftHandOperand, rightHandOperand, options) {
+ // If we have a comparator, we can't assume anything; so bail to its check first.
+ if (options && options.comparator) {
+ return extensiveDeepEqual(leftHandOperand, rightHandOperand, options);
+ }
+
+ var simpleResult = simpleEqual(leftHandOperand, rightHandOperand);
+ if (simpleResult !== null) {
+ return simpleResult;
+ }
+
+ // Deeper comparisons are pushed through to a larger function
+ return extensiveDeepEqual(leftHandOperand, rightHandOperand, options);
+}
+
+/**
+ * Many comparisons can be canceled out early via simple equality or primitive checks.
+ * @param {Mixed} leftHandOperand
+ * @param {Mixed} rightHandOperand
+ * @return {Boolean|null} equal match
+ */
+function simpleEqual(leftHandOperand, rightHandOperand) {
+ // Equal references (except for Numbers) can be returned early
+ if (leftHandOperand === rightHandOperand) {
+ // Handle +-0 cases
+ return leftHandOperand !== 0 || 1 / leftHandOperand === 1 / rightHandOperand;
+ }
+
+ // handle NaN cases
+ if (
+ leftHandOperand !== leftHandOperand && // eslint-disable-line no-self-compare
+ rightHandOperand !== rightHandOperand // eslint-disable-line no-self-compare
+ ) {
+ return true;
+ }
+
+ // Anything that is not an 'object', i.e. symbols, functions, booleans, numbers,
+ // strings, and undefined, can be compared by reference.
+ if (isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
+ // Easy out b/c it would have passed the first equality check
+ return false;
+ }
+ return null;
+}
+
+/*!
+ * The main logic of the `deepEqual` function.
+ *
+ * @param {Mixed} leftHandOperand
+ * @param {Mixed} rightHandOperand
+ * @param {Object} [options] (optional) Additional options
+ * @param {Array} [options.comparator] (optional) Override default algorithm, determining custom equality.
+ * @param {Array} [options.memoize] (optional) Provide a custom memoization object which will cache the results of
+ complex objects for a speed boost. By passing `false` you can disable memoization, but this will cause circular
+ references to blow the stack.
+ * @return {Boolean} equal match
+*/
+function extensiveDeepEqual(leftHandOperand, rightHandOperand, options) {
+ options = options || {};
+ options.memoize = options.memoize === false ? false : options.memoize || new MemoizeMap();
+ var comparator = options && options.comparator;
+
+ // Check if a memoized result exists.
+ var memoizeResultLeft = memoizeCompare(leftHandOperand, rightHandOperand, options.memoize);
+ if (memoizeResultLeft !== null) {
+ return memoizeResultLeft;
+ }
+ var memoizeResultRight = memoizeCompare(rightHandOperand, leftHandOperand, options.memoize);
+ if (memoizeResultRight !== null) {
+ return memoizeResultRight;
+ }
+
+ // If a comparator is present, use it.
+ if (comparator) {
+ var comparatorResult = comparator(leftHandOperand, rightHandOperand);
+ // Comparators may return null, in which case we want to go back to default behavior.
+ if (comparatorResult === false || comparatorResult === true) {
+ memoizeSet(leftHandOperand, rightHandOperand, options.memoize, comparatorResult);
+ return comparatorResult;
+ }
+ // To allow comparators to override *any* behavior, we ran them first. Since it didn't decide
+ // what to do, we need to make sure to return the basic tests first before we move on.
+ var simpleResult = simpleEqual(leftHandOperand, rightHandOperand);
+ if (simpleResult !== null) {
+ // Don't memoize this, it takes longer to set/retrieve than to just compare.
+ return simpleResult;
+ }
+ }
+
+ var leftHandType = type(leftHandOperand);
+ if (leftHandType !== type(rightHandOperand)) {
+ memoizeSet(leftHandOperand, rightHandOperand, options.memoize, false);
+ return false;
+ }
+
+ // Temporarily set the operands in the memoize object to prevent blowing the stack
+ memoizeSet(leftHandOperand, rightHandOperand, options.memoize, true);
+
+ var result = extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options);
+ memoizeSet(leftHandOperand, rightHandOperand, options.memoize, result);
+ return result;
+}
+
+function extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options) {
+ switch (leftHandType) {
+ case 'String':
+ case 'Number':
+ case 'Boolean':
+ case 'Date':
+ // If these types are their instance types (e.g. `new Number`) then re-deepEqual against their values
+ return deepEqual(leftHandOperand.valueOf(), rightHandOperand.valueOf());
+ case 'Promise':
+ case 'Symbol':
+ case 'function':
+ case 'WeakMap':
+ case 'WeakSet':
+ case 'Error':
+ return leftHandOperand === rightHandOperand;
+ case 'Arguments':
+ case 'Int8Array':
+ case 'Uint8Array':
+ case 'Uint8ClampedArray':
+ case 'Int16Array':
+ case 'Uint16Array':
+ case 'Int32Array':
+ case 'Uint32Array':
+ case 'Float32Array':
+ case 'Float64Array':
+ case 'Array':
+ return iterableEqual(leftHandOperand, rightHandOperand, options);
+ case 'RegExp':
+ return regexpEqual(leftHandOperand, rightHandOperand);
+ case 'Generator':
+ return generatorEqual(leftHandOperand, rightHandOperand, options);
+ case 'DataView':
+ return iterableEqual(new Uint8Array(leftHandOperand.buffer), new Uint8Array(rightHandOperand.buffer), options);
+ case 'ArrayBuffer':
+ return iterableEqual(new Uint8Array(leftHandOperand), new Uint8Array(rightHandOperand), options);
+ case 'Set':
+ return entriesEqual(leftHandOperand, rightHandOperand, options);
+ case 'Map':
+ return entriesEqual(leftHandOperand, rightHandOperand, options);
+ default:
+ return objectEqual(leftHandOperand, rightHandOperand, options);
+ }
+}
+
+/*!
+ * Compare two Regular Expressions for equality.
+ *
+ * @param {RegExp} leftHandOperand
+ * @param {RegExp} rightHandOperand
+ * @return {Boolean} result
+ */
+
+function regexpEqual(leftHandOperand, rightHandOperand) {
+ return leftHandOperand.toString() === rightHandOperand.toString();
+}
+
+/*!
+ * Compare two Sets/Maps for equality. Faster than other equality functions.
+ *
+ * @param {Set} leftHandOperand
+ * @param {Set} rightHandOperand
+ * @param {Object} [options] (Optional)
+ * @return {Boolean} result
+ */
+
+function entriesEqual(leftHandOperand, rightHandOperand, options) {
+ // IE11 doesn't support Set#entries or Set#@@iterator, so we need manually populate using Set#forEach
+ if (leftHandOperand.size !== rightHandOperand.size) {
+ return false;
+ }
+ if (leftHandOperand.size === 0) {
+ return true;
+ }
+ var leftHandItems = [];
+ var rightHandItems = [];
+ leftHandOperand.forEach(function gatherEntries(key, value) {
+ leftHandItems.push([ key, value ]);
+ });
+ rightHandOperand.forEach(function gatherEntries(key, value) {
+ rightHandItems.push([ key, value ]);
+ });
+ return iterableEqual(leftHandItems.sort(), rightHandItems.sort(), options);
+}
+
+/*!
+ * Simple equality for flat iterable objects such as Arrays, TypedArrays or Node.js buffers.
+ *
+ * @param {Iterable} leftHandOperand
+ * @param {Iterable} rightHandOperand
+ * @param {Object} [options] (Optional)
+ * @return {Boolean} result
+ */
+
+function iterableEqual(leftHandOperand, rightHandOperand, options) {
+ var length = leftHandOperand.length;
+ if (length !== rightHandOperand.length) {
+ return false;
+ }
+ if (length === 0) {
+ return true;
+ }
+ var index = -1;
+ while (++index < length) {
+ if (deepEqual(leftHandOperand[index], rightHandOperand[index], options) === false) {
+ return false;
+ }
+ }
+ return true;
+}
+
+/*!
+ * Simple equality for generator objects such as those returned by generator functions.
+ *
+ * @param {Iterable} leftHandOperand
+ * @param {Iterable} rightHandOperand
+ * @param {Object} [options] (Optional)
+ * @return {Boolean} result
+ */
+
+function generatorEqual(leftHandOperand, rightHandOperand, options) {
+ return iterableEqual(getGeneratorEntries(leftHandOperand), getGeneratorEntries(rightHandOperand), options);
+}
+
+/*!
+ * Determine if the given object has an @@iterator function.
+ *
+ * @param {Object} target
+ * @return {Boolean} `true` if the object has an @@iterator function.
+ */
+function hasIteratorFunction(target) {
+ return typeof Symbol !== 'undefined' &&
+ typeof target === 'object' &&
+ typeof Symbol.iterator !== 'undefined' &&
+ typeof target[Symbol.iterator] === 'function';
+}
+
+/*!
+ * Gets all iterator entries from the given Object. If the Object has no @@iterator function, returns an empty array.
+ * This will consume the iterator - which could have side effects depending on the @@iterator implementation.
+ *
+ * @param {Object} target
+ * @returns {Array} an array of entries from the @@iterator function
+ */
+function getIteratorEntries(target) {
+ if (hasIteratorFunction(target)) {
+ try {
+ return getGeneratorEntries(target[Symbol.iterator]());
+ } catch (iteratorError) {
+ return [];
+ }
+ }
+ return [];
+}
+
+/*!
+ * Gets all entries from a Generator. This will consume the generator - which could have side effects.
+ *
+ * @param {Generator} target
+ * @returns {Array} an array of entries from the Generator.
+ */
+function getGeneratorEntries(generator) {
+ var generatorResult = generator.next();
+ var accumulator = [ generatorResult.value ];
+ while (generatorResult.done === false) {
+ generatorResult = generator.next();
+ accumulator.push(generatorResult.value);
+ }
+ return accumulator;
+}
+
+/*!
+ * Gets all own and inherited enumerable keys from a target.
+ *
+ * @param {Object} target
+ * @returns {Array} an array of own and inherited enumerable keys from the target.
+ */
+function getEnumerableKeys(target) {
+ var keys = [];
+ for (var key in target) {
+ keys.push(key);
+ }
+ return keys;
+}
+
+/*!
+ * Determines if two objects have matching values, given a set of keys. Defers to deepEqual for the equality check of
+ * each key. If any value of the given key is not equal, the function will return false (early).
+ *
+ * @param {Mixed} leftHandOperand
+ * @param {Mixed} rightHandOperand
+ * @param {Array} keys An array of keys to compare the values of leftHandOperand and rightHandOperand against
+ * @param {Object} [options] (Optional)
+ * @return {Boolean} result
+ */
+function keysEqual(leftHandOperand, rightHandOperand, keys, options) {
+ var length = keys.length;
+ if (length === 0) {
+ return true;
+ }
+ for (var i = 0; i < length; i += 1) {
+ if (deepEqual(leftHandOperand[keys[i]], rightHandOperand[keys[i]], options) === false) {
+ return false;
+ }
+ }
+ return true;
+}
+
+/*!
+ * Recursively check the equality of two Objects. Once basic sameness has been established it will defer to `deepEqual`
+ * for each enumerable key in the object.
+ *
+ * @param {Mixed} leftHandOperand
+ * @param {Mixed} rightHandOperand
+ * @param {Object} [options] (Optional)
+ * @return {Boolean} result
+ */
+
+function objectEqual(leftHandOperand, rightHandOperand, options) {
+ var leftHandKeys = getEnumerableKeys(leftHandOperand);
+ var rightHandKeys = getEnumerableKeys(rightHandOperand);
+ if (leftHandKeys.length && leftHandKeys.length === rightHandKeys.length) {
+ leftHandKeys.sort();
+ rightHandKeys.sort();
+ if (iterableEqual(leftHandKeys, rightHandKeys) === false) {
+ return false;
+ }
+ return keysEqual(leftHandOperand, rightHandOperand, leftHandKeys, options);
+ }
+
+ var leftHandEntries = getIteratorEntries(leftHandOperand);
+ var rightHandEntries = getIteratorEntries(rightHandOperand);
+ if (leftHandEntries.length && leftHandEntries.length === rightHandEntries.length) {
+ leftHandEntries.sort();
+ rightHandEntries.sort();
+ return iterableEqual(leftHandEntries, rightHandEntries, options);
+ }
+
+ if (leftHandKeys.length === 0 &&
+ leftHandEntries.length === 0 &&
+ rightHandKeys.length === 0 &&
+ rightHandEntries.length === 0) {
+ return true;
+ }
+
+ return false;
+}
+
+/*!
+ * Returns true if the argument is a primitive.
+ *
+ * This intentionally returns true for all objects that can be compared by reference,
+ * including functions and symbols.
+ *
+ * @param {Mixed} value
+ * @return {Boolean} result
+ */
+function isPrimitive(value) {
+ return value === null || typeof value !== 'object';
+}
+
+},{"type-detect":38}],36:[function(require,module,exports){
+'use strict';
+
+/* !
+ * Chai - getFuncName utility
+ * Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+
+/**
+ * ### .getFuncName(constructorFn)
+ *
+ * Returns the name of a function.
+ * When a non-function instance is passed, returns `null`.
+ * This also includes a polyfill function if `aFunc.name` is not defined.
+ *
+ * @name getFuncName
+ * @param {Function} funct
+ * @namespace Utils
+ * @api public
+ */
+
+var toString = Function.prototype.toString;
+var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
+function getFuncName(aFunc) {
+ if (typeof aFunc !== 'function') {
+ return null;
+ }
+
+ var name = '';
+ if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
+ // Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
+ var match = toString.call(aFunc).match(functionNameMatch);
+ if (match) {
+ name = match[1];
+ }
+ } else {
+ // If we've got a `name` property we just use it
+ name = aFunc.name;
+ }
+
+ return name;
+}
+
+module.exports = getFuncName;
+
+},{}],37:[function(require,module,exports){
+'use strict';
+
+/* !
+ * Chai - pathval utility
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
+ * @see https://github.com/logicalparadox/filtr
+ * MIT Licensed
+ */
+
+/**
+ * ### .hasProperty(object, name)
+ *
+ * This allows checking whether an object has own
+ * or inherited from prototype chain named property.
+ *
+ * Basically does the same thing as the `in`
+ * operator but works properly with null/undefined values
+ * and other primitives.
+ *
+ * var obj = {
+ * arr: ['a', 'b', 'c']
+ * , str: 'Hello'
+ * }
+ *
+ * The following would be the results.
+ *
+ * hasProperty(obj, 'str'); // true
+ * hasProperty(obj, 'constructor'); // true
+ * hasProperty(obj, 'bar'); // false
+ *
+ * hasProperty(obj.str, 'length'); // true
+ * hasProperty(obj.str, 1); // true
+ * hasProperty(obj.str, 5); // false
+ *
+ * hasProperty(obj.arr, 'length'); // true
+ * hasProperty(obj.arr, 2); // true
+ * hasProperty(obj.arr, 3); // false
+ *
+ * @param {Object} object
+ * @param {String|Symbol} name
+ * @returns {Boolean} whether it exists
+ * @namespace Utils
+ * @name hasProperty
+ * @api public
+ */
+
+function hasProperty(obj, name) {
+ if (typeof obj === 'undefined' || obj === null) {
+ return false;
+ }
+
+ // The `in` operator does not work with primitives.
+ return name in Object(obj);
+}
+
+/* !
+ * ## parsePath(path)
+ *
+ * Helper function used to parse string object
+ * paths. Use in conjunction with `internalGetPathValue`.
+ *
+ * var parsed = parsePath('myobject.property.subprop');
+ *
+ * ### Paths:
+ *
+ * * Can be infinitely deep and nested.
+ * * Arrays are also valid using the formal `myobject.document[3].property`.
+ * * Literal dots and brackets (not delimiter) must be backslash-escaped.
+ *
+ * @param {String} path
+ * @returns {Object} parsed
+ * @api private
+ */
+
+function parsePath(path) {
+ var str = path.replace(/([^\\])\[/g, '$1.[');
+ var parts = str.match(/(\\\.|[^.]+?)+/g);
+ return parts.map(function mapMatches(value) {
+ var regexp = /^\[(\d+)\]$/;
+ var mArr = regexp.exec(value);
+ var parsed = null;
+ if (mArr) {
+ parsed = { i: parseFloat(mArr[1]) };
+ } else {
+ parsed = { p: value.replace(/\\([.\[\]])/g, '$1') };
+ }
+
+ return parsed;
+ });
+}
+
+/* !
+ * ## internalGetPathValue(obj, parsed[, pathDepth])
+ *
+ * Helper companion function for `.parsePath` that returns
+ * the value located at the parsed address.
+ *
+ * var value = getPathValue(obj, parsed);
+ *
+ * @param {Object} object to search against
+ * @param {Object} parsed definition from `parsePath`.
+ * @param {Number} depth (nesting level) of the property we want to retrieve
+ * @returns {Object|Undefined} value
+ * @api private
+ */
+
+function internalGetPathValue(obj, parsed, pathDepth) {
+ var temporaryValue = obj;
+ var res = null;
+ pathDepth = (typeof pathDepth === 'undefined' ? parsed.length : pathDepth);
+
+ for (var i = 0; i < pathDepth; i++) {
+ var part = parsed[i];
+ if (temporaryValue) {
+ if (typeof part.p === 'undefined') {
+ temporaryValue = temporaryValue[part.i];
+ } else {
+ temporaryValue = temporaryValue[part.p];
+ }
+
+ if (i === (pathDepth - 1)) {
+ res = temporaryValue;
+ }
+ }
+ }
+
+ return res;
+}
+
+/* !
+ * ## internalSetPathValue(obj, value, parsed)
+ *
+ * Companion function for `parsePath` that sets
+ * the value located at a parsed address.
+ *
+ * internalSetPathValue(obj, 'value', parsed);
+ *
+ * @param {Object} object to search and define on
+ * @param {*} value to use upon set
+ * @param {Object} parsed definition from `parsePath`
+ * @api private
+ */
+
+function internalSetPathValue(obj, val, parsed) {
+ var tempObj = obj;
+ var pathDepth = parsed.length;
+ var part = null;
+ // Here we iterate through every part of the path
+ for (var i = 0; i < pathDepth; i++) {
+ var propName = null;
+ var propVal = null;
+ part = parsed[i];
+
+ // If it's the last part of the path, we set the 'propName' value with the property name
+ if (i === (pathDepth - 1)) {
+ propName = typeof part.p === 'undefined' ? part.i : part.p;
+ // Now we set the property with the name held by 'propName' on object with the desired val
+ tempObj[propName] = val;
+ } else if (typeof part.p !== 'undefined' && tempObj[part.p]) {
+ tempObj = tempObj[part.p];
+ } else if (typeof part.i !== 'undefined' && tempObj[part.i]) {
+ tempObj = tempObj[part.i];
+ } else {
+ // If the obj doesn't have the property we create one with that name to define it
+ var next = parsed[i + 1];
+ // Here we set the name of the property which will be defined
+ propName = typeof part.p === 'undefined' ? part.i : part.p;
+ // Here we decide if this property will be an array or a new object
+ propVal = typeof next.p === 'undefined' ? [] : {};
+ tempObj[propName] = propVal;
+ tempObj = tempObj[propName];
+ }
+ }
+}
+
+/**
+ * ### .getPathInfo(object, path)
+ *
+ * This allows the retrieval of property info in an
+ * object given a string path.
+ *
+ * The path info consists of an object with the
+ * following properties:
+ *
+ * * parent - The parent object of the property referenced by `path`
+ * * name - The name of the final property, a number if it was an array indexer
+ * * value - The value of the property, if it exists, otherwise `undefined`
+ * * exists - Whether the property exists or not
+ *
+ * @param {Object} object
+ * @param {String} path
+ * @returns {Object} info
+ * @namespace Utils
+ * @name getPathInfo
+ * @api public
+ */
+
+function getPathInfo(obj, path) {
+ var parsed = parsePath(path);
+ var last = parsed[parsed.length - 1];
+ var info = {
+ parent: parsed.length > 1 ? internalGetPathValue(obj, parsed, parsed.length - 1) : obj,
+ name: last.p || last.i,
+ value: internalGetPathValue(obj, parsed),
+ };
+ info.exists = hasProperty(info.parent, info.name);
+
+ return info;
+}
+
+/**
+ * ### .getPathValue(object, path)
+ *
+ * This allows the retrieval of values in an
+ * object given a string path.
+ *
+ * var obj = {
+ * prop1: {
+ * arr: ['a', 'b', 'c']
+ * , str: 'Hello'
+ * }
+ * , prop2: {
+ * arr: [ { nested: 'Universe' } ]
+ * , str: 'Hello again!'
+ * }
+ * }
+ *
+ * The following would be the results.
+ *
+ * getPathValue(obj, 'prop1.str'); // Hello
+ * getPathValue(obj, 'prop1.att[2]'); // b
+ * getPathValue(obj, 'prop2.arr[0].nested'); // Universe
+ *
+ * @param {Object} object
+ * @param {String} path
+ * @returns {Object} value or `undefined`
+ * @namespace Utils
+ * @name getPathValue
+ * @api public
+ */
+
+function getPathValue(obj, path) {
+ var info = getPathInfo(obj, path);
+ return info.value;
+}
+
+/**
+ * ### .setPathValue(object, path, value)
+ *
+ * Define the value in an object at a given string path.
+ *
+ * ```js
+ * var obj = {
+ * prop1: {
+ * arr: ['a', 'b', 'c']
+ * , str: 'Hello'
+ * }
+ * , prop2: {
+ * arr: [ { nested: 'Universe' } ]
+ * , str: 'Hello again!'
+ * }
+ * };
+ * ```
+ *
+ * The following would be acceptable.
+ *
+ * ```js
+ * var properties = require('tea-properties');
+ * properties.set(obj, 'prop1.str', 'Hello Universe!');
+ * properties.set(obj, 'prop1.arr[2]', 'B');
+ * properties.set(obj, 'prop2.arr[0].nested.value', { hello: 'universe' });
+ * ```
+ *
+ * @param {Object} object
+ * @param {String} path
+ * @param {Mixed} value
+ * @api private
+ */
+
+function setPathValue(obj, path, val) {
+ var parsed = parsePath(path);
+ internalSetPathValue(obj, val, parsed);
+ return obj;
+}
+
+module.exports = {
+ hasProperty: hasProperty,
+ getPathInfo: getPathInfo,
+ getPathValue: getPathValue,
+ setPathValue: setPathValue,
+};
+
+},{}],38:[function(require,module,exports){
+'use strict';
+
+/* !
+ * type-detect
+ * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
+ * MIT Licensed
+ */
+var promiseExists = typeof Promise === 'function';
+var globalObject = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : self; // eslint-disable-line
+var isDom = 'location' in globalObject && 'document' in globalObject;
+var symbolExists = typeof Symbol !== 'undefined';
+var mapExists = typeof Map !== 'undefined';
+var setExists = typeof Set !== 'undefined';
+var weakMapExists = typeof WeakMap !== 'undefined';
+var weakSetExists = typeof WeakSet !== 'undefined';
+var dataViewExists = typeof DataView !== 'undefined';
+var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
+var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
+var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
+var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
+var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
+var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
+var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
+var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
+var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
+var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
+var toStringLeftSliceLength = 8;
+var toStringRightSliceLength = -1;
+/**
+ * ### typeOf (obj)
+ *
+ * Uses `Object.prototype.toString` to determine the type of an object,
+ * normalising behaviour across engine versions & well optimised.
+ *
+ * @param {Mixed} object
+ * @return {String} object type
+ * @api public
+ */
+module.exports = function typeDetect(obj) {
+ /* ! Speed optimisation
+ * Pre:
+ * string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
+ * boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
+ * number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
+ * undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
+ * function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
+ * Post:
+ * string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
+ * boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
+ * number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
+ * undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
+ * function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
+ */
+ var typeofObj = typeof obj;
+ if (typeofObj !== 'object') {
+ return typeofObj;
+ }
+
+ /* ! Speed optimisation
+ * Pre:
+ * null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
+ * Post:
+ * null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
+ */
+ if (obj === null) {
+ return 'null';
+ }
+
+ /* ! Spec Conformance
+ * Test: `Object.prototype.toString.call(window)``
+ * - Node === "[object global]"
+ * - Chrome === "[object global]"
+ * - Firefox === "[object Window]"
+ * - PhantomJS === "[object Window]"
+ * - Safari === "[object Window]"
+ * - IE 11 === "[object Window]"
+ * - IE Edge === "[object Window]"
+ * Test: `Object.prototype.toString.call(this)``
+ * - Chrome Worker === "[object global]"
+ * - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
+ * - Safari Worker === "[object DedicatedWorkerGlobalScope]"
+ * - IE 11 Worker === "[object WorkerGlobalScope]"
+ * - IE Edge Worker === "[object WorkerGlobalScope]"
+ */
+ if (obj === globalObject) {
+ return 'global';
+ }
+
+ /* ! Speed optimisation
+ * Pre:
+ * array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
+ * Post:
+ * array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
+ */
+ if (
+ Array.isArray(obj) &&
+ (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
+ ) {
+ return 'Array';
+ }
+
+ if (isDom) {
+ /* ! Spec Conformance
+ * (https://html.spec.whatwg.org/multipage/browsers.html#location)
+ * WhatWG HTML$7.7.3 - The `Location` interface
+ * Test: `Object.prototype.toString.call(window.location)``
+ * - IE <=11 === "[object Object]"
+ * - IE Edge <=13 === "[object Object]"
+ */
+ if (obj === globalObject.location) {
+ return 'Location';
+ }
+
+ /* ! Spec Conformance
+ * (https://html.spec.whatwg.org/#document)
+ * WhatWG HTML$3.1.1 - The `Document` object
+ * Note: Most browsers currently adher to the W3C DOM Level 2 spec
+ * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
+ * which suggests that browsers should use HTMLTableCellElement for
+ * both TD and TH elements. WhatWG separates these.
+ * WhatWG HTML states:
+ * > For historical reasons, Window objects must also have a
+ * > writable, configurable, non-enumerable property named
+ * > HTMLDocument whose value is the Document interface object.
+ * Test: `Object.prototype.toString.call(document)``
+ * - Chrome === "[object HTMLDocument]"
+ * - Firefox === "[object HTMLDocument]"
+ * - Safari === "[object HTMLDocument]"
+ * - IE <=10 === "[object Document]"
+ * - IE 11 === "[object HTMLDocument]"
+ * - IE Edge <=13 === "[object HTMLDocument]"
+ */
+ if (obj === globalObject.document) {
+ return 'Document';
+ }
+
+ /* ! Spec Conformance
+ * (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
+ * WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
+ * Test: `Object.prototype.toString.call(navigator.mimeTypes)``
+ * - IE <=10 === "[object MSMimeTypesCollection]"
+ */
+ if (obj === (globalObject.navigator || {}).mimeTypes) {
+ return 'MimeTypeArray';
+ }
+
+ /* ! Spec Conformance
+ * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
+ * WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
+ * Test: `Object.prototype.toString.call(navigator.plugins)``
+ * - IE <=10 === "[object MSPluginsCollection]"
+ */
+ if (obj === (globalObject.navigator || {}).plugins) {
+ return 'PluginArray';
+ }
+
+ /* ! Spec Conformance
+ * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
+ * WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
+ * Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
+ * - IE <=10 === "[object HTMLBlockElement]"
+ */
+ if (obj instanceof HTMLElement && obj.tagName === 'BLOCKQUOTE') {
+ return 'HTMLQuoteElement';
+ }
+
+ /* ! Spec Conformance
+ * (https://html.spec.whatwg.org/#htmltabledatacellelement)
+ * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
+ * Note: Most browsers currently adher to the W3C DOM Level 2 spec
+ * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
+ * which suggests that browsers should use HTMLTableCellElement for
+ * both TD and TH elements. WhatWG separates these.
+ * Test: Object.prototype.toString.call(document.createElement('td'))
+ * - Chrome === "[object HTMLTableCellElement]"
+ * - Firefox === "[object HTMLTableCellElement]"
+ * - Safari === "[object HTMLTableCellElement]"
+ */
+ if (obj instanceof HTMLElement && obj.tagName === 'TD') {
+ return 'HTMLTableDataCellElement';
+ }
+
+ /* ! Spec Conformance
+ * (https://html.spec.whatwg.org/#htmltableheadercellelement)
+ * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
+ * Note: Most browsers currently adher to the W3C DOM Level 2 spec
+ * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
+ * which suggests that browsers should use HTMLTableCellElement for
+ * both TD and TH elements. WhatWG separates these.
+ * Test: Object.prototype.toString.call(document.createElement('th'))
+ * - Chrome === "[object HTMLTableCellElement]"
+ * - Firefox === "[object HTMLTableCellElement]"
+ * - Safari === "[object HTMLTableCellElement]"
+ */
+ if (obj instanceof HTMLElement && obj.tagName === 'TH') {
+ return 'HTMLTableHeaderCellElement';
+ }
+ }
+
+ /* ! Speed optimisation
+ * Pre:
+ * Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
+ * Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
+ * Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
+ * Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
+ * Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
+ * Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
+ * Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
+ * Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
+ * Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
+ * Post:
+ * Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
+ * Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
+ * Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
+ * Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
+ * Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
+ * Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
+ * Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
+ * Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
+ * Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
+ */
+ var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
+ if (typeof stringTag === 'string') {
+ return stringTag;
+ }
+
+ var objPrototype = Object.getPrototypeOf(obj);
+ /* ! Speed optimisation
+ * Pre:
+ * regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
+ * regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
+ * Post:
+ * regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
+ * regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
+ */
+ if (objPrototype === RegExp.prototype) {
+ return 'RegExp';
+ }
+
+ /* ! Speed optimisation
+ * Pre:
+ * date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
+ * Post:
+ * date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
+ */
+ if (objPrototype === Date.prototype) {
+ return 'Date';
+ }
+
+ /* ! Spec Conformance
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
+ * ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
+ * Test: `Object.prototype.toString.call(Promise.resolve())``
+ * - Chrome <=47 === "[object Object]"
+ * - Edge <=20 === "[object Object]"
+ * - Firefox 29-Latest === "[object Promise]"
+ * - Safari 7.1-Latest === "[object Promise]"
+ */
+ if (promiseExists && objPrototype === Promise.prototype) {
+ return 'Promise';
+ }
+
+ /* ! Speed optimisation
+ * Pre:
+ * set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
+ * Post:
+ * set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
+ */
+ if (setExists && objPrototype === Set.prototype) {
+ return 'Set';
+ }
+
+ /* ! Speed optimisation
+ * Pre:
+ * map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
+ * Post:
+ * map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
+ */
+ if (mapExists && objPrototype === Map.prototype) {
+ return 'Map';
+ }
+
+ /* ! Speed optimisation
+ * Pre:
+ * weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
+ * Post:
+ * weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
+ */
+ if (weakSetExists && objPrototype === WeakSet.prototype) {
+ return 'WeakSet';
+ }
+
+ /* ! Speed optimisation
+ * Pre:
+ * weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
+ * Post:
+ * weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
+ */
+ if (weakMapExists && objPrototype === WeakMap.prototype) {
+ return 'WeakMap';
+ }
+
+ /* ! Spec Conformance
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
+ * ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
+ * Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
+ * - Edge <=13 === "[object Object]"
+ */
+ if (dataViewExists && objPrototype === DataView.prototype) {
+ return 'DataView';
+ }
+
+ /* ! Spec Conformance
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
+ * ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
+ * Test: `Object.prototype.toString.call(new Map().entries())``
+ * - Edge <=13 === "[object Object]"
+ */
+ if (mapExists && objPrototype === mapIteratorPrototype) {
+ return 'Map Iterator';
+ }
+
+ /* ! Spec Conformance
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
+ * ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
+ * Test: `Object.prototype.toString.call(new Set().entries())``
+ * - Edge <=13 === "[object Object]"
+ */
+ if (setExists && objPrototype === setIteratorPrototype) {
+ return 'Set Iterator';
+ }
+
+ /* ! Spec Conformance
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
+ * ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
+ * Test: `Object.prototype.toString.call([][Symbol.iterator]())``
+ * - Edge <=13 === "[object Object]"
+ */
+ if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
+ return 'Array Iterator';
+ }
+
+ /* ! Spec Conformance
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
+ * ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
+ * Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
+ * - Edge <=13 === "[object Object]"
+ */
+ if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
+ return 'String Iterator';
+ }
+
+ /* ! Speed optimisation
+ * Pre:
+ * object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
+ * Post:
+ * object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
+ */
+ if (objPrototype === null) {
+ return 'Object';
+ }
+
+ return Object
+ .prototype
+ .toString
+ .call(obj)
+ .slice(toStringLeftSliceLength, toStringRightSliceLength);
+};
+
+module.exports.typeDetect = module.exports;
+
+},{}]},{},[1])(1)
+});
\ No newline at end of file
--- /dev/null
+/*
+MIT License
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
+(function (process,global){
+'use strict';
+
+/* eslint no-unused-vars: off */
+/* eslint-env commonjs */
+
+/**
+ * Shim process.stdout.
+ */
+
+process.stdout = require('browser-stdout')({level: false});
+
+var Mocha = require('./lib/mocha');
+
+/**
+ * Create a Mocha instance.
+ *
+ * @return {undefined}
+ */
+
+var mocha = new Mocha({ reporter: 'html' });
+
+/**
+ * Save timer references to avoid Sinon interfering (see GH-237).
+ */
+
+var Date = global.Date;
+var setTimeout = global.setTimeout;
+var setInterval = global.setInterval;
+var clearTimeout = global.clearTimeout;
+var clearInterval = global.clearInterval;
+
+var uncaughtExceptionHandlers = [];
+
+var originalOnerrorHandler = global.onerror;
+
+/**
+ * Remove uncaughtException listener.
+ * Revert to original onerror handler if previously defined.
+ */
+
+process.removeListener = function (e, fn) {
+ if (e === 'uncaughtException') {
+ if (originalOnerrorHandler) {
+ global.onerror = originalOnerrorHandler;
+ } else {
+ global.onerror = function () {};
+ }
+ var i = uncaughtExceptionHandlers.indexOf(fn);
+ if (i !== -1) {
+ uncaughtExceptionHandlers.splice(i, 1);
+ }
+ }
+};
+
+/**
+ * Implements uncaughtException listener.
+ */
+
+process.on = function (e, fn) {
+ if (e === 'uncaughtException') {
+ global.onerror = function (err, url, line) {
+ fn(new Error(err + ' (' + url + ':' + line + ')'));
+ return !mocha.allowUncaught;
+ };
+ uncaughtExceptionHandlers.push(fn);
+ }
+};
+
+// The BDD UI is registered by default, but no UI will be functional in the
+// browser without an explicit call to the overridden `mocha.ui` (see below).
+// Ensure that this default UI does not expose its methods to the global scope.
+mocha.suite.removeAllListeners('pre-require');
+
+var immediateQueue = [];
+var immediateTimeout;
+
+function timeslice () {
+ var immediateStart = new Date().getTime();
+ while (immediateQueue.length && (new Date().getTime() - immediateStart) < 100) {
+ immediateQueue.shift()();
+ }
+ if (immediateQueue.length) {
+ immediateTimeout = setTimeout(timeslice, 0);
+ } else {
+ immediateTimeout = null;
+ }
+}
+
+/**
+ * High-performance override of Runner.immediately.
+ */
+
+Mocha.Runner.immediately = function (callback) {
+ immediateQueue.push(callback);
+ if (!immediateTimeout) {
+ immediateTimeout = setTimeout(timeslice, 0);
+ }
+};
+
+/**
+ * Function to allow assertion libraries to throw errors directly into mocha.
+ * This is useful when running tests in a browser because window.onerror will
+ * only receive the 'message' attribute of the Error.
+ */
+mocha.throwError = function (err) {
+ uncaughtExceptionHandlers.forEach(function (fn) {
+ fn(err);
+ });
+ throw err;
+};
+
+/**
+ * Override ui to ensure that the ui functions are initialized.
+ * Normally this would happen in Mocha.prototype.loadFiles.
+ */
+
+mocha.ui = function (ui) {
+ Mocha.prototype.ui.call(this, ui);
+ this.suite.emit('pre-require', global, null, this);
+ return this;
+};
+
+/**
+ * Setup mocha with the given setting options.
+ */
+
+mocha.setup = function (opts) {
+ if (typeof opts === 'string') {
+ opts = { ui: opts };
+ }
+ for (var opt in opts) {
+ if (opts.hasOwnProperty(opt)) {
+ this[opt](opts[opt]);
+ }
+ }
+ return this;
+};
+
+/**
+ * Run mocha, returning the Runner.
+ */
+
+mocha.run = function (fn) {
+ var options = mocha.options;
+ mocha.globals('location');
+
+ var query = Mocha.utils.parseQuery(global.location.search || '');
+ if (query.grep) {
+ mocha.grep(query.grep);
+ }
+ if (query.fgrep) {
+ mocha.fgrep(query.fgrep);
+ }
+ if (query.invert) {
+ mocha.invert();
+ }
+
+ return Mocha.prototype.run.call(mocha, function (err) {
+ // The DOM Document is not available in Web Workers.
+ var document = global.document;
+ if (document && document.getElementById('mocha') && options.noHighlighting !== true) {
+ Mocha.utils.highlightTags('code');
+ }
+ if (fn) {
+ fn(err);
+ }
+ });
+};
+
+/**
+ * Expose the process shim.
+ * https://github.com/mochajs/mocha/pull/916
+ */
+
+Mocha.process = process;
+
+/**
+ * Expose mocha.
+ */
+
+global.Mocha = Mocha;
+global.mocha = mocha;
+
+// this allows test/acceptance/required-tokens.js to pass; thus,
+// you can now do `const describe = require('mocha').describe` in a
+// browser context (assuming browserification). should fix #880
+module.exports = global;
+
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"./lib/mocha":13,"_process":55,"browser-stdout":39}],2:[function(require,module,exports){
+'use strict';
+
+// just stub out growl
+
+module.exports = require('../utils').noop;
+
+},{"../utils":36}],3:[function(require,module,exports){
+'use strict';
+
+/**
+ * Expose `Progress`.
+ */
+
+module.exports = Progress;
+
+/**
+ * Initialize a new `Progress` indicator.
+ */
+function Progress () {
+ this.percent = 0;
+ this.size(0);
+ this.fontSize(11);
+ this.font('helvetica, arial, sans-serif');
+}
+
+/**
+ * Set progress size to `size`.
+ *
+ * @api public
+ * @param {number} size
+ * @return {Progress} Progress instance.
+ */
+Progress.prototype.size = function (size) {
+ this._size = size;
+ return this;
+};
+
+/**
+ * Set text to `text`.
+ *
+ * @api public
+ * @param {string} text
+ * @return {Progress} Progress instance.
+ */
+Progress.prototype.text = function (text) {
+ this._text = text;
+ return this;
+};
+
+/**
+ * Set font size to `size`.
+ *
+ * @api public
+ * @param {number} size
+ * @return {Progress} Progress instance.
+ */
+Progress.prototype.fontSize = function (size) {
+ this._fontSize = size;
+ return this;
+};
+
+/**
+ * Set font to `family`.
+ *
+ * @param {string} family
+ * @return {Progress} Progress instance.
+ */
+Progress.prototype.font = function (family) {
+ this._font = family;
+ return this;
+};
+
+/**
+ * Update percentage to `n`.
+ *
+ * @param {number} n
+ * @return {Progress} Progress instance.
+ */
+Progress.prototype.update = function (n) {
+ this.percent = n;
+ return this;
+};
+
+/**
+ * Draw on `ctx`.
+ *
+ * @param {CanvasRenderingContext2d} ctx
+ * @return {Progress} Progress instance.
+ */
+Progress.prototype.draw = function (ctx) {
+ try {
+ var percent = Math.min(this.percent, 100);
+ var size = this._size;
+ var half = size / 2;
+ var x = half;
+ var y = half;
+ var rad = half - 1;
+ var fontSize = this._fontSize;
+
+ ctx.font = fontSize + 'px ' + this._font;
+
+ var angle = Math.PI * 2 * (percent / 100);
+ ctx.clearRect(0, 0, size, size);
+
+ // outer circle
+ ctx.strokeStyle = '#9f9f9f';
+ ctx.beginPath();
+ ctx.arc(x, y, rad, 0, angle, false);
+ ctx.stroke();
+
+ // inner circle
+ ctx.strokeStyle = '#eee';
+ ctx.beginPath();
+ ctx.arc(x, y, rad - 1, 0, angle, true);
+ ctx.stroke();
+
+ // text
+ var text = this._text || (percent | 0) + '%';
+ var w = ctx.measureText(text).width;
+
+ ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
+ } catch (err) {
+ // don't fail if we can't render progress
+ }
+ return this;
+};
+
+},{}],4:[function(require,module,exports){
+(function (global){
+'use strict';
+
+exports.isatty = function isatty () {
+ return true;
+};
+
+exports.getWindowSize = function getWindowSize () {
+ if ('innerHeight' in global) {
+ return [global.innerHeight, global.innerWidth];
+ }
+ // In a Web Worker, the DOM Window is not available.
+ return [640, 480];
+};
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{}],5:[function(require,module,exports){
+'use strict';
+
+/**
+ * Expose `Context`.
+ */
+
+module.exports = Context;
+
+/**
+ * Initialize a new `Context`.
+ *
+ * @api private
+ */
+function Context () {}
+
+/**
+ * Set or get the context `Runnable` to `runnable`.
+ *
+ * @api private
+ * @param {Runnable} runnable
+ * @return {Context}
+ */
+Context.prototype.runnable = function (runnable) {
+ if (!arguments.length) {
+ return this._runnable;
+ }
+ this.test = this._runnable = runnable;
+ return this;
+};
+
+/**
+ * Set test timeout `ms`.
+ *
+ * @api private
+ * @param {number} ms
+ * @return {Context} self
+ */
+Context.prototype.timeout = function (ms) {
+ if (!arguments.length) {
+ return this.runnable().timeout();
+ }
+ this.runnable().timeout(ms);
+ return this;
+};
+
+/**
+ * Set test timeout `enabled`.
+ *
+ * @api private
+ * @param {boolean} enabled
+ * @return {Context} self
+ */
+Context.prototype.enableTimeouts = function (enabled) {
+ this.runnable().enableTimeouts(enabled);
+ return this;
+};
+
+/**
+ * Set test slowness threshold `ms`.
+ *
+ * @api private
+ * @param {number} ms
+ * @return {Context} self
+ */
+Context.prototype.slow = function (ms) {
+ this.runnable().slow(ms);
+ return this;
+};
+
+/**
+ * Mark a test as skipped.
+ *
+ * @api private
+ * @throws Pending
+ */
+Context.prototype.skip = function () {
+ this.runnable().skip();
+};
+
+/**
+ * Allow a number of retries on failed tests
+ *
+ * @api private
+ * @param {number} n
+ * @return {Context} self
+ */
+Context.prototype.retries = function (n) {
+ if (!arguments.length) {
+ return this.runnable().retries();
+ }
+ this.runnable().retries(n);
+ return this;
+};
+
+/**
+ * Inspect the context void of `._runnable`.
+ *
+ * @api private
+ * @return {string}
+ */
+Context.prototype.inspect = function () {
+ return JSON.stringify(this, function (key, val) {
+ return key === 'runnable' || key === 'test' ? undefined : val;
+ }, 2);
+};
+
+},{}],6:[function(require,module,exports){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Runnable = require('./runnable');
+var inherits = require('./utils').inherits;
+
+/**
+ * Expose `Hook`.
+ */
+
+module.exports = Hook;
+
+/**
+ * Initialize a new `Hook` with the given `title` and callback `fn`.
+ *
+ * @param {String} title
+ * @param {Function} fn
+ * @api private
+ */
+function Hook (title, fn) {
+ Runnable.call(this, title, fn);
+ this.type = 'hook';
+}
+
+/**
+ * Inherit from `Runnable.prototype`.
+ */
+inherits(Hook, Runnable);
+
+/**
+ * Get or set the test `err`.
+ *
+ * @param {Error} err
+ * @return {Error}
+ * @api public
+ */
+Hook.prototype.error = function (err) {
+ if (!arguments.length) {
+ err = this._error;
+ this._error = null;
+ return err;
+ }
+
+ this._error = err;
+};
+
+},{"./runnable":32,"./utils":36}],7:[function(require,module,exports){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Test = require('../test');
+
+/**
+ * BDD-style interface:
+ *
+ * describe('Array', function() {
+ * describe('#indexOf()', function() {
+ * it('should return -1 when not present', function() {
+ * // ...
+ * });
+ *
+ * it('should return the index when present', function() {
+ * // ...
+ * });
+ * });
+ * });
+ *
+ * @param {Suite} suite Root suite.
+ */
+module.exports = function (suite) {
+ var suites = [suite];
+
+ suite.on('pre-require', function (context, file, mocha) {
+ var common = require('./common')(suites, context, mocha);
+
+ context.before = common.before;
+ context.after = common.after;
+ context.beforeEach = common.beforeEach;
+ context.afterEach = common.afterEach;
+ context.run = mocha.options.delay && common.runWithSuite(suite);
+ /**
+ * Describe a "suite" with the given `title`
+ * and callback `fn` containing nested suites
+ * and/or tests.
+ */
+
+ context.describe = context.context = function (title, fn) {
+ return common.suite.create({
+ title: title,
+ file: file,
+ fn: fn
+ });
+ };
+
+ /**
+ * Pending describe.
+ */
+
+ context.xdescribe = context.xcontext = context.describe.skip = function (title, fn) {
+ return common.suite.skip({
+ title: title,
+ file: file,
+ fn: fn
+ });
+ };
+
+ /**
+ * Exclusive suite.
+ */
+
+ context.describe.only = function (title, fn) {
+ return common.suite.only({
+ title: title,
+ file: file,
+ fn: fn
+ });
+ };
+
+ /**
+ * Describe a specification or test-case
+ * with the given `title` and callback `fn`
+ * acting as a thunk.
+ */
+
+ context.it = context.specify = function (title, fn) {
+ var suite = suites[0];
+ if (suite.isPending()) {
+ fn = null;
+ }
+ var test = new Test(title, fn);
+ test.file = file;
+ suite.addTest(test);
+ return test;
+ };
+
+ /**
+ * Exclusive test-case.
+ */
+
+ context.it.only = function (title, fn) {
+ return common.test.only(mocha, context.it(title, fn));
+ };
+
+ /**
+ * Pending test case.
+ */
+
+ context.xit = context.xspecify = context.it.skip = function (title) {
+ context.it(title);
+ };
+
+ /**
+ * Number of attempts to retry.
+ */
+ context.it.retries = function (n) {
+ context.retries(n);
+ };
+ });
+};
+
+},{"../test":35,"./common":8}],8:[function(require,module,exports){
+'use strict';
+
+var Suite = require('../suite');
+
+/**
+ * Functions common to more than one interface.
+ *
+ * @param {Suite[]} suites
+ * @param {Context} context
+ * @param {Mocha} mocha
+ * @return {Object} An object containing common functions.
+ */
+module.exports = function (suites, context, mocha) {
+ return {
+ /**
+ * This is only present if flag --delay is passed into Mocha. It triggers
+ * root suite execution.
+ *
+ * @param {Suite} suite The root suite.
+ * @return {Function} A function which runs the root suite
+ */
+ runWithSuite: function runWithSuite (suite) {
+ return function run () {
+ suite.run();
+ };
+ },
+
+ /**
+ * Execute before running tests.
+ *
+ * @param {string} name
+ * @param {Function} fn
+ */
+ before: function (name, fn) {
+ suites[0].beforeAll(name, fn);
+ },
+
+ /**
+ * Execute after running tests.
+ *
+ * @param {string} name
+ * @param {Function} fn
+ */
+ after: function (name, fn) {
+ suites[0].afterAll(name, fn);
+ },
+
+ /**
+ * Execute before each test case.
+ *
+ * @param {string} name
+ * @param {Function} fn
+ */
+ beforeEach: function (name, fn) {
+ suites[0].beforeEach(name, fn);
+ },
+
+ /**
+ * Execute after each test case.
+ *
+ * @param {string} name
+ * @param {Function} fn
+ */
+ afterEach: function (name, fn) {
+ suites[0].afterEach(name, fn);
+ },
+
+ suite: {
+ /**
+ * Create an exclusive Suite; convenience function
+ * See docstring for create() below.
+ *
+ * @param {Object} opts
+ * @returns {Suite}
+ */
+ only: function only (opts) {
+ opts.isOnly = true;
+ return this.create(opts);
+ },
+
+ /**
+ * Create a Suite, but skip it; convenience function
+ * See docstring for create() below.
+ *
+ * @param {Object} opts
+ * @returns {Suite}
+ */
+ skip: function skip (opts) {
+ opts.pending = true;
+ return this.create(opts);
+ },
+
+ /**
+ * Creates a suite.
+ * @param {Object} opts Options
+ * @param {string} opts.title Title of Suite
+ * @param {Function} [opts.fn] Suite Function (not always applicable)
+ * @param {boolean} [opts.pending] Is Suite pending?
+ * @param {string} [opts.file] Filepath where this Suite resides
+ * @param {boolean} [opts.isOnly] Is Suite exclusive?
+ * @returns {Suite}
+ */
+ create: function create (opts) {
+ var suite = Suite.create(suites[0], opts.title);
+ suite.pending = Boolean(opts.pending);
+ suite.file = opts.file;
+ suites.unshift(suite);
+ if (opts.isOnly) {
+ suite.parent._onlySuites = suite.parent._onlySuites.concat(suite);
+ }
+ if (typeof opts.fn === 'function') {
+ opts.fn.call(suite);
+ suites.shift();
+ } else if (typeof opts.fn === 'undefined' && !suite.pending) {
+ throw new Error('Suite "' + suite.fullTitle() + '" was defined but no callback was supplied. Supply a callback or explicitly skip the suite.');
+ }
+
+ return suite;
+ }
+ },
+
+ test: {
+
+ /**
+ * Exclusive test-case.
+ *
+ * @param {Object} mocha
+ * @param {Function} test
+ * @returns {*}
+ */
+ only: function (mocha, test) {
+ test.parent._onlyTests = test.parent._onlyTests.concat(test);
+ return test;
+ },
+
+ /**
+ * Pending test case.
+ *
+ * @param {string} title
+ */
+ skip: function (title) {
+ context.test(title);
+ },
+
+ /**
+ * Number of retry attempts
+ *
+ * @param {number} n
+ */
+ retries: function (n) {
+ context.retries(n);
+ }
+ }
+ };
+};
+
+},{"../suite":34}],9:[function(require,module,exports){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Suite = require('../suite');
+var Test = require('../test');
+
+/**
+ * Exports-style (as Node.js module) interface:
+ *
+ * exports.Array = {
+ * '#indexOf()': {
+ * 'should return -1 when the value is not present': function() {
+ *
+ * },
+ *
+ * 'should return the correct index when the value is present': function() {
+ *
+ * }
+ * }
+ * };
+ *
+ * @param {Suite} suite Root suite.
+ */
+module.exports = function (suite) {
+ var suites = [suite];
+
+ suite.on('require', visit);
+
+ function visit (obj, file) {
+ var suite;
+ for (var key in obj) {
+ if (typeof obj[key] === 'function') {
+ var fn = obj[key];
+ switch (key) {
+ case 'before':
+ suites[0].beforeAll(fn);
+ break;
+ case 'after':
+ suites[0].afterAll(fn);
+ break;
+ case 'beforeEach':
+ suites[0].beforeEach(fn);
+ break;
+ case 'afterEach':
+ suites[0].afterEach(fn);
+ break;
+ default:
+ var test = new Test(key, fn);
+ test.file = file;
+ suites[0].addTest(test);
+ }
+ } else {
+ suite = Suite.create(suites[0], key);
+ suites.unshift(suite);
+ visit(obj[key], file);
+ suites.shift();
+ }
+ }
+ }
+};
+
+},{"../suite":34,"../test":35}],10:[function(require,module,exports){
+'use strict';
+
+exports.bdd = require('./bdd');
+exports.tdd = require('./tdd');
+exports.qunit = require('./qunit');
+exports.exports = require('./exports');
+
+},{"./bdd":7,"./exports":9,"./qunit":11,"./tdd":12}],11:[function(require,module,exports){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Test = require('../test');
+
+/**
+ * QUnit-style interface:
+ *
+ * suite('Array');
+ *
+ * test('#length', function() {
+ * var arr = [1,2,3];
+ * ok(arr.length == 3);
+ * });
+ *
+ * test('#indexOf()', function() {
+ * var arr = [1,2,3];
+ * ok(arr.indexOf(1) == 0);
+ * ok(arr.indexOf(2) == 1);
+ * ok(arr.indexOf(3) == 2);
+ * });
+ *
+ * suite('String');
+ *
+ * test('#length', function() {
+ * ok('foo'.length == 3);
+ * });
+ *
+ * @param {Suite} suite Root suite.
+ */
+module.exports = function (suite) {
+ var suites = [suite];
+
+ suite.on('pre-require', function (context, file, mocha) {
+ var common = require('./common')(suites, context, mocha);
+
+ context.before = common.before;
+ context.after = common.after;
+ context.beforeEach = common.beforeEach;
+ context.afterEach = common.afterEach;
+ context.run = mocha.options.delay && common.runWithSuite(suite);
+ /**
+ * Describe a "suite" with the given `title`.
+ */
+
+ context.suite = function (title) {
+ if (suites.length > 1) {
+ suites.shift();
+ }
+ return common.suite.create({
+ title: title,
+ file: file,
+ fn: false
+ });
+ };
+
+ /**
+ * Exclusive Suite.
+ */
+
+ context.suite.only = function (title) {
+ if (suites.length > 1) {
+ suites.shift();
+ }
+ return common.suite.only({
+ title: title,
+ file: file,
+ fn: false
+ });
+ };
+
+ /**
+ * Describe a specification or test-case
+ * with the given `title` and callback `fn`
+ * acting as a thunk.
+ */
+
+ context.test = function (title, fn) {
+ var test = new Test(title, fn);
+ test.file = file;
+ suites[0].addTest(test);
+ return test;
+ };
+
+ /**
+ * Exclusive test-case.
+ */
+
+ context.test.only = function (title, fn) {
+ return common.test.only(mocha, context.test(title, fn));
+ };
+
+ context.test.skip = common.test.skip;
+ context.test.retries = common.test.retries;
+ });
+};
+
+},{"../test":35,"./common":8}],12:[function(require,module,exports){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Test = require('../test');
+
+/**
+ * TDD-style interface:
+ *
+ * suite('Array', function() {
+ * suite('#indexOf()', function() {
+ * suiteSetup(function() {
+ *
+ * });
+ *
+ * test('should return -1 when not present', function() {
+ *
+ * });
+ *
+ * test('should return the index when present', function() {
+ *
+ * });
+ *
+ * suiteTeardown(function() {
+ *
+ * });
+ * });
+ * });
+ *
+ * @param {Suite} suite Root suite.
+ */
+module.exports = function (suite) {
+ var suites = [suite];
+
+ suite.on('pre-require', function (context, file, mocha) {
+ var common = require('./common')(suites, context, mocha);
+
+ context.setup = common.beforeEach;
+ context.teardown = common.afterEach;
+ context.suiteSetup = common.before;
+ context.suiteTeardown = common.after;
+ context.run = mocha.options.delay && common.runWithSuite(suite);
+
+ /**
+ * Describe a "suite" with the given `title` and callback `fn` containing
+ * nested suites and/or tests.
+ */
+ context.suite = function (title, fn) {
+ return common.suite.create({
+ title: title,
+ file: file,
+ fn: fn
+ });
+ };
+
+ /**
+ * Pending suite.
+ */
+ context.suite.skip = function (title, fn) {
+ return common.suite.skip({
+ title: title,
+ file: file,
+ fn: fn
+ });
+ };
+
+ /**
+ * Exclusive test-case.
+ */
+ context.suite.only = function (title, fn) {
+ return common.suite.only({
+ title: title,
+ file: file,
+ fn: fn
+ });
+ };
+
+ /**
+ * Describe a specification or test-case with the given `title` and
+ * callback `fn` acting as a thunk.
+ */
+ context.test = function (title, fn) {
+ var suite = suites[0];
+ if (suite.isPending()) {
+ fn = null;
+ }
+ var test = new Test(title, fn);
+ test.file = file;
+ suite.addTest(test);
+ return test;
+ };
+
+ /**
+ * Exclusive test-case.
+ */
+
+ context.test.only = function (title, fn) {
+ return common.test.only(mocha, context.test(title, fn));
+ };
+
+ context.test.skip = common.test.skip;
+ context.test.retries = common.test.retries;
+ });
+};
+
+},{"../test":35,"./common":8}],13:[function(require,module,exports){
+(function (process,global,__dirname){
+'use strict';
+
+/*!
+ * mocha
+ * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var escapeRe = require('escape-string-regexp');
+var path = require('path');
+var reporters = require('./reporters');
+var utils = require('./utils');
+
+/**
+ * Expose `Mocha`.
+ */
+
+exports = module.exports = Mocha;
+
+/**
+ * To require local UIs and reporters when running in node.
+ */
+
+if (!process.browser) {
+ var cwd = process.cwd();
+ module.paths.push(cwd, path.join(cwd, 'node_modules'));
+}
+
+/**
+ * Expose internals.
+ */
+
+exports.utils = utils;
+exports.interfaces = require('./interfaces');
+exports.reporters = reporters;
+exports.Runnable = require('./runnable');
+exports.Context = require('./context');
+exports.Runner = require('./runner');
+exports.Suite = require('./suite');
+exports.Hook = require('./hook');
+exports.Test = require('./test');
+
+/**
+ * Return image `name` path.
+ *
+ * @api private
+ * @param {string} name
+ * @return {string}
+ */
+function image (name) {
+ return path.join(__dirname, '../images', name + '.png');
+}
+
+/**
+ * Set up mocha with `options`.
+ *
+ * Options:
+ *
+ * - `ui` name "bdd", "tdd", "exports" etc
+ * - `reporter` reporter instance, defaults to `mocha.reporters.spec`
+ * - `globals` array of accepted globals
+ * - `timeout` timeout in milliseconds
+ * - `retries` number of times to retry failed tests
+ * - `bail` bail on the first test failure
+ * - `slow` milliseconds to wait before considering a test slow
+ * - `ignoreLeaks` ignore global leaks
+ * - `fullTrace` display the full stack-trace on failing
+ * - `grep` string or regexp to filter tests with
+ *
+ * @param {Object} options
+ * @api public
+ */
+function Mocha (options) {
+ options = options || {};
+ this.files = [];
+ this.options = options;
+ if (options.grep) {
+ this.grep(new RegExp(options.grep));
+ }
+ if (options.fgrep) {
+ this.fgrep(options.fgrep);
+ }
+ this.suite = new exports.Suite('', new exports.Context());
+ this.ui(options.ui);
+ this.bail(options.bail);
+ this.reporter(options.reporter, options.reporterOptions);
+ if (typeof options.timeout !== 'undefined' && options.timeout !== null) {
+ this.timeout(options.timeout);
+ }
+ if (typeof options.retries !== 'undefined' && options.retries !== null) {
+ this.retries(options.retries);
+ }
+ this.useColors(options.useColors);
+ if (options.enableTimeouts !== null) {
+ this.enableTimeouts(options.enableTimeouts);
+ }
+ if (options.slow) {
+ this.slow(options.slow);
+ }
+}
+
+/**
+ * Enable or disable bailing on the first failure.
+ *
+ * @api public
+ * @param {boolean} [bail]
+ */
+Mocha.prototype.bail = function (bail) {
+ if (!arguments.length) {
+ bail = true;
+ }
+ this.suite.bail(bail);
+ return this;
+};
+
+/**
+ * Add test `file`.
+ *
+ * @api public
+ * @param {string} file
+ */
+Mocha.prototype.addFile = function (file) {
+ this.files.push(file);
+ return this;
+};
+
+/**
+ * Set reporter to `reporter`, defaults to "spec".
+ *
+ * @param {String|Function} reporter name or constructor
+ * @param {Object} reporterOptions optional options
+ * @api public
+ * @param {string|Function} reporter name or constructor
+ * @param {Object} reporterOptions optional options
+ */
+Mocha.prototype.reporter = function (reporter, reporterOptions) {
+ if (typeof reporter === 'function') {
+ this._reporter = reporter;
+ } else {
+ reporter = reporter || 'spec';
+ var _reporter;
+ // Try to load a built-in reporter.
+ if (reporters[reporter]) {
+ _reporter = reporters[reporter];
+ }
+ // Try to load reporters from process.cwd() and node_modules
+ if (!_reporter) {
+ try {
+ _reporter = require(reporter);
+ } catch (err) {
+ if (err.message.indexOf('Cannot find module') !== -1) {
+ // Try to load reporters from a path (absolute or relative)
+ try {
+ _reporter = require(path.resolve(process.cwd(), reporter));
+ } catch (_err) {
+ err.message.indexOf('Cannot find module') !== -1 ? console.warn('"' + reporter + '" reporter not found')
+ : console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
+ }
+ } else {
+ console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
+ }
+ }
+ }
+ if (!_reporter && reporter === 'teamcity') {
+ console.warn('The Teamcity reporter was moved to a package named ' +
+ 'mocha-teamcity-reporter ' +
+ '(https://npmjs.org/package/mocha-teamcity-reporter).');
+ }
+ if (!_reporter) {
+ throw new Error('invalid reporter "' + reporter + '"');
+ }
+ this._reporter = _reporter;
+ }
+ this.options.reporterOptions = reporterOptions;
+ return this;
+};
+
+/**
+ * Set test UI `name`, defaults to "bdd".
+ *
+ * @api public
+ * @param {string} bdd
+ */
+Mocha.prototype.ui = function (name) {
+ name = name || 'bdd';
+ this._ui = exports.interfaces[name];
+ if (!this._ui) {
+ try {
+ this._ui = require(name);
+ } catch (err) {
+ throw new Error('invalid interface "' + name + '"');
+ }
+ }
+ this._ui = this._ui(this.suite);
+
+ this.suite.on('pre-require', function (context) {
+ exports.afterEach = context.afterEach || context.teardown;
+ exports.after = context.after || context.suiteTeardown;
+ exports.beforeEach = context.beforeEach || context.setup;
+ exports.before = context.before || context.suiteSetup;
+ exports.describe = context.describe || context.suite;
+ exports.it = context.it || context.test;
+ exports.xit = context.xit || context.test.skip;
+ exports.setup = context.setup || context.beforeEach;
+ exports.suiteSetup = context.suiteSetup || context.before;
+ exports.suiteTeardown = context.suiteTeardown || context.after;
+ exports.suite = context.suite || context.describe;
+ exports.teardown = context.teardown || context.afterEach;
+ exports.test = context.test || context.it;
+ exports.run = context.run;
+ });
+
+ return this;
+};
+
+/**
+ * Load registered files.
+ *
+ * @api private
+ */
+Mocha.prototype.loadFiles = function (fn) {
+ var self = this;
+ var suite = this.suite;
+ this.files.forEach(function (file) {
+ file = path.resolve(file);
+ suite.emit('pre-require', global, file, self);
+ suite.emit('require', require(file), file, self);
+ suite.emit('post-require', global, file, self);
+ });
+ fn && fn();
+};
+
+/**
+ * Enable growl support.
+ *
+ * @api private
+ */
+Mocha.prototype._growl = function (runner, reporter) {
+ var notify = require('growl');
+
+ runner.on('end', function () {
+ var stats = reporter.stats;
+ if (stats.failures) {
+ var msg = stats.failures + ' of ' + runner.total + ' tests failed';
+ notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
+ } else {
+ notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
+ name: 'mocha',
+ title: 'Passed',
+ image: image('ok')
+ });
+ }
+ });
+};
+
+/**
+ * Escape string and add it to grep as a regexp.
+ *
+ * @api public
+ * @param str
+ * @returns {Mocha}
+ */
+Mocha.prototype.fgrep = function (str) {
+ return this.grep(new RegExp(escapeRe(str)));
+};
+
+/**
+ * Add regexp to grep, if `re` is a string it is escaped.
+ *
+ * @param {RegExp|String} re
+ * @return {Mocha}
+ * @api public
+ * @param {RegExp|string} re
+ * @return {Mocha}
+ */
+Mocha.prototype.grep = function (re) {
+ if (utils.isString(re)) {
+ // extract args if it's regex-like, i.e: [string, pattern, flag]
+ var arg = re.match(/^\/(.*)\/(g|i|)$|.*/);
+ this.options.grep = new RegExp(arg[1] || arg[0], arg[2]);
+ } else {
+ this.options.grep = re;
+ }
+ return this;
+};
+/**
+ * Invert `.grep()` matches.
+ *
+ * @return {Mocha}
+ * @api public
+ */
+Mocha.prototype.invert = function () {
+ this.options.invert = true;
+ return this;
+};
+
+/**
+ * Ignore global leaks.
+ *
+ * @param {Boolean} ignore
+ * @return {Mocha}
+ * @api public
+ * @param {boolean} ignore
+ * @return {Mocha}
+ */
+Mocha.prototype.ignoreLeaks = function (ignore) {
+ this.options.ignoreLeaks = Boolean(ignore);
+ return this;
+};
+
+/**
+ * Enable global leak checking.
+ *
+ * @return {Mocha}
+ * @api public
+ */
+Mocha.prototype.checkLeaks = function () {
+ this.options.ignoreLeaks = false;
+ return this;
+};
+
+/**
+ * Display long stack-trace on failing
+ *
+ * @return {Mocha}
+ * @api public
+ */
+Mocha.prototype.fullTrace = function () {
+ this.options.fullStackTrace = true;
+ return this;
+};
+
+/**
+ * Enable growl support.
+ *
+ * @return {Mocha}
+ * @api public
+ */
+Mocha.prototype.growl = function () {
+ this.options.growl = true;
+ return this;
+};
+
+/**
+ * Ignore `globals` array or string.
+ *
+ * @param {Array|String} globals
+ * @return {Mocha}
+ * @api public
+ * @param {Array|string} globals
+ * @return {Mocha}
+ */
+Mocha.prototype.globals = function (globals) {
+ this.options.globals = (this.options.globals || []).concat(globals);
+ return this;
+};
+
+/**
+ * Emit color output.
+ *
+ * @param {Boolean} colors
+ * @return {Mocha}
+ * @api public
+ * @param {boolean} colors
+ * @return {Mocha}
+ */
+Mocha.prototype.useColors = function (colors) {
+ if (colors !== undefined) {
+ this.options.useColors = colors;
+ }
+ return this;
+};
+
+/**
+ * Use inline diffs rather than +/-.
+ *
+ * @param {Boolean} inlineDiffs
+ * @return {Mocha}
+ * @api public
+ * @param {boolean} inlineDiffs
+ * @return {Mocha}
+ */
+Mocha.prototype.useInlineDiffs = function (inlineDiffs) {
+ this.options.useInlineDiffs = inlineDiffs !== undefined && inlineDiffs;
+ return this;
+};
+
+/**
+ * Set the timeout in milliseconds.
+ *
+ * @param {Number} timeout
+ * @return {Mocha}
+ * @api public
+ * @param {number} timeout
+ * @return {Mocha}
+ */
+Mocha.prototype.timeout = function (timeout) {
+ this.suite.timeout(timeout);
+ return this;
+};
+
+/**
+ * Set the number of times to retry failed tests.
+ *
+ * @param {Number} retry times
+ * @return {Mocha}
+ * @api public
+ */
+Mocha.prototype.retries = function (n) {
+ this.suite.retries(n);
+ return this;
+};
+
+/**
+ * Set slowness threshold in milliseconds.
+ *
+ * @param {Number} slow
+ * @return {Mocha}
+ * @api public
+ * @param {number} slow
+ * @return {Mocha}
+ */
+Mocha.prototype.slow = function (slow) {
+ this.suite.slow(slow);
+ return this;
+};
+
+/**
+ * Enable timeouts.
+ *
+ * @param {Boolean} enabled
+ * @return {Mocha}
+ * @api public
+ * @param {boolean} enabled
+ * @return {Mocha}
+ */
+Mocha.prototype.enableTimeouts = function (enabled) {
+ this.suite.enableTimeouts(arguments.length && enabled !== undefined ? enabled : true);
+ return this;
+};
+
+/**
+ * Makes all tests async (accepting a callback)
+ *
+ * @return {Mocha}
+ * @api public
+ */
+Mocha.prototype.asyncOnly = function () {
+ this.options.asyncOnly = true;
+ return this;
+};
+
+/**
+ * Disable syntax highlighting (in browser).
+ *
+ * @api public
+ */
+Mocha.prototype.noHighlighting = function () {
+ this.options.noHighlighting = true;
+ return this;
+};
+
+/**
+ * Enable uncaught errors to propagate (in browser).
+ *
+ * @return {Mocha}
+ * @api public
+ */
+Mocha.prototype.allowUncaught = function () {
+ this.options.allowUncaught = true;
+ return this;
+};
+
+/**
+ * Delay root suite execution.
+ * @returns {Mocha}
+ */
+Mocha.prototype.delay = function delay () {
+ this.options.delay = true;
+ return this;
+};
+
+/**
+ * Tests marked only fail the suite
+ * @returns {Mocha}
+ */
+Mocha.prototype.forbidOnly = function () {
+ this.options.forbidOnly = true;
+ return this;
+};
+
+/**
+ * Pending tests and tests marked skip fail the suite
+ * @returns {Mocha}
+ */
+Mocha.prototype.forbidPending = function () {
+ this.options.forbidPending = true;
+ return this;
+};
+
+/**
+ * Run tests and invoke `fn()` when complete.
+ *
+ * @api public
+ * @param {Function} fn
+ * @return {Runner}
+ */
+Mocha.prototype.run = function (fn) {
+ if (this.files.length) {
+ this.loadFiles();
+ }
+ var suite = this.suite;
+ var options = this.options;
+ options.files = this.files;
+ var runner = new exports.Runner(suite, options.delay);
+ var reporter = new this._reporter(runner, options);
+ runner.ignoreLeaks = options.ignoreLeaks !== false;
+ runner.fullStackTrace = options.fullStackTrace;
+ runner.asyncOnly = options.asyncOnly;
+ runner.allowUncaught = options.allowUncaught;
+ runner.forbidOnly = options.forbidOnly;
+ runner.forbidPending = options.forbidPending;
+ if (options.grep) {
+ runner.grep(options.grep, options.invert);
+ }
+ if (options.globals) {
+ runner.globals(options.globals);
+ }
+ if (options.growl) {
+ this._growl(runner, reporter);
+ }
+ if (options.useColors !== undefined) {
+ exports.reporters.Base.useColors = options.useColors;
+ }
+ exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
+
+ function done (failures) {
+ if (reporter.done) {
+ reporter.done(failures, fn);
+ } else {
+ fn && fn(failures);
+ }
+ }
+
+ return runner.run(done);
+};
+
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},"/lib")
+},{"./context":5,"./hook":6,"./interfaces":10,"./reporters":20,"./runnable":32,"./runner":33,"./suite":34,"./test":35,"./utils":36,"_process":55,"escape-string-regexp":45,"growl":2,"path":40}],14:[function(require,module,exports){
+'use strict';
+
+/**
+ * Helpers.
+ */
+
+var s = 1000;
+var m = s * 60;
+var h = m * 60;
+var d = h * 24;
+var y = d * 365.25;
+
+/**
+ * Parse or format the given `val`.
+ *
+ * Options:
+ *
+ * - `long` verbose formatting [false]
+ *
+ * @api public
+ * @param {string|number} val
+ * @param {Object} options
+ * @return {string|number}
+ */
+module.exports = function (val, options) {
+ options = options || {};
+ if (typeof val === 'string') {
+ return parse(val);
+ }
+ // https://github.com/mochajs/mocha/pull/1035
+ return options['long'] ? longFormat(val) : shortFormat(val);
+};
+
+/**
+ * Parse the given `str` and return milliseconds.
+ *
+ * @api private
+ * @param {string} str
+ * @return {number}
+ */
+function parse (str) {
+ var match = (/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i).exec(str);
+ if (!match) {
+ return;
+ }
+ var n = parseFloat(match[1]);
+ var type = (match[2] || 'ms').toLowerCase();
+ switch (type) {
+ case 'years':
+ case 'year':
+ case 'y':
+ return n * y;
+ case 'days':
+ case 'day':
+ case 'd':
+ return n * d;
+ case 'hours':
+ case 'hour':
+ case 'h':
+ return n * h;
+ case 'minutes':
+ case 'minute':
+ case 'm':
+ return n * m;
+ case 'seconds':
+ case 'second':
+ case 's':
+ return n * s;
+ case 'ms':
+ return n;
+ default:
+ // No default case
+ }
+}
+
+/**
+ * Short format for `ms`.
+ *
+ * @api private
+ * @param {number} ms
+ * @return {string}
+ */
+function shortFormat (ms) {
+ if (ms >= d) {
+ return Math.round(ms / d) + 'd';
+ }
+ if (ms >= h) {
+ return Math.round(ms / h) + 'h';
+ }
+ if (ms >= m) {
+ return Math.round(ms / m) + 'm';
+ }
+ if (ms >= s) {
+ return Math.round(ms / s) + 's';
+ }
+ return ms + 'ms';
+}
+
+/**
+ * Long format for `ms`.
+ *
+ * @api private
+ * @param {number} ms
+ * @return {string}
+ */
+function longFormat (ms) {
+ return plural(ms, d, 'day') ||
+ plural(ms, h, 'hour') ||
+ plural(ms, m, 'minute') ||
+ plural(ms, s, 'second') ||
+ ms + ' ms';
+}
+
+/**
+ * Pluralization helper.
+ *
+ * @api private
+ * @param {number} ms
+ * @param {number} n
+ * @param {string} name
+ */
+function plural (ms, n, name) {
+ if (ms < n) {
+ return;
+ }
+ if (ms < n * 1.5) {
+ return Math.floor(ms / n) + ' ' + name;
+ }
+ return Math.ceil(ms / n) + ' ' + name + 's';
+}
+
+},{}],15:[function(require,module,exports){
+'use strict';
+
+/**
+ * Expose `Pending`.
+ */
+
+module.exports = Pending;
+
+/**
+ * Initialize a new `Pending` error with the given message.
+ *
+ * @param {string} message
+ */
+function Pending (message) {
+ this.message = message;
+}
+
+},{}],16:[function(require,module,exports){
+(function (process,global){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var tty = require('tty');
+var diff = require('diff');
+var ms = require('../ms');
+var utils = require('../utils');
+var supportsColor = process.browser ? null : require('supports-color');
+
+/**
+ * Expose `Base`.
+ */
+
+exports = module.exports = Base;
+
+/**
+ * Save timer references to avoid Sinon interfering.
+ * See: https://github.com/mochajs/mocha/issues/237
+ */
+
+/* eslint-disable no-unused-vars, no-native-reassign */
+var Date = global.Date;
+var setTimeout = global.setTimeout;
+var setInterval = global.setInterval;
+var clearTimeout = global.clearTimeout;
+var clearInterval = global.clearInterval;
+/* eslint-enable no-unused-vars, no-native-reassign */
+
+/**
+ * Check if both stdio streams are associated with a tty.
+ */
+
+var isatty = tty.isatty(1) && tty.isatty(2);
+
+/**
+ * Enable coloring by default, except in the browser interface.
+ */
+
+exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
+
+/**
+ * Inline diffs instead of +/-
+ */
+
+exports.inlineDiffs = false;
+
+/**
+ * Default color map.
+ */
+
+exports.colors = {
+ pass: 90,
+ fail: 31,
+ 'bright pass': 92,
+ 'bright fail': 91,
+ 'bright yellow': 93,
+ pending: 36,
+ suite: 0,
+ 'error title': 0,
+ 'error message': 31,
+ 'error stack': 90,
+ checkmark: 32,
+ fast: 90,
+ medium: 33,
+ slow: 31,
+ green: 32,
+ light: 90,
+ 'diff gutter': 90,
+ 'diff added': 32,
+ 'diff removed': 31
+};
+
+/**
+ * Default symbol map.
+ */
+
+exports.symbols = {
+ ok: '✓',
+ err: '✖',
+ dot: '․',
+ comma: ',',
+ bang: '!'
+};
+
+// With node.js on Windows: use symbols available in terminal default fonts
+if (process.platform === 'win32') {
+ exports.symbols.ok = '\u221A';
+ exports.symbols.err = '\u00D7';
+ exports.symbols.dot = '.';
+}
+
+/**
+ * Color `str` with the given `type`,
+ * allowing colors to be disabled,
+ * as well as user-defined color
+ * schemes.
+ *
+ * @param {string} type
+ * @param {string} str
+ * @return {string}
+ * @api private
+ */
+var color = exports.color = function (type, str) {
+ if (!exports.useColors) {
+ return String(str);
+ }
+ return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
+};
+
+/**
+ * Expose term window size, with some defaults for when stderr is not a tty.
+ */
+
+exports.window = {
+ width: 75
+};
+
+if (isatty) {
+ exports.window.width = process.stdout.getWindowSize
+ ? process.stdout.getWindowSize(1)[0]
+ : tty.getWindowSize()[1];
+}
+
+/**
+ * Expose some basic cursor interactions that are common among reporters.
+ */
+
+exports.cursor = {
+ hide: function () {
+ isatty && process.stdout.write('\u001b[?25l');
+ },
+
+ show: function () {
+ isatty && process.stdout.write('\u001b[?25h');
+ },
+
+ deleteLine: function () {
+ isatty && process.stdout.write('\u001b[2K');
+ },
+
+ beginningOfLine: function () {
+ isatty && process.stdout.write('\u001b[0G');
+ },
+
+ CR: function () {
+ if (isatty) {
+ exports.cursor.deleteLine();
+ exports.cursor.beginningOfLine();
+ } else {
+ process.stdout.write('\r');
+ }
+ }
+};
+
+/**
+ * Output the given `failures` as a list.
+ *
+ * @param {Array} failures
+ * @api public
+ */
+
+exports.list = function (failures) {
+ console.log();
+ failures.forEach(function (test, i) {
+ // format
+ var fmt = color('error title', ' %s) %s:\n') +
+ color('error message', ' %s') +
+ color('error stack', '\n%s\n');
+
+ // msg
+ var msg;
+ var err = test.err;
+ var message;
+ if (err.message && typeof err.message.toString === 'function') {
+ message = err.message + '';
+ } else if (typeof err.inspect === 'function') {
+ message = err.inspect() + '';
+ } else {
+ message = '';
+ }
+ var stack = err.stack || message;
+ var index = message ? stack.indexOf(message) : -1;
+ var actual = err.actual;
+ var expected = err.expected;
+ var escape = true;
+
+ if (index === -1) {
+ msg = message;
+ } else {
+ index += message.length;
+ msg = stack.slice(0, index);
+ // remove msg from stack
+ stack = stack.slice(index + 1);
+ }
+
+ // uncaught
+ if (err.uncaught) {
+ msg = 'Uncaught ' + msg;
+ }
+ // explicitly show diff
+ if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
+ escape = false;
+ if (!(utils.isString(actual) && utils.isString(expected))) {
+ err.actual = actual = utils.stringify(actual);
+ err.expected = expected = utils.stringify(expected);
+ }
+
+ fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
+ var match = message.match(/^([^:]+): expected/);
+ msg = '\n ' + color('error message', match ? match[1] : msg);
+
+ if (exports.inlineDiffs) {
+ msg += inlineDiff(err, escape);
+ } else {
+ msg += unifiedDiff(err, escape);
+ }
+ }
+
+ // indent stack trace
+ stack = stack.replace(/^/gm, ' ');
+
+ // indented test title
+ var testTitle = '';
+ test.titlePath().forEach(function (str, index) {
+ if (index !== 0) {
+ testTitle += '\n ';
+ }
+ for (var i = 0; i < index; i++) {
+ testTitle += ' ';
+ }
+ testTitle += str;
+ });
+
+ console.log(fmt, (i + 1), testTitle, msg, stack);
+ });
+};
+
+/**
+ * Initialize a new `Base` reporter.
+ *
+ * All other reporters generally
+ * inherit from this reporter, providing
+ * stats such as test duration, number
+ * of tests passed / failed etc.
+ *
+ * @param {Runner} runner
+ * @api public
+ */
+
+function Base (runner) {
+ var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
+ var failures = this.failures = [];
+
+ if (!runner) {
+ return;
+ }
+ this.runner = runner;
+
+ runner.stats = stats;
+
+ runner.on('start', function () {
+ stats.start = new Date();
+ });
+
+ runner.on('suite', function (suite) {
+ stats.suites = stats.suites || 0;
+ suite.root || stats.suites++;
+ });
+
+ runner.on('test end', function () {
+ stats.tests = stats.tests || 0;
+ stats.tests++;
+ });
+
+ runner.on('pass', function (test) {
+ stats.passes = stats.passes || 0;
+
+ if (test.duration > test.slow()) {
+ test.speed = 'slow';
+ } else if (test.duration > test.slow() / 2) {
+ test.speed = 'medium';
+ } else {
+ test.speed = 'fast';
+ }
+
+ stats.passes++;
+ });
+
+ runner.on('fail', function (test, err) {
+ stats.failures = stats.failures || 0;
+ stats.failures++;
+ test.err = err;
+ failures.push(test);
+ });
+
+ runner.on('end', function () {
+ stats.end = new Date();
+ stats.duration = new Date() - stats.start;
+ });
+
+ runner.on('pending', function () {
+ stats.pending++;
+ });
+}
+
+/**
+ * Output common epilogue used by many of
+ * the bundled reporters.
+ *
+ * @api public
+ */
+Base.prototype.epilogue = function () {
+ var stats = this.stats;
+ var fmt;
+
+ console.log();
+
+ // passes
+ fmt = color('bright pass', ' ') +
+ color('green', ' %d passing') +
+ color('light', ' (%s)');
+
+ console.log(fmt,
+ stats.passes || 0,
+ ms(stats.duration));
+
+ // pending
+ if (stats.pending) {
+ fmt = color('pending', ' ') +
+ color('pending', ' %d pending');
+
+ console.log(fmt, stats.pending);
+ }
+
+ // failures
+ if (stats.failures) {
+ fmt = color('fail', ' %d failing');
+
+ console.log(fmt, stats.failures);
+
+ Base.list(this.failures);
+ console.log();
+ }
+
+ console.log();
+};
+
+/**
+ * Pad the given `str` to `len`.
+ *
+ * @api private
+ * @param {string} str
+ * @param {string} len
+ * @return {string}
+ */
+function pad (str, len) {
+ str = String(str);
+ return Array(len - str.length + 1).join(' ') + str;
+}
+
+/**
+ * Returns an inline diff between 2 strings with coloured ANSI output
+ *
+ * @api private
+ * @param {Error} err with actual/expected
+ * @param {boolean} escape
+ * @return {string} Diff
+ */
+function inlineDiff (err, escape) {
+ var msg = errorDiff(err, 'WordsWithSpace', escape);
+
+ // linenos
+ var lines = msg.split('\n');
+ if (lines.length > 4) {
+ var width = String(lines.length).length;
+ msg = lines.map(function (str, i) {
+ return pad(++i, width) + ' |' + ' ' + str;
+ }).join('\n');
+ }
+
+ // legend
+ msg = '\n' +
+ color('diff removed', 'actual') +
+ ' ' +
+ color('diff added', 'expected') +
+ '\n\n' +
+ msg +
+ '\n';
+
+ // indent
+ msg = msg.replace(/^/gm, ' ');
+ return msg;
+}
+
+/**
+ * Returns a unified diff between two strings.
+ *
+ * @api private
+ * @param {Error} err with actual/expected
+ * @param {boolean} escape
+ * @return {string} The diff.
+ */
+function unifiedDiff (err, escape) {
+ var indent = ' ';
+ function cleanUp (line) {
+ if (escape) {
+ line = escapeInvisibles(line);
+ }
+ if (line[0] === '+') {
+ return indent + colorLines('diff added', line);
+ }
+ if (line[0] === '-') {
+ return indent + colorLines('diff removed', line);
+ }
+ if (line.match(/@@/)) {
+ return '--';
+ }
+ if (line.match(/\\ No newline/)) {
+ return null;
+ }
+ return indent + line;
+ }
+ function notBlank (line) {
+ return typeof line !== 'undefined' && line !== null;
+ }
+ var msg = diff.createPatch('string', err.actual, err.expected);
+ var lines = msg.split('\n').splice(5);
+ return '\n ' +
+ colorLines('diff added', '+ expected') + ' ' +
+ colorLines('diff removed', '- actual') +
+ '\n\n' +
+ lines.map(cleanUp).filter(notBlank).join('\n');
+}
+
+/**
+ * Return a character diff for `err`.
+ *
+ * @api private
+ * @param {Error} err
+ * @param {string} type
+ * @param {boolean} escape
+ * @return {string}
+ */
+function errorDiff (err, type, escape) {
+ var actual = escape ? escapeInvisibles(err.actual) : err.actual;
+ var expected = escape ? escapeInvisibles(err.expected) : err.expected;
+ return diff['diff' + type](actual, expected).map(function (str) {
+ if (str.added) {
+ return colorLines('diff added', str.value);
+ }
+ if (str.removed) {
+ return colorLines('diff removed', str.value);
+ }
+ return str.value;
+ }).join('');
+}
+
+/**
+ * Returns a string with all invisible characters in plain text
+ *
+ * @api private
+ * @param {string} line
+ * @return {string}
+ */
+function escapeInvisibles (line) {
+ return line.replace(/\t/g, '<tab>')
+ .replace(/\r/g, '<CR>')
+ .replace(/\n/g, '<LF>\n');
+}
+
+/**
+ * Color lines for `str`, using the color `name`.
+ *
+ * @api private
+ * @param {string} name
+ * @param {string} str
+ * @return {string}
+ */
+function colorLines (name, str) {
+ return str.split('\n').map(function (str) {
+ return color(name, str);
+ }).join('\n');
+}
+
+/**
+ * Object#toString reference.
+ */
+var objToString = Object.prototype.toString;
+
+/**
+ * Check that a / b have the same type.
+ *
+ * @api private
+ * @param {Object} a
+ * @param {Object} b
+ * @return {boolean}
+ */
+function sameType (a, b) {
+ return objToString.call(a) === objToString.call(b);
+}
+
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"../ms":14,"../utils":36,"_process":55,"diff":44,"supports-color":40,"tty":4}],17:[function(require,module,exports){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var utils = require('../utils');
+
+/**
+ * Expose `Doc`.
+ */
+
+exports = module.exports = Doc;
+
+/**
+ * Initialize a new `Doc` reporter.
+ *
+ * @param {Runner} runner
+ * @api public
+ */
+function Doc (runner) {
+ Base.call(this, runner);
+
+ var indents = 2;
+
+ function indent () {
+ return Array(indents).join(' ');
+ }
+
+ runner.on('suite', function (suite) {
+ if (suite.root) {
+ return;
+ }
+ ++indents;
+ console.log('%s<section class="suite">', indent());
+ ++indents;
+ console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
+ console.log('%s<dl>', indent());
+ });
+
+ runner.on('suite end', function (suite) {
+ if (suite.root) {
+ return;
+ }
+ console.log('%s</dl>', indent());
+ --indents;
+ console.log('%s</section>', indent());
+ --indents;
+ });
+
+ runner.on('pass', function (test) {
+ console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
+ var code = utils.escape(utils.clean(test.body));
+ console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
+ });
+
+ runner.on('fail', function (test, err) {
+ console.log('%s <dt class="error">%s</dt>', indent(), utils.escape(test.title));
+ var code = utils.escape(utils.clean(test.body));
+ console.log('%s <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
+ console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
+ });
+}
+
+},{"../utils":36,"./base":16}],18:[function(require,module,exports){
+(function (process){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var inherits = require('../utils').inherits;
+var color = Base.color;
+
+/**
+ * Expose `Dot`.
+ */
+
+exports = module.exports = Dot;
+
+/**
+ * Initialize a new `Dot` matrix test reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function Dot (runner) {
+ Base.call(this, runner);
+
+ var self = this;
+ var width = Base.window.width * 0.75 | 0;
+ var n = -1;
+
+ runner.on('start', function () {
+ process.stdout.write('\n');
+ });
+
+ runner.on('pending', function () {
+ if (++n % width === 0) {
+ process.stdout.write('\n ');
+ }
+ process.stdout.write(color('pending', Base.symbols.comma));
+ });
+
+ runner.on('pass', function (test) {
+ if (++n % width === 0) {
+ process.stdout.write('\n ');
+ }
+ if (test.speed === 'slow') {
+ process.stdout.write(color('bright yellow', Base.symbols.dot));
+ } else {
+ process.stdout.write(color(test.speed, Base.symbols.dot));
+ }
+ });
+
+ runner.on('fail', function () {
+ if (++n % width === 0) {
+ process.stdout.write('\n ');
+ }
+ process.stdout.write(color('fail', Base.symbols.bang));
+ });
+
+ runner.on('end', function () {
+ console.log();
+ self.epilogue();
+ });
+}
+
+/**
+ * Inherit from `Base.prototype`.
+ */
+inherits(Dot, Base);
+
+}).call(this,require('_process'))
+},{"../utils":36,"./base":16,"_process":55}],19:[function(require,module,exports){
+(function (global){
+'use strict';
+
+/* eslint-env browser */
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var utils = require('../utils');
+var Progress = require('../browser/progress');
+var escapeRe = require('escape-string-regexp');
+var escape = utils.escape;
+
+/**
+ * Save timer references to avoid Sinon interfering (see GH-237).
+ */
+
+/* eslint-disable no-unused-vars, no-native-reassign */
+var Date = global.Date;
+var setTimeout = global.setTimeout;
+var setInterval = global.setInterval;
+var clearTimeout = global.clearTimeout;
+var clearInterval = global.clearInterval;
+/* eslint-enable no-unused-vars, no-native-reassign */
+
+/**
+ * Expose `HTML`.
+ */
+
+exports = module.exports = HTML;
+
+/**
+ * Stats template.
+ */
+
+var statsTemplate = '<ul id="mocha-stats">' +
+ '<li class="progress"><canvas width="40" height="40"></canvas></li>' +
+ '<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
+ '<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
+ '<li class="duration">duration: <em>0</em>s</li>' +
+ '</ul>';
+
+var playIcon = '‣';
+
+/**
+ * Initialize a new `HTML` reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function HTML (runner) {
+ Base.call(this, runner);
+
+ var self = this;
+ var stats = this.stats;
+ var stat = fragment(statsTemplate);
+ var items = stat.getElementsByTagName('li');
+ var passes = items[1].getElementsByTagName('em')[0];
+ var passesLink = items[1].getElementsByTagName('a')[0];
+ var failures = items[2].getElementsByTagName('em')[0];
+ var failuresLink = items[2].getElementsByTagName('a')[0];
+ var duration = items[3].getElementsByTagName('em')[0];
+ var canvas = stat.getElementsByTagName('canvas')[0];
+ var report = fragment('<ul id="mocha-report"></ul>');
+ var stack = [report];
+ var progress;
+ var ctx;
+ var root = document.getElementById('mocha');
+
+ if (canvas.getContext) {
+ var ratio = window.devicePixelRatio || 1;
+ canvas.style.width = canvas.width;
+ canvas.style.height = canvas.height;
+ canvas.width *= ratio;
+ canvas.height *= ratio;
+ ctx = canvas.getContext('2d');
+ ctx.scale(ratio, ratio);
+ progress = new Progress();
+ }
+
+ if (!root) {
+ return error('#mocha div missing, add it to your document');
+ }
+
+ // pass toggle
+ on(passesLink, 'click', function (evt) {
+ evt.preventDefault();
+ unhide();
+ var name = (/pass/).test(report.className) ? '' : ' pass';
+ report.className = report.className.replace(/fail|pass/g, '') + name;
+ if (report.className.trim()) {
+ hideSuitesWithout('test pass');
+ }
+ });
+
+ // failure toggle
+ on(failuresLink, 'click', function (evt) {
+ evt.preventDefault();
+ unhide();
+ var name = (/fail/).test(report.className) ? '' : ' fail';
+ report.className = report.className.replace(/fail|pass/g, '') + name;
+ if (report.className.trim()) {
+ hideSuitesWithout('test fail');
+ }
+ });
+
+ root.appendChild(stat);
+ root.appendChild(report);
+
+ if (progress) {
+ progress.size(40);
+ }
+
+ runner.on('suite', function (suite) {
+ if (suite.root) {
+ return;
+ }
+
+ // suite
+ var url = self.suiteURL(suite);
+ var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
+
+ // container
+ stack[0].appendChild(el);
+ stack.unshift(document.createElement('ul'));
+ el.appendChild(stack[0]);
+ });
+
+ runner.on('suite end', function (suite) {
+ if (suite.root) {
+ updateStats();
+ return;
+ }
+ stack.shift();
+ });
+
+ runner.on('pass', function (test) {
+ var url = self.testURL(test);
+ var markup = '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> ' +
+ '<a href="%s" class="replay">' + playIcon + '</a></h2></li>';
+ var el = fragment(markup, test.speed, test.title, test.duration, url);
+ self.addCodeToggle(el, test.body);
+ appendToStack(el);
+ updateStats();
+ });
+
+ runner.on('fail', function (test) {
+ var el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">' + playIcon + '</a></h2></li>',
+ test.title, self.testURL(test));
+ var stackString; // Note: Includes leading newline
+ var message = test.err.toString();
+
+ // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
+ // check for the result of the stringifying.
+ if (message === '[object Error]') {
+ message = test.err.message;
+ }
+
+ if (test.err.stack) {
+ var indexOfMessage = test.err.stack.indexOf(test.err.message);
+ if (indexOfMessage === -1) {
+ stackString = test.err.stack;
+ } else {
+ stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
+ }
+ } else if (test.err.sourceURL && test.err.line !== undefined) {
+ // Safari doesn't give you a stack. Let's at least provide a source line.
+ stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
+ }
+
+ stackString = stackString || '';
+
+ if (test.err.htmlMessage && stackString) {
+ el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',
+ test.err.htmlMessage, stackString));
+ } else if (test.err.htmlMessage) {
+ el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
+ } else {
+ el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
+ }
+
+ self.addCodeToggle(el, test.body);
+ appendToStack(el);
+ updateStats();
+ });
+
+ runner.on('pending', function (test) {
+ var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
+ appendToStack(el);
+ updateStats();
+ });
+
+ function appendToStack (el) {
+ // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
+ if (stack[0]) {
+ stack[0].appendChild(el);
+ }
+ }
+
+ function updateStats () {
+ // TODO: add to stats
+ var percent = stats.tests / runner.total * 100 | 0;
+ if (progress) {
+ progress.update(percent).draw(ctx);
+ }
+
+ // update stats
+ var ms = new Date() - stats.start;
+ text(passes, stats.passes);
+ text(failures, stats.failures);
+ text(duration, (ms / 1000).toFixed(2));
+ }
+}
+
+/**
+ * Makes a URL, preserving querystring ("search") parameters.
+ *
+ * @param {string} s
+ * @return {string} A new URL.
+ */
+function makeUrl (s) {
+ var search = window.location.search;
+
+ // Remove previous grep query parameter if present
+ if (search) {
+ search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
+ }
+
+ return window.location.pathname + (search ? search + '&' : '?') + 'grep=' + encodeURIComponent(escapeRe(s));
+}
+
+/**
+ * Provide suite URL.
+ *
+ * @param {Object} [suite]
+ */
+HTML.prototype.suiteURL = function (suite) {
+ return makeUrl(suite.fullTitle());
+};
+
+/**
+ * Provide test URL.
+ *
+ * @param {Object} [test]
+ */
+HTML.prototype.testURL = function (test) {
+ return makeUrl(test.fullTitle());
+};
+
+/**
+ * Adds code toggle functionality for the provided test's list element.
+ *
+ * @param {HTMLLIElement} el
+ * @param {string} contents
+ */
+HTML.prototype.addCodeToggle = function (el, contents) {
+ var h2 = el.getElementsByTagName('h2')[0];
+
+ on(h2, 'click', function () {
+ pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
+ });
+
+ var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
+ el.appendChild(pre);
+ pre.style.display = 'none';
+};
+
+/**
+ * Display error `msg`.
+ *
+ * @param {string} msg
+ */
+function error (msg) {
+ document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
+}
+
+/**
+ * Return a DOM fragment from `html`.
+ *
+ * @param {string} html
+ */
+function fragment (html) {
+ var args = arguments;
+ var div = document.createElement('div');
+ var i = 1;
+
+ div.innerHTML = html.replace(/%([se])/g, function (_, type) {
+ switch (type) {
+ case 's': return String(args[i++]);
+ case 'e': return escape(args[i++]);
+ // no default
+ }
+ });
+
+ return div.firstChild;
+}
+
+/**
+ * Check for suites that do not have elements
+ * with `classname`, and hide them.
+ *
+ * @param {text} classname
+ */
+function hideSuitesWithout (classname) {
+ var suites = document.getElementsByClassName('suite');
+ for (var i = 0; i < suites.length; i++) {
+ var els = suites[i].getElementsByClassName(classname);
+ if (!els.length) {
+ suites[i].className += ' hidden';
+ }
+ }
+}
+
+/**
+ * Unhide .hidden suites.
+ */
+function unhide () {
+ var els = document.getElementsByClassName('suite hidden');
+ for (var i = 0; i < els.length; ++i) {
+ els[i].className = els[i].className.replace('suite hidden', 'suite');
+ }
+}
+
+/**
+ * Set an element's text contents.
+ *
+ * @param {HTMLElement} el
+ * @param {string} contents
+ */
+function text (el, contents) {
+ if (el.textContent) {
+ el.textContent = contents;
+ } else {
+ el.innerText = contents;
+ }
+}
+
+/**
+ * Listen on `event` with callback `fn`.
+ */
+function on (el, event, fn) {
+ if (el.addEventListener) {
+ el.addEventListener(event, fn, false);
+ } else {
+ el.attachEvent('on' + event, fn);
+ }
+}
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"../browser/progress":3,"../utils":36,"./base":16,"escape-string-regexp":45}],20:[function(require,module,exports){
+'use strict';
+
+// Alias exports to a their normalized format Mocha#reporter to prevent a need
+// for dynamic (try/catch) requires, which Browserify doesn't handle.
+exports.Base = exports.base = require('./base');
+exports.Dot = exports.dot = require('./dot');
+exports.Doc = exports.doc = require('./doc');
+exports.TAP = exports.tap = require('./tap');
+exports.JSON = exports.json = require('./json');
+exports.HTML = exports.html = require('./html');
+exports.List = exports.list = require('./list');
+exports.Min = exports.min = require('./min');
+exports.Spec = exports.spec = require('./spec');
+exports.Nyan = exports.nyan = require('./nyan');
+exports.XUnit = exports.xunit = require('./xunit');
+exports.Markdown = exports.markdown = require('./markdown');
+exports.Progress = exports.progress = require('./progress');
+exports.Landing = exports.landing = require('./landing');
+exports.JSONStream = exports['json-stream'] = require('./json-stream');
+
+},{"./base":16,"./doc":17,"./dot":18,"./html":19,"./json":22,"./json-stream":21,"./landing":23,"./list":24,"./markdown":25,"./min":26,"./nyan":27,"./progress":28,"./spec":29,"./tap":30,"./xunit":31}],21:[function(require,module,exports){
+(function (process){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+
+/**
+ * Expose `List`.
+ */
+
+exports = module.exports = List;
+
+/**
+ * Initialize a new `List` test reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function List (runner) {
+ Base.call(this, runner);
+
+ var self = this;
+ var total = runner.total;
+
+ runner.on('start', function () {
+ console.log(JSON.stringify(['start', { total: total }]));
+ });
+
+ runner.on('pass', function (test) {
+ console.log(JSON.stringify(['pass', clean(test)]));
+ });
+
+ runner.on('fail', function (test, err) {
+ test = clean(test);
+ test.err = err.message;
+ test.stack = err.stack || null;
+ console.log(JSON.stringify(['fail', test]));
+ });
+
+ runner.on('end', function () {
+ process.stdout.write(JSON.stringify(['end', self.stats]));
+ });
+}
+
+/**
+ * Return a plain-object representation of `test`
+ * free of cyclic properties etc.
+ *
+ * @api private
+ * @param {Object} test
+ * @return {Object}
+ */
+function clean (test) {
+ return {
+ title: test.title,
+ fullTitle: test.fullTitle(),
+ duration: test.duration,
+ currentRetry: test.currentRetry()
+ };
+}
+
+}).call(this,require('_process'))
+},{"./base":16,"_process":55}],22:[function(require,module,exports){
+(function (process){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+
+/**
+ * Expose `JSON`.
+ */
+
+exports = module.exports = JSONReporter;
+
+/**
+ * Initialize a new `JSON` reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function JSONReporter (runner) {
+ Base.call(this, runner);
+
+ var self = this;
+ var tests = [];
+ var pending = [];
+ var failures = [];
+ var passes = [];
+
+ runner.on('test end', function (test) {
+ tests.push(test);
+ });
+
+ runner.on('pass', function (test) {
+ passes.push(test);
+ });
+
+ runner.on('fail', function (test) {
+ failures.push(test);
+ });
+
+ runner.on('pending', function (test) {
+ pending.push(test);
+ });
+
+ runner.on('end', function () {
+ var obj = {
+ stats: self.stats,
+ tests: tests.map(clean),
+ pending: pending.map(clean),
+ failures: failures.map(clean),
+ passes: passes.map(clean)
+ };
+
+ runner.testResults = obj;
+
+ process.stdout.write(JSON.stringify(obj, null, 2));
+ });
+}
+
+/**
+ * Return a plain-object representation of `test`
+ * free of cyclic properties etc.
+ *
+ * @api private
+ * @param {Object} test
+ * @return {Object}
+ */
+function clean (test) {
+ return {
+ title: test.title,
+ fullTitle: test.fullTitle(),
+ duration: test.duration,
+ currentRetry: test.currentRetry(),
+ err: errorJSON(test.err || {})
+ };
+}
+
+/**
+ * Transform `error` into a JSON object.
+ *
+ * @api private
+ * @param {Error} err
+ * @return {Object}
+ */
+function errorJSON (err) {
+ var res = {};
+ Object.getOwnPropertyNames(err).forEach(function (key) {
+ res[key] = err[key];
+ }, err);
+ return res;
+}
+
+}).call(this,require('_process'))
+},{"./base":16,"_process":55}],23:[function(require,module,exports){
+(function (process){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var inherits = require('../utils').inherits;
+var cursor = Base.cursor;
+var color = Base.color;
+
+/**
+ * Expose `Landing`.
+ */
+
+exports = module.exports = Landing;
+
+/**
+ * Airplane color.
+ */
+
+Base.colors.plane = 0;
+
+/**
+ * Airplane crash color.
+ */
+
+Base.colors['plane crash'] = 31;
+
+/**
+ * Runway color.
+ */
+
+Base.colors.runway = 90;
+
+/**
+ * Initialize a new `Landing` reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function Landing (runner) {
+ Base.call(this, runner);
+
+ var self = this;
+ var width = Base.window.width * 0.75 | 0;
+ var total = runner.total;
+ var stream = process.stdout;
+ var plane = color('plane', '✈');
+ var crashed = -1;
+ var n = 0;
+
+ function runway () {
+ var buf = Array(width).join('-');
+ return ' ' + color('runway', buf);
+ }
+
+ runner.on('start', function () {
+ stream.write('\n\n\n ');
+ cursor.hide();
+ });
+
+ runner.on('test end', function (test) {
+ // check if the plane crashed
+ var col = crashed === -1 ? width * ++n / total | 0 : crashed;
+
+ // show the crash
+ if (test.state === 'failed') {
+ plane = color('plane crash', '✈');
+ crashed = col;
+ }
+
+ // render landing strip
+ stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
+ stream.write(runway());
+ stream.write('\n ');
+ stream.write(color('runway', Array(col).join('⋅')));
+ stream.write(plane);
+ stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
+ stream.write(runway());
+ stream.write('\u001b[0m');
+ });
+
+ runner.on('end', function () {
+ cursor.show();
+ console.log();
+ self.epilogue();
+ });
+}
+
+/**
+ * Inherit from `Base.prototype`.
+ */
+inherits(Landing, Base);
+
+}).call(this,require('_process'))
+},{"../utils":36,"./base":16,"_process":55}],24:[function(require,module,exports){
+(function (process){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var inherits = require('../utils').inherits;
+var color = Base.color;
+var cursor = Base.cursor;
+
+/**
+ * Expose `List`.
+ */
+
+exports = module.exports = List;
+
+/**
+ * Initialize a new `List` test reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function List (runner) {
+ Base.call(this, runner);
+
+ var self = this;
+ var n = 0;
+
+ runner.on('start', function () {
+ console.log();
+ });
+
+ runner.on('test', function (test) {
+ process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
+ });
+
+ runner.on('pending', function (test) {
+ var fmt = color('checkmark', ' -') +
+ color('pending', ' %s');
+ console.log(fmt, test.fullTitle());
+ });
+
+ runner.on('pass', function (test) {
+ var fmt = color('checkmark', ' ' + Base.symbols.ok) +
+ color('pass', ' %s: ') +
+ color(test.speed, '%dms');
+ cursor.CR();
+ console.log(fmt, test.fullTitle(), test.duration);
+ });
+
+ runner.on('fail', function (test) {
+ cursor.CR();
+ console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
+ });
+
+ runner.on('end', self.epilogue.bind(self));
+}
+
+/**
+ * Inherit from `Base.prototype`.
+ */
+inherits(List, Base);
+
+}).call(this,require('_process'))
+},{"../utils":36,"./base":16,"_process":55}],25:[function(require,module,exports){
+(function (process){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var utils = require('../utils');
+
+/**
+ * Constants
+ */
+
+var SUITE_PREFIX = '$';
+
+/**
+ * Expose `Markdown`.
+ */
+
+exports = module.exports = Markdown;
+
+/**
+ * Initialize a new `Markdown` reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function Markdown (runner) {
+ Base.call(this, runner);
+
+ var level = 0;
+ var buf = '';
+
+ function title (str) {
+ return Array(level).join('#') + ' ' + str;
+ }
+
+ function mapTOC (suite, obj) {
+ var ret = obj;
+ var key = SUITE_PREFIX + suite.title;
+
+ obj = obj[key] = obj[key] || { suite: suite };
+ suite.suites.forEach(function (suite) {
+ mapTOC(suite, obj);
+ });
+
+ return ret;
+ }
+
+ function stringifyTOC (obj, level) {
+ ++level;
+ var buf = '';
+ var link;
+ for (var key in obj) {
+ if (key === 'suite') {
+ continue;
+ }
+ if (key !== SUITE_PREFIX) {
+ link = ' - [' + key.substring(1) + ']';
+ link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
+ buf += Array(level).join(' ') + link;
+ }
+ buf += stringifyTOC(obj[key], level);
+ }
+ return buf;
+ }
+
+ function generateTOC (suite) {
+ var obj = mapTOC(suite, {});
+ return stringifyTOC(obj, 0);
+ }
+
+ generateTOC(runner.suite);
+
+ runner.on('suite', function (suite) {
+ ++level;
+ var slug = utils.slug(suite.fullTitle());
+ buf += '<a name="' + slug + '"></a>' + '\n';
+ buf += title(suite.title) + '\n';
+ });
+
+ runner.on('suite end', function () {
+ --level;
+ });
+
+ runner.on('pass', function (test) {
+ var code = utils.clean(test.body);
+ buf += test.title + '.\n';
+ buf += '\n```js\n';
+ buf += code + '\n';
+ buf += '```\n\n';
+ });
+
+ runner.on('end', function () {
+ process.stdout.write('# TOC\n');
+ process.stdout.write(generateTOC(runner.suite));
+ process.stdout.write(buf);
+ });
+}
+
+}).call(this,require('_process'))
+},{"../utils":36,"./base":16,"_process":55}],26:[function(require,module,exports){
+(function (process){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var inherits = require('../utils').inherits;
+
+/**
+ * Expose `Min`.
+ */
+
+exports = module.exports = Min;
+
+/**
+ * Initialize a new `Min` minimal test reporter (best used with --watch).
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function Min (runner) {
+ Base.call(this, runner);
+
+ runner.on('start', function () {
+ // clear screen
+ process.stdout.write('\u001b[2J');
+ // set cursor position
+ process.stdout.write('\u001b[1;3H');
+ });
+
+ runner.on('end', this.epilogue.bind(this));
+}
+
+/**
+ * Inherit from `Base.prototype`.
+ */
+inherits(Min, Base);
+
+}).call(this,require('_process'))
+},{"../utils":36,"./base":16,"_process":55}],27:[function(require,module,exports){
+(function (process){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var inherits = require('../utils').inherits;
+
+/**
+ * Expose `Dot`.
+ */
+
+exports = module.exports = NyanCat;
+
+/**
+ * Initialize a new `Dot` matrix test reporter.
+ *
+ * @param {Runner} runner
+ * @api public
+ */
+
+function NyanCat (runner) {
+ Base.call(this, runner);
+
+ var self = this;
+ var width = Base.window.width * 0.75 | 0;
+ var nyanCatWidth = this.nyanCatWidth = 11;
+
+ this.colorIndex = 0;
+ this.numberOfLines = 4;
+ this.rainbowColors = self.generateColors();
+ this.scoreboardWidth = 5;
+ this.tick = 0;
+ this.trajectories = [[], [], [], []];
+ this.trajectoryWidthMax = (width - nyanCatWidth);
+
+ runner.on('start', function () {
+ Base.cursor.hide();
+ self.draw();
+ });
+
+ runner.on('pending', function () {
+ self.draw();
+ });
+
+ runner.on('pass', function () {
+ self.draw();
+ });
+
+ runner.on('fail', function () {
+ self.draw();
+ });
+
+ runner.on('end', function () {
+ Base.cursor.show();
+ for (var i = 0; i < self.numberOfLines; i++) {
+ write('\n');
+ }
+ self.epilogue();
+ });
+}
+
+/**
+ * Inherit from `Base.prototype`.
+ */
+inherits(NyanCat, Base);
+
+/**
+ * Draw the nyan cat
+ *
+ * @api private
+ */
+
+NyanCat.prototype.draw = function () {
+ this.appendRainbow();
+ this.drawScoreboard();
+ this.drawRainbow();
+ this.drawNyanCat();
+ this.tick = !this.tick;
+};
+
+/**
+ * Draw the "scoreboard" showing the number
+ * of passes, failures and pending tests.
+ *
+ * @api private
+ */
+
+NyanCat.prototype.drawScoreboard = function () {
+ var stats = this.stats;
+
+ function draw (type, n) {
+ write(' ');
+ write(Base.color(type, n));
+ write('\n');
+ }
+
+ draw('green', stats.passes);
+ draw('fail', stats.failures);
+ draw('pending', stats.pending);
+ write('\n');
+
+ this.cursorUp(this.numberOfLines);
+};
+
+/**
+ * Append the rainbow.
+ *
+ * @api private
+ */
+
+NyanCat.prototype.appendRainbow = function () {
+ var segment = this.tick ? '_' : '-';
+ var rainbowified = this.rainbowify(segment);
+
+ for (var index = 0; index < this.numberOfLines; index++) {
+ var trajectory = this.trajectories[index];
+ if (trajectory.length >= this.trajectoryWidthMax) {
+ trajectory.shift();
+ }
+ trajectory.push(rainbowified);
+ }
+};
+
+/**
+ * Draw the rainbow.
+ *
+ * @api private
+ */
+
+NyanCat.prototype.drawRainbow = function () {
+ var self = this;
+
+ this.trajectories.forEach(function (line) {
+ write('\u001b[' + self.scoreboardWidth + 'C');
+ write(line.join(''));
+ write('\n');
+ });
+
+ this.cursorUp(this.numberOfLines);
+};
+
+/**
+ * Draw the nyan cat
+ *
+ * @api private
+ */
+NyanCat.prototype.drawNyanCat = function () {
+ var self = this;
+ var startWidth = this.scoreboardWidth + this.trajectories[0].length;
+ var dist = '\u001b[' + startWidth + 'C';
+ var padding = '';
+
+ write(dist);
+ write('_,------,');
+ write('\n');
+
+ write(dist);
+ padding = self.tick ? ' ' : ' ';
+ write('_|' + padding + '/\\_/\\ ');
+ write('\n');
+
+ write(dist);
+ padding = self.tick ? '_' : '__';
+ var tail = self.tick ? '~' : '^';
+ write(tail + '|' + padding + this.face() + ' ');
+ write('\n');
+
+ write(dist);
+ padding = self.tick ? ' ' : ' ';
+ write(padding + '"" "" ');
+ write('\n');
+
+ this.cursorUp(this.numberOfLines);
+};
+
+/**
+ * Draw nyan cat face.
+ *
+ * @api private
+ * @return {string}
+ */
+
+NyanCat.prototype.face = function () {
+ var stats = this.stats;
+ if (stats.failures) {
+ return '( x .x)';
+ } else if (stats.pending) {
+ return '( o .o)';
+ } else if (stats.passes) {
+ return '( ^ .^)';
+ }
+ return '( - .-)';
+};
+
+/**
+ * Move cursor up `n`.
+ *
+ * @api private
+ * @param {number} n
+ */
+
+NyanCat.prototype.cursorUp = function (n) {
+ write('\u001b[' + n + 'A');
+};
+
+/**
+ * Move cursor down `n`.
+ *
+ * @api private
+ * @param {number} n
+ */
+
+NyanCat.prototype.cursorDown = function (n) {
+ write('\u001b[' + n + 'B');
+};
+
+/**
+ * Generate rainbow colors.
+ *
+ * @api private
+ * @return {Array}
+ */
+NyanCat.prototype.generateColors = function () {
+ var colors = [];
+
+ for (var i = 0; i < (6 * 7); i++) {
+ var pi3 = Math.floor(Math.PI / 3);
+ var n = (i * (1.0 / 6));
+ var r = Math.floor(3 * Math.sin(n) + 3);
+ var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
+ var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
+ colors.push(36 * r + 6 * g + b + 16);
+ }
+
+ return colors;
+};
+
+/**
+ * Apply rainbow to the given `str`.
+ *
+ * @api private
+ * @param {string} str
+ * @return {string}
+ */
+NyanCat.prototype.rainbowify = function (str) {
+ if (!Base.useColors) {
+ return str;
+ }
+ var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
+ this.colorIndex += 1;
+ return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
+};
+
+/**
+ * Stdout helper.
+ *
+ * @param {string} string A message to write to stdout.
+ */
+function write (string) {
+ process.stdout.write(string);
+}
+
+}).call(this,require('_process'))
+},{"../utils":36,"./base":16,"_process":55}],28:[function(require,module,exports){
+(function (process){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var inherits = require('../utils').inherits;
+var color = Base.color;
+var cursor = Base.cursor;
+
+/**
+ * Expose `Progress`.
+ */
+
+exports = module.exports = Progress;
+
+/**
+ * General progress bar color.
+ */
+
+Base.colors.progress = 90;
+
+/**
+ * Initialize a new `Progress` bar test reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ * @param {Object} options
+ */
+function Progress (runner, options) {
+ Base.call(this, runner);
+
+ var self = this;
+ var width = Base.window.width * 0.50 | 0;
+ var total = runner.total;
+ var complete = 0;
+ var lastN = -1;
+
+ // default chars
+ options = options || {};
+ options.open = options.open || '[';
+ options.complete = options.complete || '▬';
+ options.incomplete = options.incomplete || Base.symbols.dot;
+ options.close = options.close || ']';
+ options.verbose = false;
+
+ // tests started
+ runner.on('start', function () {
+ console.log();
+ cursor.hide();
+ });
+
+ // tests complete
+ runner.on('test end', function () {
+ complete++;
+
+ var percent = complete / total;
+ var n = width * percent | 0;
+ var i = width - n;
+
+ if (n === lastN && !options.verbose) {
+ // Don't re-render the line if it hasn't changed
+ return;
+ }
+ lastN = n;
+
+ cursor.CR();
+ process.stdout.write('\u001b[J');
+ process.stdout.write(color('progress', ' ' + options.open));
+ process.stdout.write(Array(n).join(options.complete));
+ process.stdout.write(Array(i).join(options.incomplete));
+ process.stdout.write(color('progress', options.close));
+ if (options.verbose) {
+ process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
+ }
+ });
+
+ // tests are complete, output some stats
+ // and the failures if any
+ runner.on('end', function () {
+ cursor.show();
+ console.log();
+ self.epilogue();
+ });
+}
+
+/**
+ * Inherit from `Base.prototype`.
+ */
+inherits(Progress, Base);
+
+}).call(this,require('_process'))
+},{"../utils":36,"./base":16,"_process":55}],29:[function(require,module,exports){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var inherits = require('../utils').inherits;
+var color = Base.color;
+
+/**
+ * Expose `Spec`.
+ */
+
+exports = module.exports = Spec;
+
+/**
+ * Initialize a new `Spec` test reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function Spec (runner) {
+ Base.call(this, runner);
+
+ var self = this;
+ var indents = 0;
+ var n = 0;
+
+ function indent () {
+ return Array(indents).join(' ');
+ }
+
+ runner.on('start', function () {
+ console.log();
+ });
+
+ runner.on('suite', function (suite) {
+ ++indents;
+ console.log(color('suite', '%s%s'), indent(), suite.title);
+ });
+
+ runner.on('suite end', function () {
+ --indents;
+ if (indents === 1) {
+ console.log();
+ }
+ });
+
+ runner.on('pending', function (test) {
+ var fmt = indent() + color('pending', ' - %s');
+ console.log(fmt, test.title);
+ });
+
+ runner.on('pass', function (test) {
+ var fmt;
+ if (test.speed === 'fast') {
+ fmt = indent() +
+ color('checkmark', ' ' + Base.symbols.ok) +
+ color('pass', ' %s');
+ console.log(fmt, test.title);
+ } else {
+ fmt = indent() +
+ color('checkmark', ' ' + Base.symbols.ok) +
+ color('pass', ' %s') +
+ color(test.speed, ' (%dms)');
+ console.log(fmt, test.title, test.duration);
+ }
+ });
+
+ runner.on('fail', function (test) {
+ console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
+ });
+
+ runner.on('end', self.epilogue.bind(self));
+}
+
+/**
+ * Inherit from `Base.prototype`.
+ */
+inherits(Spec, Base);
+
+},{"../utils":36,"./base":16}],30:[function(require,module,exports){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+
+/**
+ * Expose `TAP`.
+ */
+
+exports = module.exports = TAP;
+
+/**
+ * Initialize a new `TAP` reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function TAP (runner) {
+ Base.call(this, runner);
+
+ var n = 1;
+ var passes = 0;
+ var failures = 0;
+
+ runner.on('start', function () {
+ var total = runner.grepTotal(runner.suite);
+ console.log('%d..%d', 1, total);
+ });
+
+ runner.on('test end', function () {
+ ++n;
+ });
+
+ runner.on('pending', function (test) {
+ console.log('ok %d %s # SKIP -', n, title(test));
+ });
+
+ runner.on('pass', function (test) {
+ passes++;
+ console.log('ok %d %s', n, title(test));
+ });
+
+ runner.on('fail', function (test, err) {
+ failures++;
+ console.log('not ok %d %s', n, title(test));
+ if (err.stack) {
+ console.log(err.stack.replace(/^/gm, ' '));
+ }
+ });
+
+ runner.on('end', function () {
+ console.log('# tests ' + (passes + failures));
+ console.log('# pass ' + passes);
+ console.log('# fail ' + failures);
+ });
+}
+
+/**
+ * Return a TAP-safe title of `test`
+ *
+ * @api private
+ * @param {Object} test
+ * @return {String}
+ */
+function title (test) {
+ return test.fullTitle().replace(/#/g, '');
+}
+
+},{"./base":16}],31:[function(require,module,exports){
+(function (process,global){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+var utils = require('../utils');
+var inherits = utils.inherits;
+var fs = require('fs');
+var escape = utils.escape;
+var mkdirp = require('mkdirp');
+var path = require('path');
+
+/**
+ * Save timer references to avoid Sinon interfering (see GH-237).
+ */
+
+/* eslint-disable no-unused-vars, no-native-reassign */
+var Date = global.Date;
+var setTimeout = global.setTimeout;
+var setInterval = global.setInterval;
+var clearTimeout = global.clearTimeout;
+var clearInterval = global.clearInterval;
+/* eslint-enable no-unused-vars, no-native-reassign */
+
+/**
+ * Expose `XUnit`.
+ */
+
+exports = module.exports = XUnit;
+
+/**
+ * Initialize a new `XUnit` reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function XUnit (runner, options) {
+ Base.call(this, runner);
+
+ var stats = this.stats;
+ var tests = [];
+ var self = this;
+
+ // the name of the test suite, as it will appear in the resulting XML file
+ var suiteName;
+
+ // the default name of the test suite if none is provided
+ var DEFAULT_SUITE_NAME = 'Mocha Tests';
+
+ if (options && options.reporterOptions) {
+ if (options.reporterOptions.output) {
+ if (!fs.createWriteStream) {
+ throw new Error('file output not supported in browser');
+ }
+
+ mkdirp.sync(path.dirname(options.reporterOptions.output));
+ self.fileStream = fs.createWriteStream(options.reporterOptions.output);
+ }
+
+ // get the suite name from the reporter options (if provided)
+ suiteName = options.reporterOptions.suiteName;
+ }
+
+ // fall back to the default suite name
+ suiteName = suiteName || DEFAULT_SUITE_NAME;
+
+ runner.on('pending', function (test) {
+ tests.push(test);
+ });
+
+ runner.on('pass', function (test) {
+ tests.push(test);
+ });
+
+ runner.on('fail', function (test) {
+ tests.push(test);
+ });
+
+ runner.on('end', function () {
+ self.write(tag('testsuite', {
+ name: suiteName,
+ tests: stats.tests,
+ failures: stats.failures,
+ errors: stats.failures,
+ skipped: stats.tests - stats.failures - stats.passes,
+ timestamp: (new Date()).toUTCString(),
+ time: (stats.duration / 1000) || 0
+ }, false));
+
+ tests.forEach(function (t) {
+ self.test(t);
+ });
+
+ self.write('</testsuite>');
+ });
+}
+
+/**
+ * Inherit from `Base.prototype`.
+ */
+inherits(XUnit, Base);
+
+/**
+ * Override done to close the stream (if it's a file).
+ *
+ * @param failures
+ * @param {Function} fn
+ */
+XUnit.prototype.done = function (failures, fn) {
+ if (this.fileStream) {
+ this.fileStream.end(function () {
+ fn(failures);
+ });
+ } else {
+ fn(failures);
+ }
+};
+
+/**
+ * Write out the given line.
+ *
+ * @param {string} line
+ */
+XUnit.prototype.write = function (line) {
+ if (this.fileStream) {
+ this.fileStream.write(line + '\n');
+ } else if (typeof process === 'object' && process.stdout) {
+ process.stdout.write(line + '\n');
+ } else {
+ console.log(line);
+ }
+};
+
+/**
+ * Output tag for the given `test.`
+ *
+ * @param {Test} test
+ */
+XUnit.prototype.test = function (test) {
+ var attrs = {
+ classname: test.parent.fullTitle(),
+ name: test.title,
+ time: (test.duration / 1000) || 0
+ };
+
+ if (test.state === 'failed') {
+ var err = test.err;
+ this.write(tag('testcase', attrs, false, tag('failure', {}, false, escape(err.message) + '\n' + escape(err.stack))));
+ } else if (test.isPending()) {
+ this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
+ } else {
+ this.write(tag('testcase', attrs, true));
+ }
+};
+
+/**
+ * HTML tag helper.
+ *
+ * @param name
+ * @param attrs
+ * @param close
+ * @param content
+ * @return {string}
+ */
+function tag (name, attrs, close, content) {
+ var end = close ? '/>' : '>';
+ var pairs = [];
+ var tag;
+
+ for (var key in attrs) {
+ if (Object.prototype.hasOwnProperty.call(attrs, key)) {
+ pairs.push(key + '="' + escape(attrs[key]) + '"');
+ }
+ }
+
+ tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
+ if (content) {
+ tag += content + '</' + name + end;
+ }
+ return tag;
+}
+
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"../utils":36,"./base":16,"_process":55,"fs":40,"mkdirp":52,"path":40}],32:[function(require,module,exports){
+(function (global){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var EventEmitter = require('events').EventEmitter;
+var Pending = require('./pending');
+var debug = require('debug')('mocha:runnable');
+var milliseconds = require('./ms');
+var utils = require('./utils');
+
+/**
+ * Save timer references to avoid Sinon interfering (see GH-237).
+ */
+
+/* eslint-disable no-unused-vars, no-native-reassign */
+var Date = global.Date;
+var setTimeout = global.setTimeout;
+var setInterval = global.setInterval;
+var clearTimeout = global.clearTimeout;
+var clearInterval = global.clearInterval;
+/* eslint-enable no-unused-vars, no-native-reassign */
+
+/**
+ * Object#toString().
+ */
+
+var toString = Object.prototype.toString;
+
+/**
+ * Expose `Runnable`.
+ */
+
+module.exports = Runnable;
+
+/**
+ * Initialize a new `Runnable` with the given `title` and callback `fn`.
+ *
+ * @param {String} title
+ * @param {Function} fn
+ * @api private
+ * @param {string} title
+ * @param {Function} fn
+ */
+function Runnable (title, fn) {
+ this.title = title;
+ this.fn = fn;
+ this.body = (fn || '').toString();
+ this.async = fn && fn.length;
+ this.sync = !this.async;
+ this._timeout = 2000;
+ this._slow = 75;
+ this._enableTimeouts = true;
+ this.timedOut = false;
+ this._trace = new Error('done() called multiple times');
+ this._retries = -1;
+ this._currentRetry = 0;
+ this.pending = false;
+}
+
+/**
+ * Inherit from `EventEmitter.prototype`.
+ */
+utils.inherits(Runnable, EventEmitter);
+
+/**
+ * Set & get timeout `ms`.
+ *
+ * @api private
+ * @param {number|string} ms
+ * @return {Runnable|number} ms or Runnable instance.
+ */
+Runnable.prototype.timeout = function (ms) {
+ if (!arguments.length) {
+ return this._timeout;
+ }
+ // see #1652 for reasoning
+ if (ms === 0 || ms > Math.pow(2, 31)) {
+ this._enableTimeouts = false;
+ }
+ if (typeof ms === 'string') {
+ ms = milliseconds(ms);
+ }
+ debug('timeout %d', ms);
+ this._timeout = ms;
+ if (this.timer) {
+ this.resetTimeout();
+ }
+ return this;
+};
+
+/**
+ * Set & get slow `ms`.
+ *
+ * @api private
+ * @param {number|string} ms
+ * @return {Runnable|number} ms or Runnable instance.
+ */
+Runnable.prototype.slow = function (ms) {
+ if (typeof ms === 'undefined') {
+ return this._slow;
+ }
+ if (typeof ms === 'string') {
+ ms = milliseconds(ms);
+ }
+ debug('timeout %d', ms);
+ this._slow = ms;
+ return this;
+};
+
+/**
+ * Set and get whether timeout is `enabled`.
+ *
+ * @api private
+ * @param {boolean} enabled
+ * @return {Runnable|boolean} enabled or Runnable instance.
+ */
+Runnable.prototype.enableTimeouts = function (enabled) {
+ if (!arguments.length) {
+ return this._enableTimeouts;
+ }
+ debug('enableTimeouts %s', enabled);
+ this._enableTimeouts = enabled;
+ return this;
+};
+
+/**
+ * Halt and mark as pending.
+ *
+ * @api public
+ */
+Runnable.prototype.skip = function () {
+ throw new Pending('sync skip');
+};
+
+/**
+ * Check if this runnable or its parent suite is marked as pending.
+ *
+ * @api private
+ */
+Runnable.prototype.isPending = function () {
+ return this.pending || (this.parent && this.parent.isPending());
+};
+
+/**
+ * Set number of retries.
+ *
+ * @api private
+ */
+Runnable.prototype.retries = function (n) {
+ if (!arguments.length) {
+ return this._retries;
+ }
+ this._retries = n;
+};
+
+/**
+ * Get current retry
+ *
+ * @api private
+ */
+Runnable.prototype.currentRetry = function (n) {
+ if (!arguments.length) {
+ return this._currentRetry;
+ }
+ this._currentRetry = n;
+};
+
+/**
+ * Return the full title generated by recursively concatenating the parent's
+ * full title.
+ *
+ * @api public
+ * @return {string}
+ */
+Runnable.prototype.fullTitle = function () {
+ return this.titlePath().join(' ');
+};
+
+/**
+ * Return the title path generated by concatenating the parent's title path with the title.
+ *
+ * @api public
+ * @return {string}
+ */
+Runnable.prototype.titlePath = function () {
+ return this.parent.titlePath().concat([this.title]);
+};
+
+/**
+ * Clear the timeout.
+ *
+ * @api private
+ */
+Runnable.prototype.clearTimeout = function () {
+ clearTimeout(this.timer);
+};
+
+/**
+ * Inspect the runnable void of private properties.
+ *
+ * @api private
+ * @return {string}
+ */
+Runnable.prototype.inspect = function () {
+ return JSON.stringify(this, function (key, val) {
+ if (key[0] === '_') {
+ return;
+ }
+ if (key === 'parent') {
+ return '#<Suite>';
+ }
+ if (key === 'ctx') {
+ return '#<Context>';
+ }
+ return val;
+ }, 2);
+};
+
+/**
+ * Reset the timeout.
+ *
+ * @api private
+ */
+Runnable.prototype.resetTimeout = function () {
+ var self = this;
+ var ms = this.timeout() || 1e9;
+
+ if (!this._enableTimeouts) {
+ return;
+ }
+ this.clearTimeout();
+ this.timer = setTimeout(function () {
+ if (!self._enableTimeouts) {
+ return;
+ }
+ self.callback(new Error('Timeout of ' + ms +
+ 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.'));
+ self.timedOut = true;
+ }, ms);
+};
+
+/**
+ * Whitelist a list of globals for this test run.
+ *
+ * @api private
+ * @param {string[]} globals
+ */
+Runnable.prototype.globals = function (globals) {
+ if (!arguments.length) {
+ return this._allowedGlobals;
+ }
+ this._allowedGlobals = globals;
+};
+
+/**
+ * Run the test and invoke `fn(err)`.
+ *
+ * @param {Function} fn
+ * @api private
+ */
+Runnable.prototype.run = function (fn) {
+ var self = this;
+ var start = new Date();
+ var ctx = this.ctx;
+ var finished;
+ var emitted;
+
+ // Sometimes the ctx exists, but it is not runnable
+ if (ctx && ctx.runnable) {
+ ctx.runnable(this);
+ }
+
+ // called multiple times
+ function multiple (err) {
+ if (emitted) {
+ return;
+ }
+ emitted = true;
+ self.emit('error', err || new Error('done() called multiple times; stacktrace may be inaccurate'));
+ }
+
+ // finished
+ function done (err) {
+ var ms = self.timeout();
+ if (self.timedOut) {
+ return;
+ }
+ if (finished) {
+ return multiple(err || self._trace);
+ }
+
+ self.clearTimeout();
+ self.duration = new Date() - start;
+ finished = true;
+ if (!err && self.duration > ms && self._enableTimeouts) {
+ err = new Error('Timeout of ' + ms +
+ 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.');
+ }
+ fn(err);
+ }
+
+ // for .resetTimeout()
+ this.callback = done;
+
+ // explicit async with `done` argument
+ if (this.async) {
+ this.resetTimeout();
+
+ // allows skip() to be used in an explicit async context
+ this.skip = function asyncSkip () {
+ done(new Pending('async skip call'));
+ // halt execution. the Runnable will be marked pending
+ // by the previous call, and the uncaught handler will ignore
+ // the failure.
+ throw new Pending('async skip; aborting execution');
+ };
+
+ if (this.allowUncaught) {
+ return callFnAsync(this.fn);
+ }
+ try {
+ callFnAsync(this.fn);
+ } catch (err) {
+ emitted = true;
+ done(utils.getError(err));
+ }
+ return;
+ }
+
+ if (this.allowUncaught) {
+ if (this.isPending()) {
+ done();
+ } else {
+ callFn(this.fn);
+ }
+ return;
+ }
+
+ // sync or promise-returning
+ try {
+ if (this.isPending()) {
+ done();
+ } else {
+ callFn(this.fn);
+ }
+ } catch (err) {
+ emitted = true;
+ done(utils.getError(err));
+ }
+
+ function callFn (fn) {
+ var result = fn.call(ctx);
+ if (result && typeof result.then === 'function') {
+ self.resetTimeout();
+ result
+ .then(function () {
+ done();
+ // Return null so libraries like bluebird do not warn about
+ // subsequently constructed Promises.
+ return null;
+ },
+ function (reason) {
+ done(reason || new Error('Promise rejected with no or falsy reason'));
+ });
+ } else {
+ if (self.asyncOnly) {
+ return done(new Error('--async-only option in use without declaring `done()` or returning a promise'));
+ }
+
+ done();
+ }
+ }
+
+ function callFnAsync (fn) {
+ var result = fn.call(ctx, function (err) {
+ if (err instanceof Error || toString.call(err) === '[object Error]') {
+ return done(err);
+ }
+ if (err) {
+ if (Object.prototype.toString.call(err) === '[object Object]') {
+ return done(new Error('done() invoked with non-Error: ' +
+ JSON.stringify(err)));
+ }
+ return done(new Error('done() invoked with non-Error: ' + err));
+ }
+ if (result && utils.isPromise(result)) {
+ return done(new Error('Resolution method is overspecified. Specify a callback *or* return a Promise; not both.'));
+ }
+
+ done();
+ });
+ }
+};
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"./ms":14,"./pending":15,"./utils":36,"debug":42,"events":46}],33:[function(require,module,exports){
+(function (process,global){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var EventEmitter = require('events').EventEmitter;
+var Pending = require('./pending');
+var utils = require('./utils');
+var inherits = utils.inherits;
+var debug = require('debug')('mocha:runner');
+var Runnable = require('./runnable');
+var stackFilter = utils.stackTraceFilter();
+var stringify = utils.stringify;
+var type = utils.type;
+var undefinedError = utils.undefinedError;
+
+/**
+ * Non-enumerable globals.
+ */
+
+var globals = [
+ 'setTimeout',
+ 'clearTimeout',
+ 'setInterval',
+ 'clearInterval',
+ 'XMLHttpRequest',
+ 'Date',
+ 'setImmediate',
+ 'clearImmediate'
+];
+
+/**
+ * Expose `Runner`.
+ */
+
+module.exports = Runner;
+
+/**
+ * Initialize a `Runner` for the given `suite`.
+ *
+ * Events:
+ *
+ * - `start` execution started
+ * - `end` execution complete
+ * - `suite` (suite) test suite execution started
+ * - `suite end` (suite) all tests (and sub-suites) have finished
+ * - `test` (test) test execution started
+ * - `test end` (test) test completed
+ * - `hook` (hook) hook execution started
+ * - `hook end` (hook) hook complete
+ * - `pass` (test) test passed
+ * - `fail` (test, err) test failed
+ * - `pending` (test) test pending
+ *
+ * @api public
+ * @param {Suite} suite Root suite
+ * @param {boolean} [delay] Whether or not to delay execution of root suite
+ * until ready.
+ */
+function Runner (suite, delay) {
+ var self = this;
+ this._globals = [];
+ this._abort = false;
+ this._delay = delay;
+ this.suite = suite;
+ this.started = false;
+ this.total = suite.total();
+ this.failures = 0;
+ this.on('test end', function (test) {
+ self.checkGlobals(test);
+ });
+ this.on('hook end', function (hook) {
+ self.checkGlobals(hook);
+ });
+ this._defaultGrep = /.*/;
+ this.grep(this._defaultGrep);
+ this.globals(this.globalProps().concat(extraGlobals()));
+}
+
+/**
+ * Wrapper for setImmediate, process.nextTick, or browser polyfill.
+ *
+ * @param {Function} fn
+ * @api private
+ */
+Runner.immediately = global.setImmediate || process.nextTick;
+
+/**
+ * Inherit from `EventEmitter.prototype`.
+ */
+inherits(Runner, EventEmitter);
+
+/**
+ * Run tests with full titles matching `re`. Updates runner.total
+ * with number of tests matched.
+ *
+ * @param {RegExp} re
+ * @param {Boolean} invert
+ * @return {Runner} for chaining
+ * @api public
+ * @param {RegExp} re
+ * @param {boolean} invert
+ * @return {Runner} Runner instance.
+ */
+Runner.prototype.grep = function (re, invert) {
+ debug('grep %s', re);
+ this._grep = re;
+ this._invert = invert;
+ this.total = this.grepTotal(this.suite);
+ return this;
+};
+
+/**
+ * Returns the number of tests matching the grep search for the
+ * given suite.
+ *
+ * @param {Suite} suite
+ * @return {Number}
+ * @api public
+ * @param {Suite} suite
+ * @return {number}
+ */
+Runner.prototype.grepTotal = function (suite) {
+ var self = this;
+ var total = 0;
+
+ suite.eachTest(function (test) {
+ var match = self._grep.test(test.fullTitle());
+ if (self._invert) {
+ match = !match;
+ }
+ if (match) {
+ total++;
+ }
+ });
+
+ return total;
+};
+
+/**
+ * Return a list of global properties.
+ *
+ * @return {Array}
+ * @api private
+ */
+Runner.prototype.globalProps = function () {
+ var props = Object.keys(global);
+
+ // non-enumerables
+ for (var i = 0; i < globals.length; ++i) {
+ if (~props.indexOf(globals[i])) {
+ continue;
+ }
+ props.push(globals[i]);
+ }
+
+ return props;
+};
+
+/**
+ * Allow the given `arr` of globals.
+ *
+ * @param {Array} arr
+ * @return {Runner} for chaining
+ * @api public
+ * @param {Array} arr
+ * @return {Runner} Runner instance.
+ */
+Runner.prototype.globals = function (arr) {
+ if (!arguments.length) {
+ return this._globals;
+ }
+ debug('globals %j', arr);
+ this._globals = this._globals.concat(arr);
+ return this;
+};
+
+/**
+ * Check for global variable leaks.
+ *
+ * @api private
+ */
+Runner.prototype.checkGlobals = function (test) {
+ if (this.ignoreLeaks) {
+ return;
+ }
+ var ok = this._globals;
+
+ var globals = this.globalProps();
+ var leaks;
+
+ if (test) {
+ ok = ok.concat(test._allowedGlobals || []);
+ }
+
+ if (this.prevGlobalsLength === globals.length) {
+ return;
+ }
+ this.prevGlobalsLength = globals.length;
+
+ leaks = filterLeaks(ok, globals);
+ this._globals = this._globals.concat(leaks);
+
+ if (leaks.length > 1) {
+ this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + ''));
+ } else if (leaks.length) {
+ this.fail(test, new Error('global leak detected: ' + leaks[0]));
+ }
+};
+
+/**
+ * Fail the given `test`.
+ *
+ * @api private
+ * @param {Test} test
+ * @param {Error} err
+ */
+Runner.prototype.fail = function (test, err) {
+ if (test.isPending()) {
+ return;
+ }
+
+ ++this.failures;
+ test.state = 'failed';
+
+ if (!(err instanceof Error || (err && typeof err.message === 'string'))) {
+ err = new Error('the ' + type(err) + ' ' + stringify(err) + ' was thrown, throw an Error :)');
+ }
+
+ try {
+ err.stack = (this.fullStackTrace || !err.stack)
+ ? err.stack
+ : stackFilter(err.stack);
+ } catch (ignored) {
+ // some environments do not take kindly to monkeying with the stack
+ }
+
+ this.emit('fail', test, err);
+};
+
+/**
+ * Fail the given `hook` with `err`.
+ *
+ * Hook failures work in the following pattern:
+ * - If bail, then exit
+ * - Failed `before` hook skips all tests in a suite and subsuites,
+ * but jumps to corresponding `after` hook
+ * - Failed `before each` hook skips remaining tests in a
+ * suite and jumps to corresponding `after each` hook,
+ * which is run only once
+ * - Failed `after` hook does not alter
+ * execution order
+ * - Failed `after each` hook skips remaining tests in a
+ * suite and subsuites, but executes other `after each`
+ * hooks
+ *
+ * @api private
+ * @param {Hook} hook
+ * @param {Error} err
+ */
+Runner.prototype.failHook = function (hook, err) {
+ if (hook.ctx && hook.ctx.currentTest) {
+ hook.originalTitle = hook.originalTitle || hook.title;
+ hook.title = hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"';
+ }
+
+ this.fail(hook, err);
+ if (this.suite.bail()) {
+ this.emit('end');
+ }
+};
+
+/**
+ * Run hook `name` callbacks and then invoke `fn()`.
+ *
+ * @api private
+ * @param {string} name
+ * @param {Function} fn
+ */
+
+Runner.prototype.hook = function (name, fn) {
+ var suite = this.suite;
+ var hooks = suite['_' + name];
+ var self = this;
+
+ function next (i) {
+ var hook = hooks[i];
+ if (!hook) {
+ return fn();
+ }
+ self.currentRunnable = hook;
+
+ hook.ctx.currentTest = self.test;
+
+ self.emit('hook', hook);
+
+ if (!hook.listeners('error').length) {
+ hook.on('error', function (err) {
+ self.failHook(hook, err);
+ });
+ }
+
+ hook.run(function (err) {
+ var testError = hook.error();
+ if (testError) {
+ self.fail(self.test, testError);
+ }
+ if (err) {
+ if (err instanceof Pending) {
+ if (name === 'beforeEach' || name === 'afterEach') {
+ self.test.pending = true;
+ } else {
+ suite.tests.forEach(function (test) {
+ test.pending = true;
+ });
+ // a pending hook won't be executed twice.
+ hook.pending = true;
+ }
+ } else {
+ self.failHook(hook, err);
+
+ // stop executing hooks, notify callee of hook err
+ return fn(err);
+ }
+ }
+ self.emit('hook end', hook);
+ delete hook.ctx.currentTest;
+ next(++i);
+ });
+ }
+
+ Runner.immediately(function () {
+ next(0);
+ });
+};
+
+/**
+ * Run hook `name` for the given array of `suites`
+ * in order, and callback `fn(err, errSuite)`.
+ *
+ * @api private
+ * @param {string} name
+ * @param {Array} suites
+ * @param {Function} fn
+ */
+Runner.prototype.hooks = function (name, suites, fn) {
+ var self = this;
+ var orig = this.suite;
+
+ function next (suite) {
+ self.suite = suite;
+
+ if (!suite) {
+ self.suite = orig;
+ return fn();
+ }
+
+ self.hook(name, function (err) {
+ if (err) {
+ var errSuite = self.suite;
+ self.suite = orig;
+ return fn(err, errSuite);
+ }
+
+ next(suites.pop());
+ });
+ }
+
+ next(suites.pop());
+};
+
+/**
+ * Run hooks from the top level down.
+ *
+ * @param {String} name
+ * @param {Function} fn
+ * @api private
+ */
+Runner.prototype.hookUp = function (name, fn) {
+ var suites = [this.suite].concat(this.parents()).reverse();
+ this.hooks(name, suites, fn);
+};
+
+/**
+ * Run hooks from the bottom up.
+ *
+ * @param {String} name
+ * @param {Function} fn
+ * @api private
+ */
+Runner.prototype.hookDown = function (name, fn) {
+ var suites = [this.suite].concat(this.parents());
+ this.hooks(name, suites, fn);
+};
+
+/**
+ * Return an array of parent Suites from
+ * closest to furthest.
+ *
+ * @return {Array}
+ * @api private
+ */
+Runner.prototype.parents = function () {
+ var suite = this.suite;
+ var suites = [];
+ while (suite.parent) {
+ suite = suite.parent;
+ suites.push(suite);
+ }
+ return suites;
+};
+
+/**
+ * Run the current test and callback `fn(err)`.
+ *
+ * @param {Function} fn
+ * @api private
+ */
+Runner.prototype.runTest = function (fn) {
+ var self = this;
+ var test = this.test;
+
+ if (!test) {
+ return;
+ }
+ if (this.forbidOnly && hasOnly(this.parents().reverse()[0] || this.suite)) {
+ fn(new Error('`.only` forbidden'));
+ return;
+ }
+ if (this.asyncOnly) {
+ test.asyncOnly = true;
+ }
+ test.on('error', function (err) {
+ self.fail(test, err);
+ });
+ if (this.allowUncaught) {
+ test.allowUncaught = true;
+ return test.run(fn);
+ }
+ try {
+ test.run(fn);
+ } catch (err) {
+ fn(err);
+ }
+};
+
+/**
+ * Run tests in the given `suite` and invoke the callback `fn()` when complete.
+ *
+ * @api private
+ * @param {Suite} suite
+ * @param {Function} fn
+ */
+Runner.prototype.runTests = function (suite, fn) {
+ var self = this;
+ var tests = suite.tests.slice();
+ var test;
+
+ function hookErr (_, errSuite, after) {
+ // before/after Each hook for errSuite failed:
+ var orig = self.suite;
+
+ // for failed 'after each' hook start from errSuite parent,
+ // otherwise start from errSuite itself
+ self.suite = after ? errSuite.parent : errSuite;
+
+ if (self.suite) {
+ // call hookUp afterEach
+ self.hookUp('afterEach', function (err2, errSuite2) {
+ self.suite = orig;
+ // some hooks may fail even now
+ if (err2) {
+ return hookErr(err2, errSuite2, true);
+ }
+ // report error suite
+ fn(errSuite);
+ });
+ } else {
+ // there is no need calling other 'after each' hooks
+ self.suite = orig;
+ fn(errSuite);
+ }
+ }
+
+ function next (err, errSuite) {
+ // if we bail after first err
+ if (self.failures && suite._bail) {
+ return fn();
+ }
+
+ if (self._abort) {
+ return fn();
+ }
+
+ if (err) {
+ return hookErr(err, errSuite, true);
+ }
+
+ // next test
+ test = tests.shift();
+
+ // all done
+ if (!test) {
+ return fn();
+ }
+
+ // grep
+ var match = self._grep.test(test.fullTitle());
+ if (self._invert) {
+ match = !match;
+ }
+ if (!match) {
+ // Run immediately only if we have defined a grep. When we
+ // define a grep — It can cause maximum callstack error if
+ // the grep is doing a large recursive loop by neglecting
+ // all tests. The run immediately function also comes with
+ // a performance cost. So we don't want to run immediately
+ // if we run the whole test suite, because running the whole
+ // test suite don't do any immediate recursive loops. Thus,
+ // allowing a JS runtime to breathe.
+ if (self._grep !== self._defaultGrep) {
+ Runner.immediately(next);
+ } else {
+ next();
+ }
+ return;
+ }
+
+ if (test.isPending()) {
+ if (self.forbidPending) {
+ test.isPending = alwaysFalse;
+ self.fail(test, new Error('Pending test forbidden'));
+ delete test.isPending;
+ } else {
+ self.emit('pending', test);
+ }
+ self.emit('test end', test);
+ return next();
+ }
+
+ // execute test and hook(s)
+ self.emit('test', self.test = test);
+ self.hookDown('beforeEach', function (err, errSuite) {
+ if (test.isPending()) {
+ if (self.forbidPending) {
+ test.isPending = alwaysFalse;
+ self.fail(test, new Error('Pending test forbidden'));
+ delete test.isPending;
+ } else {
+ self.emit('pending', test);
+ }
+ self.emit('test end', test);
+ return next();
+ }
+ if (err) {
+ return hookErr(err, errSuite, false);
+ }
+ self.currentRunnable = self.test;
+ self.runTest(function (err) {
+ test = self.test;
+ if (err) {
+ var retry = test.currentRetry();
+ if (err instanceof Pending && self.forbidPending) {
+ self.fail(test, new Error('Pending test forbidden'));
+ } else if (err instanceof Pending) {
+ test.pending = true;
+ self.emit('pending', test);
+ } else if (retry < test.retries()) {
+ var clonedTest = test.clone();
+ clonedTest.currentRetry(retry + 1);
+ tests.unshift(clonedTest);
+
+ // Early return + hook trigger so that it doesn't
+ // increment the count wrong
+ return self.hookUp('afterEach', next);
+ } else {
+ self.fail(test, err);
+ }
+ self.emit('test end', test);
+
+ if (err instanceof Pending) {
+ return next();
+ }
+
+ return self.hookUp('afterEach', next);
+ }
+
+ test.state = 'passed';
+ self.emit('pass', test);
+ self.emit('test end', test);
+ self.hookUp('afterEach', next);
+ });
+ });
+ }
+
+ this.next = next;
+ this.hookErr = hookErr;
+ next();
+};
+
+function alwaysFalse () {
+ return false;
+}
+
+/**
+ * Run the given `suite` and invoke the callback `fn()` when complete.
+ *
+ * @api private
+ * @param {Suite} suite
+ * @param {Function} fn
+ */
+Runner.prototype.runSuite = function (suite, fn) {
+ var i = 0;
+ var self = this;
+ var total = this.grepTotal(suite);
+ var afterAllHookCalled = false;
+
+ debug('run suite %s', suite.fullTitle());
+
+ if (!total || (self.failures && suite._bail)) {
+ return fn();
+ }
+
+ this.emit('suite', this.suite = suite);
+
+ function next (errSuite) {
+ if (errSuite) {
+ // current suite failed on a hook from errSuite
+ if (errSuite === suite) {
+ // if errSuite is current suite
+ // continue to the next sibling suite
+ return done();
+ }
+ // errSuite is among the parents of current suite
+ // stop execution of errSuite and all sub-suites
+ return done(errSuite);
+ }
+
+ if (self._abort) {
+ return done();
+ }
+
+ var curr = suite.suites[i++];
+ if (!curr) {
+ return done();
+ }
+
+ // Avoid grep neglecting large number of tests causing a
+ // huge recursive loop and thus a maximum call stack error.
+ // See comment in `this.runTests()` for more information.
+ if (self._grep !== self._defaultGrep) {
+ Runner.immediately(function () {
+ self.runSuite(curr, next);
+ });
+ } else {
+ self.runSuite(curr, next);
+ }
+ }
+
+ function done (errSuite) {
+ self.suite = suite;
+ self.nextSuite = next;
+
+ if (afterAllHookCalled) {
+ fn(errSuite);
+ } else {
+ // mark that the afterAll block has been called once
+ // and so can be skipped if there is an error in it.
+ afterAllHookCalled = true;
+
+ // remove reference to test
+ delete self.test;
+
+ self.hook('afterAll', function () {
+ self.emit('suite end', suite);
+ fn(errSuite);
+ });
+ }
+ }
+
+ this.nextSuite = next;
+
+ this.hook('beforeAll', function (err) {
+ if (err) {
+ return done();
+ }
+ self.runTests(suite, next);
+ });
+};
+
+/**
+ * Handle uncaught exceptions.
+ *
+ * @param {Error} err
+ * @api private
+ */
+Runner.prototype.uncaught = function (err) {
+ if (err) {
+ debug('uncaught exception %s', err === (function () {
+ return this;
+ }.call(err)) ? (err.message || err) : err);
+ } else {
+ debug('uncaught undefined exception');
+ err = undefinedError();
+ }
+ err.uncaught = true;
+
+ var runnable = this.currentRunnable;
+
+ if (!runnable) {
+ runnable = new Runnable('Uncaught error outside test suite');
+ runnable.parent = this.suite;
+
+ if (this.started) {
+ this.fail(runnable, err);
+ } else {
+ // Can't recover from this failure
+ this.emit('start');
+ this.fail(runnable, err);
+ this.emit('end');
+ }
+
+ return;
+ }
+
+ runnable.clearTimeout();
+
+ // Ignore errors if complete or pending
+ if (runnable.state || runnable.isPending()) {
+ return;
+ }
+ this.fail(runnable, err);
+
+ // recover from test
+ if (runnable.type === 'test') {
+ this.emit('test end', runnable);
+ this.hookUp('afterEach', this.next);
+ return;
+ }
+
+ // recover from hooks
+ if (runnable.type === 'hook') {
+ var errSuite = this.suite;
+ // if hook failure is in afterEach block
+ if (runnable.fullTitle().indexOf('after each') > -1) {
+ return this.hookErr(err, errSuite, true);
+ }
+ // if hook failure is in beforeEach block
+ if (runnable.fullTitle().indexOf('before each') > -1) {
+ return this.hookErr(err, errSuite, false);
+ }
+ // if hook failure is in after or before blocks
+ return this.nextSuite(errSuite);
+ }
+
+ // bail
+ this.emit('end');
+};
+
+/**
+ * Cleans up the references to all the deferred functions
+ * (before/after/beforeEach/afterEach) and tests of a Suite.
+ * These must be deleted otherwise a memory leak can happen,
+ * as those functions may reference variables from closures,
+ * thus those variables can never be garbage collected as long
+ * as the deferred functions exist.
+ *
+ * @param {Suite} suite
+ */
+function cleanSuiteReferences (suite) {
+ function cleanArrReferences (arr) {
+ for (var i = 0; i < arr.length; i++) {
+ delete arr[i].fn;
+ }
+ }
+
+ if (Array.isArray(suite._beforeAll)) {
+ cleanArrReferences(suite._beforeAll);
+ }
+
+ if (Array.isArray(suite._beforeEach)) {
+ cleanArrReferences(suite._beforeEach);
+ }
+
+ if (Array.isArray(suite._afterAll)) {
+ cleanArrReferences(suite._afterAll);
+ }
+
+ if (Array.isArray(suite._afterEach)) {
+ cleanArrReferences(suite._afterEach);
+ }
+
+ for (var i = 0; i < suite.tests.length; i++) {
+ delete suite.tests[i].fn;
+ }
+}
+
+/**
+ * Run the root suite and invoke `fn(failures)`
+ * on completion.
+ *
+ * @param {Function} fn
+ * @return {Runner} for chaining
+ * @api public
+ * @param {Function} fn
+ * @return {Runner} Runner instance.
+ */
+Runner.prototype.run = function (fn) {
+ var self = this;
+ var rootSuite = this.suite;
+
+ // If there is an `only` filter
+ if (hasOnly(rootSuite)) {
+ filterOnly(rootSuite);
+ }
+
+ fn = fn || function () {};
+
+ function uncaught (err) {
+ self.uncaught(err);
+ }
+
+ function start () {
+ self.started = true;
+ self.emit('start');
+ self.runSuite(rootSuite, function () {
+ debug('finished running');
+ self.emit('end');
+ });
+ }
+
+ debug('start');
+
+ // references cleanup to avoid memory leaks
+ this.on('suite end', cleanSuiteReferences);
+
+ // callback
+ this.on('end', function () {
+ debug('end');
+ process.removeListener('uncaughtException', uncaught);
+ fn(self.failures);
+ });
+
+ // uncaught exception
+ process.on('uncaughtException', uncaught);
+
+ if (this._delay) {
+ // for reporters, I guess.
+ // might be nice to debounce some dots while we wait.
+ this.emit('waiting', rootSuite);
+ rootSuite.once('run', start);
+ } else {
+ start();
+ }
+
+ return this;
+};
+
+/**
+ * Cleanly abort execution.
+ *
+ * @api public
+ * @return {Runner} Runner instance.
+ */
+Runner.prototype.abort = function () {
+ debug('aborting');
+ this._abort = true;
+
+ return this;
+};
+
+/**
+ * Filter suites based on `isOnly` logic.
+ *
+ * @param {Array} suite
+ * @returns {Boolean}
+ * @api private
+ */
+function filterOnly (suite) {
+ if (suite._onlyTests.length) {
+ // If the suite contains `only` tests, run those and ignore any nested suites.
+ suite.tests = suite._onlyTests;
+ suite.suites = [];
+ } else {
+ // Otherwise, do not run any of the tests in this suite.
+ suite.tests = [];
+ suite._onlySuites.forEach(function (onlySuite) {
+ // If there are other `only` tests/suites nested in the current `only` suite, then filter that `only` suite.
+ // Otherwise, all of the tests on this `only` suite should be run, so don't filter it.
+ if (hasOnly(onlySuite)) {
+ filterOnly(onlySuite);
+ }
+ });
+ // Run the `only` suites, as well as any other suites that have `only` tests/suites as descendants.
+ suite.suites = suite.suites.filter(function (childSuite) {
+ return suite._onlySuites.indexOf(childSuite) !== -1 || filterOnly(childSuite);
+ });
+ }
+ // Keep the suite only if there is something to run
+ return suite.tests.length || suite.suites.length;
+}
+
+/**
+ * Determines whether a suite has an `only` test or suite as a descendant.
+ *
+ * @param {Array} suite
+ * @returns {Boolean}
+ * @api private
+ */
+function hasOnly (suite) {
+ return suite._onlyTests.length || suite._onlySuites.length || suite.suites.some(hasOnly);
+}
+
+/**
+ * Filter leaks with the given globals flagged as `ok`.
+ *
+ * @api private
+ * @param {Array} ok
+ * @param {Array} globals
+ * @return {Array}
+ */
+function filterLeaks (ok, globals) {
+ return globals.filter(function (key) {
+ // Firefox and Chrome exposes iframes as index inside the window object
+ if (/^\d+/.test(key)) {
+ return false;
+ }
+
+ // in firefox
+ // if runner runs in an iframe, this iframe's window.getInterface method
+ // not init at first it is assigned in some seconds
+ if (global.navigator && (/^getInterface/).test(key)) {
+ return false;
+ }
+
+ // an iframe could be approached by window[iframeIndex]
+ // in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak
+ if (global.navigator && (/^\d+/).test(key)) {
+ return false;
+ }
+
+ // Opera and IE expose global variables for HTML element IDs (issue #243)
+ if (/^mocha-/.test(key)) {
+ return false;
+ }
+
+ var matched = ok.filter(function (ok) {
+ if (~ok.indexOf('*')) {
+ return key.indexOf(ok.split('*')[0]) === 0;
+ }
+ return key === ok;
+ });
+ return !matched.length && (!global.navigator || key !== 'onerror');
+ });
+}
+
+/**
+ * Array of globals dependent on the environment.
+ *
+ * @return {Array}
+ * @api private
+ */
+function extraGlobals () {
+ if (typeof process === 'object' && typeof process.version === 'string') {
+ var parts = process.version.split('.');
+ var nodeVersion = parts.reduce(function (a, v) {
+ return a << 8 | v;
+ });
+
+ // 'errno' was renamed to process._errno in v0.9.11.
+
+ if (nodeVersion < 0x00090B) {
+ return ['errno'];
+ }
+ }
+
+ return [];
+}
+
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"./pending":15,"./runnable":32,"./utils":36,"_process":55,"debug":42,"events":46}],34:[function(require,module,exports){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var EventEmitter = require('events').EventEmitter;
+var Hook = require('./hook');
+var utils = require('./utils');
+var inherits = utils.inherits;
+var debug = require('debug')('mocha:suite');
+var milliseconds = require('./ms');
+
+/**
+ * Expose `Suite`.
+ */
+
+exports = module.exports = Suite;
+
+/**
+ * Create a new `Suite` with the given `title` and parent `Suite`. When a suite
+ * with the same title is already present, that suite is returned to provide
+ * nicer reporter and more flexible meta-testing.
+ *
+ * @api public
+ * @param {Suite} parent
+ * @param {string} title
+ * @return {Suite}
+ */
+exports.create = function (parent, title) {
+ var suite = new Suite(title, parent.ctx);
+ suite.parent = parent;
+ title = suite.fullTitle();
+ parent.addSuite(suite);
+ return suite;
+};
+
+/**
+ * Initialize a new `Suite` with the given `title` and `ctx`.
+ *
+ * @api private
+ * @param {string} title
+ * @param {Context} parentContext
+ */
+function Suite (title, parentContext) {
+ if (!utils.isString(title)) {
+ throw new Error('Suite `title` should be a "string" but "' + typeof title + '" was given instead.');
+ }
+ this.title = title;
+ function Context () {}
+ Context.prototype = parentContext;
+ this.ctx = new Context();
+ this.suites = [];
+ this.tests = [];
+ this.pending = false;
+ this._beforeEach = [];
+ this._beforeAll = [];
+ this._afterEach = [];
+ this._afterAll = [];
+ this.root = !title;
+ this._timeout = 2000;
+ this._enableTimeouts = true;
+ this._slow = 75;
+ this._bail = false;
+ this._retries = -1;
+ this._onlyTests = [];
+ this._onlySuites = [];
+ this.delayed = false;
+}
+
+/**
+ * Inherit from `EventEmitter.prototype`.
+ */
+inherits(Suite, EventEmitter);
+
+/**
+ * Return a clone of this `Suite`.
+ *
+ * @api private
+ * @return {Suite}
+ */
+Suite.prototype.clone = function () {
+ var suite = new Suite(this.title);
+ debug('clone');
+ suite.ctx = this.ctx;
+ suite.timeout(this.timeout());
+ suite.retries(this.retries());
+ suite.enableTimeouts(this.enableTimeouts());
+ suite.slow(this.slow());
+ suite.bail(this.bail());
+ return suite;
+};
+
+/**
+ * Set timeout `ms` or short-hand such as "2s".
+ *
+ * @api private
+ * @param {number|string} ms
+ * @return {Suite|number} for chaining
+ */
+Suite.prototype.timeout = function (ms) {
+ if (!arguments.length) {
+ return this._timeout;
+ }
+ if (ms.toString() === '0') {
+ this._enableTimeouts = false;
+ }
+ if (typeof ms === 'string') {
+ ms = milliseconds(ms);
+ }
+ debug('timeout %d', ms);
+ this._timeout = parseInt(ms, 10);
+ return this;
+};
+
+/**
+ * Set number of times to retry a failed test.
+ *
+ * @api private
+ * @param {number|string} n
+ * @return {Suite|number} for chaining
+ */
+Suite.prototype.retries = function (n) {
+ if (!arguments.length) {
+ return this._retries;
+ }
+ debug('retries %d', n);
+ this._retries = parseInt(n, 10) || 0;
+ return this;
+};
+
+/**
+ * Set timeout to `enabled`.
+ *
+ * @api private
+ * @param {boolean} enabled
+ * @return {Suite|boolean} self or enabled
+ */
+Suite.prototype.enableTimeouts = function (enabled) {
+ if (!arguments.length) {
+ return this._enableTimeouts;
+ }
+ debug('enableTimeouts %s', enabled);
+ this._enableTimeouts = enabled;
+ return this;
+};
+
+/**
+ * Set slow `ms` or short-hand such as "2s".
+ *
+ * @api private
+ * @param {number|string} ms
+ * @return {Suite|number} for chaining
+ */
+Suite.prototype.slow = function (ms) {
+ if (!arguments.length) {
+ return this._slow;
+ }
+ if (typeof ms === 'string') {
+ ms = milliseconds(ms);
+ }
+ debug('slow %d', ms);
+ this._slow = ms;
+ return this;
+};
+
+/**
+ * Sets whether to bail after first error.
+ *
+ * @api private
+ * @param {boolean} bail
+ * @return {Suite|number} for chaining
+ */
+Suite.prototype.bail = function (bail) {
+ if (!arguments.length) {
+ return this._bail;
+ }
+ debug('bail %s', bail);
+ this._bail = bail;
+ return this;
+};
+
+/**
+ * Check if this suite or its parent suite is marked as pending.
+ *
+ * @api private
+ */
+Suite.prototype.isPending = function () {
+ return this.pending || (this.parent && this.parent.isPending());
+};
+
+/**
+ * Run `fn(test[, done])` before running tests.
+ *
+ * @api private
+ * @param {string} title
+ * @param {Function} fn
+ * @return {Suite} for chaining
+ */
+Suite.prototype.beforeAll = function (title, fn) {
+ if (this.isPending()) {
+ return this;
+ }
+ if (typeof title === 'function') {
+ fn = title;
+ title = fn.name;
+ }
+ title = '"before all" hook' + (title ? ': ' + title : '');
+
+ var hook = new Hook(title, fn);
+ hook.parent = this;
+ hook.timeout(this.timeout());
+ hook.retries(this.retries());
+ hook.enableTimeouts(this.enableTimeouts());
+ hook.slow(this.slow());
+ hook.ctx = this.ctx;
+ this._beforeAll.push(hook);
+ this.emit('beforeAll', hook);
+ return this;
+};
+
+/**
+ * Run `fn(test[, done])` after running tests.
+ *
+ * @api private
+ * @param {string} title
+ * @param {Function} fn
+ * @return {Suite} for chaining
+ */
+Suite.prototype.afterAll = function (title, fn) {
+ if (this.isPending()) {
+ return this;
+ }
+ if (typeof title === 'function') {
+ fn = title;
+ title = fn.name;
+ }
+ title = '"after all" hook' + (title ? ': ' + title : '');
+
+ var hook = new Hook(title, fn);
+ hook.parent = this;
+ hook.timeout(this.timeout());
+ hook.retries(this.retries());
+ hook.enableTimeouts(this.enableTimeouts());
+ hook.slow(this.slow());
+ hook.ctx = this.ctx;
+ this._afterAll.push(hook);
+ this.emit('afterAll', hook);
+ return this;
+};
+
+/**
+ * Run `fn(test[, done])` before each test case.
+ *
+ * @api private
+ * @param {string} title
+ * @param {Function} fn
+ * @return {Suite} for chaining
+ */
+Suite.prototype.beforeEach = function (title, fn) {
+ if (this.isPending()) {
+ return this;
+ }
+ if (typeof title === 'function') {
+ fn = title;
+ title = fn.name;
+ }
+ title = '"before each" hook' + (title ? ': ' + title : '');
+
+ var hook = new Hook(title, fn);
+ hook.parent = this;
+ hook.timeout(this.timeout());
+ hook.retries(this.retries());
+ hook.enableTimeouts(this.enableTimeouts());
+ hook.slow(this.slow());
+ hook.ctx = this.ctx;
+ this._beforeEach.push(hook);
+ this.emit('beforeEach', hook);
+ return this;
+};
+
+/**
+ * Run `fn(test[, done])` after each test case.
+ *
+ * @api private
+ * @param {string} title
+ * @param {Function} fn
+ * @return {Suite} for chaining
+ */
+Suite.prototype.afterEach = function (title, fn) {
+ if (this.isPending()) {
+ return this;
+ }
+ if (typeof title === 'function') {
+ fn = title;
+ title = fn.name;
+ }
+ title = '"after each" hook' + (title ? ': ' + title : '');
+
+ var hook = new Hook(title, fn);
+ hook.parent = this;
+ hook.timeout(this.timeout());
+ hook.retries(this.retries());
+ hook.enableTimeouts(this.enableTimeouts());
+ hook.slow(this.slow());
+ hook.ctx = this.ctx;
+ this._afterEach.push(hook);
+ this.emit('afterEach', hook);
+ return this;
+};
+
+/**
+ * Add a test `suite`.
+ *
+ * @api private
+ * @param {Suite} suite
+ * @return {Suite} for chaining
+ */
+Suite.prototype.addSuite = function (suite) {
+ suite.parent = this;
+ suite.timeout(this.timeout());
+ suite.retries(this.retries());
+ suite.enableTimeouts(this.enableTimeouts());
+ suite.slow(this.slow());
+ suite.bail(this.bail());
+ this.suites.push(suite);
+ this.emit('suite', suite);
+ return this;
+};
+
+/**
+ * Add a `test` to this suite.
+ *
+ * @api private
+ * @param {Test} test
+ * @return {Suite} for chaining
+ */
+Suite.prototype.addTest = function (test) {
+ test.parent = this;
+ test.timeout(this.timeout());
+ test.retries(this.retries());
+ test.enableTimeouts(this.enableTimeouts());
+ test.slow(this.slow());
+ test.ctx = this.ctx;
+ this.tests.push(test);
+ this.emit('test', test);
+ return this;
+};
+
+/**
+ * Return the full title generated by recursively concatenating the parent's
+ * full title.
+ *
+ * @api public
+ * @return {string}
+ */
+Suite.prototype.fullTitle = function () {
+ return this.titlePath().join(' ');
+};
+
+/**
+ * Return the title path generated by recursively concatenating the parent's
+ * title path.
+ *
+ * @api public
+ * @return {string}
+ */
+Suite.prototype.titlePath = function () {
+ var result = [];
+ if (this.parent) {
+ result = result.concat(this.parent.titlePath());
+ }
+ if (!this.root) {
+ result.push(this.title);
+ }
+ return result;
+};
+
+/**
+ * Return the total number of tests.
+ *
+ * @api public
+ * @return {number}
+ */
+Suite.prototype.total = function () {
+ return this.suites.reduce(function (sum, suite) {
+ return sum + suite.total();
+ }, 0) + this.tests.length;
+};
+
+/**
+ * Iterates through each suite recursively to find all tests. Applies a
+ * function in the format `fn(test)`.
+ *
+ * @api private
+ * @param {Function} fn
+ * @return {Suite}
+ */
+Suite.prototype.eachTest = function (fn) {
+ this.tests.forEach(fn);
+ this.suites.forEach(function (suite) {
+ suite.eachTest(fn);
+ });
+ return this;
+};
+
+/**
+ * This will run the root suite if we happen to be running in delayed mode.
+ */
+Suite.prototype.run = function run () {
+ if (this.root) {
+ this.emit('run');
+ }
+};
+
+},{"./hook":6,"./ms":14,"./utils":36,"debug":42,"events":46}],35:[function(require,module,exports){
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var Runnable = require('./runnable');
+var utils = require('./utils');
+var isString = utils.isString;
+
+/**
+ * Expose `Test`.
+ */
+
+module.exports = Test;
+
+/**
+ * Initialize a new `Test` with the given `title` and callback `fn`.
+ *
+ * @api private
+ * @param {String} title
+ * @param {Function} fn
+ */
+function Test (title, fn) {
+ if (!isString(title)) {
+ throw new Error('Test `title` should be a "string" but "' + typeof title + '" was given instead.');
+ }
+ Runnable.call(this, title, fn);
+ this.pending = !fn;
+ this.type = 'test';
+}
+
+/**
+ * Inherit from `Runnable.prototype`.
+ */
+utils.inherits(Test, Runnable);
+
+Test.prototype.clone = function () {
+ var test = new Test(this.title, this.fn);
+ test.timeout(this.timeout());
+ test.slow(this.slow());
+ test.enableTimeouts(this.enableTimeouts());
+ test.retries(this.retries());
+ test.currentRetry(this.currentRetry());
+ test.globals(this.globals());
+ test.parent = this.parent;
+ test.file = this.file;
+ test.ctx = this.ctx;
+ return test;
+};
+
+},{"./runnable":32,"./utils":36}],36:[function(require,module,exports){
+(function (process,Buffer){
+'use strict';
+
+/* eslint-env browser */
+
+/**
+ * Module dependencies.
+ */
+
+var basename = require('path').basename;
+var debug = require('debug')('mocha:watch');
+var exists = require('fs').existsSync;
+var glob = require('glob');
+var path = require('path');
+var join = path.join;
+var readdirSync = require('fs').readdirSync;
+var statSync = require('fs').statSync;
+var watchFile = require('fs').watchFile;
+var lstatSync = require('fs').lstatSync;
+var he = require('he');
+
+/**
+ * Ignored directories.
+ */
+
+var ignore = ['node_modules', '.git'];
+
+exports.inherits = require('util').inherits;
+
+/**
+ * Escape special characters in the given string of html.
+ *
+ * @api private
+ * @param {string} html
+ * @return {string}
+ */
+exports.escape = function (html) {
+ return he.encode(String(html), { useNamedReferences: false });
+};
+
+/**
+ * Test if the given obj is type of string.
+ *
+ * @api private
+ * @param {Object} obj
+ * @return {boolean}
+ */
+exports.isString = function (obj) {
+ return typeof obj === 'string';
+};
+
+/**
+ * Watch the given `files` for changes
+ * and invoke `fn(file)` on modification.
+ *
+ * @api private
+ * @param {Array} files
+ * @param {Function} fn
+ */
+exports.watch = function (files, fn) {
+ var options = { interval: 100 };
+ files.forEach(function (file) {
+ debug('file %s', file);
+ watchFile(file, options, function (curr, prev) {
+ if (prev.mtime < curr.mtime) {
+ fn(file);
+ }
+ });
+ });
+};
+
+/**
+ * Ignored files.
+ *
+ * @api private
+ * @param {string} path
+ * @return {boolean}
+ */
+function ignored (path) {
+ return !~ignore.indexOf(path);
+}
+
+/**
+ * Lookup files in the given `dir`.
+ *
+ * @api private
+ * @param {string} dir
+ * @param {string[]} [ext=['.js']]
+ * @param {Array} [ret=[]]
+ * @return {Array}
+ */
+exports.files = function (dir, ext, ret) {
+ ret = ret || [];
+ ext = ext || ['js'];
+
+ var re = new RegExp('\\.(' + ext.join('|') + ')$');
+
+ readdirSync(dir)
+ .filter(ignored)
+ .forEach(function (path) {
+ path = join(dir, path);
+ if (lstatSync(path).isDirectory()) {
+ exports.files(path, ext, ret);
+ } else if (path.match(re)) {
+ ret.push(path);
+ }
+ });
+
+ return ret;
+};
+
+/**
+ * Compute a slug from the given `str`.
+ *
+ * @api private
+ * @param {string} str
+ * @return {string}
+ */
+exports.slug = function (str) {
+ return str
+ .toLowerCase()
+ .replace(/ +/g, '-')
+ .replace(/[^-\w]/g, '');
+};
+
+/**
+ * Strip the function definition from `str`, and re-indent for pre whitespace.
+ *
+ * @param {string} str
+ * @return {string}
+ */
+exports.clean = function (str) {
+ str = str
+ .replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '')
+ // (traditional)-> space/name parameters body (lambda)-> parameters body multi-statement/single keep body content
+ .replace(/^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/, '$1$2$3');
+
+ var spaces = str.match(/^\n?( *)/)[1].length;
+ var tabs = str.match(/^\n?(\t*)/)[1].length;
+ var re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs || spaces) + '}', 'gm');
+
+ str = str.replace(re, '');
+
+ return str.trim();
+};
+
+/**
+ * Parse the given `qs`.
+ *
+ * @api private
+ * @param {string} qs
+ * @return {Object}
+ */
+exports.parseQuery = function (qs) {
+ return qs.replace('?', '').split('&').reduce(function (obj, pair) {
+ var i = pair.indexOf('=');
+ var key = pair.slice(0, i);
+ var val = pair.slice(++i);
+
+ // Due to how the URLSearchParams API treats spaces
+ obj[key] = decodeURIComponent(val.replace(/\+/g, '%20'));
+
+ return obj;
+ }, {});
+};
+
+/**
+ * Highlight the given string of `js`.
+ *
+ * @api private
+ * @param {string} js
+ * @return {string}
+ */
+function highlight (js) {
+ return js
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
+ .replace(/('.*?')/gm, '<span class="string">$1</span>')
+ .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
+ .replace(/(\d+)/gm, '<span class="number">$1</span>')
+ .replace(/\bnew[ \t]+(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
+ .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>');
+}
+
+/**
+ * Highlight the contents of tag `name`.
+ *
+ * @api private
+ * @param {string} name
+ */
+exports.highlightTags = function (name) {
+ var code = document.getElementById('mocha').getElementsByTagName(name);
+ for (var i = 0, len = code.length; i < len; ++i) {
+ code[i].innerHTML = highlight(code[i].innerHTML);
+ }
+};
+
+/**
+ * If a value could have properties, and has none, this function is called,
+ * which returns a string representation of the empty value.
+ *
+ * Functions w/ no properties return `'[Function]'`
+ * Arrays w/ length === 0 return `'[]'`
+ * Objects w/ no properties return `'{}'`
+ * All else: return result of `value.toString()`
+ *
+ * @api private
+ * @param {*} value The value to inspect.
+ * @param {string} typeHint The type of the value
+ * @returns {string}
+ */
+function emptyRepresentation (value, typeHint) {
+ switch (typeHint) {
+ case 'function':
+ return '[Function]';
+ case 'object':
+ return '{}';
+ case 'array':
+ return '[]';
+ default:
+ return value.toString();
+ }
+}
+
+/**
+ * Takes some variable and asks `Object.prototype.toString()` what it thinks it
+ * is.
+ *
+ * @api private
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
+ * @param {*} value The value to test.
+ * @returns {string} Computed type
+ * @example
+ * type({}) // 'object'
+ * type([]) // 'array'
+ * type(1) // 'number'
+ * type(false) // 'boolean'
+ * type(Infinity) // 'number'
+ * type(null) // 'null'
+ * type(new Date()) // 'date'
+ * type(/foo/) // 'regexp'
+ * type('type') // 'string'
+ * type(global) // 'global'
+ * type(new String('foo') // 'object'
+ */
+var type = exports.type = function type (value) {
+ if (value === undefined) {
+ return 'undefined';
+ } else if (value === null) {
+ return 'null';
+ } else if (Buffer.isBuffer(value)) {
+ return 'buffer';
+ }
+ return Object.prototype.toString.call(value)
+ .replace(/^\[.+\s(.+?)]$/, '$1')
+ .toLowerCase();
+};
+
+/**
+ * Stringify `value`. Different behavior depending on type of value:
+ *
+ * - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
+ * - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
+ * - If `value` is an *empty* object, function, or array, return result of function
+ * {@link emptyRepresentation}.
+ * - If `value` has properties, call {@link exports.canonicalize} on it, then return result of
+ * JSON.stringify().
+ *
+ * @api private
+ * @see exports.type
+ * @param {*} value
+ * @return {string}
+ */
+exports.stringify = function (value) {
+ var typeHint = type(value);
+
+ if (!~['object', 'array', 'function'].indexOf(typeHint)) {
+ if (typeHint === 'buffer') {
+ var json = Buffer.prototype.toJSON.call(value);
+ // Based on the toJSON result
+ return jsonStringify(json.data && json.type ? json.data : json, 2)
+ .replace(/,(\n|$)/g, '$1');
+ }
+
+ // IE7/IE8 has a bizarre String constructor; needs to be coerced
+ // into an array and back to obj.
+ if (typeHint === 'string' && typeof value === 'object') {
+ value = value.split('').reduce(function (acc, char, idx) {
+ acc[idx] = char;
+ return acc;
+ }, {});
+ typeHint = 'object';
+ } else {
+ return jsonStringify(value);
+ }
+ }
+
+ for (var prop in value) {
+ if (Object.prototype.hasOwnProperty.call(value, prop)) {
+ return jsonStringify(exports.canonicalize(value, null, typeHint), 2).replace(/,(\n|$)/g, '$1');
+ }
+ }
+
+ return emptyRepresentation(value, typeHint);
+};
+
+/**
+ * like JSON.stringify but more sense.
+ *
+ * @api private
+ * @param {Object} object
+ * @param {number=} spaces
+ * @param {number=} depth
+ * @returns {*}
+ */
+function jsonStringify (object, spaces, depth) {
+ if (typeof spaces === 'undefined') {
+ // primitive types
+ return _stringify(object);
+ }
+
+ depth = depth || 1;
+ var space = spaces * depth;
+ var str = Array.isArray(object) ? '[' : '{';
+ var end = Array.isArray(object) ? ']' : '}';
+ var length = typeof object.length === 'number' ? object.length : Object.keys(object).length;
+ // `.repeat()` polyfill
+ function repeat (s, n) {
+ return new Array(n).join(s);
+ }
+
+ function _stringify (val) {
+ switch (type(val)) {
+ case 'null':
+ case 'undefined':
+ val = '[' + val + ']';
+ break;
+ case 'array':
+ case 'object':
+ val = jsonStringify(val, spaces, depth + 1);
+ break;
+ case 'boolean':
+ case 'regexp':
+ case 'symbol':
+ case 'number':
+ val = val === 0 && (1 / val) === -Infinity // `-0`
+ ? '-0'
+ : val.toString();
+ break;
+ case 'date':
+ var sDate = isNaN(val.getTime()) ? val.toString() : val.toISOString();
+ val = '[Date: ' + sDate + ']';
+ break;
+ case 'buffer':
+ var json = val.toJSON();
+ // Based on the toJSON result
+ json = json.data && json.type ? json.data : json;
+ val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
+ break;
+ default:
+ val = (val === '[Function]' || val === '[Circular]')
+ ? val
+ : JSON.stringify(val); // string
+ }
+ return val;
+ }
+
+ for (var i in object) {
+ if (!Object.prototype.hasOwnProperty.call(object, i)) {
+ continue; // not my business
+ }
+ --length;
+ str += '\n ' + repeat(' ', space) +
+ (Array.isArray(object) ? '' : '"' + i + '": ') + // key
+ _stringify(object[i]) + // value
+ (length ? ',' : ''); // comma
+ }
+
+ return str +
+ // [], {}
+ (str.length !== 1 ? '\n' + repeat(' ', --space) + end : end);
+}
+
+/**
+ * Return a new Thing that has the keys in sorted order. Recursive.
+ *
+ * If the Thing...
+ * - has already been seen, return string `'[Circular]'`
+ * - is `undefined`, return string `'[undefined]'`
+ * - is `null`, return value `null`
+ * - is some other primitive, return the value
+ * - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
+ * - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
+ * - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()`
+ *
+ * @api private
+ * @see {@link exports.stringify}
+ * @param {*} value Thing to inspect. May or may not have properties.
+ * @param {Array} [stack=[]] Stack of seen values
+ * @param {string} [typeHint] Type hint
+ * @return {(Object|Array|Function|string|undefined)}
+ */
+exports.canonicalize = function canonicalize (value, stack, typeHint) {
+ var canonicalizedObj;
+ /* eslint-disable no-unused-vars */
+ var prop;
+ /* eslint-enable no-unused-vars */
+ typeHint = typeHint || type(value);
+ function withStack (value, fn) {
+ stack.push(value);
+ fn();
+ stack.pop();
+ }
+
+ stack = stack || [];
+
+ if (stack.indexOf(value) !== -1) {
+ return '[Circular]';
+ }
+
+ switch (typeHint) {
+ case 'undefined':
+ case 'buffer':
+ case 'null':
+ canonicalizedObj = value;
+ break;
+ case 'array':
+ withStack(value, function () {
+ canonicalizedObj = value.map(function (item) {
+ return exports.canonicalize(item, stack);
+ });
+ });
+ break;
+ case 'function':
+ /* eslint-disable guard-for-in */
+ for (prop in value) {
+ canonicalizedObj = {};
+ break;
+ }
+ /* eslint-enable guard-for-in */
+ if (!canonicalizedObj) {
+ canonicalizedObj = emptyRepresentation(value, typeHint);
+ break;
+ }
+ /* falls through */
+ case 'object':
+ canonicalizedObj = canonicalizedObj || {};
+ withStack(value, function () {
+ Object.keys(value).sort().forEach(function (key) {
+ canonicalizedObj[key] = exports.canonicalize(value[key], stack);
+ });
+ });
+ break;
+ case 'date':
+ case 'number':
+ case 'regexp':
+ case 'boolean':
+ case 'symbol':
+ canonicalizedObj = value;
+ break;
+ default:
+ canonicalizedObj = value + '';
+ }
+
+ return canonicalizedObj;
+};
+
+/**
+ * Lookup file names at the given `path`.
+ *
+ * @api public
+ * @param {string} path Base path to start searching from.
+ * @param {string[]} extensions File extensions to look for.
+ * @param {boolean} recursive Whether or not to recurse into subdirectories.
+ * @return {string[]} An array of paths.
+ */
+exports.lookupFiles = function lookupFiles (path, extensions, recursive) {
+ var files = [];
+ var re = new RegExp('\\.(' + extensions.join('|') + ')$');
+
+ if (!exists(path)) {
+ if (exists(path + '.js')) {
+ path += '.js';
+ } else {
+ files = glob.sync(path);
+ if (!files.length) {
+ throw new Error("cannot resolve path (or pattern) '" + path + "'");
+ }
+ return files;
+ }
+ }
+
+ try {
+ var stat = statSync(path);
+ if (stat.isFile()) {
+ return path;
+ }
+ } catch (err) {
+ // ignore error
+ return;
+ }
+
+ readdirSync(path).forEach(function (file) {
+ file = join(path, file);
+ try {
+ var stat = statSync(file);
+ if (stat.isDirectory()) {
+ if (recursive) {
+ files = files.concat(lookupFiles(file, extensions, recursive));
+ }
+ return;
+ }
+ } catch (err) {
+ // ignore error
+ return;
+ }
+ if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') {
+ return;
+ }
+ files.push(file);
+ });
+
+ return files;
+};
+
+/**
+ * Generate an undefined error with a message warning the user.
+ *
+ * @return {Error}
+ */
+
+exports.undefinedError = function () {
+ return new Error('Caught undefined error, did you throw without specifying what?');
+};
+
+/**
+ * Generate an undefined error if `err` is not defined.
+ *
+ * @param {Error} err
+ * @return {Error}
+ */
+
+exports.getError = function (err) {
+ return err || exports.undefinedError();
+};
+
+/**
+ * @summary
+ * This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
+ * @description
+ * When invoking this function you get a filter function that get the Error.stack as an input,
+ * and return a prettify output.
+ * (i.e: strip Mocha and internal node functions from stack trace).
+ * @returns {Function}
+ */
+exports.stackTraceFilter = function () {
+ // TODO: Replace with `process.browser`
+ var is = typeof document === 'undefined' ? { node: true } : { browser: true };
+ var slash = path.sep;
+ var cwd;
+ if (is.node) {
+ cwd = process.cwd() + slash;
+ } else {
+ cwd = (typeof location === 'undefined'
+ ? window.location
+ : location).href.replace(/\/[^/]*$/, '/');
+ slash = '/';
+ }
+
+ function isMochaInternal (line) {
+ return (~line.indexOf('node_modules' + slash + 'mocha' + slash)) ||
+ (~line.indexOf('node_modules' + slash + 'mocha.js')) ||
+ (~line.indexOf('bower_components' + slash + 'mocha.js')) ||
+ (~line.indexOf(slash + 'mocha.js'));
+ }
+
+ function isNodeInternal (line) {
+ return (~line.indexOf('(timers.js:')) ||
+ (~line.indexOf('(events.js:')) ||
+ (~line.indexOf('(node.js:')) ||
+ (~line.indexOf('(module.js:')) ||
+ (~line.indexOf('GeneratorFunctionPrototype.next (native)')) ||
+ false;
+ }
+
+ return function (stack) {
+ stack = stack.split('\n');
+
+ stack = stack.reduce(function (list, line) {
+ if (isMochaInternal(line)) {
+ return list;
+ }
+
+ if (is.node && isNodeInternal(line)) {
+ return list;
+ }
+
+ // Clean up cwd(absolute)
+ if (/\(?.+:\d+:\d+\)?$/.test(line)) {
+ line = line.replace(cwd, '');
+ }
+
+ list.push(line);
+ return list;
+ }, []);
+
+ return stack.join('\n');
+ };
+};
+
+/**
+ * Crude, but effective.
+ * @api
+ * @param {*} value
+ * @returns {boolean} Whether or not `value` is a Promise
+ */
+exports.isPromise = function isPromise (value) {
+ return typeof value === 'object' && typeof value.then === 'function';
+};
+
+/**
+ * It's a noop.
+ * @api
+ */
+exports.noop = function () {};
+
+}).call(this,require('_process'),require("buffer").Buffer)
+},{"_process":55,"buffer":"buffer","debug":42,"fs":40,"glob":40,"he":47,"path":40,"util":75}],37:[function(require,module,exports){
+'use strict'
+
+exports.byteLength = byteLength
+exports.toByteArray = toByteArray
+exports.fromByteArray = fromByteArray
+
+var lookup = []
+var revLookup = []
+var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
+
+var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
+for (var i = 0, len = code.length; i < len; ++i) {
+ lookup[i] = code[i]
+ revLookup[code.charCodeAt(i)] = i
+}
+
+revLookup['-'.charCodeAt(0)] = 62
+revLookup['_'.charCodeAt(0)] = 63
+
+function placeHoldersCount (b64) {
+ var len = b64.length
+ if (len % 4 > 0) {
+ throw new Error('Invalid string. Length must be a multiple of 4')
+ }
+
+ // the number of equal signs (place holders)
+ // if there are two placeholders, than the two characters before it
+ // represent one byte
+ // if there is only one, then the three characters before it represent 2 bytes
+ // this is just a cheap hack to not do indexOf twice
+ return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
+}
+
+function byteLength (b64) {
+ // base64 is 4/3 + up to two characters of the original data
+ return (b64.length * 3 / 4) - placeHoldersCount(b64)
+}
+
+function toByteArray (b64) {
+ var i, l, tmp, placeHolders, arr
+ var len = b64.length
+ placeHolders = placeHoldersCount(b64)
+
+ arr = new Arr((len * 3 / 4) - placeHolders)
+
+ // if there are placeholders, only get up to the last complete 4 chars
+ l = placeHolders > 0 ? len - 4 : len
+
+ var L = 0
+
+ for (i = 0; i < l; i += 4) {
+ tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
+ arr[L++] = (tmp >> 16) & 0xFF
+ arr[L++] = (tmp >> 8) & 0xFF
+ arr[L++] = tmp & 0xFF
+ }
+
+ if (placeHolders === 2) {
+ tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
+ arr[L++] = tmp & 0xFF
+ } else if (placeHolders === 1) {
+ tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
+ arr[L++] = (tmp >> 8) & 0xFF
+ arr[L++] = tmp & 0xFF
+ }
+
+ return arr
+}
+
+function tripletToBase64 (num) {
+ return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
+}
+
+function encodeChunk (uint8, start, end) {
+ var tmp
+ var output = []
+ for (var i = start; i < end; i += 3) {
+ tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
+ output.push(tripletToBase64(tmp))
+ }
+ return output.join('')
+}
+
+function fromByteArray (uint8) {
+ var tmp
+ var len = uint8.length
+ var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
+ var output = ''
+ var parts = []
+ var maxChunkLength = 16383 // must be multiple of 3
+
+ // go through the array every three bytes, we'll deal with trailing stuff later
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
+ }
+
+ // pad the end with zeros, but make sure to not forget the extra bytes
+ if (extraBytes === 1) {
+ tmp = uint8[len - 1]
+ output += lookup[tmp >> 2]
+ output += lookup[(tmp << 4) & 0x3F]
+ output += '=='
+ } else if (extraBytes === 2) {
+ tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
+ output += lookup[tmp >> 10]
+ output += lookup[(tmp >> 4) & 0x3F]
+ output += lookup[(tmp << 2) & 0x3F]
+ output += '='
+ }
+
+ parts.push(output)
+
+ return parts.join('')
+}
+
+},{}],38:[function(require,module,exports){
+
+},{}],39:[function(require,module,exports){
+(function (process){
+var WritableStream = require('stream').Writable
+var inherits = require('util').inherits
+
+module.exports = BrowserStdout
+
+
+inherits(BrowserStdout, WritableStream)
+
+function BrowserStdout(opts) {
+ if (!(this instanceof BrowserStdout)) return new BrowserStdout(opts)
+
+ opts = opts || {}
+ WritableStream.call(this, opts)
+ this.label = (opts.label !== undefined) ? opts.label : 'stdout'
+}
+
+BrowserStdout.prototype._write = function(chunks, encoding, cb) {
+ var output = chunks.toString ? chunks.toString() : chunks
+ if (this.label === false) {
+ console.log(output)
+ } else {
+ console.log(this.label+':', output)
+ }
+ process.nextTick(cb)
+}
+
+}).call(this,require('_process'))
+},{"_process":55,"stream":70,"util":75}],40:[function(require,module,exports){
+arguments[4][38][0].apply(exports,arguments)
+},{"dup":38}],41:[function(require,module,exports){
+(function (Buffer){
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// NOTE: These type checking functions intentionally don't use `instanceof`
+// because it is fragile and can be easily faked with `Object.create()`.
+
+function isArray(arg) {
+ if (Array.isArray) {
+ return Array.isArray(arg);
+ }
+ return objectToString(arg) === '[object Array]';
+}
+exports.isArray = isArray;
+
+function isBoolean(arg) {
+ return typeof arg === 'boolean';
+}
+exports.isBoolean = isBoolean;
+
+function isNull(arg) {
+ return arg === null;
+}
+exports.isNull = isNull;
+
+function isNullOrUndefined(arg) {
+ return arg == null;
+}
+exports.isNullOrUndefined = isNullOrUndefined;
+
+function isNumber(arg) {
+ return typeof arg === 'number';
+}
+exports.isNumber = isNumber;
+
+function isString(arg) {
+ return typeof arg === 'string';
+}
+exports.isString = isString;
+
+function isSymbol(arg) {
+ return typeof arg === 'symbol';
+}
+exports.isSymbol = isSymbol;
+
+function isUndefined(arg) {
+ return arg === void 0;
+}
+exports.isUndefined = isUndefined;
+
+function isRegExp(re) {
+ return objectToString(re) === '[object RegExp]';
+}
+exports.isRegExp = isRegExp;
+
+function isObject(arg) {
+ return typeof arg === 'object' && arg !== null;
+}
+exports.isObject = isObject;
+
+function isDate(d) {
+ return objectToString(d) === '[object Date]';
+}
+exports.isDate = isDate;
+
+function isError(e) {
+ return (objectToString(e) === '[object Error]' || e instanceof Error);
+}
+exports.isError = isError;
+
+function isFunction(arg) {
+ return typeof arg === 'function';
+}
+exports.isFunction = isFunction;
+
+function isPrimitive(arg) {
+ return arg === null ||
+ typeof arg === 'boolean' ||
+ typeof arg === 'number' ||
+ typeof arg === 'string' ||
+ typeof arg === 'symbol' || // ES6 symbol
+ typeof arg === 'undefined';
+}
+exports.isPrimitive = isPrimitive;
+
+exports.isBuffer = Buffer.isBuffer;
+
+function objectToString(o) {
+ return Object.prototype.toString.call(o);
+}
+
+}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
+},{"../../is-buffer/index.js":50}],42:[function(require,module,exports){
+(function (process){
+/**
+ * This is the web browser implementation of `debug()`.
+ *
+ * Expose `debug()` as the module.
+ */
+
+exports = module.exports = require('./debug');
+exports.log = log;
+exports.formatArgs = formatArgs;
+exports.save = save;
+exports.load = load;
+exports.useColors = useColors;
+exports.storage = 'undefined' != typeof chrome
+ && 'undefined' != typeof chrome.storage
+ ? chrome.storage.local
+ : localstorage();
+
+/**
+ * Colors.
+ */
+
+exports.colors = [
+ '#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC',
+ '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF',
+ '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC',
+ '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF',
+ '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC',
+ '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033',
+ '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366',
+ '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933',
+ '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC',
+ '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF',
+ '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'
+];
+
+/**
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
+ * and the Firebug extension (any Firefox version) are known
+ * to support "%c" CSS customizations.
+ *
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
+ */
+
+function useColors() {
+ // NB: In an Electron preload script, document will be defined but not fully
+ // initialized. Since we know we're in Chrome, we'll just detect this case
+ // explicitly
+ if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {
+ return true;
+ }
+
+ // Internet Explorer and Edge do not support colors.
+ if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
+ return false;
+ }
+
+ // is webkit? http://stackoverflow.com/a/16459606/376773
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
+ return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
+ // is firebug? http://stackoverflow.com/a/398120/376773
+ (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
+ // is firefox >= v31?
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
+ // double check webkit in userAgent just in case we are in a worker
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
+}
+
+/**
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
+ */
+
+exports.formatters.j = function(v) {
+ try {
+ return JSON.stringify(v);
+ } catch (err) {
+ return '[UnexpectedJSONParseError]: ' + err.message;
+ }
+};
+
+
+/**
+ * Colorize log arguments if enabled.
+ *
+ * @api public
+ */
+
+function formatArgs(args) {
+ var useColors = this.useColors;
+
+ args[0] = (useColors ? '%c' : '')
+ + this.namespace
+ + (useColors ? ' %c' : ' ')
+ + args[0]
+ + (useColors ? '%c ' : ' ')
+ + '+' + exports.humanize(this.diff);
+
+ if (!useColors) return;
+
+ var c = 'color: ' + this.color;
+ args.splice(1, 0, c, 'color: inherit')
+
+ // the final "%c" is somewhat tricky, because there could be other
+ // arguments passed either before or after the %c, so we need to
+ // figure out the correct index to insert the CSS into
+ var index = 0;
+ var lastC = 0;
+ args[0].replace(/%[a-zA-Z%]/g, function(match) {
+ if ('%%' === match) return;
+ index++;
+ if ('%c' === match) {
+ // we only are interested in the *last* %c
+ // (the user may have provided their own)
+ lastC = index;
+ }
+ });
+
+ args.splice(lastC, 0, c);
+}
+
+/**
+ * Invokes `console.log()` when available.
+ * No-op when `console.log` is not a "function".
+ *
+ * @api public
+ */
+
+function log() {
+ // this hackery is required for IE8/9, where
+ // the `console.log` function doesn't have 'apply'
+ return 'object' === typeof console
+ && console.log
+ && Function.prototype.apply.call(console.log, console, arguments);
+}
+
+/**
+ * Save `namespaces`.
+ *
+ * @param {String} namespaces
+ * @api private
+ */
+
+function save(namespaces) {
+ try {
+ if (null == namespaces) {
+ exports.storage.removeItem('debug');
+ } else {
+ exports.storage.debug = namespaces;
+ }
+ } catch(e) {}
+}
+
+/**
+ * Load `namespaces`.
+ *
+ * @return {String} returns the previously persisted debug modes
+ * @api private
+ */
+
+function load() {
+ var r;
+ try {
+ r = exports.storage.debug;
+ } catch(e) {}
+
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
+ r = process.env.DEBUG;
+ }
+
+ return r;
+}
+
+/**
+ * Enable namespaces listed in `localStorage.debug` initially.
+ */
+
+exports.enable(load());
+
+/**
+ * Localstorage attempts to return the localstorage.
+ *
+ * This is necessary because safari throws
+ * when a user disables cookies/localstorage
+ * and you attempt to access it.
+ *
+ * @return {LocalStorage}
+ * @api private
+ */
+
+function localstorage() {
+ try {
+ return window.localStorage;
+ } catch (e) {}
+}
+
+}).call(this,require('_process'))
+},{"./debug":43,"_process":55}],43:[function(require,module,exports){
+
+/**
+ * This is the common logic for both the Node.js and web browser
+ * implementations of `debug()`.
+ *
+ * Expose `debug()` as the module.
+ */
+
+exports = module.exports = createDebug.debug = createDebug['default'] = createDebug;
+exports.coerce = coerce;
+exports.disable = disable;
+exports.enable = enable;
+exports.enabled = enabled;
+exports.humanize = require('ms');
+
+/**
+ * Active `debug` instances.
+ */
+exports.instances = [];
+
+/**
+ * The currently active debug mode names, and names to skip.
+ */
+
+exports.names = [];
+exports.skips = [];
+
+/**
+ * Map of special "%n" handling functions, for the debug "format" argument.
+ *
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
+ */
+
+exports.formatters = {};
+
+/**
+ * Select a color.
+ * @param {String} namespace
+ * @return {Number}
+ * @api private
+ */
+
+function selectColor(namespace) {
+ var hash = 0, i;
+
+ for (i in namespace) {
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
+ hash |= 0; // Convert to 32bit integer
+ }
+
+ return exports.colors[Math.abs(hash) % exports.colors.length];
+}
+
+/**
+ * Create a debugger with the given `namespace`.
+ *
+ * @param {String} namespace
+ * @return {Function}
+ * @api public
+ */
+
+function createDebug(namespace) {
+
+ var prevTime;
+
+ function debug() {
+ // disabled?
+ if (!debug.enabled) return;
+
+ var self = debug;
+
+ // set `diff` timestamp
+ var curr = +new Date();
+ var ms = curr - (prevTime || curr);
+ self.diff = ms;
+ self.prev = prevTime;
+ self.curr = curr;
+ prevTime = curr;
+
+ // turn the `arguments` into a proper Array
+ var args = new Array(arguments.length);
+ for (var i = 0; i < args.length; i++) {
+ args[i] = arguments[i];
+ }
+
+ args[0] = exports.coerce(args[0]);
+
+ if ('string' !== typeof args[0]) {
+ // anything else let's inspect with %O
+ args.unshift('%O');
+ }
+
+ // apply any `formatters` transformations
+ var index = 0;
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
+ // if we encounter an escaped % then don't increase the array index
+ if (match === '%%') return match;
+ index++;
+ var formatter = exports.formatters[format];
+ if ('function' === typeof formatter) {
+ var val = args[index];
+ match = formatter.call(self, val);
+
+ // now we need to remove `args[index]` since it's inlined in the `format`
+ args.splice(index, 1);
+ index--;
+ }
+ return match;
+ });
+
+ // apply env-specific formatting (colors, etc.)
+ exports.formatArgs.call(self, args);
+
+ var logFn = debug.log || exports.log || console.log.bind(console);
+ logFn.apply(self, args);
+ }
+
+ debug.namespace = namespace;
+ debug.enabled = exports.enabled(namespace);
+ debug.useColors = exports.useColors();
+ debug.color = selectColor(namespace);
+ debug.destroy = destroy;
+
+ // env-specific initialization logic for debug instances
+ if ('function' === typeof exports.init) {
+ exports.init(debug);
+ }
+
+ exports.instances.push(debug);
+
+ return debug;
+}
+
+function destroy () {
+ var index = exports.instances.indexOf(this);
+ if (index !== -1) {
+ exports.instances.splice(index, 1);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/**
+ * Enables a debug mode by namespaces. This can include modes
+ * separated by a colon and wildcards.
+ *
+ * @param {String} namespaces
+ * @api public
+ */
+
+function enable(namespaces) {
+ exports.save(namespaces);
+
+ exports.names = [];
+ exports.skips = [];
+
+ var i;
+ var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
+ var len = split.length;
+
+ for (i = 0; i < len; i++) {
+ if (!split[i]) continue; // ignore empty strings
+ namespaces = split[i].replace(/\*/g, '.*?');
+ if (namespaces[0] === '-') {
+ exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
+ } else {
+ exports.names.push(new RegExp('^' + namespaces + '$'));
+ }
+ }
+
+ for (i = 0; i < exports.instances.length; i++) {
+ var instance = exports.instances[i];
+ instance.enabled = exports.enabled(instance.namespace);
+ }
+}
+
+/**
+ * Disable debug output.
+ *
+ * @api public
+ */
+
+function disable() {
+ exports.enable('');
+}
+
+/**
+ * Returns true if the given mode name is enabled, false otherwise.
+ *
+ * @param {String} name
+ * @return {Boolean}
+ * @api public
+ */
+
+function enabled(name) {
+ if (name[name.length - 1] === '*') {
+ return true;
+ }
+ var i, len;
+ for (i = 0, len = exports.skips.length; i < len; i++) {
+ if (exports.skips[i].test(name)) {
+ return false;
+ }
+ }
+ for (i = 0, len = exports.names.length; i < len; i++) {
+ if (exports.names[i].test(name)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * Coerce `val`.
+ *
+ * @param {Mixed} val
+ * @return {Mixed}
+ * @api private
+ */
+
+function coerce(val) {
+ if (val instanceof Error) return val.stack || val.message;
+ return val;
+}
+
+},{"ms":53}],44:[function(require,module,exports){
+/*!
+
+ diff v3.3.1
+
+Software License Agreement (BSD License)
+
+Copyright (c) 2009-2015, Kevin Decker <kpdecker@gmail.com>
+
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* Neither the name of Kevin Decker nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+@license
+*/
+(function webpackUniversalModuleDefinition(root, factory) {
+ if(typeof exports === 'object' && typeof module === 'object')
+ module.exports = factory();
+ else if(false)
+ define([], factory);
+ else if(typeof exports === 'object')
+ exports["JsDiff"] = factory();
+ else
+ root["JsDiff"] = factory();
+})(this, function() {
+return /******/ (function(modules) { // webpackBootstrap
+/******/ // The module cache
+/******/ var installedModules = {};
+
+/******/ // The require function
+/******/ function __webpack_require__(moduleId) {
+
+/******/ // Check if module is in cache
+/******/ if(installedModules[moduleId])
+/******/ return installedModules[moduleId].exports;
+
+/******/ // Create a new module (and put it into the cache)
+/******/ var module = installedModules[moduleId] = {
+/******/ exports: {},
+/******/ id: moduleId,
+/******/ loaded: false
+/******/ };
+
+/******/ // Execute the module function
+/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
+
+/******/ // Flag the module as loaded
+/******/ module.loaded = true;
+
+/******/ // Return the exports of the module
+/******/ return module.exports;
+/******/ }
+
+
+/******/ // expose the modules object (__webpack_modules__)
+/******/ __webpack_require__.m = modules;
+
+/******/ // expose the module cache
+/******/ __webpack_require__.c = installedModules;
+
+/******/ // __webpack_public_path__
+/******/ __webpack_require__.p = "";
+
+/******/ // Load entry module and return exports
+/******/ return __webpack_require__(0);
+/******/ })
+/************************************************************************/
+/******/ ([
+/* 0 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports.canonicalize = exports.convertChangesToXML = exports.convertChangesToDMP = exports.merge = exports.parsePatch = exports.applyPatches = exports.applyPatch = exports.createPatch = exports.createTwoFilesPatch = exports.structuredPatch = exports.diffArrays = exports.diffJson = exports.diffCss = exports.diffSentences = exports.diffTrimmedLines = exports.diffLines = exports.diffWordsWithSpace = exports.diffWords = exports.diffChars = exports.Diff = undefined;
+
+ /*istanbul ignore end*/var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
+
+ /*istanbul ignore end*/var /*istanbul ignore start*/_character = __webpack_require__(2) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_word = __webpack_require__(3) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_line = __webpack_require__(5) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_sentence = __webpack_require__(6) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_css = __webpack_require__(7) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_json = __webpack_require__(8) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_array = __webpack_require__(9) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_apply = __webpack_require__(10) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_parse = __webpack_require__(11) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_merge = __webpack_require__(13) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_create = __webpack_require__(14) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_dmp = __webpack_require__(16) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_xml = __webpack_require__(17) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+ /* See LICENSE file for terms of use */
+
+ /*
+ * Text diff implementation.
+ *
+ * This library supports the following APIS:
+ * JsDiff.diffChars: Character by character diff
+ * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
+ * JsDiff.diffLines: Line based diff
+ *
+ * JsDiff.diffCss: Diff targeted at CSS content
+ *
+ * These methods are based on the implementation proposed in
+ * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
+ * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
+ */
+ exports. /*istanbul ignore end*/Diff = _base2['default'];
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffChars = _character.diffChars;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffWords = _word.diffWords;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffWordsWithSpace = _word.diffWordsWithSpace;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffLines = _line.diffLines;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffTrimmedLines = _line.diffTrimmedLines;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffSentences = _sentence.diffSentences;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffCss = _css.diffCss;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffJson = _json.diffJson;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffArrays = _array.diffArrays;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/structuredPatch = _create.structuredPatch;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/createTwoFilesPatch = _create.createTwoFilesPatch;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/createPatch = _create.createPatch;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatch = _apply.applyPatch;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatches = _apply.applyPatches;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/parsePatch = _parse.parsePatch;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/merge = _merge.merge;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/convertChangesToDMP = _dmp.convertChangesToDMP;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/convertChangesToXML = _xml.convertChangesToXML;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/canonicalize = _json.canonicalize;
+
+
+
+/***/ }),
+/* 1 */
+/***/ (function(module, exports) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports['default'] = /*istanbul ignore end*/Diff;
+ function Diff() {}
+
+ Diff.prototype = {
+ /*istanbul ignore start*/ /*istanbul ignore end*/diff: function diff(oldString, newString) {
+ /*istanbul ignore start*/var /*istanbul ignore end*/options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+
+ var callback = options.callback;
+ if (typeof options === 'function') {
+ callback = options;
+ options = {};
+ }
+ this.options = options;
+
+ var self = this;
+
+ function done(value) {
+ if (callback) {
+ setTimeout(function () {
+ callback(undefined, value);
+ }, 0);
+ return true;
+ } else {
+ return value;
+ }
+ }
+
+ // Allow subclasses to massage the input prior to running
+ oldString = this.castInput(oldString);
+ newString = this.castInput(newString);
+
+ oldString = this.removeEmpty(this.tokenize(oldString));
+ newString = this.removeEmpty(this.tokenize(newString));
+
+ var newLen = newString.length,
+ oldLen = oldString.length;
+ var editLength = 1;
+ var maxEditLength = newLen + oldLen;
+ var bestPath = [{ newPos: -1, components: [] }];
+
+ // Seed editLength = 0, i.e. the content starts with the same values
+ var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
+ if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
+ // Identity per the equality and tokenizer
+ return done([{ value: this.join(newString), count: newString.length }]);
+ }
+
+ // Main worker method. checks all permutations of a given edit length for acceptance.
+ function execEditLength() {
+ for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
+ var basePath = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
+ var addPath = bestPath[diagonalPath - 1],
+ removePath = bestPath[diagonalPath + 1],
+ _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
+ if (addPath) {
+ // No one else is going to attempt to use this value, clear it
+ bestPath[diagonalPath - 1] = undefined;
+ }
+
+ var canAdd = addPath && addPath.newPos + 1 < newLen,
+ canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
+ if (!canAdd && !canRemove) {
+ // If this path is a terminal then prune
+ bestPath[diagonalPath] = undefined;
+ continue;
+ }
+
+ // Select the diagonal that we want to branch from. We select the prior
+ // path whose position in the new string is the farthest from the origin
+ // and does not pass the bounds of the diff graph
+ if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
+ basePath = clonePath(removePath);
+ self.pushComponent(basePath.components, undefined, true);
+ } else {
+ basePath = addPath; // No need to clone, we've pulled it from the list
+ basePath.newPos++;
+ self.pushComponent(basePath.components, true, undefined);
+ }
+
+ _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
+
+ // If we have hit the end of both strings, then we are done
+ if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
+ return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
+ } else {
+ // Otherwise track this path as a potential candidate and continue.
+ bestPath[diagonalPath] = basePath;
+ }
+ }
+
+ editLength++;
+ }
+
+ // Performs the length of edit iteration. Is a bit fugly as this has to support the
+ // sync and async mode which is never fun. Loops over execEditLength until a value
+ // is produced.
+ if (callback) {
+ (function exec() {
+ setTimeout(function () {
+ // This should not happen, but we want to be safe.
+ /* istanbul ignore next */
+ if (editLength > maxEditLength) {
+ return callback();
+ }
+
+ if (!execEditLength()) {
+ exec();
+ }
+ }, 0);
+ })();
+ } else {
+ while (editLength <= maxEditLength) {
+ var ret = execEditLength();
+ if (ret) {
+ return ret;
+ }
+ }
+ }
+ },
+ /*istanbul ignore start*/ /*istanbul ignore end*/pushComponent: function pushComponent(components, added, removed) {
+ var last = components[components.length - 1];
+ if (last && last.added === added && last.removed === removed) {
+ // We need to clone here as the component clone operation is just
+ // as shallow array clone
+ components[components.length - 1] = { count: last.count + 1, added: added, removed: removed };
+ } else {
+ components.push({ count: 1, added: added, removed: removed });
+ }
+ },
+ /*istanbul ignore start*/ /*istanbul ignore end*/extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
+ var newLen = newString.length,
+ oldLen = oldString.length,
+ newPos = basePath.newPos,
+ oldPos = newPos - diagonalPath,
+ commonCount = 0;
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
+ newPos++;
+ oldPos++;
+ commonCount++;
+ }
+
+ if (commonCount) {
+ basePath.components.push({ count: commonCount });
+ }
+
+ basePath.newPos = newPos;
+ return oldPos;
+ },
+ /*istanbul ignore start*/ /*istanbul ignore end*/equals: function equals(left, right) {
+ return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
+ },
+ /*istanbul ignore start*/ /*istanbul ignore end*/removeEmpty: function removeEmpty(array) {
+ var ret = [];
+ for (var i = 0; i < array.length; i++) {
+ if (array[i]) {
+ ret.push(array[i]);
+ }
+ }
+ return ret;
+ },
+ /*istanbul ignore start*/ /*istanbul ignore end*/castInput: function castInput(value) {
+ return value;
+ },
+ /*istanbul ignore start*/ /*istanbul ignore end*/tokenize: function tokenize(value) {
+ return value.split('');
+ },
+ /*istanbul ignore start*/ /*istanbul ignore end*/join: function join(chars) {
+ return chars.join('');
+ }
+ };
+
+ function buildValues(diff, components, newString, oldString, useLongestToken) {
+ var componentPos = 0,
+ componentLen = components.length,
+ newPos = 0,
+ oldPos = 0;
+
+ for (; componentPos < componentLen; componentPos++) {
+ var component = components[componentPos];
+ if (!component.removed) {
+ if (!component.added && useLongestToken) {
+ var value = newString.slice(newPos, newPos + component.count);
+ value = value.map(function (value, i) {
+ var oldValue = oldString[oldPos + i];
+ return oldValue.length > value.length ? oldValue : value;
+ });
+
+ component.value = diff.join(value);
+ } else {
+ component.value = diff.join(newString.slice(newPos, newPos + component.count));
+ }
+ newPos += component.count;
+
+ // Common case
+ if (!component.added) {
+ oldPos += component.count;
+ }
+ } else {
+ component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
+ oldPos += component.count;
+
+ // Reverse add and remove so removes are output first to match common convention
+ // The diffing algorithm is tied to add then remove output and this is the simplest
+ // route to get the desired output with minimal overhead.
+ if (componentPos && components[componentPos - 1].added) {
+ var tmp = components[componentPos - 1];
+ components[componentPos - 1] = components[componentPos];
+ components[componentPos] = tmp;
+ }
+ }
+ }
+
+ // Special case handle for when one terminal is ignored. For this case we merge the
+ // terminal into the prior string and drop the change.
+ var lastComponent = components[componentLen - 1];
+ if (componentLen > 1 && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
+ components[componentLen - 2].value += lastComponent.value;
+ components.pop();
+ }
+
+ return components;
+ }
+
+ function clonePath(path) {
+ return { newPos: path.newPos, components: path.components.slice(0) };
+ }
+
+
+
+/***/ }),
+/* 2 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports.characterDiff = undefined;
+ exports. /*istanbul ignore end*/diffChars = diffChars;
+
+ var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
+
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+ /*istanbul ignore end*/var characterDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/characterDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
+ function diffChars(oldStr, newStr, options) {
+ return characterDiff.diff(oldStr, newStr, options);
+ }
+
+
+
+/***/ }),
+/* 3 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports.wordDiff = undefined;
+ exports. /*istanbul ignore end*/diffWords = diffWords;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffWordsWithSpace = diffWordsWithSpace;
+
+ var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
+
+ /*istanbul ignore end*/var /*istanbul ignore start*/_params = __webpack_require__(4) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+ /*istanbul ignore end*/ // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
+ //
+ // Ranges and exceptions:
+ // Latin-1 Supplement, 0080–00FF
+ // - U+00D7 × Multiplication sign
+ // - U+00F7 ÷ Division sign
+ // Latin Extended-A, 0100–017F
+ // Latin Extended-B, 0180–024F
+ // IPA Extensions, 0250–02AF
+ // Spacing Modifier Letters, 02B0–02FF
+ // - U+02C7 ˇ ˇ Caron
+ // - U+02D8 ˘ ˘ Breve
+ // - U+02D9 ˙ ˙ Dot Above
+ // - U+02DA ˚ ˚ Ring Above
+ // - U+02DB ˛ ˛ Ogonek
+ // - U+02DC ˜ ˜ Small Tilde
+ // - U+02DD ˝ ˝ Double Acute Accent
+ // Latin Extended Additional, 1E00–1EFF
+ var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
+
+ var reWhitespace = /\S/;
+
+ var wordDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/wordDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
+ wordDiff.equals = function (left, right) {
+ if (this.options.ignoreCase) {
+ left = left.toLowerCase();
+ right = right.toLowerCase();
+ }
+ return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
+ };
+ wordDiff.tokenize = function (value) {
+ var tokens = value.split(/(\s+|\b)/);
+
+ // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
+ for (var i = 0; i < tokens.length - 1; i++) {
+ // If we have an empty string in the next field and we have only word chars before and after, merge
+ if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
+ tokens[i] += tokens[i + 2];
+ tokens.splice(i + 1, 2);
+ i--;
+ }
+ }
+
+ return tokens;
+ };
+
+ function diffWords(oldStr, newStr, options) {
+ options = /*istanbul ignore start*/(0, _params.generateOptions) /*istanbul ignore end*/(options, { ignoreWhitespace: true });
+ return wordDiff.diff(oldStr, newStr, options);
+ }
+
+ function diffWordsWithSpace(oldStr, newStr, options) {
+ return wordDiff.diff(oldStr, newStr, options);
+ }
+
+
+
+/***/ }),
+/* 4 */
+/***/ (function(module, exports) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports. /*istanbul ignore end*/generateOptions = generateOptions;
+ function generateOptions(options, defaults) {
+ if (typeof options === 'function') {
+ defaults.callback = options;
+ } else if (options) {
+ for (var name in options) {
+ /* istanbul ignore else */
+ if (options.hasOwnProperty(name)) {
+ defaults[name] = options[name];
+ }
+ }
+ }
+ return defaults;
+ }
+
+
+
+/***/ }),
+/* 5 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports.lineDiff = undefined;
+ exports. /*istanbul ignore end*/diffLines = diffLines;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/diffTrimmedLines = diffTrimmedLines;
+
+ var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
+
+ /*istanbul ignore end*/var /*istanbul ignore start*/_params = __webpack_require__(4) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+ /*istanbul ignore end*/var lineDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/lineDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
+ lineDiff.tokenize = function (value) {
+ var retLines = [],
+ linesAndNewlines = value.split(/(\n|\r\n)/);
+
+ // Ignore the final empty token that occurs if the string ends with a new line
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) {
+ linesAndNewlines.pop();
+ }
+
+ // Merge the content and line separators into single tokens
+ for (var i = 0; i < linesAndNewlines.length; i++) {
+ var line = linesAndNewlines[i];
+
+ if (i % 2 && !this.options.newlineIsToken) {
+ retLines[retLines.length - 1] += line;
+ } else {
+ if (this.options.ignoreWhitespace) {
+ line = line.trim();
+ }
+ retLines.push(line);
+ }
+ }
+
+ return retLines;
+ };
+
+ function diffLines(oldStr, newStr, callback) {
+ return lineDiff.diff(oldStr, newStr, callback);
+ }
+ function diffTrimmedLines(oldStr, newStr, callback) {
+ var options = /*istanbul ignore start*/(0, _params.generateOptions) /*istanbul ignore end*/(callback, { ignoreWhitespace: true });
+ return lineDiff.diff(oldStr, newStr, options);
+ }
+
+
+
+/***/ }),
+/* 6 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports.sentenceDiff = undefined;
+ exports. /*istanbul ignore end*/diffSentences = diffSentences;
+
+ var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
+
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+ /*istanbul ignore end*/var sentenceDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/sentenceDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
+ sentenceDiff.tokenize = function (value) {
+ return value.split(/(\S.+?[.!?])(?=\s+|$)/);
+ };
+
+ function diffSentences(oldStr, newStr, callback) {
+ return sentenceDiff.diff(oldStr, newStr, callback);
+ }
+
+
+
+/***/ }),
+/* 7 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports.cssDiff = undefined;
+ exports. /*istanbul ignore end*/diffCss = diffCss;
+
+ var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
+
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+ /*istanbul ignore end*/var cssDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/cssDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
+ cssDiff.tokenize = function (value) {
+ return value.split(/([{}:;,]|\s+)/);
+ };
+
+ function diffCss(oldStr, newStr, callback) {
+ return cssDiff.diff(oldStr, newStr, callback);
+ }
+
+
+
+/***/ }),
+/* 8 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports.jsonDiff = undefined;
+
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
+
+ exports. /*istanbul ignore end*/diffJson = diffJson;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/canonicalize = canonicalize;
+
+ var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
+
+ /*istanbul ignore end*/var /*istanbul ignore start*/_line = __webpack_require__(5) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+ /*istanbul ignore end*/var objectPrototypeToString = Object.prototype.toString;
+
+ var jsonDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/jsonDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
+ // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
+ // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
+ jsonDiff.useLongestToken = true;
+
+ jsonDiff.tokenize = /*istanbul ignore start*/_line.lineDiff /*istanbul ignore end*/.tokenize;
+ jsonDiff.castInput = function (value) {
+ /*istanbul ignore start*/var /*istanbul ignore end*/undefinedReplacement = this.options.undefinedReplacement;
+
+
+ return typeof value === 'string' ? value : JSON.stringify(canonicalize(value), function (k, v) {
+ if (typeof v === 'undefined') {
+ return undefinedReplacement;
+ }
+
+ return v;
+ }, ' ');
+ };
+ jsonDiff.equals = function (left, right) {
+ return (/*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'))
+ );
+ };
+
+ function diffJson(oldObj, newObj, options) {
+ return jsonDiff.diff(oldObj, newObj, options);
+ }
+
+ // This function handles the presence of circular references by bailing out when encountering an
+ // object that is already on the "stack" of items being processed.
+ function canonicalize(obj, stack, replacementStack) {
+ stack = stack || [];
+ replacementStack = replacementStack || [];
+
+ var i = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
+
+ for (i = 0; i < stack.length; i += 1) {
+ if (stack[i] === obj) {
+ return replacementStack[i];
+ }
+ }
+
+ var canonicalizedObj = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
+
+ if ('[object Array]' === objectPrototypeToString.call(obj)) {
+ stack.push(obj);
+ canonicalizedObj = new Array(obj.length);
+ replacementStack.push(canonicalizedObj);
+ for (i = 0; i < obj.length; i += 1) {
+ canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
+ }
+ stack.pop();
+ replacementStack.pop();
+ return canonicalizedObj;
+ }
+
+ if (obj && obj.toJSON) {
+ obj = obj.toJSON();
+ }
+
+ if ( /*istanbul ignore start*/(typeof /*istanbul ignore end*/obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj !== null) {
+ stack.push(obj);
+ canonicalizedObj = {};
+ replacementStack.push(canonicalizedObj);
+ var sortedKeys = [],
+ key = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
+ for (key in obj) {
+ /* istanbul ignore else */
+ if (obj.hasOwnProperty(key)) {
+ sortedKeys.push(key);
+ }
+ }
+ sortedKeys.sort();
+ for (i = 0; i < sortedKeys.length; i += 1) {
+ key = sortedKeys[i];
+ canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
+ }
+ stack.pop();
+ replacementStack.pop();
+ } else {
+ canonicalizedObj = obj;
+ }
+ return canonicalizedObj;
+ }
+
+
+
+/***/ }),
+/* 9 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports.arrayDiff = undefined;
+ exports. /*istanbul ignore end*/diffArrays = diffArrays;
+
+ var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
+
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+ /*istanbul ignore end*/var arrayDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/arrayDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
+ arrayDiff.tokenize = arrayDiff.join = function (value) {
+ return value.slice();
+ };
+
+ function diffArrays(oldArr, newArr, callback) {
+ return arrayDiff.diff(oldArr, newArr, callback);
+ }
+
+
+
+/***/ }),
+/* 10 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports. /*istanbul ignore end*/applyPatch = applyPatch;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatches = applyPatches;
+
+ var /*istanbul ignore start*/_parse = __webpack_require__(11) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_distanceIterator = __webpack_require__(12) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/var _distanceIterator2 = _interopRequireDefault(_distanceIterator);
+
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+ /*istanbul ignore end*/function applyPatch(source, uniDiff) {
+ /*istanbul ignore start*/var /*istanbul ignore end*/options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+
+ if (typeof uniDiff === 'string') {
+ uniDiff = /*istanbul ignore start*/(0, _parse.parsePatch) /*istanbul ignore end*/(uniDiff);
+ }
+
+ if (Array.isArray(uniDiff)) {
+ if (uniDiff.length > 1) {
+ throw new Error('applyPatch only works with a single input.');
+ }
+
+ uniDiff = uniDiff[0];
+ }
+
+ // Apply the diff to the input
+ var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
+ delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
+ hunks = uniDiff.hunks,
+ compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) /*istanbul ignore start*/{
+ return (/*istanbul ignore end*/line === patchContent
+ );
+ },
+ errorCount = 0,
+ fuzzFactor = options.fuzzFactor || 0,
+ minLine = 0,
+ offset = 0,
+ removeEOFNL = /*istanbul ignore start*/void 0 /*istanbul ignore end*/,
+ addEOFNL = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
+
+ /**
+ * Checks if the hunk exactly fits on the provided location
+ */
+ function hunkFits(hunk, toPos) {
+ for (var j = 0; j < hunk.lines.length; j++) {
+ var line = hunk.lines[j],
+ operation = line[0],
+ content = line.substr(1);
+
+ if (operation === ' ' || operation === '-') {
+ // Context sanity check
+ if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
+ errorCount++;
+
+ if (errorCount > fuzzFactor) {
+ return false;
+ }
+ }
+ toPos++;
+ }
+ }
+
+ return true;
+ }
+
+ // Search best fit offsets for each hunk based on the previous ones
+ for (var i = 0; i < hunks.length; i++) {
+ var hunk = hunks[i],
+ maxLine = lines.length - hunk.oldLines,
+ localOffset = 0,
+ toPos = offset + hunk.oldStart - 1;
+
+ var iterator = /*istanbul ignore start*/(0, _distanceIterator2['default']) /*istanbul ignore end*/(toPos, minLine, maxLine);
+
+ for (; localOffset !== undefined; localOffset = iterator()) {
+ if (hunkFits(hunk, toPos + localOffset)) {
+ hunk.offset = offset += localOffset;
+ break;
+ }
+ }
+
+ if (localOffset === undefined) {
+ return false;
+ }
+
+ // Set lower text limit to end of the current hunk, so next ones don't try
+ // to fit over already patched text
+ minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
+ }
+
+ // Apply patch hunks
+ var diffOffset = 0;
+ for (var _i = 0; _i < hunks.length; _i++) {
+ var _hunk = hunks[_i],
+ _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
+ diffOffset += _hunk.newLines - _hunk.oldLines;
+
+ if (_toPos < 0) {
+ // Creating a new file
+ _toPos = 0;
+ }
+
+ for (var j = 0; j < _hunk.lines.length; j++) {
+ var line = _hunk.lines[j],
+ operation = line[0],
+ content = line.substr(1),
+ delimiter = _hunk.linedelimiters[j];
+
+ if (operation === ' ') {
+ _toPos++;
+ } else if (operation === '-') {
+ lines.splice(_toPos, 1);
+ delimiters.splice(_toPos, 1);
+ /* istanbul ignore else */
+ } else if (operation === '+') {
+ lines.splice(_toPos, 0, content);
+ delimiters.splice(_toPos, 0, delimiter);
+ _toPos++;
+ } else if (operation === '\\') {
+ var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
+ if (previousOperation === '+') {
+ removeEOFNL = true;
+ } else if (previousOperation === '-') {
+ addEOFNL = true;
+ }
+ }
+ }
+ }
+
+ // Handle EOFNL insertion/removal
+ if (removeEOFNL) {
+ while (!lines[lines.length - 1]) {
+ lines.pop();
+ delimiters.pop();
+ }
+ } else if (addEOFNL) {
+ lines.push('');
+ delimiters.push('\n');
+ }
+ for (var _k = 0; _k < lines.length - 1; _k++) {
+ lines[_k] = lines[_k] + delimiters[_k];
+ }
+ return lines.join('');
+ }
+
+ // Wrapper that supports multiple file patches via callbacks.
+ function applyPatches(uniDiff, options) {
+ if (typeof uniDiff === 'string') {
+ uniDiff = /*istanbul ignore start*/(0, _parse.parsePatch) /*istanbul ignore end*/(uniDiff);
+ }
+
+ var currentIndex = 0;
+ function processIndex() {
+ var index = uniDiff[currentIndex++];
+ if (!index) {
+ return options.complete();
+ }
+
+ options.loadFile(index, function (err, data) {
+ if (err) {
+ return options.complete(err);
+ }
+
+ var updatedContent = applyPatch(data, index, options);
+ options.patched(index, updatedContent, function (err) {
+ if (err) {
+ return options.complete(err);
+ }
+
+ processIndex();
+ });
+ });
+ }
+ processIndex();
+ }
+
+
+
+/***/ }),
+/* 11 */
+/***/ (function(module, exports) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports. /*istanbul ignore end*/parsePatch = parsePatch;
+ function parsePatch(uniDiff) {
+ /*istanbul ignore start*/var /*istanbul ignore end*/options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+
+ var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
+ delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
+ list = [],
+ i = 0;
+
+ function parseIndex() {
+ var index = {};
+ list.push(index);
+
+ // Parse diff metadata
+ while (i < diffstr.length) {
+ var line = diffstr[i];
+
+ // File header found, end parsing diff metadata
+ if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
+ break;
+ }
+
+ // Diff index
+ var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
+ if (header) {
+ index.index = header[1];
+ }
+
+ i++;
+ }
+
+ // Parse file headers if they are defined. Unified diff requires them, but
+ // there's no technical issues to have an isolated hunk without file header
+ parseFileHeader(index);
+ parseFileHeader(index);
+
+ // Parse hunks
+ index.hunks = [];
+
+ while (i < diffstr.length) {
+ var _line = diffstr[i];
+
+ if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
+ break;
+ } else if (/^@@/.test(_line)) {
+ index.hunks.push(parseHunk());
+ } else if (_line && options.strict) {
+ // Ignore unexpected content unless in strict mode
+ throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
+ } else {
+ i++;
+ }
+ }
+ }
+
+ // Parses the --- and +++ headers, if none are found, no lines
+ // are consumed.
+ function parseFileHeader(index) {
+ var headerPattern = /^(---|\+\+\+)\s+([\S ]*)(?:\t(.*?)\s*)?$/;
+ var fileHeader = headerPattern.exec(diffstr[i]);
+ if (fileHeader) {
+ var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
+ var fileName = fileHeader[2].replace(/\\\\/g, '\\');
+ if (/^".*"$/.test(fileName)) {
+ fileName = fileName.substr(1, fileName.length - 2);
+ }
+ index[keyPrefix + 'FileName'] = fileName;
+ index[keyPrefix + 'Header'] = fileHeader[3];
+
+ i++;
+ }
+ }
+
+ // Parses a hunk
+ // This assumes that we are at the start of a hunk.
+ function parseHunk() {
+ var chunkHeaderIndex = i,
+ chunkHeaderLine = diffstr[i++],
+ chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
+
+ var hunk = {
+ oldStart: +chunkHeader[1],
+ oldLines: +chunkHeader[2] || 1,
+ newStart: +chunkHeader[3],
+ newLines: +chunkHeader[4] || 1,
+ lines: [],
+ linedelimiters: []
+ };
+
+ var addCount = 0,
+ removeCount = 0;
+ for (; i < diffstr.length; i++) {
+ // Lines starting with '---' could be mistaken for the "remove line" operation
+ // But they could be the header for the next file. Therefore prune such cases out.
+ if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
+ break;
+ }
+ var operation = diffstr[i][0];
+
+ if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
+ hunk.lines.push(diffstr[i]);
+ hunk.linedelimiters.push(delimiters[i] || '\n');
+
+ if (operation === '+') {
+ addCount++;
+ } else if (operation === '-') {
+ removeCount++;
+ } else if (operation === ' ') {
+ addCount++;
+ removeCount++;
+ }
+ } else {
+ break;
+ }
+ }
+
+ // Handle the empty block count case
+ if (!addCount && hunk.newLines === 1) {
+ hunk.newLines = 0;
+ }
+ if (!removeCount && hunk.oldLines === 1) {
+ hunk.oldLines = 0;
+ }
+
+ // Perform optional sanity checking
+ if (options.strict) {
+ if (addCount !== hunk.newLines) {
+ throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
+ }
+ if (removeCount !== hunk.oldLines) {
+ throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
+ }
+ }
+
+ return hunk;
+ }
+
+ while (i < diffstr.length) {
+ parseIndex();
+ }
+
+ return list;
+ }
+
+
+
+/***/ }),
+/* 12 */
+/***/ (function(module, exports) {
+
+ /*istanbul ignore start*/"use strict";
+
+ exports.__esModule = true;
+
+ exports["default"] = /*istanbul ignore end*/function (start, minLine, maxLine) {
+ var wantForward = true,
+ backwardExhausted = false,
+ forwardExhausted = false,
+ localOffset = 1;
+
+ return function iterator() {
+ if (wantForward && !forwardExhausted) {
+ if (backwardExhausted) {
+ localOffset++;
+ } else {
+ wantForward = false;
+ }
+
+ // Check if trying to fit beyond text length, and if not, check it fits
+ // after offset location (or desired location on first iteration)
+ if (start + localOffset <= maxLine) {
+ return localOffset;
+ }
+
+ forwardExhausted = true;
+ }
+
+ if (!backwardExhausted) {
+ if (!forwardExhausted) {
+ wantForward = true;
+ }
+
+ // Check if trying to fit before text beginning, and if not, check it fits
+ // before offset location
+ if (minLine <= start - localOffset) {
+ return -localOffset++;
+ }
+
+ backwardExhausted = true;
+ return iterator();
+ }
+
+ // We tried to fit hunk before text beginning and beyond text length, then
+ // hunk can't fit on the text. Return undefined
+ };
+ };
+
+
+
+/***/ }),
+/* 13 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports. /*istanbul ignore end*/calcLineCount = calcLineCount;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/merge = merge;
+
+ var /*istanbul ignore start*/_create = __webpack_require__(14) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_parse = __webpack_require__(11) /*istanbul ignore end*/;
+
+ var /*istanbul ignore start*/_array = __webpack_require__(15) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
+
+ /*istanbul ignore end*/function calcLineCount(hunk) {
+ var conflicted = false;
+
+ hunk.oldLines = 0;
+ hunk.newLines = 0;
+
+ hunk.lines.forEach(function (line) {
+ if (typeof line !== 'string') {
+ conflicted = true;
+ return;
+ }
+
+ if (line[0] === '+' || line[0] === ' ') {
+ hunk.newLines++;
+ }
+ if (line[0] === '-' || line[0] === ' ') {
+ hunk.oldLines++;
+ }
+ });
+
+ if (conflicted) {
+ delete hunk.oldLines;
+ delete hunk.newLines;
+ }
+ }
+
+ function merge(mine, theirs, base) {
+ mine = loadPatch(mine, base);
+ theirs = loadPatch(theirs, base);
+
+ var ret = {};
+
+ // For index we just let it pass through as it doesn't have any necessary meaning.
+ // Leaving sanity checks on this to the API consumer that may know more about the
+ // meaning in their own context.
+ if (mine.index || theirs.index) {
+ ret.index = mine.index || theirs.index;
+ }
+
+ if (mine.newFileName || theirs.newFileName) {
+ if (!fileNameChanged(mine)) {
+ // No header or no change in ours, use theirs (and ours if theirs does not exist)
+ ret.oldFileName = theirs.oldFileName || mine.oldFileName;
+ ret.newFileName = theirs.newFileName || mine.newFileName;
+ ret.oldHeader = theirs.oldHeader || mine.oldHeader;
+ ret.newHeader = theirs.newHeader || mine.newHeader;
+ } else if (!fileNameChanged(theirs)) {
+ // No header or no change in theirs, use ours
+ ret.oldFileName = mine.oldFileName;
+ ret.newFileName = mine.newFileName;
+ ret.oldHeader = mine.oldHeader;
+ ret.newHeader = mine.newHeader;
+ } else {
+ // Both changed... figure it out
+ ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
+ ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
+ ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
+ ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
+ }
+ }
+
+ ret.hunks = [];
+
+ var mineIndex = 0,
+ theirsIndex = 0,
+ mineOffset = 0,
+ theirsOffset = 0;
+
+ while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
+ var mineCurrent = mine.hunks[mineIndex] || { oldStart: Infinity },
+ theirsCurrent = theirs.hunks[theirsIndex] || { oldStart: Infinity };
+
+ if (hunkBefore(mineCurrent, theirsCurrent)) {
+ // This patch does not overlap with any of the others, yay.
+ ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
+ mineIndex++;
+ theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
+ } else if (hunkBefore(theirsCurrent, mineCurrent)) {
+ // This patch does not overlap with any of the others, yay.
+ ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
+ theirsIndex++;
+ mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
+ } else {
+ // Overlap, merge as best we can
+ var mergedHunk = {
+ oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
+ oldLines: 0,
+ newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
+ newLines: 0,
+ lines: []
+ };
+ mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
+ theirsIndex++;
+ mineIndex++;
+
+ ret.hunks.push(mergedHunk);
+ }
+ }
+
+ return ret;
+ }
+
+ function loadPatch(param, base) {
+ if (typeof param === 'string') {
+ if (/^@@/m.test(param) || /^Index:/m.test(param)) {
+ return (/*istanbul ignore start*/(0, _parse.parsePatch) /*istanbul ignore end*/(param)[0]
+ );
+ }
+
+ if (!base) {
+ throw new Error('Must provide a base reference or pass in a patch');
+ }
+ return (/*istanbul ignore start*/(0, _create.structuredPatch) /*istanbul ignore end*/(undefined, undefined, base, param)
+ );
+ }
+
+ return param;
+ }
+
+ function fileNameChanged(patch) {
+ return patch.newFileName && patch.newFileName !== patch.oldFileName;
+ }
+
+ function selectField(index, mine, theirs) {
+ if (mine === theirs) {
+ return mine;
+ } else {
+ index.conflict = true;
+ return { mine: mine, theirs: theirs };
+ }
+ }
+
+ function hunkBefore(test, check) {
+ return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
+ }
+
+ function cloneHunk(hunk, offset) {
+ return {
+ oldStart: hunk.oldStart, oldLines: hunk.oldLines,
+ newStart: hunk.newStart + offset, newLines: hunk.newLines,
+ lines: hunk.lines
+ };
+ }
+
+ function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
+ // This will generally result in a conflicted hunk, but there are cases where the context
+ // is the only overlap where we can successfully merge the content here.
+ var mine = { offset: mineOffset, lines: mineLines, index: 0 },
+ their = { offset: theirOffset, lines: theirLines, index: 0 };
+
+ // Handle any leading content
+ insertLeading(hunk, mine, their);
+ insertLeading(hunk, their, mine);
+
+ // Now in the overlap content. Scan through and select the best changes from each.
+ while (mine.index < mine.lines.length && their.index < their.lines.length) {
+ var mineCurrent = mine.lines[mine.index],
+ theirCurrent = their.lines[their.index];
+
+ if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
+ // Both modified ...
+ mutualChange(hunk, mine, their);
+ } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
+ /*istanbul ignore start*/var _hunk$lines;
+
+ /*istanbul ignore end*/ // Mine inserted
+ /*istanbul ignore start*/(_hunk$lines = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/collectChange(mine)));
+ } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
+ /*istanbul ignore start*/var _hunk$lines2;
+
+ /*istanbul ignore end*/ // Theirs inserted
+ /*istanbul ignore start*/(_hunk$lines2 = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines2 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/collectChange(their)));
+ } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
+ // Mine removed or edited
+ removal(hunk, mine, their);
+ } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
+ // Their removed or edited
+ removal(hunk, their, mine, true);
+ } else if (mineCurrent === theirCurrent) {
+ // Context identity
+ hunk.lines.push(mineCurrent);
+ mine.index++;
+ their.index++;
+ } else {
+ // Context mismatch
+ conflict(hunk, collectChange(mine), collectChange(their));
+ }
+ }
+
+ // Now push anything that may be remaining
+ insertTrailing(hunk, mine);
+ insertTrailing(hunk, their);
+
+ calcLineCount(hunk);
+ }
+
+ function mutualChange(hunk, mine, their) {
+ var myChanges = collectChange(mine),
+ theirChanges = collectChange(their);
+
+ if (allRemoves(myChanges) && allRemoves(theirChanges)) {
+ // Special case for remove changes that are supersets of one another
+ if ( /*istanbul ignore start*/(0, _array.arrayStartsWith) /*istanbul ignore end*/(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
+ /*istanbul ignore start*/var _hunk$lines3;
+
+ /*istanbul ignore end*/ /*istanbul ignore start*/(_hunk$lines3 = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines3 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/myChanges));
+ return;
+ } else if ( /*istanbul ignore start*/(0, _array.arrayStartsWith) /*istanbul ignore end*/(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
+ /*istanbul ignore start*/var _hunk$lines4;
+
+ /*istanbul ignore end*/ /*istanbul ignore start*/(_hunk$lines4 = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines4 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/theirChanges));
+ return;
+ }
+ } else if ( /*istanbul ignore start*/(0, _array.arrayEqual) /*istanbul ignore end*/(myChanges, theirChanges)) {
+ /*istanbul ignore start*/var _hunk$lines5;
+
+ /*istanbul ignore end*/ /*istanbul ignore start*/(_hunk$lines5 = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines5 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/myChanges));
+ return;
+ }
+
+ conflict(hunk, myChanges, theirChanges);
+ }
+
+ function removal(hunk, mine, their, swap) {
+ var myChanges = collectChange(mine),
+ theirChanges = collectContext(their, myChanges);
+ if (theirChanges.merged) {
+ /*istanbul ignore start*/var _hunk$lines6;
+
+ /*istanbul ignore end*/ /*istanbul ignore start*/(_hunk$lines6 = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines6 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/theirChanges.merged));
+ } else {
+ conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
+ }
+ }
+
+ function conflict(hunk, mine, their) {
+ hunk.conflict = true;
+ hunk.lines.push({
+ conflict: true,
+ mine: mine,
+ theirs: their
+ });
+ }
+
+ function insertLeading(hunk, insert, their) {
+ while (insert.offset < their.offset && insert.index < insert.lines.length) {
+ var line = insert.lines[insert.index++];
+ hunk.lines.push(line);
+ insert.offset++;
+ }
+ }
+ function insertTrailing(hunk, insert) {
+ while (insert.index < insert.lines.length) {
+ var line = insert.lines[insert.index++];
+ hunk.lines.push(line);
+ }
+ }
+
+ function collectChange(state) {
+ var ret = [],
+ operation = state.lines[state.index][0];
+ while (state.index < state.lines.length) {
+ var line = state.lines[state.index];
+
+ // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
+ if (operation === '-' && line[0] === '+') {
+ operation = '+';
+ }
+
+ if (operation === line[0]) {
+ ret.push(line);
+ state.index++;
+ } else {
+ break;
+ }
+ }
+
+ return ret;
+ }
+ function collectContext(state, matchChanges) {
+ var changes = [],
+ merged = [],
+ matchIndex = 0,
+ contextChanges = false,
+ conflicted = false;
+ while (matchIndex < matchChanges.length && state.index < state.lines.length) {
+ var change = state.lines[state.index],
+ match = matchChanges[matchIndex];
+
+ // Once we've hit our add, then we are done
+ if (match[0] === '+') {
+ break;
+ }
+
+ contextChanges = contextChanges || change[0] !== ' ';
+
+ merged.push(match);
+ matchIndex++;
+
+ // Consume any additions in the other block as a conflict to attempt
+ // to pull in the remaining context after this
+ if (change[0] === '+') {
+ conflicted = true;
+
+ while (change[0] === '+') {
+ changes.push(change);
+ change = state.lines[++state.index];
+ }
+ }
+
+ if (match.substr(1) === change.substr(1)) {
+ changes.push(change);
+ state.index++;
+ } else {
+ conflicted = true;
+ }
+ }
+
+ if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
+ conflicted = true;
+ }
+
+ if (conflicted) {
+ return changes;
+ }
+
+ while (matchIndex < matchChanges.length) {
+ merged.push(matchChanges[matchIndex++]);
+ }
+
+ return {
+ merged: merged,
+ changes: changes
+ };
+ }
+
+ function allRemoves(changes) {
+ return changes.reduce(function (prev, change) {
+ return prev && change[0] === '-';
+ }, true);
+ }
+ function skipRemoveSuperset(state, removeChanges, delta) {
+ for (var i = 0; i < delta; i++) {
+ var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
+ if (state.lines[state.index + i] !== ' ' + changeContent) {
+ return false;
+ }
+ }
+
+ state.index += delta;
+ return true;
+ }
+
+
+
+/***/ }),
+/* 14 */
+/***/ (function(module, exports, __webpack_require__) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports. /*istanbul ignore end*/structuredPatch = structuredPatch;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/createTwoFilesPatch = createTwoFilesPatch;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/createPatch = createPatch;
+
+ var /*istanbul ignore start*/_line = __webpack_require__(5) /*istanbul ignore end*/;
+
+ /*istanbul ignore start*/function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
+
+ /*istanbul ignore end*/function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
+ if (!options) {
+ options = {};
+ }
+ if (typeof options.context === 'undefined') {
+ options.context = 4;
+ }
+
+ var diff = /*istanbul ignore start*/(0, _line.diffLines) /*istanbul ignore end*/(oldStr, newStr, options);
+ diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
+
+ function contextLines(lines) {
+ return lines.map(function (entry) {
+ return ' ' + entry;
+ });
+ }
+
+ var hunks = [];
+ var oldRangeStart = 0,
+ newRangeStart = 0,
+ curRange = [],
+ oldLine = 1,
+ newLine = 1;
+
+ /*istanbul ignore start*/var _loop = function _loop( /*istanbul ignore end*/i) {
+ var current = diff[i],
+ lines = current.lines || current.value.replace(/\n$/, '').split('\n');
+ current.lines = lines;
+
+ if (current.added || current.removed) {
+ /*istanbul ignore start*/var _curRange;
+
+ /*istanbul ignore end*/ // If we have previous context, start with that
+ if (!oldRangeStart) {
+ var prev = diff[i - 1];
+ oldRangeStart = oldLine;
+ newRangeStart = newLine;
+
+ if (prev) {
+ curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
+ oldRangeStart -= curRange.length;
+ newRangeStart -= curRange.length;
+ }
+ }
+
+ // Output our changes
+ /*istanbul ignore start*/(_curRange = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/lines.map(function (entry) {
+ return (current.added ? '+' : '-') + entry;
+ })));
+
+ // Track the updated file position
+ if (current.added) {
+ newLine += lines.length;
+ } else {
+ oldLine += lines.length;
+ }
+ } else {
+ // Identical context lines. Track line changes
+ if (oldRangeStart) {
+ // Close out any changes that have been output (or join overlapping)
+ if (lines.length <= options.context * 2 && i < diff.length - 2) {
+ /*istanbul ignore start*/var _curRange2;
+
+ /*istanbul ignore end*/ // Overlapping
+ /*istanbul ignore start*/(_curRange2 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange2 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines)));
+ } else {
+ /*istanbul ignore start*/var _curRange3;
+
+ /*istanbul ignore end*/ // end the range and output
+ var contextSize = Math.min(lines.length, options.context);
+ /*istanbul ignore start*/(_curRange3 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange3 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines.slice(0, contextSize))));
+
+ var hunk = {
+ oldStart: oldRangeStart,
+ oldLines: oldLine - oldRangeStart + contextSize,
+ newStart: newRangeStart,
+ newLines: newLine - newRangeStart + contextSize,
+ lines: curRange
+ };
+ if (i >= diff.length - 2 && lines.length <= options.context) {
+ // EOF is inside this hunk
+ var oldEOFNewline = /\n$/.test(oldStr);
+ var newEOFNewline = /\n$/.test(newStr);
+ if (lines.length == 0 && !oldEOFNewline) {
+ // special case: old has no eol and no trailing context; no-nl can end up before adds
+ curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
+ } else if (!oldEOFNewline || !newEOFNewline) {
+ curRange.push('\\ No newline at end of file');
+ }
+ }
+ hunks.push(hunk);
+
+ oldRangeStart = 0;
+ newRangeStart = 0;
+ curRange = [];
+ }
+ }
+ oldLine += lines.length;
+ newLine += lines.length;
+ }
+ };
+
+ for (var i = 0; i < diff.length; i++) {
+ /*istanbul ignore start*/_loop( /*istanbul ignore end*/i);
+ }
+
+ return {
+ oldFileName: oldFileName, newFileName: newFileName,
+ oldHeader: oldHeader, newHeader: newHeader,
+ hunks: hunks
+ };
+ }
+
+ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
+ var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
+
+ var ret = [];
+ if (oldFileName == newFileName) {
+ ret.push('Index: ' + oldFileName);
+ }
+ ret.push('===================================================================');
+ ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
+ ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
+
+ for (var i = 0; i < diff.hunks.length; i++) {
+ var hunk = diff.hunks[i];
+ ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
+ ret.push.apply(ret, hunk.lines);
+ }
+
+ return ret.join('\n') + '\n';
+ }
+
+ function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
+ return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
+ }
+
+
+
+/***/ }),
+/* 15 */
+/***/ (function(module, exports) {
+
+ /*istanbul ignore start*/"use strict";
+
+ exports.__esModule = true;
+ exports. /*istanbul ignore end*/arrayEqual = arrayEqual;
+ /*istanbul ignore start*/exports. /*istanbul ignore end*/arrayStartsWith = arrayStartsWith;
+ function arrayEqual(a, b) {
+ if (a.length !== b.length) {
+ return false;
+ }
+
+ return arrayStartsWith(a, b);
+ }
+
+ function arrayStartsWith(array, start) {
+ if (start.length > array.length) {
+ return false;
+ }
+
+ for (var i = 0; i < start.length; i++) {
+ if (start[i] !== array[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+
+/***/ }),
+/* 16 */
+/***/ (function(module, exports) {
+
+ /*istanbul ignore start*/"use strict";
+
+ exports.__esModule = true;
+ exports. /*istanbul ignore end*/convertChangesToDMP = convertChangesToDMP;
+ // See: http://code.google.com/p/google-diff-match-patch/wiki/API
+ function convertChangesToDMP(changes) {
+ var ret = [],
+ change = /*istanbul ignore start*/void 0 /*istanbul ignore end*/,
+ operation = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
+ for (var i = 0; i < changes.length; i++) {
+ change = changes[i];
+ if (change.added) {
+ operation = 1;
+ } else if (change.removed) {
+ operation = -1;
+ } else {
+ operation = 0;
+ }
+
+ ret.push([operation, change.value]);
+ }
+ return ret;
+ }
+
+
+
+/***/ }),
+/* 17 */
+/***/ (function(module, exports) {
+
+ /*istanbul ignore start*/'use strict';
+
+ exports.__esModule = true;
+ exports. /*istanbul ignore end*/convertChangesToXML = convertChangesToXML;
+ function convertChangesToXML(changes) {
+ var ret = [];
+ for (var i = 0; i < changes.length; i++) {
+ var change = changes[i];
+ if (change.added) {
+ ret.push('<ins>');
+ } else if (change.removed) {
+ ret.push('<del>');
+ }
+
+ ret.push(escapeHTML(change.value));
+
+ if (change.added) {
+ ret.push('</ins>');
+ } else if (change.removed) {
+ ret.push('</del>');
+ }
+ }
+ return ret.join('');
+ }
+
+ function escapeHTML(s) {
+ var n = s;
+ n = n.replace(/&/g, '&');
+ n = n.replace(/</g, '<');
+ n = n.replace(/>/g, '>');
+ n = n.replace(/"/g, '"');
+
+ return n;
+ }
+
+
+
+/***/ })
+/******/ ])
+});
+;
+},{}],45:[function(require,module,exports){
+'use strict';
+
+var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
+
+module.exports = function (str) {
+ if (typeof str !== 'string') {
+ throw new TypeError('Expected a string');
+ }
+
+ return str.replace(matchOperatorsRe, '\\$&');
+};
+
+},{}],46:[function(require,module,exports){
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+function EventEmitter() {
+ this._events = this._events || {};
+ this._maxListeners = this._maxListeners || undefined;
+}
+module.exports = EventEmitter;
+
+// Backwards-compat with node 0.10.x
+EventEmitter.EventEmitter = EventEmitter;
+
+EventEmitter.prototype._events = undefined;
+EventEmitter.prototype._maxListeners = undefined;
+
+// By default EventEmitters will print a warning if more than 10 listeners are
+// added to it. This is a useful default which helps finding memory leaks.
+EventEmitter.defaultMaxListeners = 10;
+
+// Obviously not all Emitters should be limited to 10. This function allows
+// that to be increased. Set to zero for unlimited.
+EventEmitter.prototype.setMaxListeners = function(n) {
+ if (!isNumber(n) || n < 0 || isNaN(n))
+ throw TypeError('n must be a positive number');
+ this._maxListeners = n;
+ return this;
+};
+
+EventEmitter.prototype.emit = function(type) {
+ var er, handler, len, args, i, listeners;
+
+ if (!this._events)
+ this._events = {};
+
+ // If there is no 'error' event listener then throw.
+ if (type === 'error') {
+ if (!this._events.error ||
+ (isObject(this._events.error) && !this._events.error.length)) {
+ er = arguments[1];
+ if (er instanceof Error) {
+ throw er; // Unhandled 'error' event
+ } else {
+ // At least give some kind of context to the user
+ var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
+ err.context = er;
+ throw err;
+ }
+ }
+ }
+
+ handler = this._events[type];
+
+ if (isUndefined(handler))
+ return false;
+
+ if (isFunction(handler)) {
+ switch (arguments.length) {
+ // fast cases
+ case 1:
+ handler.call(this);
+ break;
+ case 2:
+ handler.call(this, arguments[1]);
+ break;
+ case 3:
+ handler.call(this, arguments[1], arguments[2]);
+ break;
+ // slower
+ default:
+ args = Array.prototype.slice.call(arguments, 1);
+ handler.apply(this, args);
+ }
+ } else if (isObject(handler)) {
+ args = Array.prototype.slice.call(arguments, 1);
+ listeners = handler.slice();
+ len = listeners.length;
+ for (i = 0; i < len; i++)
+ listeners[i].apply(this, args);
+ }
+
+ return true;
+};
+
+EventEmitter.prototype.addListener = function(type, listener) {
+ var m;
+
+ if (!isFunction(listener))
+ throw TypeError('listener must be a function');
+
+ if (!this._events)
+ this._events = {};
+
+ // To avoid recursion in the case that type === "newListener"! Before
+ // adding it to the listeners, first emit "newListener".
+ if (this._events.newListener)
+ this.emit('newListener', type,
+ isFunction(listener.listener) ?
+ listener.listener : listener);
+
+ if (!this._events[type])
+ // Optimize the case of one listener. Don't need the extra array object.
+ this._events[type] = listener;
+ else if (isObject(this._events[type]))
+ // If we've already got an array, just append.
+ this._events[type].push(listener);
+ else
+ // Adding the second element, need to change to array.
+ this._events[type] = [this._events[type], listener];
+
+ // Check for listener leak
+ if (isObject(this._events[type]) && !this._events[type].warned) {
+ if (!isUndefined(this._maxListeners)) {
+ m = this._maxListeners;
+ } else {
+ m = EventEmitter.defaultMaxListeners;
+ }
+
+ if (m && m > 0 && this._events[type].length > m) {
+ this._events[type].warned = true;
+ console.error('(node) warning: possible EventEmitter memory ' +
+ 'leak detected. %d listeners added. ' +
+ 'Use emitter.setMaxListeners() to increase limit.',
+ this._events[type].length);
+ if (typeof console.trace === 'function') {
+ // not supported in IE 10
+ console.trace();
+ }
+ }
+ }
+
+ return this;
+};
+
+EventEmitter.prototype.on = EventEmitter.prototype.addListener;
+
+EventEmitter.prototype.once = function(type, listener) {
+ if (!isFunction(listener))
+ throw TypeError('listener must be a function');
+
+ var fired = false;
+
+ function g() {
+ this.removeListener(type, g);
+
+ if (!fired) {
+ fired = true;
+ listener.apply(this, arguments);
+ }
+ }
+
+ g.listener = listener;
+ this.on(type, g);
+
+ return this;
+};
+
+// emits a 'removeListener' event iff the listener was removed
+EventEmitter.prototype.removeListener = function(type, listener) {
+ var list, position, length, i;
+
+ if (!isFunction(listener))
+ throw TypeError('listener must be a function');
+
+ if (!this._events || !this._events[type])
+ return this;
+
+ list = this._events[type];
+ length = list.length;
+ position = -1;
+
+ if (list === listener ||
+ (isFunction(list.listener) && list.listener === listener)) {
+ delete this._events[type];
+ if (this._events.removeListener)
+ this.emit('removeListener', type, listener);
+
+ } else if (isObject(list)) {
+ for (i = length; i-- > 0;) {
+ if (list[i] === listener ||
+ (list[i].listener && list[i].listener === listener)) {
+ position = i;
+ break;
+ }
+ }
+
+ if (position < 0)
+ return this;
+
+ if (list.length === 1) {
+ list.length = 0;
+ delete this._events[type];
+ } else {
+ list.splice(position, 1);
+ }
+
+ if (this._events.removeListener)
+ this.emit('removeListener', type, listener);
+ }
+
+ return this;
+};
+
+EventEmitter.prototype.removeAllListeners = function(type) {
+ var key, listeners;
+
+ if (!this._events)
+ return this;
+
+ // not listening for removeListener, no need to emit
+ if (!this._events.removeListener) {
+ if (arguments.length === 0)
+ this._events = {};
+ else if (this._events[type])
+ delete this._events[type];
+ return this;
+ }
+
+ // emit removeListener for all listeners on all events
+ if (arguments.length === 0) {
+ for (key in this._events) {
+ if (key === 'removeListener') continue;
+ this.removeAllListeners(key);
+ }
+ this.removeAllListeners('removeListener');
+ this._events = {};
+ return this;
+ }
+
+ listeners = this._events[type];
+
+ if (isFunction(listeners)) {
+ this.removeListener(type, listeners);
+ } else if (listeners) {
+ // LIFO order
+ while (listeners.length)
+ this.removeListener(type, listeners[listeners.length - 1]);
+ }
+ delete this._events[type];
+
+ return this;
+};
+
+EventEmitter.prototype.listeners = function(type) {
+ var ret;
+ if (!this._events || !this._events[type])
+ ret = [];
+ else if (isFunction(this._events[type]))
+ ret = [this._events[type]];
+ else
+ ret = this._events[type].slice();
+ return ret;
+};
+
+EventEmitter.prototype.listenerCount = function(type) {
+ if (this._events) {
+ var evlistener = this._events[type];
+
+ if (isFunction(evlistener))
+ return 1;
+ else if (evlistener)
+ return evlistener.length;
+ }
+ return 0;
+};
+
+EventEmitter.listenerCount = function(emitter, type) {
+ return emitter.listenerCount(type);
+};
+
+function isFunction(arg) {
+ return typeof arg === 'function';
+}
+
+function isNumber(arg) {
+ return typeof arg === 'number';
+}
+
+function isObject(arg) {
+ return typeof arg === 'object' && arg !== null;
+}
+
+function isUndefined(arg) {
+ return arg === void 0;
+}
+
+},{}],47:[function(require,module,exports){
+(function (global){
+/*! https://mths.be/he v1.1.1 by @mathias | MIT license */
+;(function(root) {
+
+ // Detect free variables `exports`.
+ var freeExports = typeof exports == 'object' && exports;
+
+ // Detect free variable `module`.
+ var freeModule = typeof module == 'object' && module &&
+ module.exports == freeExports && module;
+
+ // Detect free variable `global`, from Node.js or Browserified code,
+ // and use it as `root`.
+ var freeGlobal = typeof global == 'object' && global;
+ if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
+ root = freeGlobal;
+ }
+
+ /*--------------------------------------------------------------------------*/
+
+ // All astral symbols.
+ var regexAstralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
+ // All ASCII symbols (not just printable ASCII) except those listed in the
+ // first column of the overrides table.
+ // https://html.spec.whatwg.org/multipage/syntax.html#table-charref-overrides
+ var regexAsciiWhitelist = /[\x01-\x7F]/g;
+ // All BMP symbols that are not ASCII newlines, printable ASCII symbols, or
+ // code points listed in the first column of the overrides table on
+ // https://html.spec.whatwg.org/multipage/syntax.html#table-charref-overrides.
+ var regexBmpWhitelist = /[\x01-\t\x0B\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g;
+
+ var regexEncodeNonAscii = /<\u20D2|=\u20E5|>\u20D2|\u205F\u200A|\u219D\u0338|\u2202\u0338|\u2220\u20D2|\u2229\uFE00|\u222A\uFE00|\u223C\u20D2|\u223D\u0331|\u223E\u0333|\u2242\u0338|\u224B\u0338|\u224D\u20D2|\u224E\u0338|\u224F\u0338|\u2250\u0338|\u2261\u20E5|\u2264\u20D2|\u2265\u20D2|\u2266\u0338|\u2267\u0338|\u2268\uFE00|\u2269\uFE00|\u226A\u0338|\u226A\u20D2|\u226B\u0338|\u226B\u20D2|\u227F\u0338|\u2282\u20D2|\u2283\u20D2|\u228A\uFE00|\u228B\uFE00|\u228F\u0338|\u2290\u0338|\u2293\uFE00|\u2294\uFE00|\u22B4\u20D2|\u22B5\u20D2|\u22D8\u0338|\u22D9\u0338|\u22DA\uFE00|\u22DB\uFE00|\u22F5\u0338|\u22F9\u0338|\u2933\u0338|\u29CF\u0338|\u29D0\u0338|\u2A6D\u0338|\u2A70\u0338|\u2A7D\u0338|\u2A7E\u0338|\u2AA1\u0338|\u2AA2\u0338|\u2AAC\uFE00|\u2AAD\uFE00|\u2AAF\u0338|\u2AB0\u0338|\u2AC5\u0338|\u2AC6\u0338|\u2ACB\uFE00|\u2ACC\uFE00|\u2AFD\u20E5|[\xA0-\u0113\u0116-\u0122\u0124-\u012B\u012E-\u014D\u0150-\u017E\u0192\u01B5\u01F5\u0237\u02C6\u02C7\u02D8-\u02DD\u0311\u0391-\u03A1\u03A3-\u03A9\u03B1-\u03C9\u03D1\u03D2\u03D5\u03D6\u03DC\u03DD\u03F0\u03F1\u03F5\u03F6\u0401-\u040C\u040E-\u044F\u0451-\u045C\u045E\u045F\u2002-\u2005\u2007-\u2010\u2013-\u2016\u2018-\u201A\u201C-\u201E\u2020-\u2022\u2025\u2026\u2030-\u2035\u2039\u203A\u203E\u2041\u2043\u2044\u204F\u2057\u205F-\u2063\u20AC\u20DB\u20DC\u2102\u2105\u210A-\u2113\u2115-\u211E\u2122\u2124\u2127-\u2129\u212C\u212D\u212F-\u2131\u2133-\u2138\u2145-\u2148\u2153-\u215E\u2190-\u219B\u219D-\u21A7\u21A9-\u21AE\u21B0-\u21B3\u21B5-\u21B7\u21BA-\u21DB\u21DD\u21E4\u21E5\u21F5\u21FD-\u2205\u2207-\u2209\u220B\u220C\u220F-\u2214\u2216-\u2218\u221A\u221D-\u2238\u223A-\u2257\u2259\u225A\u225C\u225F-\u2262\u2264-\u228B\u228D-\u229B\u229D-\u22A5\u22A7-\u22B0\u22B2-\u22BB\u22BD-\u22DB\u22DE-\u22E3\u22E6-\u22F7\u22F9-\u22FE\u2305\u2306\u2308-\u2310\u2312\u2313\u2315\u2316\u231C-\u231F\u2322\u2323\u232D\u232E\u2336\u233D\u233F\u237C\u23B0\u23B1\u23B4-\u23B6\u23DC-\u23DF\u23E2\u23E7\u2423\u24C8\u2500\u2502\u250C\u2510\u2514\u2518\u251C\u2524\u252C\u2534\u253C\u2550-\u256C\u2580\u2584\u2588\u2591-\u2593\u25A1\u25AA\u25AB\u25AD\u25AE\u25B1\u25B3-\u25B5\u25B8\u25B9\u25BD-\u25BF\u25C2\u25C3\u25CA\u25CB\u25EC\u25EF\u25F8-\u25FC\u2605\u2606\u260E\u2640\u2642\u2660\u2663\u2665\u2666\u266A\u266D-\u266F\u2713\u2717\u2720\u2736\u2758\u2772\u2773\u27C8\u27C9\u27E6-\u27ED\u27F5-\u27FA\u27FC\u27FF\u2902-\u2905\u290C-\u2913\u2916\u2919-\u2920\u2923-\u292A\u2933\u2935-\u2939\u293C\u293D\u2945\u2948-\u294B\u294E-\u2976\u2978\u2979\u297B-\u297F\u2985\u2986\u298B-\u2996\u299A\u299C\u299D\u29A4-\u29B7\u29B9\u29BB\u29BC\u29BE-\u29C5\u29C9\u29CD-\u29D0\u29DC-\u29DE\u29E3-\u29E5\u29EB\u29F4\u29F6\u2A00-\u2A02\u2A04\u2A06\u2A0C\u2A0D\u2A10-\u2A17\u2A22-\u2A27\u2A29\u2A2A\u2A2D-\u2A31\u2A33-\u2A3C\u2A3F\u2A40\u2A42-\u2A4D\u2A50\u2A53-\u2A58\u2A5A-\u2A5D\u2A5F\u2A66\u2A6A\u2A6D-\u2A75\u2A77-\u2A9A\u2A9D-\u2AA2\u2AA4-\u2AB0\u2AB3-\u2AC8\u2ACB\u2ACC\u2ACF-\u2ADB\u2AE4\u2AE6-\u2AE9\u2AEB-\u2AF3\u2AFD\uFB00-\uFB04]|\uD835[\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDCCF\uDD04\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDD6B]/g;
+ var encodeMap = {'\xAD':'shy','\u200C':'zwnj','\u200D':'zwj','\u200E':'lrm','\u2063':'ic','\u2062':'it','\u2061':'af','\u200F':'rlm','\u200B':'ZeroWidthSpace','\u2060':'NoBreak','\u0311':'DownBreve','\u20DB':'tdot','\u20DC':'DotDot','\t':'Tab','\n':'NewLine','\u2008':'puncsp','\u205F':'MediumSpace','\u2009':'thinsp','\u200A':'hairsp','\u2004':'emsp13','\u2002':'ensp','\u2005':'emsp14','\u2003':'emsp','\u2007':'numsp','\xA0':'nbsp','\u205F\u200A':'ThickSpace','\u203E':'oline','_':'lowbar','\u2010':'dash','\u2013':'ndash','\u2014':'mdash','\u2015':'horbar',',':'comma',';':'semi','\u204F':'bsemi',':':'colon','\u2A74':'Colone','!':'excl','\xA1':'iexcl','?':'quest','\xBF':'iquest','.':'period','\u2025':'nldr','\u2026':'mldr','\xB7':'middot','\'':'apos','\u2018':'lsquo','\u2019':'rsquo','\u201A':'sbquo','\u2039':'lsaquo','\u203A':'rsaquo','"':'quot','\u201C':'ldquo','\u201D':'rdquo','\u201E':'bdquo','\xAB':'laquo','\xBB':'raquo','(':'lpar',')':'rpar','[':'lsqb',']':'rsqb','{':'lcub','}':'rcub','\u2308':'lceil','\u2309':'rceil','\u230A':'lfloor','\u230B':'rfloor','\u2985':'lopar','\u2986':'ropar','\u298B':'lbrke','\u298C':'rbrke','\u298D':'lbrkslu','\u298E':'rbrksld','\u298F':'lbrksld','\u2990':'rbrkslu','\u2991':'langd','\u2992':'rangd','\u2993':'lparlt','\u2994':'rpargt','\u2995':'gtlPar','\u2996':'ltrPar','\u27E6':'lobrk','\u27E7':'robrk','\u27E8':'lang','\u27E9':'rang','\u27EA':'Lang','\u27EB':'Rang','\u27EC':'loang','\u27ED':'roang','\u2772':'lbbrk','\u2773':'rbbrk','\u2016':'Vert','\xA7':'sect','\xB6':'para','@':'commat','*':'ast','/':'sol','undefined':null,'&':'amp','#':'num','%':'percnt','\u2030':'permil','\u2031':'pertenk','\u2020':'dagger','\u2021':'Dagger','\u2022':'bull','\u2043':'hybull','\u2032':'prime','\u2033':'Prime','\u2034':'tprime','\u2057':'qprime','\u2035':'bprime','\u2041':'caret','`':'grave','\xB4':'acute','\u02DC':'tilde','^':'Hat','\xAF':'macr','\u02D8':'breve','\u02D9':'dot','\xA8':'die','\u02DA':'ring','\u02DD':'dblac','\xB8':'cedil','\u02DB':'ogon','\u02C6':'circ','\u02C7':'caron','\xB0':'deg','\xA9':'copy','\xAE':'reg','\u2117':'copysr','\u2118':'wp','\u211E':'rx','\u2127':'mho','\u2129':'iiota','\u2190':'larr','\u219A':'nlarr','\u2192':'rarr','\u219B':'nrarr','\u2191':'uarr','\u2193':'darr','\u2194':'harr','\u21AE':'nharr','\u2195':'varr','\u2196':'nwarr','\u2197':'nearr','\u2198':'searr','\u2199':'swarr','\u219D':'rarrw','\u219D\u0338':'nrarrw','\u219E':'Larr','\u219F':'Uarr','\u21A0':'Rarr','\u21A1':'Darr','\u21A2':'larrtl','\u21A3':'rarrtl','\u21A4':'mapstoleft','\u21A5':'mapstoup','\u21A6':'map','\u21A7':'mapstodown','\u21A9':'larrhk','\u21AA':'rarrhk','\u21AB':'larrlp','\u21AC':'rarrlp','\u21AD':'harrw','\u21B0':'lsh','\u21B1':'rsh','\u21B2':'ldsh','\u21B3':'rdsh','\u21B5':'crarr','\u21B6':'cularr','\u21B7':'curarr','\u21BA':'olarr','\u21BB':'orarr','\u21BC':'lharu','\u21BD':'lhard','\u21BE':'uharr','\u21BF':'uharl','\u21C0':'rharu','\u21C1':'rhard','\u21C2':'dharr','\u21C3':'dharl','\u21C4':'rlarr','\u21C5':'udarr','\u21C6':'lrarr','\u21C7':'llarr','\u21C8':'uuarr','\u21C9':'rrarr','\u21CA':'ddarr','\u21CB':'lrhar','\u21CC':'rlhar','\u21D0':'lArr','\u21CD':'nlArr','\u21D1':'uArr','\u21D2':'rArr','\u21CF':'nrArr','\u21D3':'dArr','\u21D4':'iff','\u21CE':'nhArr','\u21D5':'vArr','\u21D6':'nwArr','\u21D7':'neArr','\u21D8':'seArr','\u21D9':'swArr','\u21DA':'lAarr','\u21DB':'rAarr','\u21DD':'zigrarr','\u21E4':'larrb','\u21E5':'rarrb','\u21F5':'duarr','\u21FD':'loarr','\u21FE':'roarr','\u21FF':'hoarr','\u2200':'forall','\u2201':'comp','\u2202':'part','\u2202\u0338':'npart','\u2203':'exist','\u2204':'nexist','\u2205':'empty','\u2207':'Del','\u2208':'in','\u2209':'notin','\u220B':'ni','\u220C':'notni','\u03F6':'bepsi','\u220F':'prod','\u2210':'coprod','\u2211':'sum','+':'plus','\xB1':'pm','\xF7':'div','\xD7':'times','<':'lt','\u226E':'nlt','<\u20D2':'nvlt','=':'equals','\u2260':'ne','=\u20E5':'bne','\u2A75':'Equal','>':'gt','\u226F':'ngt','>\u20D2':'nvgt','\xAC':'not','|':'vert','\xA6':'brvbar','\u2212':'minus','\u2213':'mp','\u2214':'plusdo','\u2044':'frasl','\u2216':'setmn','\u2217':'lowast','\u2218':'compfn','\u221A':'Sqrt','\u221D':'prop','\u221E':'infin','\u221F':'angrt','\u2220':'ang','\u2220\u20D2':'nang','\u2221':'angmsd','\u2222':'angsph','\u2223':'mid','\u2224':'nmid','\u2225':'par','\u2226':'npar','\u2227':'and','\u2228':'or','\u2229':'cap','\u2229\uFE00':'caps','\u222A':'cup','\u222A\uFE00':'cups','\u222B':'int','\u222C':'Int','\u222D':'tint','\u2A0C':'qint','\u222E':'oint','\u222F':'Conint','\u2230':'Cconint','\u2231':'cwint','\u2232':'cwconint','\u2233':'awconint','\u2234':'there4','\u2235':'becaus','\u2236':'ratio','\u2237':'Colon','\u2238':'minusd','\u223A':'mDDot','\u223B':'homtht','\u223C':'sim','\u2241':'nsim','\u223C\u20D2':'nvsim','\u223D':'bsim','\u223D\u0331':'race','\u223E':'ac','\u223E\u0333':'acE','\u223F':'acd','\u2240':'wr','\u2242':'esim','\u2242\u0338':'nesim','\u2243':'sime','\u2244':'nsime','\u2245':'cong','\u2247':'ncong','\u2246':'simne','\u2248':'ap','\u2249':'nap','\u224A':'ape','\u224B':'apid','\u224B\u0338':'napid','\u224C':'bcong','\u224D':'CupCap','\u226D':'NotCupCap','\u224D\u20D2':'nvap','\u224E':'bump','\u224E\u0338':'nbump','\u224F':'bumpe','\u224F\u0338':'nbumpe','\u2250':'doteq','\u2250\u0338':'nedot','\u2251':'eDot','\u2252':'efDot','\u2253':'erDot','\u2254':'colone','\u2255':'ecolon','\u2256':'ecir','\u2257':'cire','\u2259':'wedgeq','\u225A':'veeeq','\u225C':'trie','\u225F':'equest','\u2261':'equiv','\u2262':'nequiv','\u2261\u20E5':'bnequiv','\u2264':'le','\u2270':'nle','\u2264\u20D2':'nvle','\u2265':'ge','\u2271':'nge','\u2265\u20D2':'nvge','\u2266':'lE','\u2266\u0338':'nlE','\u2267':'gE','\u2267\u0338':'ngE','\u2268\uFE00':'lvnE','\u2268':'lnE','\u2269':'gnE','\u2269\uFE00':'gvnE','\u226A':'ll','\u226A\u0338':'nLtv','\u226A\u20D2':'nLt','\u226B':'gg','\u226B\u0338':'nGtv','\u226B\u20D2':'nGt','\u226C':'twixt','\u2272':'lsim','\u2274':'nlsim','\u2273':'gsim','\u2275':'ngsim','\u2276':'lg','\u2278':'ntlg','\u2277':'gl','\u2279':'ntgl','\u227A':'pr','\u2280':'npr','\u227B':'sc','\u2281':'nsc','\u227C':'prcue','\u22E0':'nprcue','\u227D':'sccue','\u22E1':'nsccue','\u227E':'prsim','\u227F':'scsim','\u227F\u0338':'NotSucceedsTilde','\u2282':'sub','\u2284':'nsub','\u2282\u20D2':'vnsub','\u2283':'sup','\u2285':'nsup','\u2283\u20D2':'vnsup','\u2286':'sube','\u2288':'nsube','\u2287':'supe','\u2289':'nsupe','\u228A\uFE00':'vsubne','\u228A':'subne','\u228B\uFE00':'vsupne','\u228B':'supne','\u228D':'cupdot','\u228E':'uplus','\u228F':'sqsub','\u228F\u0338':'NotSquareSubset','\u2290':'sqsup','\u2290\u0338':'NotSquareSuperset','\u2291':'sqsube','\u22E2':'nsqsube','\u2292':'sqsupe','\u22E3':'nsqsupe','\u2293':'sqcap','\u2293\uFE00':'sqcaps','\u2294':'sqcup','\u2294\uFE00':'sqcups','\u2295':'oplus','\u2296':'ominus','\u2297':'otimes','\u2298':'osol','\u2299':'odot','\u229A':'ocir','\u229B':'oast','\u229D':'odash','\u229E':'plusb','\u229F':'minusb','\u22A0':'timesb','\u22A1':'sdotb','\u22A2':'vdash','\u22AC':'nvdash','\u22A3':'dashv','\u22A4':'top','\u22A5':'bot','\u22A7':'models','\u22A8':'vDash','\u22AD':'nvDash','\u22A9':'Vdash','\u22AE':'nVdash','\u22AA':'Vvdash','\u22AB':'VDash','\u22AF':'nVDash','\u22B0':'prurel','\u22B2':'vltri','\u22EA':'nltri','\u22B3':'vrtri','\u22EB':'nrtri','\u22B4':'ltrie','\u22EC':'nltrie','\u22B4\u20D2':'nvltrie','\u22B5':'rtrie','\u22ED':'nrtrie','\u22B5\u20D2':'nvrtrie','\u22B6':'origof','\u22B7':'imof','\u22B8':'mumap','\u22B9':'hercon','\u22BA':'intcal','\u22BB':'veebar','\u22BD':'barvee','\u22BE':'angrtvb','\u22BF':'lrtri','\u22C0':'Wedge','\u22C1':'Vee','\u22C2':'xcap','\u22C3':'xcup','\u22C4':'diam','\u22C5':'sdot','\u22C6':'Star','\u22C7':'divonx','\u22C8':'bowtie','\u22C9':'ltimes','\u22CA':'rtimes','\u22CB':'lthree','\u22CC':'rthree','\u22CD':'bsime','\u22CE':'cuvee','\u22CF':'cuwed','\u22D0':'Sub','\u22D1':'Sup','\u22D2':'Cap','\u22D3':'Cup','\u22D4':'fork','\u22D5':'epar','\u22D6':'ltdot','\u22D7':'gtdot','\u22D8':'Ll','\u22D8\u0338':'nLl','\u22D9':'Gg','\u22D9\u0338':'nGg','\u22DA\uFE00':'lesg','\u22DA':'leg','\u22DB':'gel','\u22DB\uFE00':'gesl','\u22DE':'cuepr','\u22DF':'cuesc','\u22E6':'lnsim','\u22E7':'gnsim','\u22E8':'prnsim','\u22E9':'scnsim','\u22EE':'vellip','\u22EF':'ctdot','\u22F0':'utdot','\u22F1':'dtdot','\u22F2':'disin','\u22F3':'isinsv','\u22F4':'isins','\u22F5':'isindot','\u22F5\u0338':'notindot','\u22F6':'notinvc','\u22F7':'notinvb','\u22F9':'isinE','\u22F9\u0338':'notinE','\u22FA':'nisd','\u22FB':'xnis','\u22FC':'nis','\u22FD':'notnivc','\u22FE':'notnivb','\u2305':'barwed','\u2306':'Barwed','\u230C':'drcrop','\u230D':'dlcrop','\u230E':'urcrop','\u230F':'ulcrop','\u2310':'bnot','\u2312':'profline','\u2313':'profsurf','\u2315':'telrec','\u2316':'target','\u231C':'ulcorn','\u231D':'urcorn','\u231E':'dlcorn','\u231F':'drcorn','\u2322':'frown','\u2323':'smile','\u232D':'cylcty','\u232E':'profalar','\u2336':'topbot','\u233D':'ovbar','\u233F':'solbar','\u237C':'angzarr','\u23B0':'lmoust','\u23B1':'rmoust','\u23B4':'tbrk','\u23B5':'bbrk','\u23B6':'bbrktbrk','\u23DC':'OverParenthesis','\u23DD':'UnderParenthesis','\u23DE':'OverBrace','\u23DF':'UnderBrace','\u23E2':'trpezium','\u23E7':'elinters','\u2423':'blank','\u2500':'boxh','\u2502':'boxv','\u250C':'boxdr','\u2510':'boxdl','\u2514':'boxur','\u2518':'boxul','\u251C':'boxvr','\u2524':'boxvl','\u252C':'boxhd','\u2534':'boxhu','\u253C':'boxvh','\u2550':'boxH','\u2551':'boxV','\u2552':'boxdR','\u2553':'boxDr','\u2554':'boxDR','\u2555':'boxdL','\u2556':'boxDl','\u2557':'boxDL','\u2558':'boxuR','\u2559':'boxUr','\u255A':'boxUR','\u255B':'boxuL','\u255C':'boxUl','\u255D':'boxUL','\u255E':'boxvR','\u255F':'boxVr','\u2560':'boxVR','\u2561':'boxvL','\u2562':'boxVl','\u2563':'boxVL','\u2564':'boxHd','\u2565':'boxhD','\u2566':'boxHD','\u2567':'boxHu','\u2568':'boxhU','\u2569':'boxHU','\u256A':'boxvH','\u256B':'boxVh','\u256C':'boxVH','\u2580':'uhblk','\u2584':'lhblk','\u2588':'block','\u2591':'blk14','\u2592':'blk12','\u2593':'blk34','\u25A1':'squ','\u25AA':'squf','\u25AB':'EmptyVerySmallSquare','\u25AD':'rect','\u25AE':'marker','\u25B1':'fltns','\u25B3':'xutri','\u25B4':'utrif','\u25B5':'utri','\u25B8':'rtrif','\u25B9':'rtri','\u25BD':'xdtri','\u25BE':'dtrif','\u25BF':'dtri','\u25C2':'ltrif','\u25C3':'ltri','\u25CA':'loz','\u25CB':'cir','\u25EC':'tridot','\u25EF':'xcirc','\u25F8':'ultri','\u25F9':'urtri','\u25FA':'lltri','\u25FB':'EmptySmallSquare','\u25FC':'FilledSmallSquare','\u2605':'starf','\u2606':'star','\u260E':'phone','\u2640':'female','\u2642':'male','\u2660':'spades','\u2663':'clubs','\u2665':'hearts','\u2666':'diams','\u266A':'sung','\u2713':'check','\u2717':'cross','\u2720':'malt','\u2736':'sext','\u2758':'VerticalSeparator','\u27C8':'bsolhsub','\u27C9':'suphsol','\u27F5':'xlarr','\u27F6':'xrarr','\u27F7':'xharr','\u27F8':'xlArr','\u27F9':'xrArr','\u27FA':'xhArr','\u27FC':'xmap','\u27FF':'dzigrarr','\u2902':'nvlArr','\u2903':'nvrArr','\u2904':'nvHarr','\u2905':'Map','\u290C':'lbarr','\u290D':'rbarr','\u290E':'lBarr','\u290F':'rBarr','\u2910':'RBarr','\u2911':'DDotrahd','\u2912':'UpArrowBar','\u2913':'DownArrowBar','\u2916':'Rarrtl','\u2919':'latail','\u291A':'ratail','\u291B':'lAtail','\u291C':'rAtail','\u291D':'larrfs','\u291E':'rarrfs','\u291F':'larrbfs','\u2920':'rarrbfs','\u2923':'nwarhk','\u2924':'nearhk','\u2925':'searhk','\u2926':'swarhk','\u2927':'nwnear','\u2928':'toea','\u2929':'tosa','\u292A':'swnwar','\u2933':'rarrc','\u2933\u0338':'nrarrc','\u2935':'cudarrr','\u2936':'ldca','\u2937':'rdca','\u2938':'cudarrl','\u2939':'larrpl','\u293C':'curarrm','\u293D':'cularrp','\u2945':'rarrpl','\u2948':'harrcir','\u2949':'Uarrocir','\u294A':'lurdshar','\u294B':'ldrushar','\u294E':'LeftRightVector','\u294F':'RightUpDownVector','\u2950':'DownLeftRightVector','\u2951':'LeftUpDownVector','\u2952':'LeftVectorBar','\u2953':'RightVectorBar','\u2954':'RightUpVectorBar','\u2955':'RightDownVectorBar','\u2956':'DownLeftVectorBar','\u2957':'DownRightVectorBar','\u2958':'LeftUpVectorBar','\u2959':'LeftDownVectorBar','\u295A':'LeftTeeVector','\u295B':'RightTeeVector','\u295C':'RightUpTeeVector','\u295D':'RightDownTeeVector','\u295E':'DownLeftTeeVector','\u295F':'DownRightTeeVector','\u2960':'LeftUpTeeVector','\u2961':'LeftDownTeeVector','\u2962':'lHar','\u2963':'uHar','\u2964':'rHar','\u2965':'dHar','\u2966':'luruhar','\u2967':'ldrdhar','\u2968':'ruluhar','\u2969':'rdldhar','\u296A':'lharul','\u296B':'llhard','\u296C':'rharul','\u296D':'lrhard','\u296E':'udhar','\u296F':'duhar','\u2970':'RoundImplies','\u2971':'erarr','\u2972':'simrarr','\u2973':'larrsim','\u2974':'rarrsim','\u2975':'rarrap','\u2976':'ltlarr','\u2978':'gtrarr','\u2979':'subrarr','\u297B':'suplarr','\u297C':'lfisht','\u297D':'rfisht','\u297E':'ufisht','\u297F':'dfisht','\u299A':'vzigzag','\u299C':'vangrt','\u299D':'angrtvbd','\u29A4':'ange','\u29A5':'range','\u29A6':'dwangle','\u29A7':'uwangle','\u29A8':'angmsdaa','\u29A9':'angmsdab','\u29AA':'angmsdac','\u29AB':'angmsdad','\u29AC':'angmsdae','\u29AD':'angmsdaf','\u29AE':'angmsdag','\u29AF':'angmsdah','\u29B0':'bemptyv','\u29B1':'demptyv','\u29B2':'cemptyv','\u29B3':'raemptyv','\u29B4':'laemptyv','\u29B5':'ohbar','\u29B6':'omid','\u29B7':'opar','\u29B9':'operp','\u29BB':'olcross','\u29BC':'odsold','\u29BE':'olcir','\u29BF':'ofcir','\u29C0':'olt','\u29C1':'ogt','\u29C2':'cirscir','\u29C3':'cirE','\u29C4':'solb','\u29C5':'bsolb','\u29C9':'boxbox','\u29CD':'trisb','\u29CE':'rtriltri','\u29CF':'LeftTriangleBar','\u29CF\u0338':'NotLeftTriangleBar','\u29D0':'RightTriangleBar','\u29D0\u0338':'NotRightTriangleBar','\u29DC':'iinfin','\u29DD':'infintie','\u29DE':'nvinfin','\u29E3':'eparsl','\u29E4':'smeparsl','\u29E5':'eqvparsl','\u29EB':'lozf','\u29F4':'RuleDelayed','\u29F6':'dsol','\u2A00':'xodot','\u2A01':'xoplus','\u2A02':'xotime','\u2A04':'xuplus','\u2A06':'xsqcup','\u2A0D':'fpartint','\u2A10':'cirfnint','\u2A11':'awint','\u2A12':'rppolint','\u2A13':'scpolint','\u2A14':'npolint','\u2A15':'pointint','\u2A16':'quatint','\u2A17':'intlarhk','\u2A22':'pluscir','\u2A23':'plusacir','\u2A24':'simplus','\u2A25':'plusdu','\u2A26':'plussim','\u2A27':'plustwo','\u2A29':'mcomma','\u2A2A':'minusdu','\u2A2D':'loplus','\u2A2E':'roplus','\u2A2F':'Cross','\u2A30':'timesd','\u2A31':'timesbar','\u2A33':'smashp','\u2A34':'lotimes','\u2A35':'rotimes','\u2A36':'otimesas','\u2A37':'Otimes','\u2A38':'odiv','\u2A39':'triplus','\u2A3A':'triminus','\u2A3B':'tritime','\u2A3C':'iprod','\u2A3F':'amalg','\u2A40':'capdot','\u2A42':'ncup','\u2A43':'ncap','\u2A44':'capand','\u2A45':'cupor','\u2A46':'cupcap','\u2A47':'capcup','\u2A48':'cupbrcap','\u2A49':'capbrcup','\u2A4A':'cupcup','\u2A4B':'capcap','\u2A4C':'ccups','\u2A4D':'ccaps','\u2A50':'ccupssm','\u2A53':'And','\u2A54':'Or','\u2A55':'andand','\u2A56':'oror','\u2A57':'orslope','\u2A58':'andslope','\u2A5A':'andv','\u2A5B':'orv','\u2A5C':'andd','\u2A5D':'ord','\u2A5F':'wedbar','\u2A66':'sdote','\u2A6A':'simdot','\u2A6D':'congdot','\u2A6D\u0338':'ncongdot','\u2A6E':'easter','\u2A6F':'apacir','\u2A70':'apE','\u2A70\u0338':'napE','\u2A71':'eplus','\u2A72':'pluse','\u2A73':'Esim','\u2A77':'eDDot','\u2A78':'equivDD','\u2A79':'ltcir','\u2A7A':'gtcir','\u2A7B':'ltquest','\u2A7C':'gtquest','\u2A7D':'les','\u2A7D\u0338':'nles','\u2A7E':'ges','\u2A7E\u0338':'nges','\u2A7F':'lesdot','\u2A80':'gesdot','\u2A81':'lesdoto','\u2A82':'gesdoto','\u2A83':'lesdotor','\u2A84':'gesdotol','\u2A85':'lap','\u2A86':'gap','\u2A87':'lne','\u2A88':'gne','\u2A89':'lnap','\u2A8A':'gnap','\u2A8B':'lEg','\u2A8C':'gEl','\u2A8D':'lsime','\u2A8E':'gsime','\u2A8F':'lsimg','\u2A90':'gsiml','\u2A91':'lgE','\u2A92':'glE','\u2A93':'lesges','\u2A94':'gesles','\u2A95':'els','\u2A96':'egs','\u2A97':'elsdot','\u2A98':'egsdot','\u2A99':'el','\u2A9A':'eg','\u2A9D':'siml','\u2A9E':'simg','\u2A9F':'simlE','\u2AA0':'simgE','\u2AA1':'LessLess','\u2AA1\u0338':'NotNestedLessLess','\u2AA2':'GreaterGreater','\u2AA2\u0338':'NotNestedGreaterGreater','\u2AA4':'glj','\u2AA5':'gla','\u2AA6':'ltcc','\u2AA7':'gtcc','\u2AA8':'lescc','\u2AA9':'gescc','\u2AAA':'smt','\u2AAB':'lat','\u2AAC':'smte','\u2AAC\uFE00':'smtes','\u2AAD':'late','\u2AAD\uFE00':'lates','\u2AAE':'bumpE','\u2AAF':'pre','\u2AAF\u0338':'npre','\u2AB0':'sce','\u2AB0\u0338':'nsce','\u2AB3':'prE','\u2AB4':'scE','\u2AB5':'prnE','\u2AB6':'scnE','\u2AB7':'prap','\u2AB8':'scap','\u2AB9':'prnap','\u2ABA':'scnap','\u2ABB':'Pr','\u2ABC':'Sc','\u2ABD':'subdot','\u2ABE':'supdot','\u2ABF':'subplus','\u2AC0':'supplus','\u2AC1':'submult','\u2AC2':'supmult','\u2AC3':'subedot','\u2AC4':'supedot','\u2AC5':'subE','\u2AC5\u0338':'nsubE','\u2AC6':'supE','\u2AC6\u0338':'nsupE','\u2AC7':'subsim','\u2AC8':'supsim','\u2ACB\uFE00':'vsubnE','\u2ACB':'subnE','\u2ACC\uFE00':'vsupnE','\u2ACC':'supnE','\u2ACF':'csub','\u2AD0':'csup','\u2AD1':'csube','\u2AD2':'csupe','\u2AD3':'subsup','\u2AD4':'supsub','\u2AD5':'subsub','\u2AD6':'supsup','\u2AD7':'suphsub','\u2AD8':'supdsub','\u2AD9':'forkv','\u2ADA':'topfork','\u2ADB':'mlcp','\u2AE4':'Dashv','\u2AE6':'Vdashl','\u2AE7':'Barv','\u2AE8':'vBar','\u2AE9':'vBarv','\u2AEB':'Vbar','\u2AEC':'Not','\u2AED':'bNot','\u2AEE':'rnmid','\u2AEF':'cirmid','\u2AF0':'midcir','\u2AF1':'topcir','\u2AF2':'nhpar','\u2AF3':'parsim','\u2AFD':'parsl','\u2AFD\u20E5':'nparsl','\u266D':'flat','\u266E':'natur','\u266F':'sharp','\xA4':'curren','\xA2':'cent','$':'dollar','\xA3':'pound','\xA5':'yen','\u20AC':'euro','\xB9':'sup1','\xBD':'half','\u2153':'frac13','\xBC':'frac14','\u2155':'frac15','\u2159':'frac16','\u215B':'frac18','\xB2':'sup2','\u2154':'frac23','\u2156':'frac25','\xB3':'sup3','\xBE':'frac34','\u2157':'frac35','\u215C':'frac38','\u2158':'frac45','\u215A':'frac56','\u215D':'frac58','\u215E':'frac78','\uD835\uDCB6':'ascr','\uD835\uDD52':'aopf','\uD835\uDD1E':'afr','\uD835\uDD38':'Aopf','\uD835\uDD04':'Afr','\uD835\uDC9C':'Ascr','\xAA':'ordf','\xE1':'aacute','\xC1':'Aacute','\xE0':'agrave','\xC0':'Agrave','\u0103':'abreve','\u0102':'Abreve','\xE2':'acirc','\xC2':'Acirc','\xE5':'aring','\xC5':'angst','\xE4':'auml','\xC4':'Auml','\xE3':'atilde','\xC3':'Atilde','\u0105':'aogon','\u0104':'Aogon','\u0101':'amacr','\u0100':'Amacr','\xE6':'aelig','\xC6':'AElig','\uD835\uDCB7':'bscr','\uD835\uDD53':'bopf','\uD835\uDD1F':'bfr','\uD835\uDD39':'Bopf','\u212C':'Bscr','\uD835\uDD05':'Bfr','\uD835\uDD20':'cfr','\uD835\uDCB8':'cscr','\uD835\uDD54':'copf','\u212D':'Cfr','\uD835\uDC9E':'Cscr','\u2102':'Copf','\u0107':'cacute','\u0106':'Cacute','\u0109':'ccirc','\u0108':'Ccirc','\u010D':'ccaron','\u010C':'Ccaron','\u010B':'cdot','\u010A':'Cdot','\xE7':'ccedil','\xC7':'Ccedil','\u2105':'incare','\uD835\uDD21':'dfr','\u2146':'dd','\uD835\uDD55':'dopf','\uD835\uDCB9':'dscr','\uD835\uDC9F':'Dscr','\uD835\uDD07':'Dfr','\u2145':'DD','\uD835\uDD3B':'Dopf','\u010F':'dcaron','\u010E':'Dcaron','\u0111':'dstrok','\u0110':'Dstrok','\xF0':'eth','\xD0':'ETH','\u2147':'ee','\u212F':'escr','\uD835\uDD22':'efr','\uD835\uDD56':'eopf','\u2130':'Escr','\uD835\uDD08':'Efr','\uD835\uDD3C':'Eopf','\xE9':'eacute','\xC9':'Eacute','\xE8':'egrave','\xC8':'Egrave','\xEA':'ecirc','\xCA':'Ecirc','\u011B':'ecaron','\u011A':'Ecaron','\xEB':'euml','\xCB':'Euml','\u0117':'edot','\u0116':'Edot','\u0119':'eogon','\u0118':'Eogon','\u0113':'emacr','\u0112':'Emacr','\uD835\uDD23':'ffr','\uD835\uDD57':'fopf','\uD835\uDCBB':'fscr','\uD835\uDD09':'Ffr','\uD835\uDD3D':'Fopf','\u2131':'Fscr','\uFB00':'fflig','\uFB03':'ffilig','\uFB04':'ffllig','\uFB01':'filig','fj':'fjlig','\uFB02':'fllig','\u0192':'fnof','\u210A':'gscr','\uD835\uDD58':'gopf','\uD835\uDD24':'gfr','\uD835\uDCA2':'Gscr','\uD835\uDD3E':'Gopf','\uD835\uDD0A':'Gfr','\u01F5':'gacute','\u011F':'gbreve','\u011E':'Gbreve','\u011D':'gcirc','\u011C':'Gcirc','\u0121':'gdot','\u0120':'Gdot','\u0122':'Gcedil','\uD835\uDD25':'hfr','\u210E':'planckh','\uD835\uDCBD':'hscr','\uD835\uDD59':'hopf','\u210B':'Hscr','\u210C':'Hfr','\u210D':'Hopf','\u0125':'hcirc','\u0124':'Hcirc','\u210F':'hbar','\u0127':'hstrok','\u0126':'Hstrok','\uD835\uDD5A':'iopf','\uD835\uDD26':'ifr','\uD835\uDCBE':'iscr','\u2148':'ii','\uD835\uDD40':'Iopf','\u2110':'Iscr','\u2111':'Im','\xED':'iacute','\xCD':'Iacute','\xEC':'igrave','\xCC':'Igrave','\xEE':'icirc','\xCE':'Icirc','\xEF':'iuml','\xCF':'Iuml','\u0129':'itilde','\u0128':'Itilde','\u0130':'Idot','\u012F':'iogon','\u012E':'Iogon','\u012B':'imacr','\u012A':'Imacr','\u0133':'ijlig','\u0132':'IJlig','\u0131':'imath','\uD835\uDCBF':'jscr','\uD835\uDD5B':'jopf','\uD835\uDD27':'jfr','\uD835\uDCA5':'Jscr','\uD835\uDD0D':'Jfr','\uD835\uDD41':'Jopf','\u0135':'jcirc','\u0134':'Jcirc','\u0237':'jmath','\uD835\uDD5C':'kopf','\uD835\uDCC0':'kscr','\uD835\uDD28':'kfr','\uD835\uDCA6':'Kscr','\uD835\uDD42':'Kopf','\uD835\uDD0E':'Kfr','\u0137':'kcedil','\u0136':'Kcedil','\uD835\uDD29':'lfr','\uD835\uDCC1':'lscr','\u2113':'ell','\uD835\uDD5D':'lopf','\u2112':'Lscr','\uD835\uDD0F':'Lfr','\uD835\uDD43':'Lopf','\u013A':'lacute','\u0139':'Lacute','\u013E':'lcaron','\u013D':'Lcaron','\u013C':'lcedil','\u013B':'Lcedil','\u0142':'lstrok','\u0141':'Lstrok','\u0140':'lmidot','\u013F':'Lmidot','\uD835\uDD2A':'mfr','\uD835\uDD5E':'mopf','\uD835\uDCC2':'mscr','\uD835\uDD10':'Mfr','\uD835\uDD44':'Mopf','\u2133':'Mscr','\uD835\uDD2B':'nfr','\uD835\uDD5F':'nopf','\uD835\uDCC3':'nscr','\u2115':'Nopf','\uD835\uDCA9':'Nscr','\uD835\uDD11':'Nfr','\u0144':'nacute','\u0143':'Nacute','\u0148':'ncaron','\u0147':'Ncaron','\xF1':'ntilde','\xD1':'Ntilde','\u0146':'ncedil','\u0145':'Ncedil','\u2116':'numero','\u014B':'eng','\u014A':'ENG','\uD835\uDD60':'oopf','\uD835\uDD2C':'ofr','\u2134':'oscr','\uD835\uDCAA':'Oscr','\uD835\uDD12':'Ofr','\uD835\uDD46':'Oopf','\xBA':'ordm','\xF3':'oacute','\xD3':'Oacute','\xF2':'ograve','\xD2':'Ograve','\xF4':'ocirc','\xD4':'Ocirc','\xF6':'ouml','\xD6':'Ouml','\u0151':'odblac','\u0150':'Odblac','\xF5':'otilde','\xD5':'Otilde','\xF8':'oslash','\xD8':'Oslash','\u014D':'omacr','\u014C':'Omacr','\u0153':'oelig','\u0152':'OElig','\uD835\uDD2D':'pfr','\uD835\uDCC5':'pscr','\uD835\uDD61':'popf','\u2119':'Popf','\uD835\uDD13':'Pfr','\uD835\uDCAB':'Pscr','\uD835\uDD62':'qopf','\uD835\uDD2E':'qfr','\uD835\uDCC6':'qscr','\uD835\uDCAC':'Qscr','\uD835\uDD14':'Qfr','\u211A':'Qopf','\u0138':'kgreen','\uD835\uDD2F':'rfr','\uD835\uDD63':'ropf','\uD835\uDCC7':'rscr','\u211B':'Rscr','\u211C':'Re','\u211D':'Ropf','\u0155':'racute','\u0154':'Racute','\u0159':'rcaron','\u0158':'Rcaron','\u0157':'rcedil','\u0156':'Rcedil','\uD835\uDD64':'sopf','\uD835\uDCC8':'sscr','\uD835\uDD30':'sfr','\uD835\uDD4A':'Sopf','\uD835\uDD16':'Sfr','\uD835\uDCAE':'Sscr','\u24C8':'oS','\u015B':'sacute','\u015A':'Sacute','\u015D':'scirc','\u015C':'Scirc','\u0161':'scaron','\u0160':'Scaron','\u015F':'scedil','\u015E':'Scedil','\xDF':'szlig','\uD835\uDD31':'tfr','\uD835\uDCC9':'tscr','\uD835\uDD65':'topf','\uD835\uDCAF':'Tscr','\uD835\uDD17':'Tfr','\uD835\uDD4B':'Topf','\u0165':'tcaron','\u0164':'Tcaron','\u0163':'tcedil','\u0162':'Tcedil','\u2122':'trade','\u0167':'tstrok','\u0166':'Tstrok','\uD835\uDCCA':'uscr','\uD835\uDD66':'uopf','\uD835\uDD32':'ufr','\uD835\uDD4C':'Uopf','\uD835\uDD18':'Ufr','\uD835\uDCB0':'Uscr','\xFA':'uacute','\xDA':'Uacute','\xF9':'ugrave','\xD9':'Ugrave','\u016D':'ubreve','\u016C':'Ubreve','\xFB':'ucirc','\xDB':'Ucirc','\u016F':'uring','\u016E':'Uring','\xFC':'uuml','\xDC':'Uuml','\u0171':'udblac','\u0170':'Udblac','\u0169':'utilde','\u0168':'Utilde','\u0173':'uogon','\u0172':'Uogon','\u016B':'umacr','\u016A':'Umacr','\uD835\uDD33':'vfr','\uD835\uDD67':'vopf','\uD835\uDCCB':'vscr','\uD835\uDD19':'Vfr','\uD835\uDD4D':'Vopf','\uD835\uDCB1':'Vscr','\uD835\uDD68':'wopf','\uD835\uDCCC':'wscr','\uD835\uDD34':'wfr','\uD835\uDCB2':'Wscr','\uD835\uDD4E':'Wopf','\uD835\uDD1A':'Wfr','\u0175':'wcirc','\u0174':'Wcirc','\uD835\uDD35':'xfr','\uD835\uDCCD':'xscr','\uD835\uDD69':'xopf','\uD835\uDD4F':'Xopf','\uD835\uDD1B':'Xfr','\uD835\uDCB3':'Xscr','\uD835\uDD36':'yfr','\uD835\uDCCE':'yscr','\uD835\uDD6A':'yopf','\uD835\uDCB4':'Yscr','\uD835\uDD1C':'Yfr','\uD835\uDD50':'Yopf','\xFD':'yacute','\xDD':'Yacute','\u0177':'ycirc','\u0176':'Ycirc','\xFF':'yuml','\u0178':'Yuml','\uD835\uDCCF':'zscr','\uD835\uDD37':'zfr','\uD835\uDD6B':'zopf','\u2128':'Zfr','\u2124':'Zopf','\uD835\uDCB5':'Zscr','\u017A':'zacute','\u0179':'Zacute','\u017E':'zcaron','\u017D':'Zcaron','\u017C':'zdot','\u017B':'Zdot','\u01B5':'imped','\xFE':'thorn','\xDE':'THORN','\u0149':'napos','\u03B1':'alpha','\u0391':'Alpha','\u03B2':'beta','\u0392':'Beta','\u03B3':'gamma','\u0393':'Gamma','\u03B4':'delta','\u0394':'Delta','\u03B5':'epsi','\u03F5':'epsiv','\u0395':'Epsilon','\u03DD':'gammad','\u03DC':'Gammad','\u03B6':'zeta','\u0396':'Zeta','\u03B7':'eta','\u0397':'Eta','\u03B8':'theta','\u03D1':'thetav','\u0398':'Theta','\u03B9':'iota','\u0399':'Iota','\u03BA':'kappa','\u03F0':'kappav','\u039A':'Kappa','\u03BB':'lambda','\u039B':'Lambda','\u03BC':'mu','\xB5':'micro','\u039C':'Mu','\u03BD':'nu','\u039D':'Nu','\u03BE':'xi','\u039E':'Xi','\u03BF':'omicron','\u039F':'Omicron','\u03C0':'pi','\u03D6':'piv','\u03A0':'Pi','\u03C1':'rho','\u03F1':'rhov','\u03A1':'Rho','\u03C3':'sigma','\u03A3':'Sigma','\u03C2':'sigmaf','\u03C4':'tau','\u03A4':'Tau','\u03C5':'upsi','\u03A5':'Upsilon','\u03D2':'Upsi','\u03C6':'phi','\u03D5':'phiv','\u03A6':'Phi','\u03C7':'chi','\u03A7':'Chi','\u03C8':'psi','\u03A8':'Psi','\u03C9':'omega','\u03A9':'ohm','\u0430':'acy','\u0410':'Acy','\u0431':'bcy','\u0411':'Bcy','\u0432':'vcy','\u0412':'Vcy','\u0433':'gcy','\u0413':'Gcy','\u0453':'gjcy','\u0403':'GJcy','\u0434':'dcy','\u0414':'Dcy','\u0452':'djcy','\u0402':'DJcy','\u0435':'iecy','\u0415':'IEcy','\u0451':'iocy','\u0401':'IOcy','\u0454':'jukcy','\u0404':'Jukcy','\u0436':'zhcy','\u0416':'ZHcy','\u0437':'zcy','\u0417':'Zcy','\u0455':'dscy','\u0405':'DScy','\u0438':'icy','\u0418':'Icy','\u0456':'iukcy','\u0406':'Iukcy','\u0457':'yicy','\u0407':'YIcy','\u0439':'jcy','\u0419':'Jcy','\u0458':'jsercy','\u0408':'Jsercy','\u043A':'kcy','\u041A':'Kcy','\u045C':'kjcy','\u040C':'KJcy','\u043B':'lcy','\u041B':'Lcy','\u0459':'ljcy','\u0409':'LJcy','\u043C':'mcy','\u041C':'Mcy','\u043D':'ncy','\u041D':'Ncy','\u045A':'njcy','\u040A':'NJcy','\u043E':'ocy','\u041E':'Ocy','\u043F':'pcy','\u041F':'Pcy','\u0440':'rcy','\u0420':'Rcy','\u0441':'scy','\u0421':'Scy','\u0442':'tcy','\u0422':'Tcy','\u045B':'tshcy','\u040B':'TSHcy','\u0443':'ucy','\u0423':'Ucy','\u045E':'ubrcy','\u040E':'Ubrcy','\u0444':'fcy','\u0424':'Fcy','\u0445':'khcy','\u0425':'KHcy','\u0446':'tscy','\u0426':'TScy','\u0447':'chcy','\u0427':'CHcy','\u045F':'dzcy','\u040F':'DZcy','\u0448':'shcy','\u0428':'SHcy','\u0449':'shchcy','\u0429':'SHCHcy','\u044A':'hardcy','\u042A':'HARDcy','\u044B':'ycy','\u042B':'Ycy','\u044C':'softcy','\u042C':'SOFTcy','\u044D':'ecy','\u042D':'Ecy','\u044E':'yucy','\u042E':'YUcy','\u044F':'yacy','\u042F':'YAcy','\u2135':'aleph','\u2136':'beth','\u2137':'gimel','\u2138':'daleth'};
+
+ var regexEscape = /["&'<>`]/g;
+ var escapeMap = {
+ '"': '"',
+ '&': '&',
+ '\'': ''',
+ '<': '<',
+ // See https://mathiasbynens.be/notes/ambiguous-ampersands: in HTML, the
+ // following is not strictly necessary unless it’s part of a tag or an
+ // unquoted attribute value. We’re only escaping it to support those
+ // situations, and for XML support.
+ '>': '>',
+ // In Internet Explorer ≤ 8, the backtick character can be used
+ // to break out of (un)quoted attribute values or HTML comments.
+ // See http://html5sec.org/#102, http://html5sec.org/#108, and
+ // http://html5sec.org/#133.
+ '`': '`'
+ };
+
+ var regexInvalidEntity = /&#(?:[xX][^a-fA-F0-9]|[^0-9xX])/;
+ var regexInvalidRawCodePoint = /[\0-\x08\x0B\x0E-\x1F\x7F-\x9F\uFDD0-\uFDEF\uFFFE\uFFFF]|[\uD83F\uD87F\uD8BF\uD8FF\uD93F\uD97F\uD9BF\uD9FF\uDA3F\uDA7F\uDABF\uDAFF\uDB3F\uDB7F\uDBBF\uDBFF][\uDFFE\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
+ var regexDecode = /&#([0-9]+)(;?)|&#[xX]([a-fA-F0-9]+)(;?)|&([0-9a-zA-Z]+);|&(Aacute|Agrave|Atilde|Ccedil|Eacute|Egrave|Iacute|Igrave|Ntilde|Oacute|Ograve|Oslash|Otilde|Uacute|Ugrave|Yacute|aacute|agrave|atilde|brvbar|ccedil|curren|divide|eacute|egrave|frac12|frac14|frac34|iacute|igrave|iquest|middot|ntilde|oacute|ograve|oslash|otilde|plusmn|uacute|ugrave|yacute|AElig|Acirc|Aring|Ecirc|Icirc|Ocirc|THORN|Ucirc|acirc|acute|aelig|aring|cedil|ecirc|icirc|iexcl|laquo|micro|ocirc|pound|raquo|szlig|thorn|times|ucirc|Auml|COPY|Euml|Iuml|Ouml|QUOT|Uuml|auml|cent|copy|euml|iuml|macr|nbsp|ordf|ordm|ouml|para|quot|sect|sup1|sup2|sup3|uuml|yuml|AMP|ETH|REG|amp|deg|eth|not|reg|shy|uml|yen|GT|LT|gt|lt)([=a-zA-Z0-9])?/g;
+ var decodeMap = {'aacute':'\xE1','Aacute':'\xC1','abreve':'\u0103','Abreve':'\u0102','ac':'\u223E','acd':'\u223F','acE':'\u223E\u0333','acirc':'\xE2','Acirc':'\xC2','acute':'\xB4','acy':'\u0430','Acy':'\u0410','aelig':'\xE6','AElig':'\xC6','af':'\u2061','afr':'\uD835\uDD1E','Afr':'\uD835\uDD04','agrave':'\xE0','Agrave':'\xC0','alefsym':'\u2135','aleph':'\u2135','alpha':'\u03B1','Alpha':'\u0391','amacr':'\u0101','Amacr':'\u0100','amalg':'\u2A3F','amp':'&','AMP':'&','and':'\u2227','And':'\u2A53','andand':'\u2A55','andd':'\u2A5C','andslope':'\u2A58','andv':'\u2A5A','ang':'\u2220','ange':'\u29A4','angle':'\u2220','angmsd':'\u2221','angmsdaa':'\u29A8','angmsdab':'\u29A9','angmsdac':'\u29AA','angmsdad':'\u29AB','angmsdae':'\u29AC','angmsdaf':'\u29AD','angmsdag':'\u29AE','angmsdah':'\u29AF','angrt':'\u221F','angrtvb':'\u22BE','angrtvbd':'\u299D','angsph':'\u2222','angst':'\xC5','angzarr':'\u237C','aogon':'\u0105','Aogon':'\u0104','aopf':'\uD835\uDD52','Aopf':'\uD835\uDD38','ap':'\u2248','apacir':'\u2A6F','ape':'\u224A','apE':'\u2A70','apid':'\u224B','apos':'\'','ApplyFunction':'\u2061','approx':'\u2248','approxeq':'\u224A','aring':'\xE5','Aring':'\xC5','ascr':'\uD835\uDCB6','Ascr':'\uD835\uDC9C','Assign':'\u2254','ast':'*','asymp':'\u2248','asympeq':'\u224D','atilde':'\xE3','Atilde':'\xC3','auml':'\xE4','Auml':'\xC4','awconint':'\u2233','awint':'\u2A11','backcong':'\u224C','backepsilon':'\u03F6','backprime':'\u2035','backsim':'\u223D','backsimeq':'\u22CD','Backslash':'\u2216','Barv':'\u2AE7','barvee':'\u22BD','barwed':'\u2305','Barwed':'\u2306','barwedge':'\u2305','bbrk':'\u23B5','bbrktbrk':'\u23B6','bcong':'\u224C','bcy':'\u0431','Bcy':'\u0411','bdquo':'\u201E','becaus':'\u2235','because':'\u2235','Because':'\u2235','bemptyv':'\u29B0','bepsi':'\u03F6','bernou':'\u212C','Bernoullis':'\u212C','beta':'\u03B2','Beta':'\u0392','beth':'\u2136','between':'\u226C','bfr':'\uD835\uDD1F','Bfr':'\uD835\uDD05','bigcap':'\u22C2','bigcirc':'\u25EF','bigcup':'\u22C3','bigodot':'\u2A00','bigoplus':'\u2A01','bigotimes':'\u2A02','bigsqcup':'\u2A06','bigstar':'\u2605','bigtriangledown':'\u25BD','bigtriangleup':'\u25B3','biguplus':'\u2A04','bigvee':'\u22C1','bigwedge':'\u22C0','bkarow':'\u290D','blacklozenge':'\u29EB','blacksquare':'\u25AA','blacktriangle':'\u25B4','blacktriangledown':'\u25BE','blacktriangleleft':'\u25C2','blacktriangleright':'\u25B8','blank':'\u2423','blk12':'\u2592','blk14':'\u2591','blk34':'\u2593','block':'\u2588','bne':'=\u20E5','bnequiv':'\u2261\u20E5','bnot':'\u2310','bNot':'\u2AED','bopf':'\uD835\uDD53','Bopf':'\uD835\uDD39','bot':'\u22A5','bottom':'\u22A5','bowtie':'\u22C8','boxbox':'\u29C9','boxdl':'\u2510','boxdL':'\u2555','boxDl':'\u2556','boxDL':'\u2557','boxdr':'\u250C','boxdR':'\u2552','boxDr':'\u2553','boxDR':'\u2554','boxh':'\u2500','boxH':'\u2550','boxhd':'\u252C','boxhD':'\u2565','boxHd':'\u2564','boxHD':'\u2566','boxhu':'\u2534','boxhU':'\u2568','boxHu':'\u2567','boxHU':'\u2569','boxminus':'\u229F','boxplus':'\u229E','boxtimes':'\u22A0','boxul':'\u2518','boxuL':'\u255B','boxUl':'\u255C','boxUL':'\u255D','boxur':'\u2514','boxuR':'\u2558','boxUr':'\u2559','boxUR':'\u255A','boxv':'\u2502','boxV':'\u2551','boxvh':'\u253C','boxvH':'\u256A','boxVh':'\u256B','boxVH':'\u256C','boxvl':'\u2524','boxvL':'\u2561','boxVl':'\u2562','boxVL':'\u2563','boxvr':'\u251C','boxvR':'\u255E','boxVr':'\u255F','boxVR':'\u2560','bprime':'\u2035','breve':'\u02D8','Breve':'\u02D8','brvbar':'\xA6','bscr':'\uD835\uDCB7','Bscr':'\u212C','bsemi':'\u204F','bsim':'\u223D','bsime':'\u22CD','bsol':'\\','bsolb':'\u29C5','bsolhsub':'\u27C8','bull':'\u2022','bullet':'\u2022','bump':'\u224E','bumpe':'\u224F','bumpE':'\u2AAE','bumpeq':'\u224F','Bumpeq':'\u224E','cacute':'\u0107','Cacute':'\u0106','cap':'\u2229','Cap':'\u22D2','capand':'\u2A44','capbrcup':'\u2A49','capcap':'\u2A4B','capcup':'\u2A47','capdot':'\u2A40','CapitalDifferentialD':'\u2145','caps':'\u2229\uFE00','caret':'\u2041','caron':'\u02C7','Cayleys':'\u212D','ccaps':'\u2A4D','ccaron':'\u010D','Ccaron':'\u010C','ccedil':'\xE7','Ccedil':'\xC7','ccirc':'\u0109','Ccirc':'\u0108','Cconint':'\u2230','ccups':'\u2A4C','ccupssm':'\u2A50','cdot':'\u010B','Cdot':'\u010A','cedil':'\xB8','Cedilla':'\xB8','cemptyv':'\u29B2','cent':'\xA2','centerdot':'\xB7','CenterDot':'\xB7','cfr':'\uD835\uDD20','Cfr':'\u212D','chcy':'\u0447','CHcy':'\u0427','check':'\u2713','checkmark':'\u2713','chi':'\u03C7','Chi':'\u03A7','cir':'\u25CB','circ':'\u02C6','circeq':'\u2257','circlearrowleft':'\u21BA','circlearrowright':'\u21BB','circledast':'\u229B','circledcirc':'\u229A','circleddash':'\u229D','CircleDot':'\u2299','circledR':'\xAE','circledS':'\u24C8','CircleMinus':'\u2296','CirclePlus':'\u2295','CircleTimes':'\u2297','cire':'\u2257','cirE':'\u29C3','cirfnint':'\u2A10','cirmid':'\u2AEF','cirscir':'\u29C2','ClockwiseContourIntegral':'\u2232','CloseCurlyDoubleQuote':'\u201D','CloseCurlyQuote':'\u2019','clubs':'\u2663','clubsuit':'\u2663','colon':':','Colon':'\u2237','colone':'\u2254','Colone':'\u2A74','coloneq':'\u2254','comma':',','commat':'@','comp':'\u2201','compfn':'\u2218','complement':'\u2201','complexes':'\u2102','cong':'\u2245','congdot':'\u2A6D','Congruent':'\u2261','conint':'\u222E','Conint':'\u222F','ContourIntegral':'\u222E','copf':'\uD835\uDD54','Copf':'\u2102','coprod':'\u2210','Coproduct':'\u2210','copy':'\xA9','COPY':'\xA9','copysr':'\u2117','CounterClockwiseContourIntegral':'\u2233','crarr':'\u21B5','cross':'\u2717','Cross':'\u2A2F','cscr':'\uD835\uDCB8','Cscr':'\uD835\uDC9E','csub':'\u2ACF','csube':'\u2AD1','csup':'\u2AD0','csupe':'\u2AD2','ctdot':'\u22EF','cudarrl':'\u2938','cudarrr':'\u2935','cuepr':'\u22DE','cuesc':'\u22DF','cularr':'\u21B6','cularrp':'\u293D','cup':'\u222A','Cup':'\u22D3','cupbrcap':'\u2A48','cupcap':'\u2A46','CupCap':'\u224D','cupcup':'\u2A4A','cupdot':'\u228D','cupor':'\u2A45','cups':'\u222A\uFE00','curarr':'\u21B7','curarrm':'\u293C','curlyeqprec':'\u22DE','curlyeqsucc':'\u22DF','curlyvee':'\u22CE','curlywedge':'\u22CF','curren':'\xA4','curvearrowleft':'\u21B6','curvearrowright':'\u21B7','cuvee':'\u22CE','cuwed':'\u22CF','cwconint':'\u2232','cwint':'\u2231','cylcty':'\u232D','dagger':'\u2020','Dagger':'\u2021','daleth':'\u2138','darr':'\u2193','dArr':'\u21D3','Darr':'\u21A1','dash':'\u2010','dashv':'\u22A3','Dashv':'\u2AE4','dbkarow':'\u290F','dblac':'\u02DD','dcaron':'\u010F','Dcaron':'\u010E','dcy':'\u0434','Dcy':'\u0414','dd':'\u2146','DD':'\u2145','ddagger':'\u2021','ddarr':'\u21CA','DDotrahd':'\u2911','ddotseq':'\u2A77','deg':'\xB0','Del':'\u2207','delta':'\u03B4','Delta':'\u0394','demptyv':'\u29B1','dfisht':'\u297F','dfr':'\uD835\uDD21','Dfr':'\uD835\uDD07','dHar':'\u2965','dharl':'\u21C3','dharr':'\u21C2','DiacriticalAcute':'\xB4','DiacriticalDot':'\u02D9','DiacriticalDoubleAcute':'\u02DD','DiacriticalGrave':'`','DiacriticalTilde':'\u02DC','diam':'\u22C4','diamond':'\u22C4','Diamond':'\u22C4','diamondsuit':'\u2666','diams':'\u2666','die':'\xA8','DifferentialD':'\u2146','digamma':'\u03DD','disin':'\u22F2','div':'\xF7','divide':'\xF7','divideontimes':'\u22C7','divonx':'\u22C7','djcy':'\u0452','DJcy':'\u0402','dlcorn':'\u231E','dlcrop':'\u230D','dollar':'$','dopf':'\uD835\uDD55','Dopf':'\uD835\uDD3B','dot':'\u02D9','Dot':'\xA8','DotDot':'\u20DC','doteq':'\u2250','doteqdot':'\u2251','DotEqual':'\u2250','dotminus':'\u2238','dotplus':'\u2214','dotsquare':'\u22A1','doublebarwedge':'\u2306','DoubleContourIntegral':'\u222F','DoubleDot':'\xA8','DoubleDownArrow':'\u21D3','DoubleLeftArrow':'\u21D0','DoubleLeftRightArrow':'\u21D4','DoubleLeftTee':'\u2AE4','DoubleLongLeftArrow':'\u27F8','DoubleLongLeftRightArrow':'\u27FA','DoubleLongRightArrow':'\u27F9','DoubleRightArrow':'\u21D2','DoubleRightTee':'\u22A8','DoubleUpArrow':'\u21D1','DoubleUpDownArrow':'\u21D5','DoubleVerticalBar':'\u2225','downarrow':'\u2193','Downarrow':'\u21D3','DownArrow':'\u2193','DownArrowBar':'\u2913','DownArrowUpArrow':'\u21F5','DownBreve':'\u0311','downdownarrows':'\u21CA','downharpoonleft':'\u21C3','downharpoonright':'\u21C2','DownLeftRightVector':'\u2950','DownLeftTeeVector':'\u295E','DownLeftVector':'\u21BD','DownLeftVectorBar':'\u2956','DownRightTeeVector':'\u295F','DownRightVector':'\u21C1','DownRightVectorBar':'\u2957','DownTee':'\u22A4','DownTeeArrow':'\u21A7','drbkarow':'\u2910','drcorn':'\u231F','drcrop':'\u230C','dscr':'\uD835\uDCB9','Dscr':'\uD835\uDC9F','dscy':'\u0455','DScy':'\u0405','dsol':'\u29F6','dstrok':'\u0111','Dstrok':'\u0110','dtdot':'\u22F1','dtri':'\u25BF','dtrif':'\u25BE','duarr':'\u21F5','duhar':'\u296F','dwangle':'\u29A6','dzcy':'\u045F','DZcy':'\u040F','dzigrarr':'\u27FF','eacute':'\xE9','Eacute':'\xC9','easter':'\u2A6E','ecaron':'\u011B','Ecaron':'\u011A','ecir':'\u2256','ecirc':'\xEA','Ecirc':'\xCA','ecolon':'\u2255','ecy':'\u044D','Ecy':'\u042D','eDDot':'\u2A77','edot':'\u0117','eDot':'\u2251','Edot':'\u0116','ee':'\u2147','efDot':'\u2252','efr':'\uD835\uDD22','Efr':'\uD835\uDD08','eg':'\u2A9A','egrave':'\xE8','Egrave':'\xC8','egs':'\u2A96','egsdot':'\u2A98','el':'\u2A99','Element':'\u2208','elinters':'\u23E7','ell':'\u2113','els':'\u2A95','elsdot':'\u2A97','emacr':'\u0113','Emacr':'\u0112','empty':'\u2205','emptyset':'\u2205','EmptySmallSquare':'\u25FB','emptyv':'\u2205','EmptyVerySmallSquare':'\u25AB','emsp':'\u2003','emsp13':'\u2004','emsp14':'\u2005','eng':'\u014B','ENG':'\u014A','ensp':'\u2002','eogon':'\u0119','Eogon':'\u0118','eopf':'\uD835\uDD56','Eopf':'\uD835\uDD3C','epar':'\u22D5','eparsl':'\u29E3','eplus':'\u2A71','epsi':'\u03B5','epsilon':'\u03B5','Epsilon':'\u0395','epsiv':'\u03F5','eqcirc':'\u2256','eqcolon':'\u2255','eqsim':'\u2242','eqslantgtr':'\u2A96','eqslantless':'\u2A95','Equal':'\u2A75','equals':'=','EqualTilde':'\u2242','equest':'\u225F','Equilibrium':'\u21CC','equiv':'\u2261','equivDD':'\u2A78','eqvparsl':'\u29E5','erarr':'\u2971','erDot':'\u2253','escr':'\u212F','Escr':'\u2130','esdot':'\u2250','esim':'\u2242','Esim':'\u2A73','eta':'\u03B7','Eta':'\u0397','eth':'\xF0','ETH':'\xD0','euml':'\xEB','Euml':'\xCB','euro':'\u20AC','excl':'!','exist':'\u2203','Exists':'\u2203','expectation':'\u2130','exponentiale':'\u2147','ExponentialE':'\u2147','fallingdotseq':'\u2252','fcy':'\u0444','Fcy':'\u0424','female':'\u2640','ffilig':'\uFB03','fflig':'\uFB00','ffllig':'\uFB04','ffr':'\uD835\uDD23','Ffr':'\uD835\uDD09','filig':'\uFB01','FilledSmallSquare':'\u25FC','FilledVerySmallSquare':'\u25AA','fjlig':'fj','flat':'\u266D','fllig':'\uFB02','fltns':'\u25B1','fnof':'\u0192','fopf':'\uD835\uDD57','Fopf':'\uD835\uDD3D','forall':'\u2200','ForAll':'\u2200','fork':'\u22D4','forkv':'\u2AD9','Fouriertrf':'\u2131','fpartint':'\u2A0D','frac12':'\xBD','frac13':'\u2153','frac14':'\xBC','frac15':'\u2155','frac16':'\u2159','frac18':'\u215B','frac23':'\u2154','frac25':'\u2156','frac34':'\xBE','frac35':'\u2157','frac38':'\u215C','frac45':'\u2158','frac56':'\u215A','frac58':'\u215D','frac78':'\u215E','frasl':'\u2044','frown':'\u2322','fscr':'\uD835\uDCBB','Fscr':'\u2131','gacute':'\u01F5','gamma':'\u03B3','Gamma':'\u0393','gammad':'\u03DD','Gammad':'\u03DC','gap':'\u2A86','gbreve':'\u011F','Gbreve':'\u011E','Gcedil':'\u0122','gcirc':'\u011D','Gcirc':'\u011C','gcy':'\u0433','Gcy':'\u0413','gdot':'\u0121','Gdot':'\u0120','ge':'\u2265','gE':'\u2267','gel':'\u22DB','gEl':'\u2A8C','geq':'\u2265','geqq':'\u2267','geqslant':'\u2A7E','ges':'\u2A7E','gescc':'\u2AA9','gesdot':'\u2A80','gesdoto':'\u2A82','gesdotol':'\u2A84','gesl':'\u22DB\uFE00','gesles':'\u2A94','gfr':'\uD835\uDD24','Gfr':'\uD835\uDD0A','gg':'\u226B','Gg':'\u22D9','ggg':'\u22D9','gimel':'\u2137','gjcy':'\u0453','GJcy':'\u0403','gl':'\u2277','gla':'\u2AA5','glE':'\u2A92','glj':'\u2AA4','gnap':'\u2A8A','gnapprox':'\u2A8A','gne':'\u2A88','gnE':'\u2269','gneq':'\u2A88','gneqq':'\u2269','gnsim':'\u22E7','gopf':'\uD835\uDD58','Gopf':'\uD835\uDD3E','grave':'`','GreaterEqual':'\u2265','GreaterEqualLess':'\u22DB','GreaterFullEqual':'\u2267','GreaterGreater':'\u2AA2','GreaterLess':'\u2277','GreaterSlantEqual':'\u2A7E','GreaterTilde':'\u2273','gscr':'\u210A','Gscr':'\uD835\uDCA2','gsim':'\u2273','gsime':'\u2A8E','gsiml':'\u2A90','gt':'>','Gt':'\u226B','GT':'>','gtcc':'\u2AA7','gtcir':'\u2A7A','gtdot':'\u22D7','gtlPar':'\u2995','gtquest':'\u2A7C','gtrapprox':'\u2A86','gtrarr':'\u2978','gtrdot':'\u22D7','gtreqless':'\u22DB','gtreqqless':'\u2A8C','gtrless':'\u2277','gtrsim':'\u2273','gvertneqq':'\u2269\uFE00','gvnE':'\u2269\uFE00','Hacek':'\u02C7','hairsp':'\u200A','half':'\xBD','hamilt':'\u210B','hardcy':'\u044A','HARDcy':'\u042A','harr':'\u2194','hArr':'\u21D4','harrcir':'\u2948','harrw':'\u21AD','Hat':'^','hbar':'\u210F','hcirc':'\u0125','Hcirc':'\u0124','hearts':'\u2665','heartsuit':'\u2665','hellip':'\u2026','hercon':'\u22B9','hfr':'\uD835\uDD25','Hfr':'\u210C','HilbertSpace':'\u210B','hksearow':'\u2925','hkswarow':'\u2926','hoarr':'\u21FF','homtht':'\u223B','hookleftarrow':'\u21A9','hookrightarrow':'\u21AA','hopf':'\uD835\uDD59','Hopf':'\u210D','horbar':'\u2015','HorizontalLine':'\u2500','hscr':'\uD835\uDCBD','Hscr':'\u210B','hslash':'\u210F','hstrok':'\u0127','Hstrok':'\u0126','HumpDownHump':'\u224E','HumpEqual':'\u224F','hybull':'\u2043','hyphen':'\u2010','iacute':'\xED','Iacute':'\xCD','ic':'\u2063','icirc':'\xEE','Icirc':'\xCE','icy':'\u0438','Icy':'\u0418','Idot':'\u0130','iecy':'\u0435','IEcy':'\u0415','iexcl':'\xA1','iff':'\u21D4','ifr':'\uD835\uDD26','Ifr':'\u2111','igrave':'\xEC','Igrave':'\xCC','ii':'\u2148','iiiint':'\u2A0C','iiint':'\u222D','iinfin':'\u29DC','iiota':'\u2129','ijlig':'\u0133','IJlig':'\u0132','Im':'\u2111','imacr':'\u012B','Imacr':'\u012A','image':'\u2111','ImaginaryI':'\u2148','imagline':'\u2110','imagpart':'\u2111','imath':'\u0131','imof':'\u22B7','imped':'\u01B5','Implies':'\u21D2','in':'\u2208','incare':'\u2105','infin':'\u221E','infintie':'\u29DD','inodot':'\u0131','int':'\u222B','Int':'\u222C','intcal':'\u22BA','integers':'\u2124','Integral':'\u222B','intercal':'\u22BA','Intersection':'\u22C2','intlarhk':'\u2A17','intprod':'\u2A3C','InvisibleComma':'\u2063','InvisibleTimes':'\u2062','iocy':'\u0451','IOcy':'\u0401','iogon':'\u012F','Iogon':'\u012E','iopf':'\uD835\uDD5A','Iopf':'\uD835\uDD40','iota':'\u03B9','Iota':'\u0399','iprod':'\u2A3C','iquest':'\xBF','iscr':'\uD835\uDCBE','Iscr':'\u2110','isin':'\u2208','isindot':'\u22F5','isinE':'\u22F9','isins':'\u22F4','isinsv':'\u22F3','isinv':'\u2208','it':'\u2062','itilde':'\u0129','Itilde':'\u0128','iukcy':'\u0456','Iukcy':'\u0406','iuml':'\xEF','Iuml':'\xCF','jcirc':'\u0135','Jcirc':'\u0134','jcy':'\u0439','Jcy':'\u0419','jfr':'\uD835\uDD27','Jfr':'\uD835\uDD0D','jmath':'\u0237','jopf':'\uD835\uDD5B','Jopf':'\uD835\uDD41','jscr':'\uD835\uDCBF','Jscr':'\uD835\uDCA5','jsercy':'\u0458','Jsercy':'\u0408','jukcy':'\u0454','Jukcy':'\u0404','kappa':'\u03BA','Kappa':'\u039A','kappav':'\u03F0','kcedil':'\u0137','Kcedil':'\u0136','kcy':'\u043A','Kcy':'\u041A','kfr':'\uD835\uDD28','Kfr':'\uD835\uDD0E','kgreen':'\u0138','khcy':'\u0445','KHcy':'\u0425','kjcy':'\u045C','KJcy':'\u040C','kopf':'\uD835\uDD5C','Kopf':'\uD835\uDD42','kscr':'\uD835\uDCC0','Kscr':'\uD835\uDCA6','lAarr':'\u21DA','lacute':'\u013A','Lacute':'\u0139','laemptyv':'\u29B4','lagran':'\u2112','lambda':'\u03BB','Lambda':'\u039B','lang':'\u27E8','Lang':'\u27EA','langd':'\u2991','langle':'\u27E8','lap':'\u2A85','Laplacetrf':'\u2112','laquo':'\xAB','larr':'\u2190','lArr':'\u21D0','Larr':'\u219E','larrb':'\u21E4','larrbfs':'\u291F','larrfs':'\u291D','larrhk':'\u21A9','larrlp':'\u21AB','larrpl':'\u2939','larrsim':'\u2973','larrtl':'\u21A2','lat':'\u2AAB','latail':'\u2919','lAtail':'\u291B','late':'\u2AAD','lates':'\u2AAD\uFE00','lbarr':'\u290C','lBarr':'\u290E','lbbrk':'\u2772','lbrace':'{','lbrack':'[','lbrke':'\u298B','lbrksld':'\u298F','lbrkslu':'\u298D','lcaron':'\u013E','Lcaron':'\u013D','lcedil':'\u013C','Lcedil':'\u013B','lceil':'\u2308','lcub':'{','lcy':'\u043B','Lcy':'\u041B','ldca':'\u2936','ldquo':'\u201C','ldquor':'\u201E','ldrdhar':'\u2967','ldrushar':'\u294B','ldsh':'\u21B2','le':'\u2264','lE':'\u2266','LeftAngleBracket':'\u27E8','leftarrow':'\u2190','Leftarrow':'\u21D0','LeftArrow':'\u2190','LeftArrowBar':'\u21E4','LeftArrowRightArrow':'\u21C6','leftarrowtail':'\u21A2','LeftCeiling':'\u2308','LeftDoubleBracket':'\u27E6','LeftDownTeeVector':'\u2961','LeftDownVector':'\u21C3','LeftDownVectorBar':'\u2959','LeftFloor':'\u230A','leftharpoondown':'\u21BD','leftharpoonup':'\u21BC','leftleftarrows':'\u21C7','leftrightarrow':'\u2194','Leftrightarrow':'\u21D4','LeftRightArrow':'\u2194','leftrightarrows':'\u21C6','leftrightharpoons':'\u21CB','leftrightsquigarrow':'\u21AD','LeftRightVector':'\u294E','LeftTee':'\u22A3','LeftTeeArrow':'\u21A4','LeftTeeVector':'\u295A','leftthreetimes':'\u22CB','LeftTriangle':'\u22B2','LeftTriangleBar':'\u29CF','LeftTriangleEqual':'\u22B4','LeftUpDownVector':'\u2951','LeftUpTeeVector':'\u2960','LeftUpVector':'\u21BF','LeftUpVectorBar':'\u2958','LeftVector':'\u21BC','LeftVectorBar':'\u2952','leg':'\u22DA','lEg':'\u2A8B','leq':'\u2264','leqq':'\u2266','leqslant':'\u2A7D','les':'\u2A7D','lescc':'\u2AA8','lesdot':'\u2A7F','lesdoto':'\u2A81','lesdotor':'\u2A83','lesg':'\u22DA\uFE00','lesges':'\u2A93','lessapprox':'\u2A85','lessdot':'\u22D6','lesseqgtr':'\u22DA','lesseqqgtr':'\u2A8B','LessEqualGreater':'\u22DA','LessFullEqual':'\u2266','LessGreater':'\u2276','lessgtr':'\u2276','LessLess':'\u2AA1','lesssim':'\u2272','LessSlantEqual':'\u2A7D','LessTilde':'\u2272','lfisht':'\u297C','lfloor':'\u230A','lfr':'\uD835\uDD29','Lfr':'\uD835\uDD0F','lg':'\u2276','lgE':'\u2A91','lHar':'\u2962','lhard':'\u21BD','lharu':'\u21BC','lharul':'\u296A','lhblk':'\u2584','ljcy':'\u0459','LJcy':'\u0409','ll':'\u226A','Ll':'\u22D8','llarr':'\u21C7','llcorner':'\u231E','Lleftarrow':'\u21DA','llhard':'\u296B','lltri':'\u25FA','lmidot':'\u0140','Lmidot':'\u013F','lmoust':'\u23B0','lmoustache':'\u23B0','lnap':'\u2A89','lnapprox':'\u2A89','lne':'\u2A87','lnE':'\u2268','lneq':'\u2A87','lneqq':'\u2268','lnsim':'\u22E6','loang':'\u27EC','loarr':'\u21FD','lobrk':'\u27E6','longleftarrow':'\u27F5','Longleftarrow':'\u27F8','LongLeftArrow':'\u27F5','longleftrightarrow':'\u27F7','Longleftrightarrow':'\u27FA','LongLeftRightArrow':'\u27F7','longmapsto':'\u27FC','longrightarrow':'\u27F6','Longrightarrow':'\u27F9','LongRightArrow':'\u27F6','looparrowleft':'\u21AB','looparrowright':'\u21AC','lopar':'\u2985','lopf':'\uD835\uDD5D','Lopf':'\uD835\uDD43','loplus':'\u2A2D','lotimes':'\u2A34','lowast':'\u2217','lowbar':'_','LowerLeftArrow':'\u2199','LowerRightArrow':'\u2198','loz':'\u25CA','lozenge':'\u25CA','lozf':'\u29EB','lpar':'(','lparlt':'\u2993','lrarr':'\u21C6','lrcorner':'\u231F','lrhar':'\u21CB','lrhard':'\u296D','lrm':'\u200E','lrtri':'\u22BF','lsaquo':'\u2039','lscr':'\uD835\uDCC1','Lscr':'\u2112','lsh':'\u21B0','Lsh':'\u21B0','lsim':'\u2272','lsime':'\u2A8D','lsimg':'\u2A8F','lsqb':'[','lsquo':'\u2018','lsquor':'\u201A','lstrok':'\u0142','Lstrok':'\u0141','lt':'<','Lt':'\u226A','LT':'<','ltcc':'\u2AA6','ltcir':'\u2A79','ltdot':'\u22D6','lthree':'\u22CB','ltimes':'\u22C9','ltlarr':'\u2976','ltquest':'\u2A7B','ltri':'\u25C3','ltrie':'\u22B4','ltrif':'\u25C2','ltrPar':'\u2996','lurdshar':'\u294A','luruhar':'\u2966','lvertneqq':'\u2268\uFE00','lvnE':'\u2268\uFE00','macr':'\xAF','male':'\u2642','malt':'\u2720','maltese':'\u2720','map':'\u21A6','Map':'\u2905','mapsto':'\u21A6','mapstodown':'\u21A7','mapstoleft':'\u21A4','mapstoup':'\u21A5','marker':'\u25AE','mcomma':'\u2A29','mcy':'\u043C','Mcy':'\u041C','mdash':'\u2014','mDDot':'\u223A','measuredangle':'\u2221','MediumSpace':'\u205F','Mellintrf':'\u2133','mfr':'\uD835\uDD2A','Mfr':'\uD835\uDD10','mho':'\u2127','micro':'\xB5','mid':'\u2223','midast':'*','midcir':'\u2AF0','middot':'\xB7','minus':'\u2212','minusb':'\u229F','minusd':'\u2238','minusdu':'\u2A2A','MinusPlus':'\u2213','mlcp':'\u2ADB','mldr':'\u2026','mnplus':'\u2213','models':'\u22A7','mopf':'\uD835\uDD5E','Mopf':'\uD835\uDD44','mp':'\u2213','mscr':'\uD835\uDCC2','Mscr':'\u2133','mstpos':'\u223E','mu':'\u03BC','Mu':'\u039C','multimap':'\u22B8','mumap':'\u22B8','nabla':'\u2207','nacute':'\u0144','Nacute':'\u0143','nang':'\u2220\u20D2','nap':'\u2249','napE':'\u2A70\u0338','napid':'\u224B\u0338','napos':'\u0149','napprox':'\u2249','natur':'\u266E','natural':'\u266E','naturals':'\u2115','nbsp':'\xA0','nbump':'\u224E\u0338','nbumpe':'\u224F\u0338','ncap':'\u2A43','ncaron':'\u0148','Ncaron':'\u0147','ncedil':'\u0146','Ncedil':'\u0145','ncong':'\u2247','ncongdot':'\u2A6D\u0338','ncup':'\u2A42','ncy':'\u043D','Ncy':'\u041D','ndash':'\u2013','ne':'\u2260','nearhk':'\u2924','nearr':'\u2197','neArr':'\u21D7','nearrow':'\u2197','nedot':'\u2250\u0338','NegativeMediumSpace':'\u200B','NegativeThickSpace':'\u200B','NegativeThinSpace':'\u200B','NegativeVeryThinSpace':'\u200B','nequiv':'\u2262','nesear':'\u2928','nesim':'\u2242\u0338','NestedGreaterGreater':'\u226B','NestedLessLess':'\u226A','NewLine':'\n','nexist':'\u2204','nexists':'\u2204','nfr':'\uD835\uDD2B','Nfr':'\uD835\uDD11','nge':'\u2271','ngE':'\u2267\u0338','ngeq':'\u2271','ngeqq':'\u2267\u0338','ngeqslant':'\u2A7E\u0338','nges':'\u2A7E\u0338','nGg':'\u22D9\u0338','ngsim':'\u2275','ngt':'\u226F','nGt':'\u226B\u20D2','ngtr':'\u226F','nGtv':'\u226B\u0338','nharr':'\u21AE','nhArr':'\u21CE','nhpar':'\u2AF2','ni':'\u220B','nis':'\u22FC','nisd':'\u22FA','niv':'\u220B','njcy':'\u045A','NJcy':'\u040A','nlarr':'\u219A','nlArr':'\u21CD','nldr':'\u2025','nle':'\u2270','nlE':'\u2266\u0338','nleftarrow':'\u219A','nLeftarrow':'\u21CD','nleftrightarrow':'\u21AE','nLeftrightarrow':'\u21CE','nleq':'\u2270','nleqq':'\u2266\u0338','nleqslant':'\u2A7D\u0338','nles':'\u2A7D\u0338','nless':'\u226E','nLl':'\u22D8\u0338','nlsim':'\u2274','nlt':'\u226E','nLt':'\u226A\u20D2','nltri':'\u22EA','nltrie':'\u22EC','nLtv':'\u226A\u0338','nmid':'\u2224','NoBreak':'\u2060','NonBreakingSpace':'\xA0','nopf':'\uD835\uDD5F','Nopf':'\u2115','not':'\xAC','Not':'\u2AEC','NotCongruent':'\u2262','NotCupCap':'\u226D','NotDoubleVerticalBar':'\u2226','NotElement':'\u2209','NotEqual':'\u2260','NotEqualTilde':'\u2242\u0338','NotExists':'\u2204','NotGreater':'\u226F','NotGreaterEqual':'\u2271','NotGreaterFullEqual':'\u2267\u0338','NotGreaterGreater':'\u226B\u0338','NotGreaterLess':'\u2279','NotGreaterSlantEqual':'\u2A7E\u0338','NotGreaterTilde':'\u2275','NotHumpDownHump':'\u224E\u0338','NotHumpEqual':'\u224F\u0338','notin':'\u2209','notindot':'\u22F5\u0338','notinE':'\u22F9\u0338','notinva':'\u2209','notinvb':'\u22F7','notinvc':'\u22F6','NotLeftTriangle':'\u22EA','NotLeftTriangleBar':'\u29CF\u0338','NotLeftTriangleEqual':'\u22EC','NotLess':'\u226E','NotLessEqual':'\u2270','NotLessGreater':'\u2278','NotLessLess':'\u226A\u0338','NotLessSlantEqual':'\u2A7D\u0338','NotLessTilde':'\u2274','NotNestedGreaterGreater':'\u2AA2\u0338','NotNestedLessLess':'\u2AA1\u0338','notni':'\u220C','notniva':'\u220C','notnivb':'\u22FE','notnivc':'\u22FD','NotPrecedes':'\u2280','NotPrecedesEqual':'\u2AAF\u0338','NotPrecedesSlantEqual':'\u22E0','NotReverseElement':'\u220C','NotRightTriangle':'\u22EB','NotRightTriangleBar':'\u29D0\u0338','NotRightTriangleEqual':'\u22ED','NotSquareSubset':'\u228F\u0338','NotSquareSubsetEqual':'\u22E2','NotSquareSuperset':'\u2290\u0338','NotSquareSupersetEqual':'\u22E3','NotSubset':'\u2282\u20D2','NotSubsetEqual':'\u2288','NotSucceeds':'\u2281','NotSucceedsEqual':'\u2AB0\u0338','NotSucceedsSlantEqual':'\u22E1','NotSucceedsTilde':'\u227F\u0338','NotSuperset':'\u2283\u20D2','NotSupersetEqual':'\u2289','NotTilde':'\u2241','NotTildeEqual':'\u2244','NotTildeFullEqual':'\u2247','NotTildeTilde':'\u2249','NotVerticalBar':'\u2224','npar':'\u2226','nparallel':'\u2226','nparsl':'\u2AFD\u20E5','npart':'\u2202\u0338','npolint':'\u2A14','npr':'\u2280','nprcue':'\u22E0','npre':'\u2AAF\u0338','nprec':'\u2280','npreceq':'\u2AAF\u0338','nrarr':'\u219B','nrArr':'\u21CF','nrarrc':'\u2933\u0338','nrarrw':'\u219D\u0338','nrightarrow':'\u219B','nRightarrow':'\u21CF','nrtri':'\u22EB','nrtrie':'\u22ED','nsc':'\u2281','nsccue':'\u22E1','nsce':'\u2AB0\u0338','nscr':'\uD835\uDCC3','Nscr':'\uD835\uDCA9','nshortmid':'\u2224','nshortparallel':'\u2226','nsim':'\u2241','nsime':'\u2244','nsimeq':'\u2244','nsmid':'\u2224','nspar':'\u2226','nsqsube':'\u22E2','nsqsupe':'\u22E3','nsub':'\u2284','nsube':'\u2288','nsubE':'\u2AC5\u0338','nsubset':'\u2282\u20D2','nsubseteq':'\u2288','nsubseteqq':'\u2AC5\u0338','nsucc':'\u2281','nsucceq':'\u2AB0\u0338','nsup':'\u2285','nsupe':'\u2289','nsupE':'\u2AC6\u0338','nsupset':'\u2283\u20D2','nsupseteq':'\u2289','nsupseteqq':'\u2AC6\u0338','ntgl':'\u2279','ntilde':'\xF1','Ntilde':'\xD1','ntlg':'\u2278','ntriangleleft':'\u22EA','ntrianglelefteq':'\u22EC','ntriangleright':'\u22EB','ntrianglerighteq':'\u22ED','nu':'\u03BD','Nu':'\u039D','num':'#','numero':'\u2116','numsp':'\u2007','nvap':'\u224D\u20D2','nvdash':'\u22AC','nvDash':'\u22AD','nVdash':'\u22AE','nVDash':'\u22AF','nvge':'\u2265\u20D2','nvgt':'>\u20D2','nvHarr':'\u2904','nvinfin':'\u29DE','nvlArr':'\u2902','nvle':'\u2264\u20D2','nvlt':'<\u20D2','nvltrie':'\u22B4\u20D2','nvrArr':'\u2903','nvrtrie':'\u22B5\u20D2','nvsim':'\u223C\u20D2','nwarhk':'\u2923','nwarr':'\u2196','nwArr':'\u21D6','nwarrow':'\u2196','nwnear':'\u2927','oacute':'\xF3','Oacute':'\xD3','oast':'\u229B','ocir':'\u229A','ocirc':'\xF4','Ocirc':'\xD4','ocy':'\u043E','Ocy':'\u041E','odash':'\u229D','odblac':'\u0151','Odblac':'\u0150','odiv':'\u2A38','odot':'\u2299','odsold':'\u29BC','oelig':'\u0153','OElig':'\u0152','ofcir':'\u29BF','ofr':'\uD835\uDD2C','Ofr':'\uD835\uDD12','ogon':'\u02DB','ograve':'\xF2','Ograve':'\xD2','ogt':'\u29C1','ohbar':'\u29B5','ohm':'\u03A9','oint':'\u222E','olarr':'\u21BA','olcir':'\u29BE','olcross':'\u29BB','oline':'\u203E','olt':'\u29C0','omacr':'\u014D','Omacr':'\u014C','omega':'\u03C9','Omega':'\u03A9','omicron':'\u03BF','Omicron':'\u039F','omid':'\u29B6','ominus':'\u2296','oopf':'\uD835\uDD60','Oopf':'\uD835\uDD46','opar':'\u29B7','OpenCurlyDoubleQuote':'\u201C','OpenCurlyQuote':'\u2018','operp':'\u29B9','oplus':'\u2295','or':'\u2228','Or':'\u2A54','orarr':'\u21BB','ord':'\u2A5D','order':'\u2134','orderof':'\u2134','ordf':'\xAA','ordm':'\xBA','origof':'\u22B6','oror':'\u2A56','orslope':'\u2A57','orv':'\u2A5B','oS':'\u24C8','oscr':'\u2134','Oscr':'\uD835\uDCAA','oslash':'\xF8','Oslash':'\xD8','osol':'\u2298','otilde':'\xF5','Otilde':'\xD5','otimes':'\u2297','Otimes':'\u2A37','otimesas':'\u2A36','ouml':'\xF6','Ouml':'\xD6','ovbar':'\u233D','OverBar':'\u203E','OverBrace':'\u23DE','OverBracket':'\u23B4','OverParenthesis':'\u23DC','par':'\u2225','para':'\xB6','parallel':'\u2225','parsim':'\u2AF3','parsl':'\u2AFD','part':'\u2202','PartialD':'\u2202','pcy':'\u043F','Pcy':'\u041F','percnt':'%','period':'.','permil':'\u2030','perp':'\u22A5','pertenk':'\u2031','pfr':'\uD835\uDD2D','Pfr':'\uD835\uDD13','phi':'\u03C6','Phi':'\u03A6','phiv':'\u03D5','phmmat':'\u2133','phone':'\u260E','pi':'\u03C0','Pi':'\u03A0','pitchfork':'\u22D4','piv':'\u03D6','planck':'\u210F','planckh':'\u210E','plankv':'\u210F','plus':'+','plusacir':'\u2A23','plusb':'\u229E','pluscir':'\u2A22','plusdo':'\u2214','plusdu':'\u2A25','pluse':'\u2A72','PlusMinus':'\xB1','plusmn':'\xB1','plussim':'\u2A26','plustwo':'\u2A27','pm':'\xB1','Poincareplane':'\u210C','pointint':'\u2A15','popf':'\uD835\uDD61','Popf':'\u2119','pound':'\xA3','pr':'\u227A','Pr':'\u2ABB','prap':'\u2AB7','prcue':'\u227C','pre':'\u2AAF','prE':'\u2AB3','prec':'\u227A','precapprox':'\u2AB7','preccurlyeq':'\u227C','Precedes':'\u227A','PrecedesEqual':'\u2AAF','PrecedesSlantEqual':'\u227C','PrecedesTilde':'\u227E','preceq':'\u2AAF','precnapprox':'\u2AB9','precneqq':'\u2AB5','precnsim':'\u22E8','precsim':'\u227E','prime':'\u2032','Prime':'\u2033','primes':'\u2119','prnap':'\u2AB9','prnE':'\u2AB5','prnsim':'\u22E8','prod':'\u220F','Product':'\u220F','profalar':'\u232E','profline':'\u2312','profsurf':'\u2313','prop':'\u221D','Proportion':'\u2237','Proportional':'\u221D','propto':'\u221D','prsim':'\u227E','prurel':'\u22B0','pscr':'\uD835\uDCC5','Pscr':'\uD835\uDCAB','psi':'\u03C8','Psi':'\u03A8','puncsp':'\u2008','qfr':'\uD835\uDD2E','Qfr':'\uD835\uDD14','qint':'\u2A0C','qopf':'\uD835\uDD62','Qopf':'\u211A','qprime':'\u2057','qscr':'\uD835\uDCC6','Qscr':'\uD835\uDCAC','quaternions':'\u210D','quatint':'\u2A16','quest':'?','questeq':'\u225F','quot':'"','QUOT':'"','rAarr':'\u21DB','race':'\u223D\u0331','racute':'\u0155','Racute':'\u0154','radic':'\u221A','raemptyv':'\u29B3','rang':'\u27E9','Rang':'\u27EB','rangd':'\u2992','range':'\u29A5','rangle':'\u27E9','raquo':'\xBB','rarr':'\u2192','rArr':'\u21D2','Rarr':'\u21A0','rarrap':'\u2975','rarrb':'\u21E5','rarrbfs':'\u2920','rarrc':'\u2933','rarrfs':'\u291E','rarrhk':'\u21AA','rarrlp':'\u21AC','rarrpl':'\u2945','rarrsim':'\u2974','rarrtl':'\u21A3','Rarrtl':'\u2916','rarrw':'\u219D','ratail':'\u291A','rAtail':'\u291C','ratio':'\u2236','rationals':'\u211A','rbarr':'\u290D','rBarr':'\u290F','RBarr':'\u2910','rbbrk':'\u2773','rbrace':'}','rbrack':']','rbrke':'\u298C','rbrksld':'\u298E','rbrkslu':'\u2990','rcaron':'\u0159','Rcaron':'\u0158','rcedil':'\u0157','Rcedil':'\u0156','rceil':'\u2309','rcub':'}','rcy':'\u0440','Rcy':'\u0420','rdca':'\u2937','rdldhar':'\u2969','rdquo':'\u201D','rdquor':'\u201D','rdsh':'\u21B3','Re':'\u211C','real':'\u211C','realine':'\u211B','realpart':'\u211C','reals':'\u211D','rect':'\u25AD','reg':'\xAE','REG':'\xAE','ReverseElement':'\u220B','ReverseEquilibrium':'\u21CB','ReverseUpEquilibrium':'\u296F','rfisht':'\u297D','rfloor':'\u230B','rfr':'\uD835\uDD2F','Rfr':'\u211C','rHar':'\u2964','rhard':'\u21C1','rharu':'\u21C0','rharul':'\u296C','rho':'\u03C1','Rho':'\u03A1','rhov':'\u03F1','RightAngleBracket':'\u27E9','rightarrow':'\u2192','Rightarrow':'\u21D2','RightArrow':'\u2192','RightArrowBar':'\u21E5','RightArrowLeftArrow':'\u21C4','rightarrowtail':'\u21A3','RightCeiling':'\u2309','RightDoubleBracket':'\u27E7','RightDownTeeVector':'\u295D','RightDownVector':'\u21C2','RightDownVectorBar':'\u2955','RightFloor':'\u230B','rightharpoondown':'\u21C1','rightharpoonup':'\u21C0','rightleftarrows':'\u21C4','rightleftharpoons':'\u21CC','rightrightarrows':'\u21C9','rightsquigarrow':'\u219D','RightTee':'\u22A2','RightTeeArrow':'\u21A6','RightTeeVector':'\u295B','rightthreetimes':'\u22CC','RightTriangle':'\u22B3','RightTriangleBar':'\u29D0','RightTriangleEqual':'\u22B5','RightUpDownVector':'\u294F','RightUpTeeVector':'\u295C','RightUpVector':'\u21BE','RightUpVectorBar':'\u2954','RightVector':'\u21C0','RightVectorBar':'\u2953','ring':'\u02DA','risingdotseq':'\u2253','rlarr':'\u21C4','rlhar':'\u21CC','rlm':'\u200F','rmoust':'\u23B1','rmoustache':'\u23B1','rnmid':'\u2AEE','roang':'\u27ED','roarr':'\u21FE','robrk':'\u27E7','ropar':'\u2986','ropf':'\uD835\uDD63','Ropf':'\u211D','roplus':'\u2A2E','rotimes':'\u2A35','RoundImplies':'\u2970','rpar':')','rpargt':'\u2994','rppolint':'\u2A12','rrarr':'\u21C9','Rrightarrow':'\u21DB','rsaquo':'\u203A','rscr':'\uD835\uDCC7','Rscr':'\u211B','rsh':'\u21B1','Rsh':'\u21B1','rsqb':']','rsquo':'\u2019','rsquor':'\u2019','rthree':'\u22CC','rtimes':'\u22CA','rtri':'\u25B9','rtrie':'\u22B5','rtrif':'\u25B8','rtriltri':'\u29CE','RuleDelayed':'\u29F4','ruluhar':'\u2968','rx':'\u211E','sacute':'\u015B','Sacute':'\u015A','sbquo':'\u201A','sc':'\u227B','Sc':'\u2ABC','scap':'\u2AB8','scaron':'\u0161','Scaron':'\u0160','sccue':'\u227D','sce':'\u2AB0','scE':'\u2AB4','scedil':'\u015F','Scedil':'\u015E','scirc':'\u015D','Scirc':'\u015C','scnap':'\u2ABA','scnE':'\u2AB6','scnsim':'\u22E9','scpolint':'\u2A13','scsim':'\u227F','scy':'\u0441','Scy':'\u0421','sdot':'\u22C5','sdotb':'\u22A1','sdote':'\u2A66','searhk':'\u2925','searr':'\u2198','seArr':'\u21D8','searrow':'\u2198','sect':'\xA7','semi':';','seswar':'\u2929','setminus':'\u2216','setmn':'\u2216','sext':'\u2736','sfr':'\uD835\uDD30','Sfr':'\uD835\uDD16','sfrown':'\u2322','sharp':'\u266F','shchcy':'\u0449','SHCHcy':'\u0429','shcy':'\u0448','SHcy':'\u0428','ShortDownArrow':'\u2193','ShortLeftArrow':'\u2190','shortmid':'\u2223','shortparallel':'\u2225','ShortRightArrow':'\u2192','ShortUpArrow':'\u2191','shy':'\xAD','sigma':'\u03C3','Sigma':'\u03A3','sigmaf':'\u03C2','sigmav':'\u03C2','sim':'\u223C','simdot':'\u2A6A','sime':'\u2243','simeq':'\u2243','simg':'\u2A9E','simgE':'\u2AA0','siml':'\u2A9D','simlE':'\u2A9F','simne':'\u2246','simplus':'\u2A24','simrarr':'\u2972','slarr':'\u2190','SmallCircle':'\u2218','smallsetminus':'\u2216','smashp':'\u2A33','smeparsl':'\u29E4','smid':'\u2223','smile':'\u2323','smt':'\u2AAA','smte':'\u2AAC','smtes':'\u2AAC\uFE00','softcy':'\u044C','SOFTcy':'\u042C','sol':'/','solb':'\u29C4','solbar':'\u233F','sopf':'\uD835\uDD64','Sopf':'\uD835\uDD4A','spades':'\u2660','spadesuit':'\u2660','spar':'\u2225','sqcap':'\u2293','sqcaps':'\u2293\uFE00','sqcup':'\u2294','sqcups':'\u2294\uFE00','Sqrt':'\u221A','sqsub':'\u228F','sqsube':'\u2291','sqsubset':'\u228F','sqsubseteq':'\u2291','sqsup':'\u2290','sqsupe':'\u2292','sqsupset':'\u2290','sqsupseteq':'\u2292','squ':'\u25A1','square':'\u25A1','Square':'\u25A1','SquareIntersection':'\u2293','SquareSubset':'\u228F','SquareSubsetEqual':'\u2291','SquareSuperset':'\u2290','SquareSupersetEqual':'\u2292','SquareUnion':'\u2294','squarf':'\u25AA','squf':'\u25AA','srarr':'\u2192','sscr':'\uD835\uDCC8','Sscr':'\uD835\uDCAE','ssetmn':'\u2216','ssmile':'\u2323','sstarf':'\u22C6','star':'\u2606','Star':'\u22C6','starf':'\u2605','straightepsilon':'\u03F5','straightphi':'\u03D5','strns':'\xAF','sub':'\u2282','Sub':'\u22D0','subdot':'\u2ABD','sube':'\u2286','subE':'\u2AC5','subedot':'\u2AC3','submult':'\u2AC1','subne':'\u228A','subnE':'\u2ACB','subplus':'\u2ABF','subrarr':'\u2979','subset':'\u2282','Subset':'\u22D0','subseteq':'\u2286','subseteqq':'\u2AC5','SubsetEqual':'\u2286','subsetneq':'\u228A','subsetneqq':'\u2ACB','subsim':'\u2AC7','subsub':'\u2AD5','subsup':'\u2AD3','succ':'\u227B','succapprox':'\u2AB8','succcurlyeq':'\u227D','Succeeds':'\u227B','SucceedsEqual':'\u2AB0','SucceedsSlantEqual':'\u227D','SucceedsTilde':'\u227F','succeq':'\u2AB0','succnapprox':'\u2ABA','succneqq':'\u2AB6','succnsim':'\u22E9','succsim':'\u227F','SuchThat':'\u220B','sum':'\u2211','Sum':'\u2211','sung':'\u266A','sup':'\u2283','Sup':'\u22D1','sup1':'\xB9','sup2':'\xB2','sup3':'\xB3','supdot':'\u2ABE','supdsub':'\u2AD8','supe':'\u2287','supE':'\u2AC6','supedot':'\u2AC4','Superset':'\u2283','SupersetEqual':'\u2287','suphsol':'\u27C9','suphsub':'\u2AD7','suplarr':'\u297B','supmult':'\u2AC2','supne':'\u228B','supnE':'\u2ACC','supplus':'\u2AC0','supset':'\u2283','Supset':'\u22D1','supseteq':'\u2287','supseteqq':'\u2AC6','supsetneq':'\u228B','supsetneqq':'\u2ACC','supsim':'\u2AC8','supsub':'\u2AD4','supsup':'\u2AD6','swarhk':'\u2926','swarr':'\u2199','swArr':'\u21D9','swarrow':'\u2199','swnwar':'\u292A','szlig':'\xDF','Tab':'\t','target':'\u2316','tau':'\u03C4','Tau':'\u03A4','tbrk':'\u23B4','tcaron':'\u0165','Tcaron':'\u0164','tcedil':'\u0163','Tcedil':'\u0162','tcy':'\u0442','Tcy':'\u0422','tdot':'\u20DB','telrec':'\u2315','tfr':'\uD835\uDD31','Tfr':'\uD835\uDD17','there4':'\u2234','therefore':'\u2234','Therefore':'\u2234','theta':'\u03B8','Theta':'\u0398','thetasym':'\u03D1','thetav':'\u03D1','thickapprox':'\u2248','thicksim':'\u223C','ThickSpace':'\u205F\u200A','thinsp':'\u2009','ThinSpace':'\u2009','thkap':'\u2248','thksim':'\u223C','thorn':'\xFE','THORN':'\xDE','tilde':'\u02DC','Tilde':'\u223C','TildeEqual':'\u2243','TildeFullEqual':'\u2245','TildeTilde':'\u2248','times':'\xD7','timesb':'\u22A0','timesbar':'\u2A31','timesd':'\u2A30','tint':'\u222D','toea':'\u2928','top':'\u22A4','topbot':'\u2336','topcir':'\u2AF1','topf':'\uD835\uDD65','Topf':'\uD835\uDD4B','topfork':'\u2ADA','tosa':'\u2929','tprime':'\u2034','trade':'\u2122','TRADE':'\u2122','triangle':'\u25B5','triangledown':'\u25BF','triangleleft':'\u25C3','trianglelefteq':'\u22B4','triangleq':'\u225C','triangleright':'\u25B9','trianglerighteq':'\u22B5','tridot':'\u25EC','trie':'\u225C','triminus':'\u2A3A','TripleDot':'\u20DB','triplus':'\u2A39','trisb':'\u29CD','tritime':'\u2A3B','trpezium':'\u23E2','tscr':'\uD835\uDCC9','Tscr':'\uD835\uDCAF','tscy':'\u0446','TScy':'\u0426','tshcy':'\u045B','TSHcy':'\u040B','tstrok':'\u0167','Tstrok':'\u0166','twixt':'\u226C','twoheadleftarrow':'\u219E','twoheadrightarrow':'\u21A0','uacute':'\xFA','Uacute':'\xDA','uarr':'\u2191','uArr':'\u21D1','Uarr':'\u219F','Uarrocir':'\u2949','ubrcy':'\u045E','Ubrcy':'\u040E','ubreve':'\u016D','Ubreve':'\u016C','ucirc':'\xFB','Ucirc':'\xDB','ucy':'\u0443','Ucy':'\u0423','udarr':'\u21C5','udblac':'\u0171','Udblac':'\u0170','udhar':'\u296E','ufisht':'\u297E','ufr':'\uD835\uDD32','Ufr':'\uD835\uDD18','ugrave':'\xF9','Ugrave':'\xD9','uHar':'\u2963','uharl':'\u21BF','uharr':'\u21BE','uhblk':'\u2580','ulcorn':'\u231C','ulcorner':'\u231C','ulcrop':'\u230F','ultri':'\u25F8','umacr':'\u016B','Umacr':'\u016A','uml':'\xA8','UnderBar':'_','UnderBrace':'\u23DF','UnderBracket':'\u23B5','UnderParenthesis':'\u23DD','Union':'\u22C3','UnionPlus':'\u228E','uogon':'\u0173','Uogon':'\u0172','uopf':'\uD835\uDD66','Uopf':'\uD835\uDD4C','uparrow':'\u2191','Uparrow':'\u21D1','UpArrow':'\u2191','UpArrowBar':'\u2912','UpArrowDownArrow':'\u21C5','updownarrow':'\u2195','Updownarrow':'\u21D5','UpDownArrow':'\u2195','UpEquilibrium':'\u296E','upharpoonleft':'\u21BF','upharpoonright':'\u21BE','uplus':'\u228E','UpperLeftArrow':'\u2196','UpperRightArrow':'\u2197','upsi':'\u03C5','Upsi':'\u03D2','upsih':'\u03D2','upsilon':'\u03C5','Upsilon':'\u03A5','UpTee':'\u22A5','UpTeeArrow':'\u21A5','upuparrows':'\u21C8','urcorn':'\u231D','urcorner':'\u231D','urcrop':'\u230E','uring':'\u016F','Uring':'\u016E','urtri':'\u25F9','uscr':'\uD835\uDCCA','Uscr':'\uD835\uDCB0','utdot':'\u22F0','utilde':'\u0169','Utilde':'\u0168','utri':'\u25B5','utrif':'\u25B4','uuarr':'\u21C8','uuml':'\xFC','Uuml':'\xDC','uwangle':'\u29A7','vangrt':'\u299C','varepsilon':'\u03F5','varkappa':'\u03F0','varnothing':'\u2205','varphi':'\u03D5','varpi':'\u03D6','varpropto':'\u221D','varr':'\u2195','vArr':'\u21D5','varrho':'\u03F1','varsigma':'\u03C2','varsubsetneq':'\u228A\uFE00','varsubsetneqq':'\u2ACB\uFE00','varsupsetneq':'\u228B\uFE00','varsupsetneqq':'\u2ACC\uFE00','vartheta':'\u03D1','vartriangleleft':'\u22B2','vartriangleright':'\u22B3','vBar':'\u2AE8','Vbar':'\u2AEB','vBarv':'\u2AE9','vcy':'\u0432','Vcy':'\u0412','vdash':'\u22A2','vDash':'\u22A8','Vdash':'\u22A9','VDash':'\u22AB','Vdashl':'\u2AE6','vee':'\u2228','Vee':'\u22C1','veebar':'\u22BB','veeeq':'\u225A','vellip':'\u22EE','verbar':'|','Verbar':'\u2016','vert':'|','Vert':'\u2016','VerticalBar':'\u2223','VerticalLine':'|','VerticalSeparator':'\u2758','VerticalTilde':'\u2240','VeryThinSpace':'\u200A','vfr':'\uD835\uDD33','Vfr':'\uD835\uDD19','vltri':'\u22B2','vnsub':'\u2282\u20D2','vnsup':'\u2283\u20D2','vopf':'\uD835\uDD67','Vopf':'\uD835\uDD4D','vprop':'\u221D','vrtri':'\u22B3','vscr':'\uD835\uDCCB','Vscr':'\uD835\uDCB1','vsubne':'\u228A\uFE00','vsubnE':'\u2ACB\uFE00','vsupne':'\u228B\uFE00','vsupnE':'\u2ACC\uFE00','Vvdash':'\u22AA','vzigzag':'\u299A','wcirc':'\u0175','Wcirc':'\u0174','wedbar':'\u2A5F','wedge':'\u2227','Wedge':'\u22C0','wedgeq':'\u2259','weierp':'\u2118','wfr':'\uD835\uDD34','Wfr':'\uD835\uDD1A','wopf':'\uD835\uDD68','Wopf':'\uD835\uDD4E','wp':'\u2118','wr':'\u2240','wreath':'\u2240','wscr':'\uD835\uDCCC','Wscr':'\uD835\uDCB2','xcap':'\u22C2','xcirc':'\u25EF','xcup':'\u22C3','xdtri':'\u25BD','xfr':'\uD835\uDD35','Xfr':'\uD835\uDD1B','xharr':'\u27F7','xhArr':'\u27FA','xi':'\u03BE','Xi':'\u039E','xlarr':'\u27F5','xlArr':'\u27F8','xmap':'\u27FC','xnis':'\u22FB','xodot':'\u2A00','xopf':'\uD835\uDD69','Xopf':'\uD835\uDD4F','xoplus':'\u2A01','xotime':'\u2A02','xrarr':'\u27F6','xrArr':'\u27F9','xscr':'\uD835\uDCCD','Xscr':'\uD835\uDCB3','xsqcup':'\u2A06','xuplus':'\u2A04','xutri':'\u25B3','xvee':'\u22C1','xwedge':'\u22C0','yacute':'\xFD','Yacute':'\xDD','yacy':'\u044F','YAcy':'\u042F','ycirc':'\u0177','Ycirc':'\u0176','ycy':'\u044B','Ycy':'\u042B','yen':'\xA5','yfr':'\uD835\uDD36','Yfr':'\uD835\uDD1C','yicy':'\u0457','YIcy':'\u0407','yopf':'\uD835\uDD6A','Yopf':'\uD835\uDD50','yscr':'\uD835\uDCCE','Yscr':'\uD835\uDCB4','yucy':'\u044E','YUcy':'\u042E','yuml':'\xFF','Yuml':'\u0178','zacute':'\u017A','Zacute':'\u0179','zcaron':'\u017E','Zcaron':'\u017D','zcy':'\u0437','Zcy':'\u0417','zdot':'\u017C','Zdot':'\u017B','zeetrf':'\u2128','ZeroWidthSpace':'\u200B','zeta':'\u03B6','Zeta':'\u0396','zfr':'\uD835\uDD37','Zfr':'\u2128','zhcy':'\u0436','ZHcy':'\u0416','zigrarr':'\u21DD','zopf':'\uD835\uDD6B','Zopf':'\u2124','zscr':'\uD835\uDCCF','Zscr':'\uD835\uDCB5','zwj':'\u200D','zwnj':'\u200C'};
+ var decodeMapLegacy = {'aacute':'\xE1','Aacute':'\xC1','acirc':'\xE2','Acirc':'\xC2','acute':'\xB4','aelig':'\xE6','AElig':'\xC6','agrave':'\xE0','Agrave':'\xC0','amp':'&','AMP':'&','aring':'\xE5','Aring':'\xC5','atilde':'\xE3','Atilde':'\xC3','auml':'\xE4','Auml':'\xC4','brvbar':'\xA6','ccedil':'\xE7','Ccedil':'\xC7','cedil':'\xB8','cent':'\xA2','copy':'\xA9','COPY':'\xA9','curren':'\xA4','deg':'\xB0','divide':'\xF7','eacute':'\xE9','Eacute':'\xC9','ecirc':'\xEA','Ecirc':'\xCA','egrave':'\xE8','Egrave':'\xC8','eth':'\xF0','ETH':'\xD0','euml':'\xEB','Euml':'\xCB','frac12':'\xBD','frac14':'\xBC','frac34':'\xBE','gt':'>','GT':'>','iacute':'\xED','Iacute':'\xCD','icirc':'\xEE','Icirc':'\xCE','iexcl':'\xA1','igrave':'\xEC','Igrave':'\xCC','iquest':'\xBF','iuml':'\xEF','Iuml':'\xCF','laquo':'\xAB','lt':'<','LT':'<','macr':'\xAF','micro':'\xB5','middot':'\xB7','nbsp':'\xA0','not':'\xAC','ntilde':'\xF1','Ntilde':'\xD1','oacute':'\xF3','Oacute':'\xD3','ocirc':'\xF4','Ocirc':'\xD4','ograve':'\xF2','Ograve':'\xD2','ordf':'\xAA','ordm':'\xBA','oslash':'\xF8','Oslash':'\xD8','otilde':'\xF5','Otilde':'\xD5','ouml':'\xF6','Ouml':'\xD6','para':'\xB6','plusmn':'\xB1','pound':'\xA3','quot':'"','QUOT':'"','raquo':'\xBB','reg':'\xAE','REG':'\xAE','sect':'\xA7','shy':'\xAD','sup1':'\xB9','sup2':'\xB2','sup3':'\xB3','szlig':'\xDF','thorn':'\xFE','THORN':'\xDE','times':'\xD7','uacute':'\xFA','Uacute':'\xDA','ucirc':'\xFB','Ucirc':'\xDB','ugrave':'\xF9','Ugrave':'\xD9','uml':'\xA8','uuml':'\xFC','Uuml':'\xDC','yacute':'\xFD','Yacute':'\xDD','yen':'\xA5','yuml':'\xFF'};
+ var decodeMapNumeric = {'0':'\uFFFD','128':'\u20AC','130':'\u201A','131':'\u0192','132':'\u201E','133':'\u2026','134':'\u2020','135':'\u2021','136':'\u02C6','137':'\u2030','138':'\u0160','139':'\u2039','140':'\u0152','142':'\u017D','145':'\u2018','146':'\u2019','147':'\u201C','148':'\u201D','149':'\u2022','150':'\u2013','151':'\u2014','152':'\u02DC','153':'\u2122','154':'\u0161','155':'\u203A','156':'\u0153','158':'\u017E','159':'\u0178'};
+ var invalidReferenceCodePoints = [1,2,3,4,5,6,7,8,11,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,64976,64977,64978,64979,64980,64981,64982,64983,64984,64985,64986,64987,64988,64989,64990,64991,64992,64993,64994,64995,64996,64997,64998,64999,65000,65001,65002,65003,65004,65005,65006,65007,65534,65535,131070,131071,196606,196607,262142,262143,327678,327679,393214,393215,458750,458751,524286,524287,589822,589823,655358,655359,720894,720895,786430,786431,851966,851967,917502,917503,983038,983039,1048574,1048575,1114110,1114111];
+
+ /*--------------------------------------------------------------------------*/
+
+ var stringFromCharCode = String.fromCharCode;
+
+ var object = {};
+ var hasOwnProperty = object.hasOwnProperty;
+ var has = function(object, propertyName) {
+ return hasOwnProperty.call(object, propertyName);
+ };
+
+ var contains = function(array, value) {
+ var index = -1;
+ var length = array.length;
+ while (++index < length) {
+ if (array[index] == value) {
+ return true;
+ }
+ }
+ return false;
+ };
+
+ var merge = function(options, defaults) {
+ if (!options) {
+ return defaults;
+ }
+ var result = {};
+ var key;
+ for (key in defaults) {
+ // A `hasOwnProperty` check is not needed here, since only recognized
+ // option names are used anyway. Any others are ignored.
+ result[key] = has(options, key) ? options[key] : defaults[key];
+ }
+ return result;
+ };
+
+ // Modified version of `ucs2encode`; see https://mths.be/punycode.
+ var codePointToSymbol = function(codePoint, strict) {
+ var output = '';
+ if ((codePoint >= 0xD800 && codePoint <= 0xDFFF) || codePoint > 0x10FFFF) {
+ // See issue #4:
+ // “Otherwise, if the number is in the range 0xD800 to 0xDFFF or is
+ // greater than 0x10FFFF, then this is a parse error. Return a U+FFFD
+ // REPLACEMENT CHARACTER.”
+ if (strict) {
+ parseError('character reference outside the permissible Unicode range');
+ }
+ return '\uFFFD';
+ }
+ if (has(decodeMapNumeric, codePoint)) {
+ if (strict) {
+ parseError('disallowed character reference');
+ }
+ return decodeMapNumeric[codePoint];
+ }
+ if (strict && contains(invalidReferenceCodePoints, codePoint)) {
+ parseError('disallowed character reference');
+ }
+ if (codePoint > 0xFFFF) {
+ codePoint -= 0x10000;
+ output += stringFromCharCode(codePoint >>> 10 & 0x3FF | 0xD800);
+ codePoint = 0xDC00 | codePoint & 0x3FF;
+ }
+ output += stringFromCharCode(codePoint);
+ return output;
+ };
+
+ var hexEscape = function(codePoint) {
+ return '&#x' + codePoint.toString(16).toUpperCase() + ';';
+ };
+
+ var decEscape = function(codePoint) {
+ return '&#' + codePoint + ';';
+ };
+
+ var parseError = function(message) {
+ throw Error('Parse error: ' + message);
+ };
+
+ /*--------------------------------------------------------------------------*/
+
+ var encode = function(string, options) {
+ options = merge(options, encode.options);
+ var strict = options.strict;
+ if (strict && regexInvalidRawCodePoint.test(string)) {
+ parseError('forbidden code point');
+ }
+ var encodeEverything = options.encodeEverything;
+ var useNamedReferences = options.useNamedReferences;
+ var allowUnsafeSymbols = options.allowUnsafeSymbols;
+ var escapeCodePoint = options.decimal ? decEscape : hexEscape;
+
+ var escapeBmpSymbol = function(symbol) {
+ return escapeCodePoint(symbol.charCodeAt(0));
+ };
+
+ if (encodeEverything) {
+ // Encode ASCII symbols.
+ string = string.replace(regexAsciiWhitelist, function(symbol) {
+ // Use named references if requested & possible.
+ if (useNamedReferences && has(encodeMap, symbol)) {
+ return '&' + encodeMap[symbol] + ';';
+ }
+ return escapeBmpSymbol(symbol);
+ });
+ // Shorten a few escapes that represent two symbols, of which at least one
+ // is within the ASCII range.
+ if (useNamedReferences) {
+ string = string
+ .replace(/>\u20D2/g, '>⃒')
+ .replace(/<\u20D2/g, '<⃒')
+ .replace(/fj/g, 'fj');
+ }
+ // Encode non-ASCII symbols.
+ if (useNamedReferences) {
+ // Encode non-ASCII symbols that can be replaced with a named reference.
+ string = string.replace(regexEncodeNonAscii, function(string) {
+ // Note: there is no need to check `has(encodeMap, string)` here.
+ return '&' + encodeMap[string] + ';';
+ });
+ }
+ // Note: any remaining non-ASCII symbols are handled outside of the `if`.
+ } else if (useNamedReferences) {
+ // Apply named character references.
+ // Encode `<>"'&` using named character references.
+ if (!allowUnsafeSymbols) {
+ string = string.replace(regexEscape, function(string) {
+ return '&' + encodeMap[string] + ';'; // no need to check `has()` here
+ });
+ }
+ // Shorten escapes that represent two symbols, of which at least one is
+ // `<>"'&`.
+ string = string
+ .replace(/>\u20D2/g, '>⃒')
+ .replace(/<\u20D2/g, '<⃒');
+ // Encode non-ASCII symbols that can be replaced with a named reference.
+ string = string.replace(regexEncodeNonAscii, function(string) {
+ // Note: there is no need to check `has(encodeMap, string)` here.
+ return '&' + encodeMap[string] + ';';
+ });
+ } else if (!allowUnsafeSymbols) {
+ // Encode `<>"'&` using hexadecimal escapes, now that they’re not handled
+ // using named character references.
+ string = string.replace(regexEscape, escapeBmpSymbol);
+ }
+ return string
+ // Encode astral symbols.
+ .replace(regexAstralSymbols, function($0) {
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
+ var high = $0.charCodeAt(0);
+ var low = $0.charCodeAt(1);
+ var codePoint = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000;
+ return escapeCodePoint(codePoint);
+ })
+ // Encode any remaining BMP symbols that are not printable ASCII symbols
+ // using a hexadecimal escape.
+ .replace(regexBmpWhitelist, escapeBmpSymbol);
+ };
+ // Expose default options (so they can be overridden globally).
+ encode.options = {
+ 'allowUnsafeSymbols': false,
+ 'encodeEverything': false,
+ 'strict': false,
+ 'useNamedReferences': false,
+ 'decimal' : false
+ };
+
+ var decode = function(html, options) {
+ options = merge(options, decode.options);
+ var strict = options.strict;
+ if (strict && regexInvalidEntity.test(html)) {
+ parseError('malformed character reference');
+ }
+ return html.replace(regexDecode, function($0, $1, $2, $3, $4, $5, $6, $7) {
+ var codePoint;
+ var semicolon;
+ var decDigits;
+ var hexDigits;
+ var reference;
+ var next;
+ if ($1) {
+ // Decode decimal escapes, e.g. `𝌆`.
+ decDigits = $1;
+ semicolon = $2;
+ if (strict && !semicolon) {
+ parseError('character reference was not terminated by a semicolon');
+ }
+ codePoint = parseInt(decDigits, 10);
+ return codePointToSymbol(codePoint, strict);
+ }
+ if ($3) {
+ // Decode hexadecimal escapes, e.g. `𝌆`.
+ hexDigits = $3;
+ semicolon = $4;
+ if (strict && !semicolon) {
+ parseError('character reference was not terminated by a semicolon');
+ }
+ codePoint = parseInt(hexDigits, 16);
+ return codePointToSymbol(codePoint, strict);
+ }
+ if ($5) {
+ // Decode named character references with trailing `;`, e.g. `©`.
+ reference = $5;
+ if (has(decodeMap, reference)) {
+ return decodeMap[reference];
+ } else {
+ // Ambiguous ampersand. https://mths.be/notes/ambiguous-ampersands
+ if (strict) {
+ parseError(
+ 'named character reference was not terminated by a semicolon'
+ );
+ }
+ return $0;
+ }
+ }
+ // If we’re still here, it’s a legacy reference for sure. No need for an
+ // extra `if` check.
+ // Decode named character references without trailing `;`, e.g. `&`
+ // This is only a parse error if it gets converted to `&`, or if it is
+ // followed by `=` in an attribute context.
+ reference = $6;
+ next = $7;
+ if (next && options.isAttributeValue) {
+ if (strict && next == '=') {
+ parseError('`&` did not start a character reference');
+ }
+ return $0;
+ } else {
+ if (strict) {
+ parseError(
+ 'named character reference was not terminated by a semicolon'
+ );
+ }
+ // Note: there is no need to check `has(decodeMapLegacy, reference)`.
+ return decodeMapLegacy[reference] + (next || '');
+ }
+ });
+ };
+ // Expose default options (so they can be overridden globally).
+ decode.options = {
+ 'isAttributeValue': false,
+ 'strict': false
+ };
+
+ var escape = function(string) {
+ return string.replace(regexEscape, function($0) {
+ // Note: there is no need to check `has(escapeMap, $0)` here.
+ return escapeMap[$0];
+ });
+ };
+
+ /*--------------------------------------------------------------------------*/
+
+ var he = {
+ 'version': '1.1.1',
+ 'encode': encode,
+ 'decode': decode,
+ 'escape': escape,
+ 'unescape': decode
+ };
+
+ // Some AMD build optimizers, like r.js, check for specific condition patterns
+ // like the following:
+ if (
+ false
+ ) {
+ define(function() {
+ return he;
+ });
+ } else if (freeExports && !freeExports.nodeType) {
+ if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
+ freeModule.exports = he;
+ } else { // in Narwhal or RingoJS v0.7.0-
+ for (var key in he) {
+ has(he, key) && (freeExports[key] = he[key]);
+ }
+ }
+ } else { // in Rhino or a web browser
+ root.he = he;
+ }
+
+}(this));
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{}],48:[function(require,module,exports){
+exports.read = function (buffer, offset, isLE, mLen, nBytes) {
+ var e, m
+ var eLen = nBytes * 8 - mLen - 1
+ var eMax = (1 << eLen) - 1
+ var eBias = eMax >> 1
+ var nBits = -7
+ var i = isLE ? (nBytes - 1) : 0
+ var d = isLE ? -1 : 1
+ var s = buffer[offset + i]
+
+ i += d
+
+ e = s & ((1 << (-nBits)) - 1)
+ s >>= (-nBits)
+ nBits += eLen
+ for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
+
+ m = e & ((1 << (-nBits)) - 1)
+ e >>= (-nBits)
+ nBits += mLen
+ for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
+
+ if (e === 0) {
+ e = 1 - eBias
+ } else if (e === eMax) {
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
+ } else {
+ m = m + Math.pow(2, mLen)
+ e = e - eBias
+ }
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
+}
+
+exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
+ var e, m, c
+ var eLen = nBytes * 8 - mLen - 1
+ var eMax = (1 << eLen) - 1
+ var eBias = eMax >> 1
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
+ var i = isLE ? 0 : (nBytes - 1)
+ var d = isLE ? 1 : -1
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
+
+ value = Math.abs(value)
+
+ if (isNaN(value) || value === Infinity) {
+ m = isNaN(value) ? 1 : 0
+ e = eMax
+ } else {
+ e = Math.floor(Math.log(value) / Math.LN2)
+ if (value * (c = Math.pow(2, -e)) < 1) {
+ e--
+ c *= 2
+ }
+ if (e + eBias >= 1) {
+ value += rt / c
+ } else {
+ value += rt * Math.pow(2, 1 - eBias)
+ }
+ if (value * c >= 2) {
+ e++
+ c /= 2
+ }
+
+ if (e + eBias >= eMax) {
+ m = 0
+ e = eMax
+ } else if (e + eBias >= 1) {
+ m = (value * c - 1) * Math.pow(2, mLen)
+ e = e + eBias
+ } else {
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
+ e = 0
+ }
+ }
+
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
+
+ e = (e << mLen) | m
+ eLen += mLen
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
+
+ buffer[offset + i - d] |= s * 128
+}
+
+},{}],49:[function(require,module,exports){
+if (typeof Object.create === 'function') {
+ // implementation from standard node.js 'util' module
+ module.exports = function inherits(ctor, superCtor) {
+ ctor.super_ = superCtor
+ ctor.prototype = Object.create(superCtor.prototype, {
+ constructor: {
+ value: ctor,
+ enumerable: false,
+ writable: true,
+ configurable: true
+ }
+ });
+ };
+} else {
+ // old school shim for old browsers
+ module.exports = function inherits(ctor, superCtor) {
+ ctor.super_ = superCtor
+ var TempCtor = function () {}
+ TempCtor.prototype = superCtor.prototype
+ ctor.prototype = new TempCtor()
+ ctor.prototype.constructor = ctor
+ }
+}
+
+},{}],50:[function(require,module,exports){
+/*!
+ * Determine if an object is a Buffer
+ *
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
+ * @license MIT
+ */
+
+// The _isBuffer check is for Safari 5-7 support, because it's missing
+// Object.prototype.constructor. Remove this eventually
+module.exports = function (obj) {
+ return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
+}
+
+function isBuffer (obj) {
+ return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
+}
+
+// For Node v0.10 support. Remove this eventually.
+function isSlowBuffer (obj) {
+ return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
+}
+
+},{}],51:[function(require,module,exports){
+var toString = {}.toString;
+
+module.exports = Array.isArray || function (arr) {
+ return toString.call(arr) == '[object Array]';
+};
+
+},{}],52:[function(require,module,exports){
+(function (process){
+var path = require('path');
+var fs = require('fs');
+var _0777 = parseInt('0777', 8);
+
+module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
+
+function mkdirP (p, opts, f, made) {
+ if (typeof opts === 'function') {
+ f = opts;
+ opts = {};
+ }
+ else if (!opts || typeof opts !== 'object') {
+ opts = { mode: opts };
+ }
+
+ var mode = opts.mode;
+ var xfs = opts.fs || fs;
+
+ if (mode === undefined) {
+ mode = _0777 & (~process.umask());
+ }
+ if (!made) made = null;
+
+ var cb = f || function () {};
+ p = path.resolve(p);
+
+ xfs.mkdir(p, mode, function (er) {
+ if (!er) {
+ made = made || p;
+ return cb(null, made);
+ }
+ switch (er.code) {
+ case 'ENOENT':
+ mkdirP(path.dirname(p), opts, function (er, made) {
+ if (er) cb(er, made);
+ else mkdirP(p, opts, cb, made);
+ });
+ break;
+
+ // In the case of any other error, just see if there's a dir
+ // there already. If so, then hooray! If not, then something
+ // is borked.
+ default:
+ xfs.stat(p, function (er2, stat) {
+ // if the stat fails, then that's super weird.
+ // let the original error be the failure reason.
+ if (er2 || !stat.isDirectory()) cb(er, made)
+ else cb(null, made);
+ });
+ break;
+ }
+ });
+}
+
+mkdirP.sync = function sync (p, opts, made) {
+ if (!opts || typeof opts !== 'object') {
+ opts = { mode: opts };
+ }
+
+ var mode = opts.mode;
+ var xfs = opts.fs || fs;
+
+ if (mode === undefined) {
+ mode = _0777 & (~process.umask());
+ }
+ if (!made) made = null;
+
+ p = path.resolve(p);
+
+ try {
+ xfs.mkdirSync(p, mode);
+ made = made || p;
+ }
+ catch (err0) {
+ switch (err0.code) {
+ case 'ENOENT' :
+ made = sync(path.dirname(p), opts, made);
+ sync(p, opts, made);
+ break;
+
+ // In the case of any other error, just see if there's a dir
+ // there already. If so, then hooray! If not, then something
+ // is borked.
+ default:
+ var stat;
+ try {
+ stat = xfs.statSync(p);
+ }
+ catch (err1) {
+ throw err0;
+ }
+ if (!stat.isDirectory()) throw err0;
+ break;
+ }
+ }
+
+ return made;
+};
+
+}).call(this,require('_process'))
+},{"_process":55,"fs":40,"path":40}],53:[function(require,module,exports){
+/**
+ * Helpers.
+ */
+
+var s = 1000;
+var m = s * 60;
+var h = m * 60;
+var d = h * 24;
+var y = d * 365.25;
+
+/**
+ * Parse or format the given `val`.
+ *
+ * Options:
+ *
+ * - `long` verbose formatting [false]
+ *
+ * @param {String|Number} val
+ * @param {Object} [options]
+ * @throws {Error} throw an error if val is not a non-empty string or a number
+ * @return {String|Number}
+ * @api public
+ */
+
+module.exports = function(val, options) {
+ options = options || {};
+ var type = typeof val;
+ if (type === 'string' && val.length > 0) {
+ return parse(val);
+ } else if (type === 'number' && isNaN(val) === false) {
+ return options.long ? fmtLong(val) : fmtShort(val);
+ }
+ throw new Error(
+ 'val is not a non-empty string or a valid number. val=' +
+ JSON.stringify(val)
+ );
+};
+
+/**
+ * Parse the given `str` and return milliseconds.
+ *
+ * @param {String} str
+ * @return {Number}
+ * @api private
+ */
+
+function parse(str) {
+ str = String(str);
+ if (str.length > 100) {
+ return;
+ }
+ var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
+ str
+ );
+ if (!match) {
+ return;
+ }
+ var n = parseFloat(match[1]);
+ var type = (match[2] || 'ms').toLowerCase();
+ switch (type) {
+ case 'years':
+ case 'year':
+ case 'yrs':
+ case 'yr':
+ case 'y':
+ return n * y;
+ case 'days':
+ case 'day':
+ case 'd':
+ return n * d;
+ case 'hours':
+ case 'hour':
+ case 'hrs':
+ case 'hr':
+ case 'h':
+ return n * h;
+ case 'minutes':
+ case 'minute':
+ case 'mins':
+ case 'min':
+ case 'm':
+ return n * m;
+ case 'seconds':
+ case 'second':
+ case 'secs':
+ case 'sec':
+ case 's':
+ return n * s;
+ case 'milliseconds':
+ case 'millisecond':
+ case 'msecs':
+ case 'msec':
+ case 'ms':
+ return n;
+ default:
+ return undefined;
+ }
+}
+
+/**
+ * Short format for `ms`.
+ *
+ * @param {Number} ms
+ * @return {String}
+ * @api private
+ */
+
+function fmtShort(ms) {
+ if (ms >= d) {
+ return Math.round(ms / d) + 'd';
+ }
+ if (ms >= h) {
+ return Math.round(ms / h) + 'h';
+ }
+ if (ms >= m) {
+ return Math.round(ms / m) + 'm';
+ }
+ if (ms >= s) {
+ return Math.round(ms / s) + 's';
+ }
+ return ms + 'ms';
+}
+
+/**
+ * Long format for `ms`.
+ *
+ * @param {Number} ms
+ * @return {String}
+ * @api private
+ */
+
+function fmtLong(ms) {
+ return plural(ms, d, 'day') ||
+ plural(ms, h, 'hour') ||
+ plural(ms, m, 'minute') ||
+ plural(ms, s, 'second') ||
+ ms + ' ms';
+}
+
+/**
+ * Pluralization helper.
+ */
+
+function plural(ms, n, name) {
+ if (ms < n) {
+ return;
+ }
+ if (ms < n * 1.5) {
+ return Math.floor(ms / n) + ' ' + name;
+ }
+ return Math.ceil(ms / n) + ' ' + name + 's';
+}
+
+},{}],54:[function(require,module,exports){
+(function (process){
+'use strict';
+
+if (!process.version ||
+ process.version.indexOf('v0.') === 0 ||
+ process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
+ module.exports = nextTick;
+} else {
+ module.exports = process.nextTick;
+}
+
+function nextTick(fn, arg1, arg2, arg3) {
+ if (typeof fn !== 'function') {
+ throw new TypeError('"callback" argument must be a function');
+ }
+ var len = arguments.length;
+ var args, i;
+ switch (len) {
+ case 0:
+ case 1:
+ return process.nextTick(fn);
+ case 2:
+ return process.nextTick(function afterTickOne() {
+ fn.call(null, arg1);
+ });
+ case 3:
+ return process.nextTick(function afterTickTwo() {
+ fn.call(null, arg1, arg2);
+ });
+ case 4:
+ return process.nextTick(function afterTickThree() {
+ fn.call(null, arg1, arg2, arg3);
+ });
+ default:
+ args = new Array(len - 1);
+ i = 0;
+ while (i < args.length) {
+ args[i++] = arguments[i];
+ }
+ return process.nextTick(function afterTick() {
+ fn.apply(null, args);
+ });
+ }
+}
+
+}).call(this,require('_process'))
+},{"_process":55}],55:[function(require,module,exports){
+// shim for using process in browser
+var process = module.exports = {};
+
+// cached from whatever global is present so that test runners that stub it
+// don't break things. But we need to wrap it in a try catch in case it is
+// wrapped in strict mode code which doesn't define any globals. It's inside a
+// function because try/catches deoptimize in certain engines.
+
+var cachedSetTimeout;
+var cachedClearTimeout;
+
+function defaultSetTimout() {
+ throw new Error('setTimeout has not been defined');
+}
+function defaultClearTimeout () {
+ throw new Error('clearTimeout has not been defined');
+}
+(function () {
+ try {
+ if (typeof setTimeout === 'function') {
+ cachedSetTimeout = setTimeout;
+ } else {
+ cachedSetTimeout = defaultSetTimout;
+ }
+ } catch (e) {
+ cachedSetTimeout = defaultSetTimout;
+ }
+ try {
+ if (typeof clearTimeout === 'function') {
+ cachedClearTimeout = clearTimeout;
+ } else {
+ cachedClearTimeout = defaultClearTimeout;
+ }
+ } catch (e) {
+ cachedClearTimeout = defaultClearTimeout;
+ }
+} ())
+function runTimeout(fun) {
+ if (cachedSetTimeout === setTimeout) {
+ //normal enviroments in sane situations
+ return setTimeout(fun, 0);
+ }
+ // if setTimeout wasn't available but was latter defined
+ if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
+ cachedSetTimeout = setTimeout;
+ return setTimeout(fun, 0);
+ }
+ try {
+ // when when somebody has screwed with setTimeout but no I.E. maddness
+ return cachedSetTimeout(fun, 0);
+ } catch(e){
+ try {
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
+ return cachedSetTimeout.call(null, fun, 0);
+ } catch(e){
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
+ return cachedSetTimeout.call(this, fun, 0);
+ }
+ }
+
+
+}
+function runClearTimeout(marker) {
+ if (cachedClearTimeout === clearTimeout) {
+ //normal enviroments in sane situations
+ return clearTimeout(marker);
+ }
+ // if clearTimeout wasn't available but was latter defined
+ if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
+ cachedClearTimeout = clearTimeout;
+ return clearTimeout(marker);
+ }
+ try {
+ // when when somebody has screwed with setTimeout but no I.E. maddness
+ return cachedClearTimeout(marker);
+ } catch (e){
+ try {
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
+ return cachedClearTimeout.call(null, marker);
+ } catch (e){
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
+ return cachedClearTimeout.call(this, marker);
+ }
+ }
+
+
+
+}
+var queue = [];
+var draining = false;
+var currentQueue;
+var queueIndex = -1;
+
+function cleanUpNextTick() {
+ if (!draining || !currentQueue) {
+ return;
+ }
+ draining = false;
+ if (currentQueue.length) {
+ queue = currentQueue.concat(queue);
+ } else {
+ queueIndex = -1;
+ }
+ if (queue.length) {
+ drainQueue();
+ }
+}
+
+function drainQueue() {
+ if (draining) {
+ return;
+ }
+ var timeout = runTimeout(cleanUpNextTick);
+ draining = true;
+
+ var len = queue.length;
+ while(len) {
+ currentQueue = queue;
+ queue = [];
+ while (++queueIndex < len) {
+ if (currentQueue) {
+ currentQueue[queueIndex].run();
+ }
+ }
+ queueIndex = -1;
+ len = queue.length;
+ }
+ currentQueue = null;
+ draining = false;
+ runClearTimeout(timeout);
+}
+
+process.nextTick = function (fun) {
+ var args = new Array(arguments.length - 1);
+ if (arguments.length > 1) {
+ for (var i = 1; i < arguments.length; i++) {
+ args[i - 1] = arguments[i];
+ }
+ }
+ queue.push(new Item(fun, args));
+ if (queue.length === 1 && !draining) {
+ runTimeout(drainQueue);
+ }
+};
+
+// v8 likes predictible objects
+function Item(fun, array) {
+ this.fun = fun;
+ this.array = array;
+}
+Item.prototype.run = function () {
+ this.fun.apply(null, this.array);
+};
+process.title = 'browser';
+process.browser = true;
+process.env = {};
+process.argv = [];
+process.version = ''; // empty string to avoid regexp issues
+process.versions = {};
+
+function noop() {}
+
+process.on = noop;
+process.addListener = noop;
+process.once = noop;
+process.off = noop;
+process.removeListener = noop;
+process.removeAllListeners = noop;
+process.emit = noop;
+process.prependListener = noop;
+process.prependOnceListener = noop;
+
+process.listeners = function (name) { return [] }
+
+process.binding = function (name) {
+ throw new Error('process.binding is not supported');
+};
+
+process.cwd = function () { return '/' };
+process.chdir = function (dir) {
+ throw new Error('process.chdir is not supported');
+};
+process.umask = function() { return 0; };
+
+},{}],56:[function(require,module,exports){
+module.exports = require('./lib/_stream_duplex.js');
+
+},{"./lib/_stream_duplex.js":57}],57:[function(require,module,exports){
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// a duplex stream is just a stream that is both readable and writable.
+// Since JS doesn't have multiple prototypal inheritance, this class
+// prototypally inherits from Readable, and then parasitically from
+// Writable.
+
+'use strict';
+
+/*<replacement>*/
+
+var processNextTick = require('process-nextick-args');
+/*</replacement>*/
+
+/*<replacement>*/
+var objectKeys = Object.keys || function (obj) {
+ var keys = [];
+ for (var key in obj) {
+ keys.push(key);
+ }return keys;
+};
+/*</replacement>*/
+
+module.exports = Duplex;
+
+/*<replacement>*/
+var util = require('core-util-is');
+util.inherits = require('inherits');
+/*</replacement>*/
+
+var Readable = require('./_stream_readable');
+var Writable = require('./_stream_writable');
+
+util.inherits(Duplex, Readable);
+
+var keys = objectKeys(Writable.prototype);
+for (var v = 0; v < keys.length; v++) {
+ var method = keys[v];
+ if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
+}
+
+function Duplex(options) {
+ if (!(this instanceof Duplex)) return new Duplex(options);
+
+ Readable.call(this, options);
+ Writable.call(this, options);
+
+ if (options && options.readable === false) this.readable = false;
+
+ if (options && options.writable === false) this.writable = false;
+
+ this.allowHalfOpen = true;
+ if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
+
+ this.once('end', onend);
+}
+
+// the no-half-open enforcer
+function onend() {
+ // if we allow half-open state, or if the writable side ended,
+ // then we're ok.
+ if (this.allowHalfOpen || this._writableState.ended) return;
+
+ // no more data can be written.
+ // But allow more writes to happen in this tick.
+ processNextTick(onEndNT, this);
+}
+
+function onEndNT(self) {
+ self.end();
+}
+
+Object.defineProperty(Duplex.prototype, 'destroyed', {
+ get: function () {
+ if (this._readableState === undefined || this._writableState === undefined) {
+ return false;
+ }
+ return this._readableState.destroyed && this._writableState.destroyed;
+ },
+ set: function (value) {
+ // we ignore the value if the stream
+ // has not been initialized yet
+ if (this._readableState === undefined || this._writableState === undefined) {
+ return;
+ }
+
+ // backward compatibility, the user is explicitly
+ // managing destroyed
+ this._readableState.destroyed = value;
+ this._writableState.destroyed = value;
+ }
+});
+
+Duplex.prototype._destroy = function (err, cb) {
+ this.push(null);
+ this.end();
+
+ processNextTick(cb, err);
+};
+
+function forEach(xs, f) {
+ for (var i = 0, l = xs.length; i < l; i++) {
+ f(xs[i], i);
+ }
+}
+},{"./_stream_readable":59,"./_stream_writable":61,"core-util-is":41,"inherits":49,"process-nextick-args":54}],58:[function(require,module,exports){
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// a passthrough stream.
+// basically just the most minimal sort of Transform stream.
+// Every written chunk gets output as-is.
+
+'use strict';
+
+module.exports = PassThrough;
+
+var Transform = require('./_stream_transform');
+
+/*<replacement>*/
+var util = require('core-util-is');
+util.inherits = require('inherits');
+/*</replacement>*/
+
+util.inherits(PassThrough, Transform);
+
+function PassThrough(options) {
+ if (!(this instanceof PassThrough)) return new PassThrough(options);
+
+ Transform.call(this, options);
+}
+
+PassThrough.prototype._transform = function (chunk, encoding, cb) {
+ cb(null, chunk);
+};
+},{"./_stream_transform":60,"core-util-is":41,"inherits":49}],59:[function(require,module,exports){
+(function (process,global){
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+'use strict';
+
+/*<replacement>*/
+
+var processNextTick = require('process-nextick-args');
+/*</replacement>*/
+
+module.exports = Readable;
+
+/*<replacement>*/
+var isArray = require('isarray');
+/*</replacement>*/
+
+/*<replacement>*/
+var Duplex;
+/*</replacement>*/
+
+Readable.ReadableState = ReadableState;
+
+/*<replacement>*/
+var EE = require('events').EventEmitter;
+
+var EElistenerCount = function (emitter, type) {
+ return emitter.listeners(type).length;
+};
+/*</replacement>*/
+
+/*<replacement>*/
+var Stream = require('./internal/streams/stream');
+/*</replacement>*/
+
+// TODO(bmeurer): Change this back to const once hole checks are
+// properly optimized away early in Ignition+TurboFan.
+/*<replacement>*/
+var Buffer = require('safe-buffer').Buffer;
+var OurUint8Array = global.Uint8Array || function () {};
+function _uint8ArrayToBuffer(chunk) {
+ return Buffer.from(chunk);
+}
+function _isUint8Array(obj) {
+ return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
+}
+/*</replacement>*/
+
+/*<replacement>*/
+var util = require('core-util-is');
+util.inherits = require('inherits');
+/*</replacement>*/
+
+/*<replacement>*/
+var debugUtil = require('util');
+var debug = void 0;
+if (debugUtil && debugUtil.debuglog) {
+ debug = debugUtil.debuglog('stream');
+} else {
+ debug = function () {};
+}
+/*</replacement>*/
+
+var BufferList = require('./internal/streams/BufferList');
+var destroyImpl = require('./internal/streams/destroy');
+var StringDecoder;
+
+util.inherits(Readable, Stream);
+
+var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
+
+function prependListener(emitter, event, fn) {
+ // Sadly this is not cacheable as some libraries bundle their own
+ // event emitter implementation with them.
+ if (typeof emitter.prependListener === 'function') {
+ return emitter.prependListener(event, fn);
+ } else {
+ // This is a hack to make sure that our error handler is attached before any
+ // userland ones. NEVER DO THIS. This is here only because this code needs
+ // to continue to work with older versions of Node.js that do not include
+ // the prependListener() method. The goal is to eventually remove this hack.
+ if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
+ }
+}
+
+function ReadableState(options, stream) {
+ Duplex = Duplex || require('./_stream_duplex');
+
+ options = options || {};
+
+ // object stream flag. Used to make read(n) ignore n and to
+ // make all the buffer merging and length checks go away
+ this.objectMode = !!options.objectMode;
+
+ if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
+
+ // the point at which it stops calling _read() to fill the buffer
+ // Note: 0 is a valid value, means "don't call _read preemptively ever"
+ var hwm = options.highWaterMark;
+ var defaultHwm = this.objectMode ? 16 : 16 * 1024;
+ this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
+
+ // cast to ints.
+ this.highWaterMark = Math.floor(this.highWaterMark);
+
+ // A linked list is used to store data chunks instead of an array because the
+ // linked list can remove elements from the beginning faster than
+ // array.shift()
+ this.buffer = new BufferList();
+ this.length = 0;
+ this.pipes = null;
+ this.pipesCount = 0;
+ this.flowing = null;
+ this.ended = false;
+ this.endEmitted = false;
+ this.reading = false;
+
+ // a flag to be able to tell if the event 'readable'/'data' is emitted
+ // immediately, or on a later tick. We set this to true at first, because
+ // any actions that shouldn't happen until "later" should generally also
+ // not happen before the first read call.
+ this.sync = true;
+
+ // whenever we return null, then we set a flag to say
+ // that we're awaiting a 'readable' event emission.
+ this.needReadable = false;
+ this.emittedReadable = false;
+ this.readableListening = false;
+ this.resumeScheduled = false;
+
+ // has it been destroyed
+ this.destroyed = false;
+
+ // Crypto is kind of old and crusty. Historically, its default string
+ // encoding is 'binary' so we have to make this configurable.
+ // Everything else in the universe uses 'utf8', though.
+ this.defaultEncoding = options.defaultEncoding || 'utf8';
+
+ // the number of writers that are awaiting a drain event in .pipe()s
+ this.awaitDrain = 0;
+
+ // if true, a maybeReadMore has been scheduled
+ this.readingMore = false;
+
+ this.decoder = null;
+ this.encoding = null;
+ if (options.encoding) {
+ if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
+ this.decoder = new StringDecoder(options.encoding);
+ this.encoding = options.encoding;
+ }
+}
+
+function Readable(options) {
+ Duplex = Duplex || require('./_stream_duplex');
+
+ if (!(this instanceof Readable)) return new Readable(options);
+
+ this._readableState = new ReadableState(options, this);
+
+ // legacy
+ this.readable = true;
+
+ if (options) {
+ if (typeof options.read === 'function') this._read = options.read;
+
+ if (typeof options.destroy === 'function') this._destroy = options.destroy;
+ }
+
+ Stream.call(this);
+}
+
+Object.defineProperty(Readable.prototype, 'destroyed', {
+ get: function () {
+ if (this._readableState === undefined) {
+ return false;
+ }
+ return this._readableState.destroyed;
+ },
+ set: function (value) {
+ // we ignore the value if the stream
+ // has not been initialized yet
+ if (!this._readableState) {
+ return;
+ }
+
+ // backward compatibility, the user is explicitly
+ // managing destroyed
+ this._readableState.destroyed = value;
+ }
+});
+
+Readable.prototype.destroy = destroyImpl.destroy;
+Readable.prototype._undestroy = destroyImpl.undestroy;
+Readable.prototype._destroy = function (err, cb) {
+ this.push(null);
+ cb(err);
+};
+
+// Manually shove something into the read() buffer.
+// This returns true if the highWaterMark has not been hit yet,
+// similar to how Writable.write() returns true if you should
+// write() some more.
+Readable.prototype.push = function (chunk, encoding) {
+ var state = this._readableState;
+ var skipChunkCheck;
+
+ if (!state.objectMode) {
+ if (typeof chunk === 'string') {
+ encoding = encoding || state.defaultEncoding;
+ if (encoding !== state.encoding) {
+ chunk = Buffer.from(chunk, encoding);
+ encoding = '';
+ }
+ skipChunkCheck = true;
+ }
+ } else {
+ skipChunkCheck = true;
+ }
+
+ return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
+};
+
+// Unshift should *always* be something directly out of read()
+Readable.prototype.unshift = function (chunk) {
+ return readableAddChunk(this, chunk, null, true, false);
+};
+
+function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
+ var state = stream._readableState;
+ if (chunk === null) {
+ state.reading = false;
+ onEofChunk(stream, state);
+ } else {
+ var er;
+ if (!skipChunkCheck) er = chunkInvalid(state, chunk);
+ if (er) {
+ stream.emit('error', er);
+ } else if (state.objectMode || chunk && chunk.length > 0) {
+ if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
+ chunk = _uint8ArrayToBuffer(chunk);
+ }
+
+ if (addToFront) {
+ if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
+ } else if (state.ended) {
+ stream.emit('error', new Error('stream.push() after EOF'));
+ } else {
+ state.reading = false;
+ if (state.decoder && !encoding) {
+ chunk = state.decoder.write(chunk);
+ if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
+ } else {
+ addChunk(stream, state, chunk, false);
+ }
+ }
+ } else if (!addToFront) {
+ state.reading = false;
+ }
+ }
+
+ return needMoreData(state);
+}
+
+function addChunk(stream, state, chunk, addToFront) {
+ if (state.flowing && state.length === 0 && !state.sync) {
+ stream.emit('data', chunk);
+ stream.read(0);
+ } else {
+ // update the buffer info.
+ state.length += state.objectMode ? 1 : chunk.length;
+ if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
+
+ if (state.needReadable) emitReadable(stream);
+ }
+ maybeReadMore(stream, state);
+}
+
+function chunkInvalid(state, chunk) {
+ var er;
+ if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
+ er = new TypeError('Invalid non-string/buffer chunk');
+ }
+ return er;
+}
+
+// if it's past the high water mark, we can push in some more.
+// Also, if we have no data yet, we can stand some
+// more bytes. This is to work around cases where hwm=0,
+// such as the repl. Also, if the push() triggered a
+// readable event, and the user called read(largeNumber) such that
+// needReadable was set, then we ought to push more, so that another
+// 'readable' event will be triggered.
+function needMoreData(state) {
+ return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
+}
+
+Readable.prototype.isPaused = function () {
+ return this._readableState.flowing === false;
+};
+
+// backwards compatibility.
+Readable.prototype.setEncoding = function (enc) {
+ if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
+ this._readableState.decoder = new StringDecoder(enc);
+ this._readableState.encoding = enc;
+ return this;
+};
+
+// Don't raise the hwm > 8MB
+var MAX_HWM = 0x800000;
+function computeNewHighWaterMark(n) {
+ if (n >= MAX_HWM) {
+ n = MAX_HWM;
+ } else {
+ // Get the next highest power of 2 to prevent increasing hwm excessively in
+ // tiny amounts
+ n--;
+ n |= n >>> 1;
+ n |= n >>> 2;
+ n |= n >>> 4;
+ n |= n >>> 8;
+ n |= n >>> 16;
+ n++;
+ }
+ return n;
+}
+
+// This function is designed to be inlinable, so please take care when making
+// changes to the function body.
+function howMuchToRead(n, state) {
+ if (n <= 0 || state.length === 0 && state.ended) return 0;
+ if (state.objectMode) return 1;
+ if (n !== n) {
+ // Only flow one buffer at a time
+ if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
+ }
+ // If we're asking for more than the current hwm, then raise the hwm.
+ if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
+ if (n <= state.length) return n;
+ // Don't have enough
+ if (!state.ended) {
+ state.needReadable = true;
+ return 0;
+ }
+ return state.length;
+}
+
+// you can override either this method, or the async _read(n) below.
+Readable.prototype.read = function (n) {
+ debug('read', n);
+ n = parseInt(n, 10);
+ var state = this._readableState;
+ var nOrig = n;
+
+ if (n !== 0) state.emittedReadable = false;
+
+ // if we're doing read(0) to trigger a readable event, but we
+ // already have a bunch of data in the buffer, then just trigger
+ // the 'readable' event and move on.
+ if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
+ debug('read: emitReadable', state.length, state.ended);
+ if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
+ return null;
+ }
+
+ n = howMuchToRead(n, state);
+
+ // if we've ended, and we're now clear, then finish it up.
+ if (n === 0 && state.ended) {
+ if (state.length === 0) endReadable(this);
+ return null;
+ }
+
+ // All the actual chunk generation logic needs to be
+ // *below* the call to _read. The reason is that in certain
+ // synthetic stream cases, such as passthrough streams, _read
+ // may be a completely synchronous operation which may change
+ // the state of the read buffer, providing enough data when
+ // before there was *not* enough.
+ //
+ // So, the steps are:
+ // 1. Figure out what the state of things will be after we do
+ // a read from the buffer.
+ //
+ // 2. If that resulting state will trigger a _read, then call _read.
+ // Note that this may be asynchronous, or synchronous. Yes, it is
+ // deeply ugly to write APIs this way, but that still doesn't mean
+ // that the Readable class should behave improperly, as streams are
+ // designed to be sync/async agnostic.
+ // Take note if the _read call is sync or async (ie, if the read call
+ // has returned yet), so that we know whether or not it's safe to emit
+ // 'readable' etc.
+ //
+ // 3. Actually pull the requested chunks out of the buffer and return.
+
+ // if we need a readable event, then we need to do some reading.
+ var doRead = state.needReadable;
+ debug('need readable', doRead);
+
+ // if we currently have less than the highWaterMark, then also read some
+ if (state.length === 0 || state.length - n < state.highWaterMark) {
+ doRead = true;
+ debug('length less than watermark', doRead);
+ }
+
+ // however, if we've ended, then there's no point, and if we're already
+ // reading, then it's unnecessary.
+ if (state.ended || state.reading) {
+ doRead = false;
+ debug('reading or ended', doRead);
+ } else if (doRead) {
+ debug('do read');
+ state.reading = true;
+ state.sync = true;
+ // if the length is currently zero, then we *need* a readable event.
+ if (state.length === 0) state.needReadable = true;
+ // call internal read method
+ this._read(state.highWaterMark);
+ state.sync = false;
+ // If _read pushed data synchronously, then `reading` will be false,
+ // and we need to re-evaluate how much data we can return to the user.
+ if (!state.reading) n = howMuchToRead(nOrig, state);
+ }
+
+ var ret;
+ if (n > 0) ret = fromList(n, state);else ret = null;
+
+ if (ret === null) {
+ state.needReadable = true;
+ n = 0;
+ } else {
+ state.length -= n;
+ }
+
+ if (state.length === 0) {
+ // If we have nothing in the buffer, then we want to know
+ // as soon as we *do* get something into the buffer.
+ if (!state.ended) state.needReadable = true;
+
+ // If we tried to read() past the EOF, then emit end on the next tick.
+ if (nOrig !== n && state.ended) endReadable(this);
+ }
+
+ if (ret !== null) this.emit('data', ret);
+
+ return ret;
+};
+
+function onEofChunk(stream, state) {
+ if (state.ended) return;
+ if (state.decoder) {
+ var chunk = state.decoder.end();
+ if (chunk && chunk.length) {
+ state.buffer.push(chunk);
+ state.length += state.objectMode ? 1 : chunk.length;
+ }
+ }
+ state.ended = true;
+
+ // emit 'readable' now to make sure it gets picked up.
+ emitReadable(stream);
+}
+
+// Don't emit readable right away in sync mode, because this can trigger
+// another read() call => stack overflow. This way, it might trigger
+// a nextTick recursion warning, but that's not so bad.
+function emitReadable(stream) {
+ var state = stream._readableState;
+ state.needReadable = false;
+ if (!state.emittedReadable) {
+ debug('emitReadable', state.flowing);
+ state.emittedReadable = true;
+ if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
+ }
+}
+
+function emitReadable_(stream) {
+ debug('emit readable');
+ stream.emit('readable');
+ flow(stream);
+}
+
+// at this point, the user has presumably seen the 'readable' event,
+// and called read() to consume some data. that may have triggered
+// in turn another _read(n) call, in which case reading = true if
+// it's in progress.
+// However, if we're not ended, or reading, and the length < hwm,
+// then go ahead and try to read some more preemptively.
+function maybeReadMore(stream, state) {
+ if (!state.readingMore) {
+ state.readingMore = true;
+ processNextTick(maybeReadMore_, stream, state);
+ }
+}
+
+function maybeReadMore_(stream, state) {
+ var len = state.length;
+ while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
+ debug('maybeReadMore read 0');
+ stream.read(0);
+ if (len === state.length)
+ // didn't get any data, stop spinning.
+ break;else len = state.length;
+ }
+ state.readingMore = false;
+}
+
+// abstract method. to be overridden in specific implementation classes.
+// call cb(er, data) where data is <= n in length.
+// for virtual (non-string, non-buffer) streams, "length" is somewhat
+// arbitrary, and perhaps not very meaningful.
+Readable.prototype._read = function (n) {
+ this.emit('error', new Error('_read() is not implemented'));
+};
+
+Readable.prototype.pipe = function (dest, pipeOpts) {
+ var src = this;
+ var state = this._readableState;
+
+ switch (state.pipesCount) {
+ case 0:
+ state.pipes = dest;
+ break;
+ case 1:
+ state.pipes = [state.pipes, dest];
+ break;
+ default:
+ state.pipes.push(dest);
+ break;
+ }
+ state.pipesCount += 1;
+ debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
+
+ var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
+
+ var endFn = doEnd ? onend : unpipe;
+ if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
+
+ dest.on('unpipe', onunpipe);
+ function onunpipe(readable, unpipeInfo) {
+ debug('onunpipe');
+ if (readable === src) {
+ if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
+ unpipeInfo.hasUnpiped = true;
+ cleanup();
+ }
+ }
+ }
+
+ function onend() {
+ debug('onend');
+ dest.end();
+ }
+
+ // when the dest drains, it reduces the awaitDrain counter
+ // on the source. This would be more elegant with a .once()
+ // handler in flow(), but adding and removing repeatedly is
+ // too slow.
+ var ondrain = pipeOnDrain(src);
+ dest.on('drain', ondrain);
+
+ var cleanedUp = false;
+ function cleanup() {
+ debug('cleanup');
+ // cleanup event handlers once the pipe is broken
+ dest.removeListener('close', onclose);
+ dest.removeListener('finish', onfinish);
+ dest.removeListener('drain', ondrain);
+ dest.removeListener('error', onerror);
+ dest.removeListener('unpipe', onunpipe);
+ src.removeListener('end', onend);
+ src.removeListener('end', unpipe);
+ src.removeListener('data', ondata);
+
+ cleanedUp = true;
+
+ // if the reader is waiting for a drain event from this
+ // specific writer, then it would cause it to never start
+ // flowing again.
+ // So, if this is awaiting a drain, then we just call it now.
+ // If we don't know, then assume that we are waiting for one.
+ if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
+ }
+
+ // If the user pushes more data while we're writing to dest then we'll end up
+ // in ondata again. However, we only want to increase awaitDrain once because
+ // dest will only emit one 'drain' event for the multiple writes.
+ // => Introduce a guard on increasing awaitDrain.
+ var increasedAwaitDrain = false;
+ src.on('data', ondata);
+ function ondata(chunk) {
+ debug('ondata');
+ increasedAwaitDrain = false;
+ var ret = dest.write(chunk);
+ if (false === ret && !increasedAwaitDrain) {
+ // If the user unpiped during `dest.write()`, it is possible
+ // to get stuck in a permanently paused state if that write
+ // also returned false.
+ // => Check whether `dest` is still a piping destination.
+ if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
+ debug('false write response, pause', src._readableState.awaitDrain);
+ src._readableState.awaitDrain++;
+ increasedAwaitDrain = true;
+ }
+ src.pause();
+ }
+ }
+
+ // if the dest has an error, then stop piping into it.
+ // however, don't suppress the throwing behavior for this.
+ function onerror(er) {
+ debug('onerror', er);
+ unpipe();
+ dest.removeListener('error', onerror);
+ if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
+ }
+
+ // Make sure our error handler is attached before userland ones.
+ prependListener(dest, 'error', onerror);
+
+ // Both close and finish should trigger unpipe, but only once.
+ function onclose() {
+ dest.removeListener('finish', onfinish);
+ unpipe();
+ }
+ dest.once('close', onclose);
+ function onfinish() {
+ debug('onfinish');
+ dest.removeListener('close', onclose);
+ unpipe();
+ }
+ dest.once('finish', onfinish);
+
+ function unpipe() {
+ debug('unpipe');
+ src.unpipe(dest);
+ }
+
+ // tell the dest that it's being piped to
+ dest.emit('pipe', src);
+
+ // start the flow if it hasn't been started already.
+ if (!state.flowing) {
+ debug('pipe resume');
+ src.resume();
+ }
+
+ return dest;
+};
+
+function pipeOnDrain(src) {
+ return function () {
+ var state = src._readableState;
+ debug('pipeOnDrain', state.awaitDrain);
+ if (state.awaitDrain) state.awaitDrain--;
+ if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
+ state.flowing = true;
+ flow(src);
+ }
+ };
+}
+
+Readable.prototype.unpipe = function (dest) {
+ var state = this._readableState;
+ var unpipeInfo = { hasUnpiped: false };
+
+ // if we're not piping anywhere, then do nothing.
+ if (state.pipesCount === 0) return this;
+
+ // just one destination. most common case.
+ if (state.pipesCount === 1) {
+ // passed in one, but it's not the right one.
+ if (dest && dest !== state.pipes) return this;
+
+ if (!dest) dest = state.pipes;
+
+ // got a match.
+ state.pipes = null;
+ state.pipesCount = 0;
+ state.flowing = false;
+ if (dest) dest.emit('unpipe', this, unpipeInfo);
+ return this;
+ }
+
+ // slow case. multiple pipe destinations.
+
+ if (!dest) {
+ // remove all.
+ var dests = state.pipes;
+ var len = state.pipesCount;
+ state.pipes = null;
+ state.pipesCount = 0;
+ state.flowing = false;
+
+ for (var i = 0; i < len; i++) {
+ dests[i].emit('unpipe', this, unpipeInfo);
+ }return this;
+ }
+
+ // try to find the right one.
+ var index = indexOf(state.pipes, dest);
+ if (index === -1) return this;
+
+ state.pipes.splice(index, 1);
+ state.pipesCount -= 1;
+ if (state.pipesCount === 1) state.pipes = state.pipes[0];
+
+ dest.emit('unpipe', this, unpipeInfo);
+
+ return this;
+};
+
+// set up data events if they are asked for
+// Ensure readable listeners eventually get something
+Readable.prototype.on = function (ev, fn) {
+ var res = Stream.prototype.on.call(this, ev, fn);
+
+ if (ev === 'data') {
+ // Start flowing on next tick if stream isn't explicitly paused
+ if (this._readableState.flowing !== false) this.resume();
+ } else if (ev === 'readable') {
+ var state = this._readableState;
+ if (!state.endEmitted && !state.readableListening) {
+ state.readableListening = state.needReadable = true;
+ state.emittedReadable = false;
+ if (!state.reading) {
+ processNextTick(nReadingNextTick, this);
+ } else if (state.length) {
+ emitReadable(this);
+ }
+ }
+ }
+
+ return res;
+};
+Readable.prototype.addListener = Readable.prototype.on;
+
+function nReadingNextTick(self) {
+ debug('readable nexttick read 0');
+ self.read(0);
+}
+
+// pause() and resume() are remnants of the legacy readable stream API
+// If the user uses them, then switch into old mode.
+Readable.prototype.resume = function () {
+ var state = this._readableState;
+ if (!state.flowing) {
+ debug('resume');
+ state.flowing = true;
+ resume(this, state);
+ }
+ return this;
+};
+
+function resume(stream, state) {
+ if (!state.resumeScheduled) {
+ state.resumeScheduled = true;
+ processNextTick(resume_, stream, state);
+ }
+}
+
+function resume_(stream, state) {
+ if (!state.reading) {
+ debug('resume read 0');
+ stream.read(0);
+ }
+
+ state.resumeScheduled = false;
+ state.awaitDrain = 0;
+ stream.emit('resume');
+ flow(stream);
+ if (state.flowing && !state.reading) stream.read(0);
+}
+
+Readable.prototype.pause = function () {
+ debug('call pause flowing=%j', this._readableState.flowing);
+ if (false !== this._readableState.flowing) {
+ debug('pause');
+ this._readableState.flowing = false;
+ this.emit('pause');
+ }
+ return this;
+};
+
+function flow(stream) {
+ var state = stream._readableState;
+ debug('flow', state.flowing);
+ while (state.flowing && stream.read() !== null) {}
+}
+
+// wrap an old-style stream as the async data source.
+// This is *not* part of the readable stream interface.
+// It is an ugly unfortunate mess of history.
+Readable.prototype.wrap = function (stream) {
+ var state = this._readableState;
+ var paused = false;
+
+ var self = this;
+ stream.on('end', function () {
+ debug('wrapped end');
+ if (state.decoder && !state.ended) {
+ var chunk = state.decoder.end();
+ if (chunk && chunk.length) self.push(chunk);
+ }
+
+ self.push(null);
+ });
+
+ stream.on('data', function (chunk) {
+ debug('wrapped data');
+ if (state.decoder) chunk = state.decoder.write(chunk);
+
+ // don't skip over falsy values in objectMode
+ if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
+
+ var ret = self.push(chunk);
+ if (!ret) {
+ paused = true;
+ stream.pause();
+ }
+ });
+
+ // proxy all the other methods.
+ // important when wrapping filters and duplexes.
+ for (var i in stream) {
+ if (this[i] === undefined && typeof stream[i] === 'function') {
+ this[i] = function (method) {
+ return function () {
+ return stream[method].apply(stream, arguments);
+ };
+ }(i);
+ }
+ }
+
+ // proxy certain important events.
+ for (var n = 0; n < kProxyEvents.length; n++) {
+ stream.on(kProxyEvents[n], self.emit.bind(self, kProxyEvents[n]));
+ }
+
+ // when we try to consume some more bytes, simply unpause the
+ // underlying stream.
+ self._read = function (n) {
+ debug('wrapped _read', n);
+ if (paused) {
+ paused = false;
+ stream.resume();
+ }
+ };
+
+ return self;
+};
+
+// exposed for testing purposes only.
+Readable._fromList = fromList;
+
+// Pluck off n bytes from an array of buffers.
+// Length is the combined lengths of all the buffers in the list.
+// This function is designed to be inlinable, so please take care when making
+// changes to the function body.
+function fromList(n, state) {
+ // nothing buffered
+ if (state.length === 0) return null;
+
+ var ret;
+ if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
+ // read it all, truncate the list
+ if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
+ state.buffer.clear();
+ } else {
+ // read part of list
+ ret = fromListPartial(n, state.buffer, state.decoder);
+ }
+
+ return ret;
+}
+
+// Extracts only enough buffered data to satisfy the amount requested.
+// This function is designed to be inlinable, so please take care when making
+// changes to the function body.
+function fromListPartial(n, list, hasStrings) {
+ var ret;
+ if (n < list.head.data.length) {
+ // slice is the same for buffers and strings
+ ret = list.head.data.slice(0, n);
+ list.head.data = list.head.data.slice(n);
+ } else if (n === list.head.data.length) {
+ // first chunk is a perfect match
+ ret = list.shift();
+ } else {
+ // result spans more than one buffer
+ ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
+ }
+ return ret;
+}
+
+// Copies a specified amount of characters from the list of buffered data
+// chunks.
+// This function is designed to be inlinable, so please take care when making
+// changes to the function body.
+function copyFromBufferString(n, list) {
+ var p = list.head;
+ var c = 1;
+ var ret = p.data;
+ n -= ret.length;
+ while (p = p.next) {
+ var str = p.data;
+ var nb = n > str.length ? str.length : n;
+ if (nb === str.length) ret += str;else ret += str.slice(0, n);
+ n -= nb;
+ if (n === 0) {
+ if (nb === str.length) {
+ ++c;
+ if (p.next) list.head = p.next;else list.head = list.tail = null;
+ } else {
+ list.head = p;
+ p.data = str.slice(nb);
+ }
+ break;
+ }
+ ++c;
+ }
+ list.length -= c;
+ return ret;
+}
+
+// Copies a specified amount of bytes from the list of buffered data chunks.
+// This function is designed to be inlinable, so please take care when making
+// changes to the function body.
+function copyFromBuffer(n, list) {
+ var ret = Buffer.allocUnsafe(n);
+ var p = list.head;
+ var c = 1;
+ p.data.copy(ret);
+ n -= p.data.length;
+ while (p = p.next) {
+ var buf = p.data;
+ var nb = n > buf.length ? buf.length : n;
+ buf.copy(ret, ret.length - n, 0, nb);
+ n -= nb;
+ if (n === 0) {
+ if (nb === buf.length) {
+ ++c;
+ if (p.next) list.head = p.next;else list.head = list.tail = null;
+ } else {
+ list.head = p;
+ p.data = buf.slice(nb);
+ }
+ break;
+ }
+ ++c;
+ }
+ list.length -= c;
+ return ret;
+}
+
+function endReadable(stream) {
+ var state = stream._readableState;
+
+ // If we get here before consuming all the bytes, then that is a
+ // bug in node. Should never happen.
+ if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
+
+ if (!state.endEmitted) {
+ state.ended = true;
+ processNextTick(endReadableNT, state, stream);
+ }
+}
+
+function endReadableNT(state, stream) {
+ // Check that we didn't get one last unshift.
+ if (!state.endEmitted && state.length === 0) {
+ state.endEmitted = true;
+ stream.readable = false;
+ stream.emit('end');
+ }
+}
+
+function forEach(xs, f) {
+ for (var i = 0, l = xs.length; i < l; i++) {
+ f(xs[i], i);
+ }
+}
+
+function indexOf(xs, x) {
+ for (var i = 0, l = xs.length; i < l; i++) {
+ if (xs[i] === x) return i;
+ }
+ return -1;
+}
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"./_stream_duplex":57,"./internal/streams/BufferList":62,"./internal/streams/destroy":63,"./internal/streams/stream":64,"_process":55,"core-util-is":41,"events":46,"inherits":49,"isarray":51,"process-nextick-args":54,"safe-buffer":69,"string_decoder/":71,"util":38}],60:[function(require,module,exports){
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// a transform stream is a readable/writable stream where you do
+// something with the data. Sometimes it's called a "filter",
+// but that's not a great name for it, since that implies a thing where
+// some bits pass through, and others are simply ignored. (That would
+// be a valid example of a transform, of course.)
+//
+// While the output is causally related to the input, it's not a
+// necessarily symmetric or synchronous transformation. For example,
+// a zlib stream might take multiple plain-text writes(), and then
+// emit a single compressed chunk some time in the future.
+//
+// Here's how this works:
+//
+// The Transform stream has all the aspects of the readable and writable
+// stream classes. When you write(chunk), that calls _write(chunk,cb)
+// internally, and returns false if there's a lot of pending writes
+// buffered up. When you call read(), that calls _read(n) until
+// there's enough pending readable data buffered up.
+//
+// In a transform stream, the written data is placed in a buffer. When
+// _read(n) is called, it transforms the queued up data, calling the
+// buffered _write cb's as it consumes chunks. If consuming a single
+// written chunk would result in multiple output chunks, then the first
+// outputted bit calls the readcb, and subsequent chunks just go into
+// the read buffer, and will cause it to emit 'readable' if necessary.
+//
+// This way, back-pressure is actually determined by the reading side,
+// since _read has to be called to start processing a new chunk. However,
+// a pathological inflate type of transform can cause excessive buffering
+// here. For example, imagine a stream where every byte of input is
+// interpreted as an integer from 0-255, and then results in that many
+// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
+// 1kb of data being output. In this case, you could write a very small
+// amount of input, and end up with a very large amount of output. In
+// such a pathological inflating mechanism, there'd be no way to tell
+// the system to stop doing the transform. A single 4MB write could
+// cause the system to run out of memory.
+//
+// However, even in such a pathological case, only a single written chunk
+// would be consumed, and then the rest would wait (un-transformed) until
+// the results of the previous transformed chunk were consumed.
+
+'use strict';
+
+module.exports = Transform;
+
+var Duplex = require('./_stream_duplex');
+
+/*<replacement>*/
+var util = require('core-util-is');
+util.inherits = require('inherits');
+/*</replacement>*/
+
+util.inherits(Transform, Duplex);
+
+function TransformState(stream) {
+ this.afterTransform = function (er, data) {
+ return afterTransform(stream, er, data);
+ };
+
+ this.needTransform = false;
+ this.transforming = false;
+ this.writecb = null;
+ this.writechunk = null;
+ this.writeencoding = null;
+}
+
+function afterTransform(stream, er, data) {
+ var ts = stream._transformState;
+ ts.transforming = false;
+
+ var cb = ts.writecb;
+
+ if (!cb) {
+ return stream.emit('error', new Error('write callback called multiple times'));
+ }
+
+ ts.writechunk = null;
+ ts.writecb = null;
+
+ if (data !== null && data !== undefined) stream.push(data);
+
+ cb(er);
+
+ var rs = stream._readableState;
+ rs.reading = false;
+ if (rs.needReadable || rs.length < rs.highWaterMark) {
+ stream._read(rs.highWaterMark);
+ }
+}
+
+function Transform(options) {
+ if (!(this instanceof Transform)) return new Transform(options);
+
+ Duplex.call(this, options);
+
+ this._transformState = new TransformState(this);
+
+ var stream = this;
+
+ // start out asking for a readable event once data is transformed.
+ this._readableState.needReadable = true;
+
+ // we have implemented the _read method, and done the other things
+ // that Readable wants before the first _read call, so unset the
+ // sync guard flag.
+ this._readableState.sync = false;
+
+ if (options) {
+ if (typeof options.transform === 'function') this._transform = options.transform;
+
+ if (typeof options.flush === 'function') this._flush = options.flush;
+ }
+
+ // When the writable side finishes, then flush out anything remaining.
+ this.once('prefinish', function () {
+ if (typeof this._flush === 'function') this._flush(function (er, data) {
+ done(stream, er, data);
+ });else done(stream);
+ });
+}
+
+Transform.prototype.push = function (chunk, encoding) {
+ this._transformState.needTransform = false;
+ return Duplex.prototype.push.call(this, chunk, encoding);
+};
+
+// This is the part where you do stuff!
+// override this function in implementation classes.
+// 'chunk' is an input chunk.
+//
+// Call `push(newChunk)` to pass along transformed output
+// to the readable side. You may call 'push' zero or more times.
+//
+// Call `cb(err)` when you are done with this chunk. If you pass
+// an error, then that'll put the hurt on the whole operation. If you
+// never call cb(), then you'll never get another chunk.
+Transform.prototype._transform = function (chunk, encoding, cb) {
+ throw new Error('_transform() is not implemented');
+};
+
+Transform.prototype._write = function (chunk, encoding, cb) {
+ var ts = this._transformState;
+ ts.writecb = cb;
+ ts.writechunk = chunk;
+ ts.writeencoding = encoding;
+ if (!ts.transforming) {
+ var rs = this._readableState;
+ if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
+ }
+};
+
+// Doesn't matter what the args are here.
+// _transform does all the work.
+// That we got here means that the readable side wants more data.
+Transform.prototype._read = function (n) {
+ var ts = this._transformState;
+
+ if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
+ ts.transforming = true;
+ this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
+ } else {
+ // mark that we need a transform, so that any data that comes in
+ // will get processed, now that we've asked for it.
+ ts.needTransform = true;
+ }
+};
+
+Transform.prototype._destroy = function (err, cb) {
+ var _this = this;
+
+ Duplex.prototype._destroy.call(this, err, function (err2) {
+ cb(err2);
+ _this.emit('close');
+ });
+};
+
+function done(stream, er, data) {
+ if (er) return stream.emit('error', er);
+
+ if (data !== null && data !== undefined) stream.push(data);
+
+ // if there's nothing in the write buffer, then that means
+ // that nothing more will ever be provided
+ var ws = stream._writableState;
+ var ts = stream._transformState;
+
+ if (ws.length) throw new Error('Calling transform done when ws.length != 0');
+
+ if (ts.transforming) throw new Error('Calling transform done when still transforming');
+
+ return stream.push(null);
+}
+},{"./_stream_duplex":57,"core-util-is":41,"inherits":49}],61:[function(require,module,exports){
+(function (process,global){
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// A bit simpler than readable streams.
+// Implement an async ._write(chunk, encoding, cb), and it'll handle all
+// the drain event emission and buffering.
+
+'use strict';
+
+/*<replacement>*/
+
+var processNextTick = require('process-nextick-args');
+/*</replacement>*/
+
+module.exports = Writable;
+
+/* <replacement> */
+function WriteReq(chunk, encoding, cb) {
+ this.chunk = chunk;
+ this.encoding = encoding;
+ this.callback = cb;
+ this.next = null;
+}
+
+// It seems a linked list but it is not
+// there will be only 2 of these for each stream
+function CorkedRequest(state) {
+ var _this = this;
+
+ this.next = null;
+ this.entry = null;
+ this.finish = function () {
+ onCorkedFinish(_this, state);
+ };
+}
+/* </replacement> */
+
+/*<replacement>*/
+var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
+/*</replacement>*/
+
+/*<replacement>*/
+var Duplex;
+/*</replacement>*/
+
+Writable.WritableState = WritableState;
+
+/*<replacement>*/
+var util = require('core-util-is');
+util.inherits = require('inherits');
+/*</replacement>*/
+
+/*<replacement>*/
+var internalUtil = {
+ deprecate: require('util-deprecate')
+};
+/*</replacement>*/
+
+/*<replacement>*/
+var Stream = require('./internal/streams/stream');
+/*</replacement>*/
+
+/*<replacement>*/
+var Buffer = require('safe-buffer').Buffer;
+var OurUint8Array = global.Uint8Array || function () {};
+function _uint8ArrayToBuffer(chunk) {
+ return Buffer.from(chunk);
+}
+function _isUint8Array(obj) {
+ return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
+}
+/*</replacement>*/
+
+var destroyImpl = require('./internal/streams/destroy');
+
+util.inherits(Writable, Stream);
+
+function nop() {}
+
+function WritableState(options, stream) {
+ Duplex = Duplex || require('./_stream_duplex');
+
+ options = options || {};
+
+ // object stream flag to indicate whether or not this stream
+ // contains buffers or objects.
+ this.objectMode = !!options.objectMode;
+
+ if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
+
+ // the point at which write() starts returning false
+ // Note: 0 is a valid value, means that we always return false if
+ // the entire buffer is not flushed immediately on write()
+ var hwm = options.highWaterMark;
+ var defaultHwm = this.objectMode ? 16 : 16 * 1024;
+ this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
+
+ // cast to ints.
+ this.highWaterMark = Math.floor(this.highWaterMark);
+
+ // if _final has been called
+ this.finalCalled = false;
+
+ // drain event flag.
+ this.needDrain = false;
+ // at the start of calling end()
+ this.ending = false;
+ // when end() has been called, and returned
+ this.ended = false;
+ // when 'finish' is emitted
+ this.finished = false;
+
+ // has it been destroyed
+ this.destroyed = false;
+
+ // should we decode strings into buffers before passing to _write?
+ // this is here so that some node-core streams can optimize string
+ // handling at a lower level.
+ var noDecode = options.decodeStrings === false;
+ this.decodeStrings = !noDecode;
+
+ // Crypto is kind of old and crusty. Historically, its default string
+ // encoding is 'binary' so we have to make this configurable.
+ // Everything else in the universe uses 'utf8', though.
+ this.defaultEncoding = options.defaultEncoding || 'utf8';
+
+ // not an actual buffer we keep track of, but a measurement
+ // of how much we're waiting to get pushed to some underlying
+ // socket or file.
+ this.length = 0;
+
+ // a flag to see when we're in the middle of a write.
+ this.writing = false;
+
+ // when true all writes will be buffered until .uncork() call
+ this.corked = 0;
+
+ // a flag to be able to tell if the onwrite cb is called immediately,
+ // or on a later tick. We set this to true at first, because any
+ // actions that shouldn't happen until "later" should generally also
+ // not happen before the first write call.
+ this.sync = true;
+
+ // a flag to know if we're processing previously buffered items, which
+ // may call the _write() callback in the same tick, so that we don't
+ // end up in an overlapped onwrite situation.
+ this.bufferProcessing = false;
+
+ // the callback that's passed to _write(chunk,cb)
+ this.onwrite = function (er) {
+ onwrite(stream, er);
+ };
+
+ // the callback that the user supplies to write(chunk,encoding,cb)
+ this.writecb = null;
+
+ // the amount that is being written when _write is called.
+ this.writelen = 0;
+
+ this.bufferedRequest = null;
+ this.lastBufferedRequest = null;
+
+ // number of pending user-supplied write callbacks
+ // this must be 0 before 'finish' can be emitted
+ this.pendingcb = 0;
+
+ // emit prefinish if the only thing we're waiting for is _write cbs
+ // This is relevant for synchronous Transform streams
+ this.prefinished = false;
+
+ // True if the error was already emitted and should not be thrown again
+ this.errorEmitted = false;
+
+ // count buffered requests
+ this.bufferedRequestCount = 0;
+
+ // allocate the first CorkedRequest, there is always
+ // one allocated and free to use, and we maintain at most two
+ this.corkedRequestsFree = new CorkedRequest(this);
+}
+
+WritableState.prototype.getBuffer = function getBuffer() {
+ var current = this.bufferedRequest;
+ var out = [];
+ while (current) {
+ out.push(current);
+ current = current.next;
+ }
+ return out;
+};
+
+(function () {
+ try {
+ Object.defineProperty(WritableState.prototype, 'buffer', {
+ get: internalUtil.deprecate(function () {
+ return this.getBuffer();
+ }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
+ });
+ } catch (_) {}
+})();
+
+// Test _writableState for inheritance to account for Duplex streams,
+// whose prototype chain only points to Readable.
+var realHasInstance;
+if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
+ realHasInstance = Function.prototype[Symbol.hasInstance];
+ Object.defineProperty(Writable, Symbol.hasInstance, {
+ value: function (object) {
+ if (realHasInstance.call(this, object)) return true;
+
+ return object && object._writableState instanceof WritableState;
+ }
+ });
+} else {
+ realHasInstance = function (object) {
+ return object instanceof this;
+ };
+}
+
+function Writable(options) {
+ Duplex = Duplex || require('./_stream_duplex');
+
+ // Writable ctor is applied to Duplexes, too.
+ // `realHasInstance` is necessary because using plain `instanceof`
+ // would return false, as no `_writableState` property is attached.
+
+ // Trying to use the custom `instanceof` for Writable here will also break the
+ // Node.js LazyTransform implementation, which has a non-trivial getter for
+ // `_writableState` that would lead to infinite recursion.
+ if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
+ return new Writable(options);
+ }
+
+ this._writableState = new WritableState(options, this);
+
+ // legacy.
+ this.writable = true;
+
+ if (options) {
+ if (typeof options.write === 'function') this._write = options.write;
+
+ if (typeof options.writev === 'function') this._writev = options.writev;
+
+ if (typeof options.destroy === 'function') this._destroy = options.destroy;
+
+ if (typeof options.final === 'function') this._final = options.final;
+ }
+
+ Stream.call(this);
+}
+
+// Otherwise people can pipe Writable streams, which is just wrong.
+Writable.prototype.pipe = function () {
+ this.emit('error', new Error('Cannot pipe, not readable'));
+};
+
+function writeAfterEnd(stream, cb) {
+ var er = new Error('write after end');
+ // TODO: defer error events consistently everywhere, not just the cb
+ stream.emit('error', er);
+ processNextTick(cb, er);
+}
+
+// Checks that a user-supplied chunk is valid, especially for the particular
+// mode the stream is in. Currently this means that `null` is never accepted
+// and undefined/non-string values are only allowed in object mode.
+function validChunk(stream, state, chunk, cb) {
+ var valid = true;
+ var er = false;
+
+ if (chunk === null) {
+ er = new TypeError('May not write null values to stream');
+ } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
+ er = new TypeError('Invalid non-string/buffer chunk');
+ }
+ if (er) {
+ stream.emit('error', er);
+ processNextTick(cb, er);
+ valid = false;
+ }
+ return valid;
+}
+
+Writable.prototype.write = function (chunk, encoding, cb) {
+ var state = this._writableState;
+ var ret = false;
+ var isBuf = _isUint8Array(chunk) && !state.objectMode;
+
+ if (isBuf && !Buffer.isBuffer(chunk)) {
+ chunk = _uint8ArrayToBuffer(chunk);
+ }
+
+ if (typeof encoding === 'function') {
+ cb = encoding;
+ encoding = null;
+ }
+
+ if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
+
+ if (typeof cb !== 'function') cb = nop;
+
+ if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
+ state.pendingcb++;
+ ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
+ }
+
+ return ret;
+};
+
+Writable.prototype.cork = function () {
+ var state = this._writableState;
+
+ state.corked++;
+};
+
+Writable.prototype.uncork = function () {
+ var state = this._writableState;
+
+ if (state.corked) {
+ state.corked--;
+
+ if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
+ }
+};
+
+Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
+ // node::ParseEncoding() requires lower case.
+ if (typeof encoding === 'string') encoding = encoding.toLowerCase();
+ if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
+ this._writableState.defaultEncoding = encoding;
+ return this;
+};
+
+function decodeChunk(state, chunk, encoding) {
+ if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
+ chunk = Buffer.from(chunk, encoding);
+ }
+ return chunk;
+}
+
+// if we're already writing something, then just put this
+// in the queue, and wait our turn. Otherwise, call _write
+// If we return false, then we need a drain event, so set that flag.
+function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
+ if (!isBuf) {
+ var newChunk = decodeChunk(state, chunk, encoding);
+ if (chunk !== newChunk) {
+ isBuf = true;
+ encoding = 'buffer';
+ chunk = newChunk;
+ }
+ }
+ var len = state.objectMode ? 1 : chunk.length;
+
+ state.length += len;
+
+ var ret = state.length < state.highWaterMark;
+ // we must ensure that previous needDrain will not be reset to false.
+ if (!ret) state.needDrain = true;
+
+ if (state.writing || state.corked) {
+ var last = state.lastBufferedRequest;
+ state.lastBufferedRequest = {
+ chunk: chunk,
+ encoding: encoding,
+ isBuf: isBuf,
+ callback: cb,
+ next: null
+ };
+ if (last) {
+ last.next = state.lastBufferedRequest;
+ } else {
+ state.bufferedRequest = state.lastBufferedRequest;
+ }
+ state.bufferedRequestCount += 1;
+ } else {
+ doWrite(stream, state, false, len, chunk, encoding, cb);
+ }
+
+ return ret;
+}
+
+function doWrite(stream, state, writev, len, chunk, encoding, cb) {
+ state.writelen = len;
+ state.writecb = cb;
+ state.writing = true;
+ state.sync = true;
+ if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
+ state.sync = false;
+}
+
+function onwriteError(stream, state, sync, er, cb) {
+ --state.pendingcb;
+
+ if (sync) {
+ // defer the callback if we are being called synchronously
+ // to avoid piling up things on the stack
+ processNextTick(cb, er);
+ // this can emit finish, and it will always happen
+ // after error
+ processNextTick(finishMaybe, stream, state);
+ stream._writableState.errorEmitted = true;
+ stream.emit('error', er);
+ } else {
+ // the caller expect this to happen before if
+ // it is async
+ cb(er);
+ stream._writableState.errorEmitted = true;
+ stream.emit('error', er);
+ // this can emit finish, but finish must
+ // always follow error
+ finishMaybe(stream, state);
+ }
+}
+
+function onwriteStateUpdate(state) {
+ state.writing = false;
+ state.writecb = null;
+ state.length -= state.writelen;
+ state.writelen = 0;
+}
+
+function onwrite(stream, er) {
+ var state = stream._writableState;
+ var sync = state.sync;
+ var cb = state.writecb;
+
+ onwriteStateUpdate(state);
+
+ if (er) onwriteError(stream, state, sync, er, cb);else {
+ // Check if we're actually ready to finish, but don't emit yet
+ var finished = needFinish(state);
+
+ if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
+ clearBuffer(stream, state);
+ }
+
+ if (sync) {
+ /*<replacement>*/
+ asyncWrite(afterWrite, stream, state, finished, cb);
+ /*</replacement>*/
+ } else {
+ afterWrite(stream, state, finished, cb);
+ }
+ }
+}
+
+function afterWrite(stream, state, finished, cb) {
+ if (!finished) onwriteDrain(stream, state);
+ state.pendingcb--;
+ cb();
+ finishMaybe(stream, state);
+}
+
+// Must force callback to be called on nextTick, so that we don't
+// emit 'drain' before the write() consumer gets the 'false' return
+// value, and has a chance to attach a 'drain' listener.
+function onwriteDrain(stream, state) {
+ if (state.length === 0 && state.needDrain) {
+ state.needDrain = false;
+ stream.emit('drain');
+ }
+}
+
+// if there's something in the buffer waiting, then process it
+function clearBuffer(stream, state) {
+ state.bufferProcessing = true;
+ var entry = state.bufferedRequest;
+
+ if (stream._writev && entry && entry.next) {
+ // Fast case, write everything using _writev()
+ var l = state.bufferedRequestCount;
+ var buffer = new Array(l);
+ var holder = state.corkedRequestsFree;
+ holder.entry = entry;
+
+ var count = 0;
+ var allBuffers = true;
+ while (entry) {
+ buffer[count] = entry;
+ if (!entry.isBuf) allBuffers = false;
+ entry = entry.next;
+ count += 1;
+ }
+ buffer.allBuffers = allBuffers;
+
+ doWrite(stream, state, true, state.length, buffer, '', holder.finish);
+
+ // doWrite is almost always async, defer these to save a bit of time
+ // as the hot path ends with doWrite
+ state.pendingcb++;
+ state.lastBufferedRequest = null;
+ if (holder.next) {
+ state.corkedRequestsFree = holder.next;
+ holder.next = null;
+ } else {
+ state.corkedRequestsFree = new CorkedRequest(state);
+ }
+ } else {
+ // Slow case, write chunks one-by-one
+ while (entry) {
+ var chunk = entry.chunk;
+ var encoding = entry.encoding;
+ var cb = entry.callback;
+ var len = state.objectMode ? 1 : chunk.length;
+
+ doWrite(stream, state, false, len, chunk, encoding, cb);
+ entry = entry.next;
+ // if we didn't call the onwrite immediately, then
+ // it means that we need to wait until it does.
+ // also, that means that the chunk and cb are currently
+ // being processed, so move the buffer counter past them.
+ if (state.writing) {
+ break;
+ }
+ }
+
+ if (entry === null) state.lastBufferedRequest = null;
+ }
+
+ state.bufferedRequestCount = 0;
+ state.bufferedRequest = entry;
+ state.bufferProcessing = false;
+}
+
+Writable.prototype._write = function (chunk, encoding, cb) {
+ cb(new Error('_write() is not implemented'));
+};
+
+Writable.prototype._writev = null;
+
+Writable.prototype.end = function (chunk, encoding, cb) {
+ var state = this._writableState;
+
+ if (typeof chunk === 'function') {
+ cb = chunk;
+ chunk = null;
+ encoding = null;
+ } else if (typeof encoding === 'function') {
+ cb = encoding;
+ encoding = null;
+ }
+
+ if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
+
+ // .end() fully uncorks
+ if (state.corked) {
+ state.corked = 1;
+ this.uncork();
+ }
+
+ // ignore unnecessary end() calls.
+ if (!state.ending && !state.finished) endWritable(this, state, cb);
+};
+
+function needFinish(state) {
+ return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
+}
+function callFinal(stream, state) {
+ stream._final(function (err) {
+ state.pendingcb--;
+ if (err) {
+ stream.emit('error', err);
+ }
+ state.prefinished = true;
+ stream.emit('prefinish');
+ finishMaybe(stream, state);
+ });
+}
+function prefinish(stream, state) {
+ if (!state.prefinished && !state.finalCalled) {
+ if (typeof stream._final === 'function') {
+ state.pendingcb++;
+ state.finalCalled = true;
+ processNextTick(callFinal, stream, state);
+ } else {
+ state.prefinished = true;
+ stream.emit('prefinish');
+ }
+ }
+}
+
+function finishMaybe(stream, state) {
+ var need = needFinish(state);
+ if (need) {
+ prefinish(stream, state);
+ if (state.pendingcb === 0) {
+ state.finished = true;
+ stream.emit('finish');
+ }
+ }
+ return need;
+}
+
+function endWritable(stream, state, cb) {
+ state.ending = true;
+ finishMaybe(stream, state);
+ if (cb) {
+ if (state.finished) processNextTick(cb);else stream.once('finish', cb);
+ }
+ state.ended = true;
+ stream.writable = false;
+}
+
+function onCorkedFinish(corkReq, state, err) {
+ var entry = corkReq.entry;
+ corkReq.entry = null;
+ while (entry) {
+ var cb = entry.callback;
+ state.pendingcb--;
+ cb(err);
+ entry = entry.next;
+ }
+ if (state.corkedRequestsFree) {
+ state.corkedRequestsFree.next = corkReq;
+ } else {
+ state.corkedRequestsFree = corkReq;
+ }
+}
+
+Object.defineProperty(Writable.prototype, 'destroyed', {
+ get: function () {
+ if (this._writableState === undefined) {
+ return false;
+ }
+ return this._writableState.destroyed;
+ },
+ set: function (value) {
+ // we ignore the value if the stream
+ // has not been initialized yet
+ if (!this._writableState) {
+ return;
+ }
+
+ // backward compatibility, the user is explicitly
+ // managing destroyed
+ this._writableState.destroyed = value;
+ }
+});
+
+Writable.prototype.destroy = destroyImpl.destroy;
+Writable.prototype._undestroy = destroyImpl.undestroy;
+Writable.prototype._destroy = function (err, cb) {
+ this.end();
+ cb(err);
+};
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"./_stream_duplex":57,"./internal/streams/destroy":63,"./internal/streams/stream":64,"_process":55,"core-util-is":41,"inherits":49,"process-nextick-args":54,"safe-buffer":69,"util-deprecate":72}],62:[function(require,module,exports){
+'use strict';
+
+/*<replacement>*/
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+var Buffer = require('safe-buffer').Buffer;
+/*</replacement>*/
+
+function copyBuffer(src, target, offset) {
+ src.copy(target, offset);
+}
+
+module.exports = function () {
+ function BufferList() {
+ _classCallCheck(this, BufferList);
+
+ this.head = null;
+ this.tail = null;
+ this.length = 0;
+ }
+
+ BufferList.prototype.push = function push(v) {
+ var entry = { data: v, next: null };
+ if (this.length > 0) this.tail.next = entry;else this.head = entry;
+ this.tail = entry;
+ ++this.length;
+ };
+
+ BufferList.prototype.unshift = function unshift(v) {
+ var entry = { data: v, next: this.head };
+ if (this.length === 0) this.tail = entry;
+ this.head = entry;
+ ++this.length;
+ };
+
+ BufferList.prototype.shift = function shift() {
+ if (this.length === 0) return;
+ var ret = this.head.data;
+ if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
+ --this.length;
+ return ret;
+ };
+
+ BufferList.prototype.clear = function clear() {
+ this.head = this.tail = null;
+ this.length = 0;
+ };
+
+ BufferList.prototype.join = function join(s) {
+ if (this.length === 0) return '';
+ var p = this.head;
+ var ret = '' + p.data;
+ while (p = p.next) {
+ ret += s + p.data;
+ }return ret;
+ };
+
+ BufferList.prototype.concat = function concat(n) {
+ if (this.length === 0) return Buffer.alloc(0);
+ if (this.length === 1) return this.head.data;
+ var ret = Buffer.allocUnsafe(n >>> 0);
+ var p = this.head;
+ var i = 0;
+ while (p) {
+ copyBuffer(p.data, ret, i);
+ i += p.data.length;
+ p = p.next;
+ }
+ return ret;
+ };
+
+ return BufferList;
+}();
+},{"safe-buffer":69}],63:[function(require,module,exports){
+'use strict';
+
+/*<replacement>*/
+
+var processNextTick = require('process-nextick-args');
+/*</replacement>*/
+
+// undocumented cb() API, needed for core, not for public API
+function destroy(err, cb) {
+ var _this = this;
+
+ var readableDestroyed = this._readableState && this._readableState.destroyed;
+ var writableDestroyed = this._writableState && this._writableState.destroyed;
+
+ if (readableDestroyed || writableDestroyed) {
+ if (cb) {
+ cb(err);
+ } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
+ processNextTick(emitErrorNT, this, err);
+ }
+ return;
+ }
+
+ // we set destroyed to true before firing error callbacks in order
+ // to make it re-entrance safe in case destroy() is called within callbacks
+
+ if (this._readableState) {
+ this._readableState.destroyed = true;
+ }
+
+ // if this is a duplex stream mark the writable part as destroyed as well
+ if (this._writableState) {
+ this._writableState.destroyed = true;
+ }
+
+ this._destroy(err || null, function (err) {
+ if (!cb && err) {
+ processNextTick(emitErrorNT, _this, err);
+ if (_this._writableState) {
+ _this._writableState.errorEmitted = true;
+ }
+ } else if (cb) {
+ cb(err);
+ }
+ });
+}
+
+function undestroy() {
+ if (this._readableState) {
+ this._readableState.destroyed = false;
+ this._readableState.reading = false;
+ this._readableState.ended = false;
+ this._readableState.endEmitted = false;
+ }
+
+ if (this._writableState) {
+ this._writableState.destroyed = false;
+ this._writableState.ended = false;
+ this._writableState.ending = false;
+ this._writableState.finished = false;
+ this._writableState.errorEmitted = false;
+ }
+}
+
+function emitErrorNT(self, err) {
+ self.emit('error', err);
+}
+
+module.exports = {
+ destroy: destroy,
+ undestroy: undestroy
+};
+},{"process-nextick-args":54}],64:[function(require,module,exports){
+module.exports = require('events').EventEmitter;
+
+},{"events":46}],65:[function(require,module,exports){
+module.exports = require('./readable').PassThrough
+
+},{"./readable":66}],66:[function(require,module,exports){
+exports = module.exports = require('./lib/_stream_readable.js');
+exports.Stream = exports;
+exports.Readable = exports;
+exports.Writable = require('./lib/_stream_writable.js');
+exports.Duplex = require('./lib/_stream_duplex.js');
+exports.Transform = require('./lib/_stream_transform.js');
+exports.PassThrough = require('./lib/_stream_passthrough.js');
+
+},{"./lib/_stream_duplex.js":57,"./lib/_stream_passthrough.js":58,"./lib/_stream_readable.js":59,"./lib/_stream_transform.js":60,"./lib/_stream_writable.js":61}],67:[function(require,module,exports){
+module.exports = require('./readable').Transform
+
+},{"./readable":66}],68:[function(require,module,exports){
+module.exports = require('./lib/_stream_writable.js');
+
+},{"./lib/_stream_writable.js":61}],69:[function(require,module,exports){
+/* eslint-disable node/no-deprecated-api */
+var buffer = require('buffer')
+var Buffer = buffer.Buffer
+
+// alternative to using Object.keys for old browsers
+function copyProps (src, dst) {
+ for (var key in src) {
+ dst[key] = src[key]
+ }
+}
+if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
+ module.exports = buffer
+} else {
+ // Copy properties from require('buffer')
+ copyProps(buffer, exports)
+ exports.Buffer = SafeBuffer
+}
+
+function SafeBuffer (arg, encodingOrOffset, length) {
+ return Buffer(arg, encodingOrOffset, length)
+}
+
+// Copy static methods from Buffer
+copyProps(Buffer, SafeBuffer)
+
+SafeBuffer.from = function (arg, encodingOrOffset, length) {
+ if (typeof arg === 'number') {
+ throw new TypeError('Argument must not be a number')
+ }
+ return Buffer(arg, encodingOrOffset, length)
+}
+
+SafeBuffer.alloc = function (size, fill, encoding) {
+ if (typeof size !== 'number') {
+ throw new TypeError('Argument must be a number')
+ }
+ var buf = Buffer(size)
+ if (fill !== undefined) {
+ if (typeof encoding === 'string') {
+ buf.fill(fill, encoding)
+ } else {
+ buf.fill(fill)
+ }
+ } else {
+ buf.fill(0)
+ }
+ return buf
+}
+
+SafeBuffer.allocUnsafe = function (size) {
+ if (typeof size !== 'number') {
+ throw new TypeError('Argument must be a number')
+ }
+ return Buffer(size)
+}
+
+SafeBuffer.allocUnsafeSlow = function (size) {
+ if (typeof size !== 'number') {
+ throw new TypeError('Argument must be a number')
+ }
+ return buffer.SlowBuffer(size)
+}
+
+},{"buffer":"buffer"}],70:[function(require,module,exports){
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+module.exports = Stream;
+
+var EE = require('events').EventEmitter;
+var inherits = require('inherits');
+
+inherits(Stream, EE);
+Stream.Readable = require('readable-stream/readable.js');
+Stream.Writable = require('readable-stream/writable.js');
+Stream.Duplex = require('readable-stream/duplex.js');
+Stream.Transform = require('readable-stream/transform.js');
+Stream.PassThrough = require('readable-stream/passthrough.js');
+
+// Backwards-compat with node 0.4.x
+Stream.Stream = Stream;
+
+
+
+// old-style streams. Note that the pipe method (the only relevant
+// part of this class) is overridden in the Readable class.
+
+function Stream() {
+ EE.call(this);
+}
+
+Stream.prototype.pipe = function(dest, options) {
+ var source = this;
+
+ function ondata(chunk) {
+ if (dest.writable) {
+ if (false === dest.write(chunk) && source.pause) {
+ source.pause();
+ }
+ }
+ }
+
+ source.on('data', ondata);
+
+ function ondrain() {
+ if (source.readable && source.resume) {
+ source.resume();
+ }
+ }
+
+ dest.on('drain', ondrain);
+
+ // If the 'end' option is not supplied, dest.end() will be called when
+ // source gets the 'end' or 'close' events. Only dest.end() once.
+ if (!dest._isStdio && (!options || options.end !== false)) {
+ source.on('end', onend);
+ source.on('close', onclose);
+ }
+
+ var didOnEnd = false;
+ function onend() {
+ if (didOnEnd) return;
+ didOnEnd = true;
+
+ dest.end();
+ }
+
+
+ function onclose() {
+ if (didOnEnd) return;
+ didOnEnd = true;
+
+ if (typeof dest.destroy === 'function') dest.destroy();
+ }
+
+ // don't leave dangling pipes when there are errors.
+ function onerror(er) {
+ cleanup();
+ if (EE.listenerCount(this, 'error') === 0) {
+ throw er; // Unhandled stream error in pipe.
+ }
+ }
+
+ source.on('error', onerror);
+ dest.on('error', onerror);
+
+ // remove all the event listeners that were added.
+ function cleanup() {
+ source.removeListener('data', ondata);
+ dest.removeListener('drain', ondrain);
+
+ source.removeListener('end', onend);
+ source.removeListener('close', onclose);
+
+ source.removeListener('error', onerror);
+ dest.removeListener('error', onerror);
+
+ source.removeListener('end', cleanup);
+ source.removeListener('close', cleanup);
+
+ dest.removeListener('close', cleanup);
+ }
+
+ source.on('end', cleanup);
+ source.on('close', cleanup);
+
+ dest.on('close', cleanup);
+
+ dest.emit('pipe', source);
+
+ // Allow for unix-like usage: A.pipe(B).pipe(C)
+ return dest;
+};
+
+},{"events":46,"inherits":49,"readable-stream/duplex.js":56,"readable-stream/passthrough.js":65,"readable-stream/readable.js":66,"readable-stream/transform.js":67,"readable-stream/writable.js":68}],71:[function(require,module,exports){
+'use strict';
+
+var Buffer = require('safe-buffer').Buffer;
+
+var isEncoding = Buffer.isEncoding || function (encoding) {
+ encoding = '' + encoding;
+ switch (encoding && encoding.toLowerCase()) {
+ case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
+ return true;
+ default:
+ return false;
+ }
+};
+
+function _normalizeEncoding(enc) {
+ if (!enc) return 'utf8';
+ var retried;
+ while (true) {
+ switch (enc) {
+ case 'utf8':
+ case 'utf-8':
+ return 'utf8';
+ case 'ucs2':
+ case 'ucs-2':
+ case 'utf16le':
+ case 'utf-16le':
+ return 'utf16le';
+ case 'latin1':
+ case 'binary':
+ return 'latin1';
+ case 'base64':
+ case 'ascii':
+ case 'hex':
+ return enc;
+ default:
+ if (retried) return; // undefined
+ enc = ('' + enc).toLowerCase();
+ retried = true;
+ }
+ }
+};
+
+// Do not cache `Buffer.isEncoding` when checking encoding names as some
+// modules monkey-patch it to support additional encodings
+function normalizeEncoding(enc) {
+ var nenc = _normalizeEncoding(enc);
+ if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
+ return nenc || enc;
+}
+
+// StringDecoder provides an interface for efficiently splitting a series of
+// buffers into a series of JS strings without breaking apart multi-byte
+// characters.
+exports.StringDecoder = StringDecoder;
+function StringDecoder(encoding) {
+ this.encoding = normalizeEncoding(encoding);
+ var nb;
+ switch (this.encoding) {
+ case 'utf16le':
+ this.text = utf16Text;
+ this.end = utf16End;
+ nb = 4;
+ break;
+ case 'utf8':
+ this.fillLast = utf8FillLast;
+ nb = 4;
+ break;
+ case 'base64':
+ this.text = base64Text;
+ this.end = base64End;
+ nb = 3;
+ break;
+ default:
+ this.write = simpleWrite;
+ this.end = simpleEnd;
+ return;
+ }
+ this.lastNeed = 0;
+ this.lastTotal = 0;
+ this.lastChar = Buffer.allocUnsafe(nb);
+}
+
+StringDecoder.prototype.write = function (buf) {
+ if (buf.length === 0) return '';
+ var r;
+ var i;
+ if (this.lastNeed) {
+ r = this.fillLast(buf);
+ if (r === undefined) return '';
+ i = this.lastNeed;
+ this.lastNeed = 0;
+ } else {
+ i = 0;
+ }
+ if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
+ return r || '';
+};
+
+StringDecoder.prototype.end = utf8End;
+
+// Returns only complete characters in a Buffer
+StringDecoder.prototype.text = utf8Text;
+
+// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
+StringDecoder.prototype.fillLast = function (buf) {
+ if (this.lastNeed <= buf.length) {
+ buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
+ }
+ buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
+ this.lastNeed -= buf.length;
+};
+
+// Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
+// continuation byte.
+function utf8CheckByte(byte) {
+ if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
+ return -1;
+}
+
+// Checks at most 3 bytes at the end of a Buffer in order to detect an
+// incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
+// needed to complete the UTF-8 character (if applicable) are returned.
+function utf8CheckIncomplete(self, buf, i) {
+ var j = buf.length - 1;
+ if (j < i) return 0;
+ var nb = utf8CheckByte(buf[j]);
+ if (nb >= 0) {
+ if (nb > 0) self.lastNeed = nb - 1;
+ return nb;
+ }
+ if (--j < i) return 0;
+ nb = utf8CheckByte(buf[j]);
+ if (nb >= 0) {
+ if (nb > 0) self.lastNeed = nb - 2;
+ return nb;
+ }
+ if (--j < i) return 0;
+ nb = utf8CheckByte(buf[j]);
+ if (nb >= 0) {
+ if (nb > 0) {
+ if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
+ }
+ return nb;
+ }
+ return 0;
+}
+
+// Validates as many continuation bytes for a multi-byte UTF-8 character as
+// needed or are available. If we see a non-continuation byte where we expect
+// one, we "replace" the validated continuation bytes we've seen so far with
+// UTF-8 replacement characters ('\ufffd'), to match v8's UTF-8 decoding
+// behavior. The continuation byte check is included three times in the case
+// where all of the continuation bytes for a character exist in the same buffer.
+// It is also done this way as a slight performance increase instead of using a
+// loop.
+function utf8CheckExtraBytes(self, buf, p) {
+ if ((buf[0] & 0xC0) !== 0x80) {
+ self.lastNeed = 0;
+ return '\ufffd'.repeat(p);
+ }
+ if (self.lastNeed > 1 && buf.length > 1) {
+ if ((buf[1] & 0xC0) !== 0x80) {
+ self.lastNeed = 1;
+ return '\ufffd'.repeat(p + 1);
+ }
+ if (self.lastNeed > 2 && buf.length > 2) {
+ if ((buf[2] & 0xC0) !== 0x80) {
+ self.lastNeed = 2;
+ return '\ufffd'.repeat(p + 2);
+ }
+ }
+ }
+}
+
+// Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
+function utf8FillLast(buf) {
+ var p = this.lastTotal - this.lastNeed;
+ var r = utf8CheckExtraBytes(this, buf, p);
+ if (r !== undefined) return r;
+ if (this.lastNeed <= buf.length) {
+ buf.copy(this.lastChar, p, 0, this.lastNeed);
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
+ }
+ buf.copy(this.lastChar, p, 0, buf.length);
+ this.lastNeed -= buf.length;
+}
+
+// Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
+// partial character, the character's bytes are buffered until the required
+// number of bytes are available.
+function utf8Text(buf, i) {
+ var total = utf8CheckIncomplete(this, buf, i);
+ if (!this.lastNeed) return buf.toString('utf8', i);
+ this.lastTotal = total;
+ var end = buf.length - (total - this.lastNeed);
+ buf.copy(this.lastChar, 0, end);
+ return buf.toString('utf8', i, end);
+}
+
+// For UTF-8, a replacement character for each buffered byte of a (partial)
+// character needs to be added to the output.
+function utf8End(buf) {
+ var r = buf && buf.length ? this.write(buf) : '';
+ if (this.lastNeed) return r + '\ufffd'.repeat(this.lastTotal - this.lastNeed);
+ return r;
+}
+
+// UTF-16LE typically needs two bytes per character, but even if we have an even
+// number of bytes available, we need to check if we end on a leading/high
+// surrogate. In that case, we need to wait for the next two bytes in order to
+// decode the last character properly.
+function utf16Text(buf, i) {
+ if ((buf.length - i) % 2 === 0) {
+ var r = buf.toString('utf16le', i);
+ if (r) {
+ var c = r.charCodeAt(r.length - 1);
+ if (c >= 0xD800 && c <= 0xDBFF) {
+ this.lastNeed = 2;
+ this.lastTotal = 4;
+ this.lastChar[0] = buf[buf.length - 2];
+ this.lastChar[1] = buf[buf.length - 1];
+ return r.slice(0, -1);
+ }
+ }
+ return r;
+ }
+ this.lastNeed = 1;
+ this.lastTotal = 2;
+ this.lastChar[0] = buf[buf.length - 1];
+ return buf.toString('utf16le', i, buf.length - 1);
+}
+
+// For UTF-16LE we do not explicitly append special replacement characters if we
+// end on a partial character, we simply let v8 handle that.
+function utf16End(buf) {
+ var r = buf && buf.length ? this.write(buf) : '';
+ if (this.lastNeed) {
+ var end = this.lastTotal - this.lastNeed;
+ return r + this.lastChar.toString('utf16le', 0, end);
+ }
+ return r;
+}
+
+function base64Text(buf, i) {
+ var n = (buf.length - i) % 3;
+ if (n === 0) return buf.toString('base64', i);
+ this.lastNeed = 3 - n;
+ this.lastTotal = 3;
+ if (n === 1) {
+ this.lastChar[0] = buf[buf.length - 1];
+ } else {
+ this.lastChar[0] = buf[buf.length - 2];
+ this.lastChar[1] = buf[buf.length - 1];
+ }
+ return buf.toString('base64', i, buf.length - n);
+}
+
+function base64End(buf) {
+ var r = buf && buf.length ? this.write(buf) : '';
+ if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
+ return r;
+}
+
+// Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
+function simpleWrite(buf) {
+ return buf.toString(this.encoding);
+}
+
+function simpleEnd(buf) {
+ return buf && buf.length ? this.write(buf) : '';
+}
+},{"safe-buffer":69}],72:[function(require,module,exports){
+(function (global){
+
+/**
+ * Module exports.
+ */
+
+module.exports = deprecate;
+
+/**
+ * Mark that a method should not be used.
+ * Returns a modified function which warns once by default.
+ *
+ * If `localStorage.noDeprecation = true` is set, then it is a no-op.
+ *
+ * If `localStorage.throwDeprecation = true` is set, then deprecated functions
+ * will throw an Error when invoked.
+ *
+ * If `localStorage.traceDeprecation = true` is set, then deprecated functions
+ * will invoke `console.trace()` instead of `console.error()`.
+ *
+ * @param {Function} fn - the function to deprecate
+ * @param {String} msg - the string to print to the console when `fn` is invoked
+ * @returns {Function} a new "deprecated" version of `fn`
+ * @api public
+ */
+
+function deprecate (fn, msg) {
+ if (config('noDeprecation')) {
+ return fn;
+ }
+
+ var warned = false;
+ function deprecated() {
+ if (!warned) {
+ if (config('throwDeprecation')) {
+ throw new Error(msg);
+ } else if (config('traceDeprecation')) {
+ console.trace(msg);
+ } else {
+ console.warn(msg);
+ }
+ warned = true;
+ }
+ return fn.apply(this, arguments);
+ }
+
+ return deprecated;
+}
+
+/**
+ * Checks `localStorage` for boolean values for the given `name`.
+ *
+ * @param {String} name
+ * @returns {Boolean}
+ * @api private
+ */
+
+function config (name) {
+ // accessing global.localStorage can trigger a DOMException in sandboxed iframes
+ try {
+ if (!global.localStorage) return false;
+ } catch (_) {
+ return false;
+ }
+ var val = global.localStorage[name];
+ if (null == val) return false;
+ return String(val).toLowerCase() === 'true';
+}
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{}],73:[function(require,module,exports){
+arguments[4][49][0].apply(exports,arguments)
+},{"dup":49}],74:[function(require,module,exports){
+module.exports = function isBuffer(arg) {
+ return arg && typeof arg === 'object'
+ && typeof arg.copy === 'function'
+ && typeof arg.fill === 'function'
+ && typeof arg.readUInt8 === 'function';
+}
+},{}],75:[function(require,module,exports){
+(function (process,global){
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var formatRegExp = /%[sdj%]/g;
+exports.format = function(f) {
+ if (!isString(f)) {
+ var objects = [];
+ for (var i = 0; i < arguments.length; i++) {
+ objects.push(inspect(arguments[i]));
+ }
+ return objects.join(' ');
+ }
+
+ var i = 1;
+ var args = arguments;
+ var len = args.length;
+ var str = String(f).replace(formatRegExp, function(x) {
+ if (x === '%%') return '%';
+ if (i >= len) return x;
+ switch (x) {
+ case '%s': return String(args[i++]);
+ case '%d': return Number(args[i++]);
+ case '%j':
+ try {
+ return JSON.stringify(args[i++]);
+ } catch (_) {
+ return '[Circular]';
+ }
+ default:
+ return x;
+ }
+ });
+ for (var x = args[i]; i < len; x = args[++i]) {
+ if (isNull(x) || !isObject(x)) {
+ str += ' ' + x;
+ } else {
+ str += ' ' + inspect(x);
+ }
+ }
+ return str;
+};
+
+
+// Mark that a method should not be used.
+// Returns a modified function which warns once by default.
+// If --no-deprecation is set, then it is a no-op.
+exports.deprecate = function(fn, msg) {
+ // Allow for deprecating things in the process of starting up.
+ if (isUndefined(global.process)) {
+ return function() {
+ return exports.deprecate(fn, msg).apply(this, arguments);
+ };
+ }
+
+ if (process.noDeprecation === true) {
+ return fn;
+ }
+
+ var warned = false;
+ function deprecated() {
+ if (!warned) {
+ if (process.throwDeprecation) {
+ throw new Error(msg);
+ } else if (process.traceDeprecation) {
+ console.trace(msg);
+ } else {
+ console.error(msg);
+ }
+ warned = true;
+ }
+ return fn.apply(this, arguments);
+ }
+
+ return deprecated;
+};
+
+
+var debugs = {};
+var debugEnviron;
+exports.debuglog = function(set) {
+ if (isUndefined(debugEnviron))
+ debugEnviron = process.env.NODE_DEBUG || '';
+ set = set.toUpperCase();
+ if (!debugs[set]) {
+ if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
+ var pid = process.pid;
+ debugs[set] = function() {
+ var msg = exports.format.apply(exports, arguments);
+ console.error('%s %d: %s', set, pid, msg);
+ };
+ } else {
+ debugs[set] = function() {};
+ }
+ }
+ return debugs[set];
+};
+
+
+/**
+ * Echos the value of a value. Trys to print the value out
+ * in the best way possible given the different types.
+ *
+ * @param {Object} obj The object to print out.
+ * @param {Object} opts Optional options object that alters the output.
+ */
+/* legacy: obj, showHidden, depth, colors*/
+function inspect(obj, opts) {
+ // default options
+ var ctx = {
+ seen: [],
+ stylize: stylizeNoColor
+ };
+ // legacy...
+ if (arguments.length >= 3) ctx.depth = arguments[2];
+ if (arguments.length >= 4) ctx.colors = arguments[3];
+ if (isBoolean(opts)) {
+ // legacy...
+ ctx.showHidden = opts;
+ } else if (opts) {
+ // got an "options" object
+ exports._extend(ctx, opts);
+ }
+ // set default options
+ if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
+ if (isUndefined(ctx.depth)) ctx.depth = 2;
+ if (isUndefined(ctx.colors)) ctx.colors = false;
+ if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
+ if (ctx.colors) ctx.stylize = stylizeWithColor;
+ return formatValue(ctx, obj, ctx.depth);
+}
+exports.inspect = inspect;
+
+
+// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
+inspect.colors = {
+ 'bold' : [1, 22],
+ 'italic' : [3, 23],
+ 'underline' : [4, 24],
+ 'inverse' : [7, 27],
+ 'white' : [37, 39],
+ 'grey' : [90, 39],
+ 'black' : [30, 39],
+ 'blue' : [34, 39],
+ 'cyan' : [36, 39],
+ 'green' : [32, 39],
+ 'magenta' : [35, 39],
+ 'red' : [31, 39],
+ 'yellow' : [33, 39]
+};
+
+// Don't use 'blue' not visible on cmd.exe
+inspect.styles = {
+ 'special': 'cyan',
+ 'number': 'yellow',
+ 'boolean': 'yellow',
+ 'undefined': 'grey',
+ 'null': 'bold',
+ 'string': 'green',
+ 'date': 'magenta',
+ // "name": intentionally not styling
+ 'regexp': 'red'
+};
+
+
+function stylizeWithColor(str, styleType) {
+ var style = inspect.styles[styleType];
+
+ if (style) {
+ return '\u001b[' + inspect.colors[style][0] + 'm' + str +
+ '\u001b[' + inspect.colors[style][1] + 'm';
+ } else {
+ return str;
+ }
+}
+
+
+function stylizeNoColor(str, styleType) {
+ return str;
+}
+
+
+function arrayToHash(array) {
+ var hash = {};
+
+ array.forEach(function(val, idx) {
+ hash[val] = true;
+ });
+
+ return hash;
+}
+
+
+function formatValue(ctx, value, recurseTimes) {
+ // Provide a hook for user-specified inspect functions.
+ // Check that value is an object with an inspect function on it
+ if (ctx.customInspect &&
+ value &&
+ isFunction(value.inspect) &&
+ // Filter out the util module, it's inspect function is special
+ value.inspect !== exports.inspect &&
+ // Also filter out any prototype objects using the circular check.
+ !(value.constructor && value.constructor.prototype === value)) {
+ var ret = value.inspect(recurseTimes, ctx);
+ if (!isString(ret)) {
+ ret = formatValue(ctx, ret, recurseTimes);
+ }
+ return ret;
+ }
+
+ // Primitive types cannot have properties
+ var primitive = formatPrimitive(ctx, value);
+ if (primitive) {
+ return primitive;
+ }
+
+ // Look up the keys of the object.
+ var keys = Object.keys(value);
+ var visibleKeys = arrayToHash(keys);
+
+ if (ctx.showHidden) {
+ keys = Object.getOwnPropertyNames(value);
+ }
+
+ // IE doesn't make error fields non-enumerable
+ // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
+ if (isError(value)
+ && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
+ return formatError(value);
+ }
+
+ // Some type of object without properties can be shortcutted.
+ if (keys.length === 0) {
+ if (isFunction(value)) {
+ var name = value.name ? ': ' + value.name : '';
+ return ctx.stylize('[Function' + name + ']', 'special');
+ }
+ if (isRegExp(value)) {
+ return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
+ }
+ if (isDate(value)) {
+ return ctx.stylize(Date.prototype.toString.call(value), 'date');
+ }
+ if (isError(value)) {
+ return formatError(value);
+ }
+ }
+
+ var base = '', array = false, braces = ['{', '}'];
+
+ // Make Array say that they are Array
+ if (isArray(value)) {
+ array = true;
+ braces = ['[', ']'];
+ }
+
+ // Make functions say that they are functions
+ if (isFunction(value)) {
+ var n = value.name ? ': ' + value.name : '';
+ base = ' [Function' + n + ']';
+ }
+
+ // Make RegExps say that they are RegExps
+ if (isRegExp(value)) {
+ base = ' ' + RegExp.prototype.toString.call(value);
+ }
+
+ // Make dates with properties first say the date
+ if (isDate(value)) {
+ base = ' ' + Date.prototype.toUTCString.call(value);
+ }
+
+ // Make error with message first say the error
+ if (isError(value)) {
+ base = ' ' + formatError(value);
+ }
+
+ if (keys.length === 0 && (!array || value.length == 0)) {
+ return braces[0] + base + braces[1];
+ }
+
+ if (recurseTimes < 0) {
+ if (isRegExp(value)) {
+ return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
+ } else {
+ return ctx.stylize('[Object]', 'special');
+ }
+ }
+
+ ctx.seen.push(value);
+
+ var output;
+ if (array) {
+ output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
+ } else {
+ output = keys.map(function(key) {
+ return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
+ });
+ }
+
+ ctx.seen.pop();
+
+ return reduceToSingleString(output, base, braces);
+}
+
+
+function formatPrimitive(ctx, value) {
+ if (isUndefined(value))
+ return ctx.stylize('undefined', 'undefined');
+ if (isString(value)) {
+ var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
+ .replace(/'/g, "\\'")
+ .replace(/\\"/g, '"') + '\'';
+ return ctx.stylize(simple, 'string');
+ }
+ if (isNumber(value))
+ return ctx.stylize('' + value, 'number');
+ if (isBoolean(value))
+ return ctx.stylize('' + value, 'boolean');
+ // For some reason typeof null is "object", so special case here.
+ if (isNull(value))
+ return ctx.stylize('null', 'null');
+}
+
+
+function formatError(value) {
+ return '[' + Error.prototype.toString.call(value) + ']';
+}
+
+
+function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
+ var output = [];
+ for (var i = 0, l = value.length; i < l; ++i) {
+ if (hasOwnProperty(value, String(i))) {
+ output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
+ String(i), true));
+ } else {
+ output.push('');
+ }
+ }
+ keys.forEach(function(key) {
+ if (!key.match(/^\d+$/)) {
+ output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
+ key, true));
+ }
+ });
+ return output;
+}
+
+
+function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
+ var name, str, desc;
+ desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
+ if (desc.get) {
+ if (desc.set) {
+ str = ctx.stylize('[Getter/Setter]', 'special');
+ } else {
+ str = ctx.stylize('[Getter]', 'special');
+ }
+ } else {
+ if (desc.set) {
+ str = ctx.stylize('[Setter]', 'special');
+ }
+ }
+ if (!hasOwnProperty(visibleKeys, key)) {
+ name = '[' + key + ']';
+ }
+ if (!str) {
+ if (ctx.seen.indexOf(desc.value) < 0) {
+ if (isNull(recurseTimes)) {
+ str = formatValue(ctx, desc.value, null);
+ } else {
+ str = formatValue(ctx, desc.value, recurseTimes - 1);
+ }
+ if (str.indexOf('\n') > -1) {
+ if (array) {
+ str = str.split('\n').map(function(line) {
+ return ' ' + line;
+ }).join('\n').substr(2);
+ } else {
+ str = '\n' + str.split('\n').map(function(line) {
+ return ' ' + line;
+ }).join('\n');
+ }
+ }
+ } else {
+ str = ctx.stylize('[Circular]', 'special');
+ }
+ }
+ if (isUndefined(name)) {
+ if (array && key.match(/^\d+$/)) {
+ return str;
+ }
+ name = JSON.stringify('' + key);
+ if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
+ name = name.substr(1, name.length - 2);
+ name = ctx.stylize(name, 'name');
+ } else {
+ name = name.replace(/'/g, "\\'")
+ .replace(/\\"/g, '"')
+ .replace(/(^"|"$)/g, "'");
+ name = ctx.stylize(name, 'string');
+ }
+ }
+
+ return name + ': ' + str;
+}
+
+
+function reduceToSingleString(output, base, braces) {
+ var numLinesEst = 0;
+ var length = output.reduce(function(prev, cur) {
+ numLinesEst++;
+ if (cur.indexOf('\n') >= 0) numLinesEst++;
+ return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
+ }, 0);
+
+ if (length > 60) {
+ return braces[0] +
+ (base === '' ? '' : base + '\n ') +
+ ' ' +
+ output.join(',\n ') +
+ ' ' +
+ braces[1];
+ }
+
+ return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
+}
+
+
+// NOTE: These type checking functions intentionally don't use `instanceof`
+// because it is fragile and can be easily faked with `Object.create()`.
+function isArray(ar) {
+ return Array.isArray(ar);
+}
+exports.isArray = isArray;
+
+function isBoolean(arg) {
+ return typeof arg === 'boolean';
+}
+exports.isBoolean = isBoolean;
+
+function isNull(arg) {
+ return arg === null;
+}
+exports.isNull = isNull;
+
+function isNullOrUndefined(arg) {
+ return arg == null;
+}
+exports.isNullOrUndefined = isNullOrUndefined;
+
+function isNumber(arg) {
+ return typeof arg === 'number';
+}
+exports.isNumber = isNumber;
+
+function isString(arg) {
+ return typeof arg === 'string';
+}
+exports.isString = isString;
+
+function isSymbol(arg) {
+ return typeof arg === 'symbol';
+}
+exports.isSymbol = isSymbol;
+
+function isUndefined(arg) {
+ return arg === void 0;
+}
+exports.isUndefined = isUndefined;
+
+function isRegExp(re) {
+ return isObject(re) && objectToString(re) === '[object RegExp]';
+}
+exports.isRegExp = isRegExp;
+
+function isObject(arg) {
+ return typeof arg === 'object' && arg !== null;
+}
+exports.isObject = isObject;
+
+function isDate(d) {
+ return isObject(d) && objectToString(d) === '[object Date]';
+}
+exports.isDate = isDate;
+
+function isError(e) {
+ return isObject(e) &&
+ (objectToString(e) === '[object Error]' || e instanceof Error);
+}
+exports.isError = isError;
+
+function isFunction(arg) {
+ return typeof arg === 'function';
+}
+exports.isFunction = isFunction;
+
+function isPrimitive(arg) {
+ return arg === null ||
+ typeof arg === 'boolean' ||
+ typeof arg === 'number' ||
+ typeof arg === 'string' ||
+ typeof arg === 'symbol' || // ES6 symbol
+ typeof arg === 'undefined';
+}
+exports.isPrimitive = isPrimitive;
+
+exports.isBuffer = require('./support/isBuffer');
+
+function objectToString(o) {
+ return Object.prototype.toString.call(o);
+}
+
+
+function pad(n) {
+ return n < 10 ? '0' + n.toString(10) : n.toString(10);
+}
+
+
+var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
+ 'Oct', 'Nov', 'Dec'];
+
+// 26 Feb 16:19:34
+function timestamp() {
+ var d = new Date();
+ var time = [pad(d.getHours()),
+ pad(d.getMinutes()),
+ pad(d.getSeconds())].join(':');
+ return [d.getDate(), months[d.getMonth()], time].join(' ');
+}
+
+
+// log is just a thin wrapper to console.log that prepends a timestamp
+exports.log = function() {
+ console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
+};
+
+
+/**
+ * Inherit the prototype methods from one constructor into another.
+ *
+ * The Function.prototype.inherits from lang.js rewritten as a standalone
+ * function (not on Function.prototype). NOTE: If this file is to be loaded
+ * during bootstrapping this function needs to be rewritten using some native
+ * functions as prototype setup using normal JavaScript does not work as
+ * expected during bootstrapping (see mirror.js in r114903).
+ *
+ * @param {function} ctor Constructor function which needs to inherit the
+ * prototype.
+ * @param {function} superCtor Constructor function to inherit prototype from.
+ */
+exports.inherits = require('inherits');
+
+exports._extend = function(origin, add) {
+ // Don't do anything if add isn't an object
+ if (!add || !isObject(add)) return origin;
+
+ var keys = Object.keys(add);
+ var i = keys.length;
+ while (i--) {
+ origin[keys[i]] = add[keys[i]];
+ }
+ return origin;
+};
+
+function hasOwnProperty(obj, prop) {
+ return Object.prototype.hasOwnProperty.call(obj, prop);
+}
+
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"./support/isBuffer":74,"_process":55,"inherits":73}],"buffer":[function(require,module,exports){
+(function (global){
+/*!
+ * The buffer module from node.js, for the browser.
+ *
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
+ * @license MIT
+ */
+/* eslint-disable no-proto */
+
+'use strict'
+
+var base64 = require('base64-js')
+var ieee754 = require('ieee754')
+var isArray = require('isarray')
+
+exports.Buffer = Buffer
+exports.SlowBuffer = SlowBuffer
+exports.INSPECT_MAX_BYTES = 50
+
+/**
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
+ * === true Use Uint8Array implementation (fastest)
+ * === false Use Object implementation (most compatible, even IE6)
+ *
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
+ * Opera 11.6+, iOS 4.2+.
+ *
+ * Due to various browser bugs, sometimes the Object implementation will be used even
+ * when the browser supports typed arrays.
+ *
+ * Note:
+ *
+ * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
+ * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
+ *
+ * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
+ *
+ * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
+ * incorrect length in some situations.
+
+ * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
+ * get the Object implementation, which is slower but behaves correctly.
+ */
+Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
+ ? global.TYPED_ARRAY_SUPPORT
+ : typedArraySupport()
+
+/*
+ * Export kMaxLength after typed array support is determined.
+ */
+exports.kMaxLength = kMaxLength()
+
+function typedArraySupport () {
+ try {
+ var arr = new Uint8Array(1)
+ arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
+ return arr.foo() === 42 && // typed array instances can be augmented
+ typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
+ arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
+ } catch (e) {
+ return false
+ }
+}
+
+function kMaxLength () {
+ return Buffer.TYPED_ARRAY_SUPPORT
+ ? 0x7fffffff
+ : 0x3fffffff
+}
+
+function createBuffer (that, length) {
+ if (kMaxLength() < length) {
+ throw new RangeError('Invalid typed array length')
+ }
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ // Return an augmented `Uint8Array` instance, for best performance
+ that = new Uint8Array(length)
+ that.__proto__ = Buffer.prototype
+ } else {
+ // Fallback: Return an object instance of the Buffer class
+ if (that === null) {
+ that = new Buffer(length)
+ }
+ that.length = length
+ }
+
+ return that
+}
+
+/**
+ * The Buffer constructor returns instances of `Uint8Array` that have their
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
+ * returns a single octet.
+ *
+ * The `Uint8Array` prototype remains unmodified.
+ */
+
+function Buffer (arg, encodingOrOffset, length) {
+ if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
+ return new Buffer(arg, encodingOrOffset, length)
+ }
+
+ // Common case.
+ if (typeof arg === 'number') {
+ if (typeof encodingOrOffset === 'string') {
+ throw new Error(
+ 'If encoding is specified then the first argument must be a string'
+ )
+ }
+ return allocUnsafe(this, arg)
+ }
+ return from(this, arg, encodingOrOffset, length)
+}
+
+Buffer.poolSize = 8192 // not used by this implementation
+
+// TODO: Legacy, not needed anymore. Remove in next major version.
+Buffer._augment = function (arr) {
+ arr.__proto__ = Buffer.prototype
+ return arr
+}
+
+function from (that, value, encodingOrOffset, length) {
+ if (typeof value === 'number') {
+ throw new TypeError('"value" argument must not be a number')
+ }
+
+ if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
+ return fromArrayBuffer(that, value, encodingOrOffset, length)
+ }
+
+ if (typeof value === 'string') {
+ return fromString(that, value, encodingOrOffset)
+ }
+
+ return fromObject(that, value)
+}
+
+/**
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
+ * if value is a number.
+ * Buffer.from(str[, encoding])
+ * Buffer.from(array)
+ * Buffer.from(buffer)
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
+ **/
+Buffer.from = function (value, encodingOrOffset, length) {
+ return from(null, value, encodingOrOffset, length)
+}
+
+if (Buffer.TYPED_ARRAY_SUPPORT) {
+ Buffer.prototype.__proto__ = Uint8Array.prototype
+ Buffer.__proto__ = Uint8Array
+ if (typeof Symbol !== 'undefined' && Symbol.species &&
+ Buffer[Symbol.species] === Buffer) {
+ // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
+ Object.defineProperty(Buffer, Symbol.species, {
+ value: null,
+ configurable: true
+ })
+ }
+}
+
+function assertSize (size) {
+ if (typeof size !== 'number') {
+ throw new TypeError('"size" argument must be a number')
+ } else if (size < 0) {
+ throw new RangeError('"size" argument must not be negative')
+ }
+}
+
+function alloc (that, size, fill, encoding) {
+ assertSize(size)
+ if (size <= 0) {
+ return createBuffer(that, size)
+ }
+ if (fill !== undefined) {
+ // Only pay attention to encoding if it's a string. This
+ // prevents accidentally sending in a number that would
+ // be interpretted as a start offset.
+ return typeof encoding === 'string'
+ ? createBuffer(that, size).fill(fill, encoding)
+ : createBuffer(that, size).fill(fill)
+ }
+ return createBuffer(that, size)
+}
+
+/**
+ * Creates a new filled Buffer instance.
+ * alloc(size[, fill[, encoding]])
+ **/
+Buffer.alloc = function (size, fill, encoding) {
+ return alloc(null, size, fill, encoding)
+}
+
+function allocUnsafe (that, size) {
+ assertSize(size)
+ that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
+ if (!Buffer.TYPED_ARRAY_SUPPORT) {
+ for (var i = 0; i < size; ++i) {
+ that[i] = 0
+ }
+ }
+ return that
+}
+
+/**
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
+ * */
+Buffer.allocUnsafe = function (size) {
+ return allocUnsafe(null, size)
+}
+/**
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
+ */
+Buffer.allocUnsafeSlow = function (size) {
+ return allocUnsafe(null, size)
+}
+
+function fromString (that, string, encoding) {
+ if (typeof encoding !== 'string' || encoding === '') {
+ encoding = 'utf8'
+ }
+
+ if (!Buffer.isEncoding(encoding)) {
+ throw new TypeError('"encoding" must be a valid string encoding')
+ }
+
+ var length = byteLength(string, encoding) | 0
+ that = createBuffer(that, length)
+
+ var actual = that.write(string, encoding)
+
+ if (actual !== length) {
+ // Writing a hex string, for example, that contains invalid characters will
+ // cause everything after the first invalid character to be ignored. (e.g.
+ // 'abxxcd' will be treated as 'ab')
+ that = that.slice(0, actual)
+ }
+
+ return that
+}
+
+function fromArrayLike (that, array) {
+ var length = array.length < 0 ? 0 : checked(array.length) | 0
+ that = createBuffer(that, length)
+ for (var i = 0; i < length; i += 1) {
+ that[i] = array[i] & 255
+ }
+ return that
+}
+
+function fromArrayBuffer (that, array, byteOffset, length) {
+ array.byteLength // this throws if `array` is not a valid ArrayBuffer
+
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
+ throw new RangeError('\'offset\' is out of bounds')
+ }
+
+ if (array.byteLength < byteOffset + (length || 0)) {
+ throw new RangeError('\'length\' is out of bounds')
+ }
+
+ if (byteOffset === undefined && length === undefined) {
+ array = new Uint8Array(array)
+ } else if (length === undefined) {
+ array = new Uint8Array(array, byteOffset)
+ } else {
+ array = new Uint8Array(array, byteOffset, length)
+ }
+
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ // Return an augmented `Uint8Array` instance, for best performance
+ that = array
+ that.__proto__ = Buffer.prototype
+ } else {
+ // Fallback: Return an object instance of the Buffer class
+ that = fromArrayLike(that, array)
+ }
+ return that
+}
+
+function fromObject (that, obj) {
+ if (Buffer.isBuffer(obj)) {
+ var len = checked(obj.length) | 0
+ that = createBuffer(that, len)
+
+ if (that.length === 0) {
+ return that
+ }
+
+ obj.copy(that, 0, 0, len)
+ return that
+ }
+
+ if (obj) {
+ if ((typeof ArrayBuffer !== 'undefined' &&
+ obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
+ if (typeof obj.length !== 'number' || isnan(obj.length)) {
+ return createBuffer(that, 0)
+ }
+ return fromArrayLike(that, obj)
+ }
+
+ if (obj.type === 'Buffer' && isArray(obj.data)) {
+ return fromArrayLike(that, obj.data)
+ }
+ }
+
+ throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
+}
+
+function checked (length) {
+ // Note: cannot use `length < kMaxLength()` here because that fails when
+ // length is NaN (which is otherwise coerced to zero.)
+ if (length >= kMaxLength()) {
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
+ 'size: 0x' + kMaxLength().toString(16) + ' bytes')
+ }
+ return length | 0
+}
+
+function SlowBuffer (length) {
+ if (+length != length) { // eslint-disable-line eqeqeq
+ length = 0
+ }
+ return Buffer.alloc(+length)
+}
+
+Buffer.isBuffer = function isBuffer (b) {
+ return !!(b != null && b._isBuffer)
+}
+
+Buffer.compare = function compare (a, b) {
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
+ throw new TypeError('Arguments must be Buffers')
+ }
+
+ if (a === b) return 0
+
+ var x = a.length
+ var y = b.length
+
+ for (var i = 0, len = Math.min(x, y); i < len; ++i) {
+ if (a[i] !== b[i]) {
+ x = a[i]
+ y = b[i]
+ break
+ }
+ }
+
+ if (x < y) return -1
+ if (y < x) return 1
+ return 0
+}
+
+Buffer.isEncoding = function isEncoding (encoding) {
+ switch (String(encoding).toLowerCase()) {
+ case 'hex':
+ case 'utf8':
+ case 'utf-8':
+ case 'ascii':
+ case 'latin1':
+ case 'binary':
+ case 'base64':
+ case 'ucs2':
+ case 'ucs-2':
+ case 'utf16le':
+ case 'utf-16le':
+ return true
+ default:
+ return false
+ }
+}
+
+Buffer.concat = function concat (list, length) {
+ if (!isArray(list)) {
+ throw new TypeError('"list" argument must be an Array of Buffers')
+ }
+
+ if (list.length === 0) {
+ return Buffer.alloc(0)
+ }
+
+ var i
+ if (length === undefined) {
+ length = 0
+ for (i = 0; i < list.length; ++i) {
+ length += list[i].length
+ }
+ }
+
+ var buffer = Buffer.allocUnsafe(length)
+ var pos = 0
+ for (i = 0; i < list.length; ++i) {
+ var buf = list[i]
+ if (!Buffer.isBuffer(buf)) {
+ throw new TypeError('"list" argument must be an Array of Buffers')
+ }
+ buf.copy(buffer, pos)
+ pos += buf.length
+ }
+ return buffer
+}
+
+function byteLength (string, encoding) {
+ if (Buffer.isBuffer(string)) {
+ return string.length
+ }
+ if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
+ (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
+ return string.byteLength
+ }
+ if (typeof string !== 'string') {
+ string = '' + string
+ }
+
+ var len = string.length
+ if (len === 0) return 0
+
+ // Use a for loop to avoid recursion
+ var loweredCase = false
+ for (;;) {
+ switch (encoding) {
+ case 'ascii':
+ case 'latin1':
+ case 'binary':
+ return len
+ case 'utf8':
+ case 'utf-8':
+ case undefined:
+ return utf8ToBytes(string).length
+ case 'ucs2':
+ case 'ucs-2':
+ case 'utf16le':
+ case 'utf-16le':
+ return len * 2
+ case 'hex':
+ return len >>> 1
+ case 'base64':
+ return base64ToBytes(string).length
+ default:
+ if (loweredCase) return utf8ToBytes(string).length // assume utf8
+ encoding = ('' + encoding).toLowerCase()
+ loweredCase = true
+ }
+ }
+}
+Buffer.byteLength = byteLength
+
+function slowToString (encoding, start, end) {
+ var loweredCase = false
+
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
+ // property of a typed array.
+
+ // This behaves neither like String nor Uint8Array in that we set start/end
+ // to their upper/lower bounds if the value passed is out of range.
+ // undefined is handled specially as per ECMA-262 6th Edition,
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
+ if (start === undefined || start < 0) {
+ start = 0
+ }
+ // Return early if start > this.length. Done here to prevent potential uint32
+ // coercion fail below.
+ if (start > this.length) {
+ return ''
+ }
+
+ if (end === undefined || end > this.length) {
+ end = this.length
+ }
+
+ if (end <= 0) {
+ return ''
+ }
+
+ // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
+ end >>>= 0
+ start >>>= 0
+
+ if (end <= start) {
+ return ''
+ }
+
+ if (!encoding) encoding = 'utf8'
+
+ while (true) {
+ switch (encoding) {
+ case 'hex':
+ return hexSlice(this, start, end)
+
+ case 'utf8':
+ case 'utf-8':
+ return utf8Slice(this, start, end)
+
+ case 'ascii':
+ return asciiSlice(this, start, end)
+
+ case 'latin1':
+ case 'binary':
+ return latin1Slice(this, start, end)
+
+ case 'base64':
+ return base64Slice(this, start, end)
+
+ case 'ucs2':
+ case 'ucs-2':
+ case 'utf16le':
+ case 'utf-16le':
+ return utf16leSlice(this, start, end)
+
+ default:
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
+ encoding = (encoding + '').toLowerCase()
+ loweredCase = true
+ }
+ }
+}
+
+// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
+// Buffer instances.
+Buffer.prototype._isBuffer = true
+
+function swap (b, n, m) {
+ var i = b[n]
+ b[n] = b[m]
+ b[m] = i
+}
+
+Buffer.prototype.swap16 = function swap16 () {
+ var len = this.length
+ if (len % 2 !== 0) {
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
+ }
+ for (var i = 0; i < len; i += 2) {
+ swap(this, i, i + 1)
+ }
+ return this
+}
+
+Buffer.prototype.swap32 = function swap32 () {
+ var len = this.length
+ if (len % 4 !== 0) {
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
+ }
+ for (var i = 0; i < len; i += 4) {
+ swap(this, i, i + 3)
+ swap(this, i + 1, i + 2)
+ }
+ return this
+}
+
+Buffer.prototype.swap64 = function swap64 () {
+ var len = this.length
+ if (len % 8 !== 0) {
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
+ }
+ for (var i = 0; i < len; i += 8) {
+ swap(this, i, i + 7)
+ swap(this, i + 1, i + 6)
+ swap(this, i + 2, i + 5)
+ swap(this, i + 3, i + 4)
+ }
+ return this
+}
+
+Buffer.prototype.toString = function toString () {
+ var length = this.length | 0
+ if (length === 0) return ''
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
+ return slowToString.apply(this, arguments)
+}
+
+Buffer.prototype.equals = function equals (b) {
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
+ if (this === b) return true
+ return Buffer.compare(this, b) === 0
+}
+
+Buffer.prototype.inspect = function inspect () {
+ var str = ''
+ var max = exports.INSPECT_MAX_BYTES
+ if (this.length > 0) {
+ str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
+ if (this.length > max) str += ' ... '
+ }
+ return '<Buffer ' + str + '>'
+}
+
+Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
+ if (!Buffer.isBuffer(target)) {
+ throw new TypeError('Argument must be a Buffer')
+ }
+
+ if (start === undefined) {
+ start = 0
+ }
+ if (end === undefined) {
+ end = target ? target.length : 0
+ }
+ if (thisStart === undefined) {
+ thisStart = 0
+ }
+ if (thisEnd === undefined) {
+ thisEnd = this.length
+ }
+
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
+ throw new RangeError('out of range index')
+ }
+
+ if (thisStart >= thisEnd && start >= end) {
+ return 0
+ }
+ if (thisStart >= thisEnd) {
+ return -1
+ }
+ if (start >= end) {
+ return 1
+ }
+
+ start >>>= 0
+ end >>>= 0
+ thisStart >>>= 0
+ thisEnd >>>= 0
+
+ if (this === target) return 0
+
+ var x = thisEnd - thisStart
+ var y = end - start
+ var len = Math.min(x, y)
+
+ var thisCopy = this.slice(thisStart, thisEnd)
+ var targetCopy = target.slice(start, end)
+
+ for (var i = 0; i < len; ++i) {
+ if (thisCopy[i] !== targetCopy[i]) {
+ x = thisCopy[i]
+ y = targetCopy[i]
+ break
+ }
+ }
+
+ if (x < y) return -1
+ if (y < x) return 1
+ return 0
+}
+
+// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
+// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
+//
+// Arguments:
+// - buffer - a Buffer to search
+// - val - a string, Buffer, or number
+// - byteOffset - an index into `buffer`; will be clamped to an int32
+// - encoding - an optional encoding, relevant is val is a string
+// - dir - true for indexOf, false for lastIndexOf
+function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
+ // Empty buffer means no match
+ if (buffer.length === 0) return -1
+
+ // Normalize byteOffset
+ if (typeof byteOffset === 'string') {
+ encoding = byteOffset
+ byteOffset = 0
+ } else if (byteOffset > 0x7fffffff) {
+ byteOffset = 0x7fffffff
+ } else if (byteOffset < -0x80000000) {
+ byteOffset = -0x80000000
+ }
+ byteOffset = +byteOffset // Coerce to Number.
+ if (isNaN(byteOffset)) {
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
+ byteOffset = dir ? 0 : (buffer.length - 1)
+ }
+
+ // Normalize byteOffset: negative offsets start from the end of the buffer
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset
+ if (byteOffset >= buffer.length) {
+ if (dir) return -1
+ else byteOffset = buffer.length - 1
+ } else if (byteOffset < 0) {
+ if (dir) byteOffset = 0
+ else return -1
+ }
+
+ // Normalize val
+ if (typeof val === 'string') {
+ val = Buffer.from(val, encoding)
+ }
+
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
+ if (Buffer.isBuffer(val)) {
+ // Special case: looking for empty string/buffer always fails
+ if (val.length === 0) {
+ return -1
+ }
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
+ } else if (typeof val === 'number') {
+ val = val & 0xFF // Search for a byte value [0-255]
+ if (Buffer.TYPED_ARRAY_SUPPORT &&
+ typeof Uint8Array.prototype.indexOf === 'function') {
+ if (dir) {
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
+ } else {
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
+ }
+ }
+ return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
+ }
+
+ throw new TypeError('val must be string, number or Buffer')
+}
+
+function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
+ var indexSize = 1
+ var arrLength = arr.length
+ var valLength = val.length
+
+ if (encoding !== undefined) {
+ encoding = String(encoding).toLowerCase()
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
+ encoding === 'utf16le' || encoding === 'utf-16le') {
+ if (arr.length < 2 || val.length < 2) {
+ return -1
+ }
+ indexSize = 2
+ arrLength /= 2
+ valLength /= 2
+ byteOffset /= 2
+ }
+ }
+
+ function read (buf, i) {
+ if (indexSize === 1) {
+ return buf[i]
+ } else {
+ return buf.readUInt16BE(i * indexSize)
+ }
+ }
+
+ var i
+ if (dir) {
+ var foundIndex = -1
+ for (i = byteOffset; i < arrLength; i++) {
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
+ if (foundIndex === -1) foundIndex = i
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
+ } else {
+ if (foundIndex !== -1) i -= i - foundIndex
+ foundIndex = -1
+ }
+ }
+ } else {
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
+ for (i = byteOffset; i >= 0; i--) {
+ var found = true
+ for (var j = 0; j < valLength; j++) {
+ if (read(arr, i + j) !== read(val, j)) {
+ found = false
+ break
+ }
+ }
+ if (found) return i
+ }
+ }
+
+ return -1
+}
+
+Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
+ return this.indexOf(val, byteOffset, encoding) !== -1
+}
+
+Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
+}
+
+Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
+}
+
+function hexWrite (buf, string, offset, length) {
+ offset = Number(offset) || 0
+ var remaining = buf.length - offset
+ if (!length) {
+ length = remaining
+ } else {
+ length = Number(length)
+ if (length > remaining) {
+ length = remaining
+ }
+ }
+
+ // must be an even number of digits
+ var strLen = string.length
+ if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
+
+ if (length > strLen / 2) {
+ length = strLen / 2
+ }
+ for (var i = 0; i < length; ++i) {
+ var parsed = parseInt(string.substr(i * 2, 2), 16)
+ if (isNaN(parsed)) return i
+ buf[offset + i] = parsed
+ }
+ return i
+}
+
+function utf8Write (buf, string, offset, length) {
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
+}
+
+function asciiWrite (buf, string, offset, length) {
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
+}
+
+function latin1Write (buf, string, offset, length) {
+ return asciiWrite(buf, string, offset, length)
+}
+
+function base64Write (buf, string, offset, length) {
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
+}
+
+function ucs2Write (buf, string, offset, length) {
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
+}
+
+Buffer.prototype.write = function write (string, offset, length, encoding) {
+ // Buffer#write(string)
+ if (offset === undefined) {
+ encoding = 'utf8'
+ length = this.length
+ offset = 0
+ // Buffer#write(string, encoding)
+ } else if (length === undefined && typeof offset === 'string') {
+ encoding = offset
+ length = this.length
+ offset = 0
+ // Buffer#write(string, offset[, length][, encoding])
+ } else if (isFinite(offset)) {
+ offset = offset | 0
+ if (isFinite(length)) {
+ length = length | 0
+ if (encoding === undefined) encoding = 'utf8'
+ } else {
+ encoding = length
+ length = undefined
+ }
+ // legacy write(string, encoding, offset, length) - remove in v0.13
+ } else {
+ throw new Error(
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
+ )
+ }
+
+ var remaining = this.length - offset
+ if (length === undefined || length > remaining) length = remaining
+
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
+ throw new RangeError('Attempt to write outside buffer bounds')
+ }
+
+ if (!encoding) encoding = 'utf8'
+
+ var loweredCase = false
+ for (;;) {
+ switch (encoding) {
+ case 'hex':
+ return hexWrite(this, string, offset, length)
+
+ case 'utf8':
+ case 'utf-8':
+ return utf8Write(this, string, offset, length)
+
+ case 'ascii':
+ return asciiWrite(this, string, offset, length)
+
+ case 'latin1':
+ case 'binary':
+ return latin1Write(this, string, offset, length)
+
+ case 'base64':
+ // Warning: maxLength not taken into account in base64Write
+ return base64Write(this, string, offset, length)
+
+ case 'ucs2':
+ case 'ucs-2':
+ case 'utf16le':
+ case 'utf-16le':
+ return ucs2Write(this, string, offset, length)
+
+ default:
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
+ encoding = ('' + encoding).toLowerCase()
+ loweredCase = true
+ }
+ }
+}
+
+Buffer.prototype.toJSON = function toJSON () {
+ return {
+ type: 'Buffer',
+ data: Array.prototype.slice.call(this._arr || this, 0)
+ }
+}
+
+function base64Slice (buf, start, end) {
+ if (start === 0 && end === buf.length) {
+ return base64.fromByteArray(buf)
+ } else {
+ return base64.fromByteArray(buf.slice(start, end))
+ }
+}
+
+function utf8Slice (buf, start, end) {
+ end = Math.min(buf.length, end)
+ var res = []
+
+ var i = start
+ while (i < end) {
+ var firstByte = buf[i]
+ var codePoint = null
+ var bytesPerSequence = (firstByte > 0xEF) ? 4
+ : (firstByte > 0xDF) ? 3
+ : (firstByte > 0xBF) ? 2
+ : 1
+
+ if (i + bytesPerSequence <= end) {
+ var secondByte, thirdByte, fourthByte, tempCodePoint
+
+ switch (bytesPerSequence) {
+ case 1:
+ if (firstByte < 0x80) {
+ codePoint = firstByte
+ }
+ break
+ case 2:
+ secondByte = buf[i + 1]
+ if ((secondByte & 0xC0) === 0x80) {
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
+ if (tempCodePoint > 0x7F) {
+ codePoint = tempCodePoint
+ }
+ }
+ break
+ case 3:
+ secondByte = buf[i + 1]
+ thirdByte = buf[i + 2]
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
+ codePoint = tempCodePoint
+ }
+ }
+ break
+ case 4:
+ secondByte = buf[i + 1]
+ thirdByte = buf[i + 2]
+ fourthByte = buf[i + 3]
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
+ codePoint = tempCodePoint
+ }
+ }
+ }
+ }
+
+ if (codePoint === null) {
+ // we did not generate a valid codePoint so insert a
+ // replacement char (U+FFFD) and advance only 1 byte
+ codePoint = 0xFFFD
+ bytesPerSequence = 1
+ } else if (codePoint > 0xFFFF) {
+ // encode to utf16 (surrogate pair dance)
+ codePoint -= 0x10000
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800)
+ codePoint = 0xDC00 | codePoint & 0x3FF
+ }
+
+ res.push(codePoint)
+ i += bytesPerSequence
+ }
+
+ return decodeCodePointsArray(res)
+}
+
+// Based on http://stackoverflow.com/a/22747272/680742, the browser with
+// the lowest limit is Chrome, with 0x10000 args.
+// We go 1 magnitude less, for safety
+var MAX_ARGUMENTS_LENGTH = 0x1000
+
+function decodeCodePointsArray (codePoints) {
+ var len = codePoints.length
+ if (len <= MAX_ARGUMENTS_LENGTH) {
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
+ }
+
+ // Decode in chunks to avoid "call stack size exceeded".
+ var res = ''
+ var i = 0
+ while (i < len) {
+ res += String.fromCharCode.apply(
+ String,
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
+ )
+ }
+ return res
+}
+
+function asciiSlice (buf, start, end) {
+ var ret = ''
+ end = Math.min(buf.length, end)
+
+ for (var i = start; i < end; ++i) {
+ ret += String.fromCharCode(buf[i] & 0x7F)
+ }
+ return ret
+}
+
+function latin1Slice (buf, start, end) {
+ var ret = ''
+ end = Math.min(buf.length, end)
+
+ for (var i = start; i < end; ++i) {
+ ret += String.fromCharCode(buf[i])
+ }
+ return ret
+}
+
+function hexSlice (buf, start, end) {
+ var len = buf.length
+
+ if (!start || start < 0) start = 0
+ if (!end || end < 0 || end > len) end = len
+
+ var out = ''
+ for (var i = start; i < end; ++i) {
+ out += toHex(buf[i])
+ }
+ return out
+}
+
+function utf16leSlice (buf, start, end) {
+ var bytes = buf.slice(start, end)
+ var res = ''
+ for (var i = 0; i < bytes.length; i += 2) {
+ res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
+ }
+ return res
+}
+
+Buffer.prototype.slice = function slice (start, end) {
+ var len = this.length
+ start = ~~start
+ end = end === undefined ? len : ~~end
+
+ if (start < 0) {
+ start += len
+ if (start < 0) start = 0
+ } else if (start > len) {
+ start = len
+ }
+
+ if (end < 0) {
+ end += len
+ if (end < 0) end = 0
+ } else if (end > len) {
+ end = len
+ }
+
+ if (end < start) end = start
+
+ var newBuf
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ newBuf = this.subarray(start, end)
+ newBuf.__proto__ = Buffer.prototype
+ } else {
+ var sliceLen = end - start
+ newBuf = new Buffer(sliceLen, undefined)
+ for (var i = 0; i < sliceLen; ++i) {
+ newBuf[i] = this[i + start]
+ }
+ }
+
+ return newBuf
+}
+
+/*
+ * Need to make sure that buffer isn't trying to write out of bounds.
+ */
+function checkOffset (offset, ext, length) {
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
+}
+
+Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
+ offset = offset | 0
+ byteLength = byteLength | 0
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
+
+ var val = this[offset]
+ var mul = 1
+ var i = 0
+ while (++i < byteLength && (mul *= 0x100)) {
+ val += this[offset + i] * mul
+ }
+
+ return val
+}
+
+Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
+ offset = offset | 0
+ byteLength = byteLength | 0
+ if (!noAssert) {
+ checkOffset(offset, byteLength, this.length)
+ }
+
+ var val = this[offset + --byteLength]
+ var mul = 1
+ while (byteLength > 0 && (mul *= 0x100)) {
+ val += this[offset + --byteLength] * mul
+ }
+
+ return val
+}
+
+Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 1, this.length)
+ return this[offset]
+}
+
+Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 2, this.length)
+ return this[offset] | (this[offset + 1] << 8)
+}
+
+Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 2, this.length)
+ return (this[offset] << 8) | this[offset + 1]
+}
+
+Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+
+ return ((this[offset]) |
+ (this[offset + 1] << 8) |
+ (this[offset + 2] << 16)) +
+ (this[offset + 3] * 0x1000000)
+}
+
+Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+
+ return (this[offset] * 0x1000000) +
+ ((this[offset + 1] << 16) |
+ (this[offset + 2] << 8) |
+ this[offset + 3])
+}
+
+Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
+ offset = offset | 0
+ byteLength = byteLength | 0
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
+
+ var val = this[offset]
+ var mul = 1
+ var i = 0
+ while (++i < byteLength && (mul *= 0x100)) {
+ val += this[offset + i] * mul
+ }
+ mul *= 0x80
+
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength)
+
+ return val
+}
+
+Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
+ offset = offset | 0
+ byteLength = byteLength | 0
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
+
+ var i = byteLength
+ var mul = 1
+ var val = this[offset + --i]
+ while (i > 0 && (mul *= 0x100)) {
+ val += this[offset + --i] * mul
+ }
+ mul *= 0x80
+
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength)
+
+ return val
+}
+
+Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 1, this.length)
+ if (!(this[offset] & 0x80)) return (this[offset])
+ return ((0xff - this[offset] + 1) * -1)
+}
+
+Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 2, this.length)
+ var val = this[offset] | (this[offset + 1] << 8)
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
+}
+
+Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 2, this.length)
+ var val = this[offset + 1] | (this[offset] << 8)
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
+}
+
+Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+
+ return (this[offset]) |
+ (this[offset + 1] << 8) |
+ (this[offset + 2] << 16) |
+ (this[offset + 3] << 24)
+}
+
+Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+
+ return (this[offset] << 24) |
+ (this[offset + 1] << 16) |
+ (this[offset + 2] << 8) |
+ (this[offset + 3])
+}
+
+Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+ return ieee754.read(this, offset, true, 23, 4)
+}
+
+Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+ return ieee754.read(this, offset, false, 23, 4)
+}
+
+Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 8, this.length)
+ return ieee754.read(this, offset, true, 52, 8)
+}
+
+Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 8, this.length)
+ return ieee754.read(this, offset, false, 52, 8)
+}
+
+function checkInt (buf, value, offset, ext, max, min) {
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
+}
+
+Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
+ value = +value
+ offset = offset | 0
+ byteLength = byteLength | 0
+ if (!noAssert) {
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1
+ checkInt(this, value, offset, byteLength, maxBytes, 0)
+ }
+
+ var mul = 1
+ var i = 0
+ this[offset] = value & 0xFF
+ while (++i < byteLength && (mul *= 0x100)) {
+ this[offset + i] = (value / mul) & 0xFF
+ }
+
+ return offset + byteLength
+}
+
+Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
+ value = +value
+ offset = offset | 0
+ byteLength = byteLength | 0
+ if (!noAssert) {
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1
+ checkInt(this, value, offset, byteLength, maxBytes, 0)
+ }
+
+ var i = byteLength - 1
+ var mul = 1
+ this[offset + i] = value & 0xFF
+ while (--i >= 0 && (mul *= 0x100)) {
+ this[offset + i] = (value / mul) & 0xFF
+ }
+
+ return offset + byteLength
+}
+
+Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
+ if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
+ this[offset] = (value & 0xff)
+ return offset + 1
+}
+
+function objectWriteUInt16 (buf, value, offset, littleEndian) {
+ if (value < 0) value = 0xffff + value + 1
+ for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
+ buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
+ (littleEndian ? i : 1 - i) * 8
+ }
+}
+
+Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value & 0xff)
+ this[offset + 1] = (value >>> 8)
+ } else {
+ objectWriteUInt16(this, value, offset, true)
+ }
+ return offset + 2
+}
+
+Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value >>> 8)
+ this[offset + 1] = (value & 0xff)
+ } else {
+ objectWriteUInt16(this, value, offset, false)
+ }
+ return offset + 2
+}
+
+function objectWriteUInt32 (buf, value, offset, littleEndian) {
+ if (value < 0) value = 0xffffffff + value + 1
+ for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
+ buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
+ }
+}
+
+Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset + 3] = (value >>> 24)
+ this[offset + 2] = (value >>> 16)
+ this[offset + 1] = (value >>> 8)
+ this[offset] = (value & 0xff)
+ } else {
+ objectWriteUInt32(this, value, offset, true)
+ }
+ return offset + 4
+}
+
+Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value >>> 24)
+ this[offset + 1] = (value >>> 16)
+ this[offset + 2] = (value >>> 8)
+ this[offset + 3] = (value & 0xff)
+ } else {
+ objectWriteUInt32(this, value, offset, false)
+ }
+ return offset + 4
+}
+
+Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) {
+ var limit = Math.pow(2, 8 * byteLength - 1)
+
+ checkInt(this, value, offset, byteLength, limit - 1, -limit)
+ }
+
+ var i = 0
+ var mul = 1
+ var sub = 0
+ this[offset] = value & 0xFF
+ while (++i < byteLength && (mul *= 0x100)) {
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
+ sub = 1
+ }
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
+ }
+
+ return offset + byteLength
+}
+
+Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) {
+ var limit = Math.pow(2, 8 * byteLength - 1)
+
+ checkInt(this, value, offset, byteLength, limit - 1, -limit)
+ }
+
+ var i = byteLength - 1
+ var mul = 1
+ var sub = 0
+ this[offset + i] = value & 0xFF
+ while (--i >= 0 && (mul *= 0x100)) {
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
+ sub = 1
+ }
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
+ }
+
+ return offset + byteLength
+}
+
+Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
+ if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
+ if (value < 0) value = 0xff + value + 1
+ this[offset] = (value & 0xff)
+ return offset + 1
+}
+
+Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value & 0xff)
+ this[offset + 1] = (value >>> 8)
+ } else {
+ objectWriteUInt16(this, value, offset, true)
+ }
+ return offset + 2
+}
+
+Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value >>> 8)
+ this[offset + 1] = (value & 0xff)
+ } else {
+ objectWriteUInt16(this, value, offset, false)
+ }
+ return offset + 2
+}
+
+Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value & 0xff)
+ this[offset + 1] = (value >>> 8)
+ this[offset + 2] = (value >>> 16)
+ this[offset + 3] = (value >>> 24)
+ } else {
+ objectWriteUInt32(this, value, offset, true)
+ }
+ return offset + 4
+}
+
+Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
+ value = +value
+ offset = offset | 0
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
+ if (value < 0) value = 0xffffffff + value + 1
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value >>> 24)
+ this[offset + 1] = (value >>> 16)
+ this[offset + 2] = (value >>> 8)
+ this[offset + 3] = (value & 0xff)
+ } else {
+ objectWriteUInt32(this, value, offset, false)
+ }
+ return offset + 4
+}
+
+function checkIEEE754 (buf, value, offset, ext, max, min) {
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
+ if (offset < 0) throw new RangeError('Index out of range')
+}
+
+function writeFloat (buf, value, offset, littleEndian, noAssert) {
+ if (!noAssert) {
+ checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
+ }
+ ieee754.write(buf, value, offset, littleEndian, 23, 4)
+ return offset + 4
+}
+
+Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
+ return writeFloat(this, value, offset, true, noAssert)
+}
+
+Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
+ return writeFloat(this, value, offset, false, noAssert)
+}
+
+function writeDouble (buf, value, offset, littleEndian, noAssert) {
+ if (!noAssert) {
+ checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
+ }
+ ieee754.write(buf, value, offset, littleEndian, 52, 8)
+ return offset + 8
+}
+
+Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
+ return writeDouble(this, value, offset, true, noAssert)
+}
+
+Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
+ return writeDouble(this, value, offset, false, noAssert)
+}
+
+// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
+Buffer.prototype.copy = function copy (target, targetStart, start, end) {
+ if (!start) start = 0
+ if (!end && end !== 0) end = this.length
+ if (targetStart >= target.length) targetStart = target.length
+ if (!targetStart) targetStart = 0
+ if (end > 0 && end < start) end = start
+
+ // Copy 0 bytes; we're done
+ if (end === start) return 0
+ if (target.length === 0 || this.length === 0) return 0
+
+ // Fatal error conditions
+ if (targetStart < 0) {
+ throw new RangeError('targetStart out of bounds')
+ }
+ if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
+
+ // Are we oob?
+ if (end > this.length) end = this.length
+ if (target.length - targetStart < end - start) {
+ end = target.length - targetStart + start
+ }
+
+ var len = end - start
+ var i
+
+ if (this === target && start < targetStart && targetStart < end) {
+ // descending copy from end
+ for (i = len - 1; i >= 0; --i) {
+ target[i + targetStart] = this[i + start]
+ }
+ } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
+ // ascending copy from start
+ for (i = 0; i < len; ++i) {
+ target[i + targetStart] = this[i + start]
+ }
+ } else {
+ Uint8Array.prototype.set.call(
+ target,
+ this.subarray(start, start + len),
+ targetStart
+ )
+ }
+
+ return len
+}
+
+// Usage:
+// buffer.fill(number[, offset[, end]])
+// buffer.fill(buffer[, offset[, end]])
+// buffer.fill(string[, offset[, end]][, encoding])
+Buffer.prototype.fill = function fill (val, start, end, encoding) {
+ // Handle string cases:
+ if (typeof val === 'string') {
+ if (typeof start === 'string') {
+ encoding = start
+ start = 0
+ end = this.length
+ } else if (typeof end === 'string') {
+ encoding = end
+ end = this.length
+ }
+ if (val.length === 1) {
+ var code = val.charCodeAt(0)
+ if (code < 256) {
+ val = code
+ }
+ }
+ if (encoding !== undefined && typeof encoding !== 'string') {
+ throw new TypeError('encoding must be a string')
+ }
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
+ throw new TypeError('Unknown encoding: ' + encoding)
+ }
+ } else if (typeof val === 'number') {
+ val = val & 255
+ }
+
+ // Invalid ranges are not set to a default, so can range check early.
+ if (start < 0 || this.length < start || this.length < end) {
+ throw new RangeError('Out of range index')
+ }
+
+ if (end <= start) {
+ return this
+ }
+
+ start = start >>> 0
+ end = end === undefined ? this.length : end >>> 0
+
+ if (!val) val = 0
+
+ var i
+ if (typeof val === 'number') {
+ for (i = start; i < end; ++i) {
+ this[i] = val
+ }
+ } else {
+ var bytes = Buffer.isBuffer(val)
+ ? val
+ : utf8ToBytes(new Buffer(val, encoding).toString())
+ var len = bytes.length
+ for (i = 0; i < end - start; ++i) {
+ this[i + start] = bytes[i % len]
+ }
+ }
+
+ return this
+}
+
+// HELPER FUNCTIONS
+// ================
+
+var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
+
+function base64clean (str) {
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
+ str = stringtrim(str).replace(INVALID_BASE64_RE, '')
+ // Node converts strings with length < 2 to ''
+ if (str.length < 2) return ''
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
+ while (str.length % 4 !== 0) {
+ str = str + '='
+ }
+ return str
+}
+
+function stringtrim (str) {
+ if (str.trim) return str.trim()
+ return str.replace(/^\s+|\s+$/g, '')
+}
+
+function toHex (n) {
+ if (n < 16) return '0' + n.toString(16)
+ return n.toString(16)
+}
+
+function utf8ToBytes (string, units) {
+ units = units || Infinity
+ var codePoint
+ var length = string.length
+ var leadSurrogate = null
+ var bytes = []
+
+ for (var i = 0; i < length; ++i) {
+ codePoint = string.charCodeAt(i)
+
+ // is surrogate component
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
+ // last char was a lead
+ if (!leadSurrogate) {
+ // no lead yet
+ if (codePoint > 0xDBFF) {
+ // unexpected trail
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
+ continue
+ } else if (i + 1 === length) {
+ // unpaired lead
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
+ continue
+ }
+
+ // valid lead
+ leadSurrogate = codePoint
+
+ continue
+ }
+
+ // 2 leads in a row
+ if (codePoint < 0xDC00) {
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
+ leadSurrogate = codePoint
+ continue
+ }
+
+ // valid surrogate pair
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
+ } else if (leadSurrogate) {
+ // valid bmp char, but last char was a lead
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
+ }
+
+ leadSurrogate = null
+
+ // encode utf8
+ if (codePoint < 0x80) {
+ if ((units -= 1) < 0) break
+ bytes.push(codePoint)
+ } else if (codePoint < 0x800) {
+ if ((units -= 2) < 0) break
+ bytes.push(
+ codePoint >> 0x6 | 0xC0,
+ codePoint & 0x3F | 0x80
+ )
+ } else if (codePoint < 0x10000) {
+ if ((units -= 3) < 0) break
+ bytes.push(
+ codePoint >> 0xC | 0xE0,
+ codePoint >> 0x6 & 0x3F | 0x80,
+ codePoint & 0x3F | 0x80
+ )
+ } else if (codePoint < 0x110000) {
+ if ((units -= 4) < 0) break
+ bytes.push(
+ codePoint >> 0x12 | 0xF0,
+ codePoint >> 0xC & 0x3F | 0x80,
+ codePoint >> 0x6 & 0x3F | 0x80,
+ codePoint & 0x3F | 0x80
+ )
+ } else {
+ throw new Error('Invalid code point')
+ }
+ }
+
+ return bytes
+}
+
+function asciiToBytes (str) {
+ var byteArray = []
+ for (var i = 0; i < str.length; ++i) {
+ // Node's code seems to be doing this and not & 0x7F..
+ byteArray.push(str.charCodeAt(i) & 0xFF)
+ }
+ return byteArray
+}
+
+function utf16leToBytes (str, units) {
+ var c, hi, lo
+ var byteArray = []
+ for (var i = 0; i < str.length; ++i) {
+ if ((units -= 2) < 0) break
+
+ c = str.charCodeAt(i)
+ hi = c >> 8
+ lo = c % 256
+ byteArray.push(lo)
+ byteArray.push(hi)
+ }
+
+ return byteArray
+}
+
+function base64ToBytes (str) {
+ return base64.toByteArray(base64clean(str))
+}
+
+function blitBuffer (src, dst, offset, length) {
+ for (var i = 0; i < length; ++i) {
+ if ((i + offset >= dst.length) || (i >= src.length)) break
+ dst[i + offset] = src[i]
+ }
+ return i
+}
+
+function isnan (val) {
+ return val !== val // eslint-disable-line no-self-compare
+}
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"base64-js":37,"ieee754":48,"isarray":51}]},{},[1]);
o: 'object'
};
+/**
+ * @brief CommonListenerManager constructor function.
+ * @param nativeMgr NativeManager handle.
+ * @param managerName Name which will be used as native listener name.
+ * @param onIdNotFound Callback without arguments invoked when trying to remove not
+ * existing listener. If unspecified it is replaced by empty
+ * function.
+ */
+var CommonListenerManager = function(nativeMgr, managerName, onIdNotFound) {
+ this.listeners = {};
+ this.nextId = 1;
+ this.numberOfListeners = 0;
+ this.name = managerName;
+ this.native = nativeMgr;
+ this.hasNativeListener = false;
+ if (onIdNotFound === undefined) {
+ this.idNotFoundBehavior = function() {};
+ } else {
+ this.idNotFoundBehavior = onIdNotFound;
+ }
+};
+
+/**
+ * @brief Callback for native listener, which invokes all existing listeners.
+ * @param msg native Arguments object for native listener callback.
+ */
+CommonListenerManager.prototype.onListenerCalled = function(msg) {
+ for (var watchId in this.listeners) {
+ if (this.listeners.hasOwnProperty(watchId)) {
+ this.listeners[watchId](msg, watchId);
+ }
+ }
+};
+
+/**
+ * @brief Registers new listener.
+ * @param callback Callback function taking single argument.
+ * @retval integer listener id. Use it later to remove listener.
+ */
+CommonListenerManager.prototype.addListener = function(callback) {
+ if (!this.hasNativeListener) {
+ this.native.addListener(this.name, this.onListenerCalled.bind(this));
+ this.hasNativeListener = true;
+ }
+ var id = this.nextId++;
+ this.listeners[id] = callback;
+ this.numberOfListeners++;
+ return id;
+};
+
+/**
+ * @brief Remove previously registered listener.
+ *
+ * If listener for given id is not found, onIdNotFound callback is invoked.
+ *
+ * @param watchId Listener id returned by addListener.
+ * @retval onIdNotFoundCallback return value.
+ */
+CommonListenerManager.prototype.removeListener = function(watchId) {
+ if (this.listeners.hasOwnProperty(watchId)) {
+ delete this.listeners[watchId];
+ this.numberOfListeners--;
+ if (this.numberOfListeners == 0) {
+ this.native.removeListener(this.name);
+ this.hasNativeListener = false;
+ this.nextId = 1;
+ }
+ } else {
+ return this.idNotFoundBehavior();
+ }
+};
+
var DateConverter = function() {};
DateConverter.prototype.toTZDate = function(v, isAllDay) {
var _dateConverter = new DateConverter();
+/**
+ * Cynara(since tizen 3.0) only support native privilege.
+ * simply web privilege convert native privilege for checking access.
+ */
+var _privilege = {
+ ACCOUNT_READ: 'http://tizen.org/privilege/account.read',
+ ACCOUNT_WRITE: 'http://tizen.org/privilege/account.write',
+ ALARM: 'http://tizen.org/privilege/alarm.get',
+ APPLICATION_INFO: 'http://tizen.org/privilege/application.info',
+ APPLICATION_LAUNCH: 'http://tizen.org/privilege/application.launch',
+ APPMANAGER_CERTIFICATE: 'http://tizen.org/privilege/appmanager.certificate',
+ APPMANAGER_KILL: 'http://tizen.org/privilege/appmanager.kill',
+ BLUETOOTH_ADMIN: 'http://tizen.org/privilege/bluetooth.admin',
+ BLUETOOTH_GAP: 'http://tizen.org/privilege/bluetooth.gap',
+ BLUETOOTH_HEALTH: 'http://tizen.org/privilege/bluetooth.health',
+ BLUETOOTH_SPP: 'http://tizen.org/privilege/bluetooth.spp',
+ BLUETOOTHMANAGER: 'http://tizen.org/privilege/bluetoothmanager',
+ BLUETOOTH: 'http://tizen.org/privilege/bluetooth',
+ BOOKMARK_READ: 'http://tizen.org/privilege/bookmark.read',
+ BOOKMARK_WRITE: 'http://tizen.org/privilege/bookmark.write',
+ CALENDAR_READ: 'http://tizen.org/privilege/calendar.read',
+ CALENDAR_WRITE: 'http://tizen.org/privilege/calendar.write',
+ CALLHISTORY_READ: 'http://tizen.org/privilege/callhistory.read',
+ CALLHISTORY_WRITE: 'http://tizen.org/privilege/callhistory.write',
+ CONTACT_READ: 'http://tizen.org/privilege/contact.read',
+ CONTACT_WRITE: 'http://tizen.org/privilege/contact.write',
+ CONTENT_READ: 'http://tizen.org/privilege/content.read',
+ CONTENT_WRITE: 'http://tizen.org/privilege/content.write',
+ DATACONTROL_CONSUMER: 'http://tizen.org/privilege/datacontrol.consumer',
+ DATASYNC: 'http://tizen.org/privilege/datasync',
+ DOWNLOAD: 'http://tizen.org/privilege/download',
+ FILESYSTEM_READ: 'http://tizen.org/privilege/filesystem.read',
+ FILESYSTEM_WRITE: 'http://tizen.org/privilege/filesystem.write',
+ HAPTIC: 'http://tizen.org/privilege/haptic',
+ HEALTHINFO: 'http://tizen.org/privilege/healthinfo',
+ INTERNET: 'http://tizen.org/privilege/internet',
+ LED: 'http://tizen.org/privilege/led',
+ LOCATION: 'http://tizen.org/privilege/location',
+ MEDIACONTROLLER_SERVER: 'http://tizen.org/privilege/mediacontroller.server',
+ MEDIACONTROLLER_CLIENT: 'http://tizen.org/privilege/mediacontroller.client',
+ MESSAGING_READ: 'http://tizen.org/privilege/messaging.read',
+ MESSAGING_WRITE: 'http://tizen.org/privilege/messaging.write',
+ NETWORKBEARERSELECTION: 'http://tizen.org/privilege/networkbearerselection',
+ NFC_ADMIN: 'http://tizen.org/privilege/nfc.admin',
+ NFC_CARDEMULATION: 'http://tizen.org/privilege/nfc.cardemulation',
+ NFC_COMMON: 'http://tizen.org/privilege/nfc.common',
+ NFC_P2P: 'http://tizen.org/privilege/nfc.p2p',
+ NFC_TAG: 'http://tizen.org/privilege/nfc.tag',
+ NOTIFICATION: 'http://tizen.org/privilege/notification',
+ PACKAGE_INFO: 'http://tizen.org/privilege/packagemanager.info',
+ PACKAGEMANAGER_INSTALL: 'http://tizen.org/privilege/packagemanager.install',
+ POWER: 'http://tizen.org/privilege/power',
+ PUSH: 'http://tizen.org/privilege/push',
+ SECUREELEMENT: 'http://tizen.org/privilege/secureelement',
+ SETTING_ADMIN: 'http://tizen.org/privilege/systemsettings.admin',
+ SETTING: 'http://tizen.org/privilege/setting',
+ SYSTEM: 'http://tizen.org/privilege/system',
+ SYSTEMMANAGER: 'http://tizen.org/privilege/systemmanager',
+ TELEPHONY: 'http://tizen.org/privilege/telephony',
+ VOLUME_SET: 'http://tizen.org/privilege/volume.set',
+ WEBSETTING: 'http://tizen.org/privilege/websetting',
+ TV_INPUT_DEVICE: 'http://tizen.org/privilege/tv.inputdevice'
+};
+
+Object.freeze(_privilege);
+
/** @constructor */
function Utils() {
- /**
- * Cynara(since tizen 3.0) only support native privilege.
- * simply web privilege convert native privilege for checking access.
- */
- var privilege = {
- ACCOUNT_READ: 'http://tizen.org/privilege/account.read',
- ACCOUNT_WRITE: 'http://tizen.org/privilege/account.write',
- ALARM: 'http://tizen.org/privilege/alarm.get',
- APPLICATION_INFO: 'http://tizen.org/privilege/application.info',
- APPLICATION_LAUNCH: 'http://tizen.org/privilege/application.launch',
- APPMANAGER_CERTIFICATE: 'http://tizen.org/privilege/appmanager.certificate',
- APPMANAGER_KILL: 'http://tizen.org/privilege/appmanager.kill',
- BLUETOOTH_ADMIN: 'http://tizen.org/privilege/bluetooth.admin',
- BLUETOOTH_GAP: 'http://tizen.org/privilege/bluetooth.gap',
- BLUETOOTH_HEALTH: 'http://tizen.org/privilege/bluetooth.health',
- BLUETOOTH_SPP: 'http://tizen.org/privilege/bluetooth.spp',
- BLUETOOTHMANAGER: 'http://tizen.org/privilege/bluetoothmanager',
- BLUETOOTH: 'http://tizen.org/privilege/bluetooth',
- BOOKMARK_READ: 'http://tizen.org/privilege/bookmark.read',
- BOOKMARK_WRITE: 'http://tizen.org/privilege/bookmark.write',
- CALENDAR_READ: 'http://tizen.org/privilege/calendar.read',
- CALENDAR_WRITE: 'http://tizen.org/privilege/calendar.write',
- CALLHISTORY_READ: 'http://tizen.org/privilege/callhistory.read',
- CALLHISTORY_WRITE: 'http://tizen.org/privilege/callhistory.write',
- CONTACT_READ: 'http://tizen.org/privilege/contact.read',
- CONTACT_WRITE: 'http://tizen.org/privilege/contact.write',
- CONTENT_READ: 'http://tizen.org/privilege/content.write',
- CONTENT_WRITE: 'http://tizen.org/privilege/content.write',
- DATACONTROL_CONSUMER: 'http://tizen.org/privilege/datacontrol.consumer',
- DATASYNC: 'http://tizen.org/privilege/datasync',
- DOWNLOAD: 'http://tizen.org/privilege/download',
- FILESYSTEM_READ: 'http://tizen.org/privilege/filesystem.read',
- FILESYSTEM_WRITE: 'http://tizen.org/privilege/filesystem.write',
- HAPTIC: 'http://tizen.org/privilege/haptic',
- HEALTHINFO: 'http://tizen.org/privilege/healthinfo',
- INTERNET: 'http://tizen.org/privilege/internet',
- LED: 'http://tizen.org/privilege/led',
- LOCATION: 'http://tizen.org/privilege/location',
- MEDIACONTROLLER_SERVER: 'http://tizen.org/privilege/mediacontroller.server',
- MEDIACONTROLLER_CLIENT: 'http://tizen.org/privilege/mediacontroller.client',
- MESSAGING_READ: 'http://tizen.org/privilege/messaging.read',
- MESSAGING_WRITE: 'http://tizen.org/privilege/messaging.write',
- NETWORKBEARERSELECTION: 'http://tizen.org/privilege/networkbearerselection',
- NFC_ADMIN: 'http://tizen.org/privilege/nfc.admin',
- NFC_CARDEMULATION: 'http://tizen.org/privilege/nfc.cardemulation',
- NFC_COMMON: 'http://tizen.org/privilege/nfc.common',
- NFC_P2P: 'http://tizen.org/privilege/nfc.p2p',
- NFC_TAG: 'http://tizen.org/privilege/nfc.tag',
- NOTIFICATION: 'http://tizen.org/privilege/notification',
- PACKAGE_INFO: 'http://tizen.org/privilege/packagemanager.info',
- PACKAGEMANAGER_INSTALL: 'http://tizen.org/privilege/packagemanager.install',
- POWER: 'http://tizen.org/privilege/power',
- PUSH: 'http://tizen.org/privilege/push',
- SECUREELEMENT: 'http://tizen.org/privilege/secureelement',
- SETTING_ADMIN: 'http://tizen.org/privilege/systemsettings.admin',
- SETTING: 'http://tizen.org/privilege/setting',
- SYSTEM: 'http://tizen.org/privilege/system',
- SYSTEMMANAGER: 'http://tizen.org/privilege/systemmanager',
- TELEPHONY: 'http://tizen.org/privilege/telephony',
- VOLUME_SET: 'http://tizen.org/privilege/volume.set',
- WEBSETTING: 'http://tizen.org/privilege/websetting',
- TV_INPUT_DEVICE: 'http://tizen.org/privilege/tv.inputdevice'
- };
-
- Object.freeze(privilege);
-
Object.defineProperty(this, 'privilege', {
- value: privilege,
+ value: _privilege,
writable: false,
enumerable: true,
configurable: false
};
Utils.prototype.getPkgApiVersion = function() {
- var result = native_.callSync('Utils_getPkgApiVersion');
+ var result = native_.callSync('UtilsGetPkgApiVersion');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
return native_.getResultObject(result);
};
+var isPrivilege = function(toCheck) {
+ if (Object.values(_privilege).indexOf(toCheck) < 0) {
+ return false;
+ }
+ return true;
+};
+
Utils.prototype.checkPrivilegeAccess = function(privilege) {
- var result = native_.callSync('Utils_checkPrivilegeAccess', {
+ if (!isPrivilege(privilege)) {
+ xwalk.utils.error(
+ 'Privilege ' + privilege + ' does not exist. Please fix your code.'
+ );
+ throw new WebAPIException(WebAPIException.SECURITY_ERR);
+ }
+
+ var result = native_.callSync('UtilsCheckPrivilegeAccess', {
privilege: _toString(privilege)
});
current_privilege,
previous_privilege
) {
- var result = native_.callSync('Utils_checkBackwardCompabilityPrivilegeAccess', {
+ var result = native_.callSync('UtilsCheckBackwardCompabilityPrivilegeAccess', {
current_privilege: _toString(current_privilege),
previous_privilege: _toString(previous_privilege)
});
};
Utils.prototype.checkProfile = function() {
- var result = native_.callSync('Utils_checkProfile', {});
+ var result = native_.callSync('UtilsCheckProfile', {});
return native_.getResultObject(result);
};
+Utils.prototype.printDeprecationWarningFor = function(name, replacement) {
+ if (_type.isUndefined(replacement)) {
+ this.warn(
+ 'DEPRECATION WARNING: ' +
+ name +
+ ' is deprecated and using it is not recommended.'
+ );
+ } else {
+ this.warn(
+ 'DEPRECATION WARNING: ' +
+ name +
+ ' is deprecated and using it is not recommended.' +
+ 'Try using ' +
+ replacement +
+ ' instead.'
+ );
+ }
+};
+
/////////////////////////////////////////////////////////////////////////////
/** @constructor */
var Type = function() {};
return Array.isArray(obj);
};
+Type.prototype.isOctet = function(value) {
+ return Number.isInteger(value) && 0 <= value && value <= 255;
+};
+
+Type.prototype.isByteStream = function(value) {
+ return value instanceof Uint8Array;
+};
+
+Type.prototype.isByteStreamArray = function(value) {
+ return Array.isArray(value) && value.every(this.isByteStream);
+};
+
+Type.prototype.isLegacyByteStream = function(value) {
+ return Array.isArray(value) && value.every(this.isOctet);
+};
+
+Type.prototype.isLegacyByteStreamArray = function(value) {
+ return (
+ Array.isArray(value) &&
+ value.every(
+ function(x) {
+ return this.isLegacyByteStream(x);
+ }.bind(this)
+ )
+ );
+};
+
Type.prototype.isFunction = function(obj) {
return typeof obj === 'function';
};
return typeof obj === 'string';
};
+Type.prototype.isStringArray = function(value) {
+ return Array.isArray(value) && value.every(this.isString);
+};
+
Type.prototype.isDate = function(obj) {
return obj instanceof Date;
};
// of requested val. We're converting the val to signed long and then pass it
// to C++ to get the value in required range.
return native_.getResultObject(
- native_.callSync('Utils_toLongLong', {
+ native_.callSync('UtilsToLongLong', {
n: _toLong(val)
})
);
// of requested val. We're converting the val to signed long and then pass it
// to C++ to get the value in required range.
return native_.getResultObject(
- native_.callSync('Utils_toUnsignedLongLong', {
+ native_.callSync('UtilsToUnsignedLongLong', {
n: _toLong(val)
})
);
* {
* name: 'first',
* type: Validator.Types.ARRAY,
- * values: Validator.Types.DOUBLE // converts elements, only primitive types are
- * supported
+ * values: Validator.Types.DOUBLE // converts elements, only primitive
+ * // types are supported
* }
* ]
* @code
*/
Validator.prototype.isConstructorCall = function(obj, instance) {
if (!(obj instanceof instance) || obj._previouslyConstructed) {
- // There is no TypeError exception in Tizen 2.3.0 API spec but it's required by
- // current TCTs.
- // For Tizen compliance it's wrapped into WebAPIException.
+ // There is no TypeError exception in Tizen 2.3.0 API spec but it's required
+ // by current TCTs. For Tizen compliance it's wrapped into WebAPIException.
throw new WebAPIException(
'TypeError',
'Constructor cannot be called as function.'
// - __EnableChromiumInternalPowerLock
// could occur. In such cases we are silently ignroing those messages.
// TODO This is workaround for missing patch in chromium-efl package
- // which should handle this special message and don't forward it to
+ // which should handle this special message and don't forward it to
// webapi JS. After chromium-efl will be updated, below checking should
// be removed.
if (json.substring(0, 2) === '__') {
});
this.constructor.prototype.__proto__ = Error.prototype;
- Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
// V8-specific code
+ Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
};
WebAPIException.prototype.toString = function() {
Utils.prototype.converter = _converter;
Utils.prototype.validator = _validator;
Utils.prototype.NativeManager = NativeManager;
+Utils.prototype.CommonListenerManager = CommonListenerManager;
var native_ = new NativeManager(extension);
Object.freeze(exports.utils);
Object.freeze(Utils.prototype);
Object.freeze(NativeManager.prototype);
+Object.freeze(CommonListenerManager.prototype);
namespace utils {
UtilsInstance::UtilsInstance() {
+ ScopeLogger();
using std::placeholders::_1;
using std::placeholders::_2;
- ScopeLogger();
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&UtilsInstance::x, this, _1, _2));
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&UtilsInstance::x, this, _1, _2));
-
- REGISTER_SYNC("Utils_getPkgApiVersion", GetPkgApiVersion);
- REGISTER_SYNC("Utils_checkPrivilegeAccess", CheckPrivilegeAccess);
- REGISTER_SYNC("Utils_checkBackwardCompabilityPrivilegeAccess",
- CheckBackwardCompabilityPrivilegeAccess);
- REGISTER_SYNC("Utils_toLongLong", ToLongLong);
- REGISTER_SYNC("Utils_toUnsignedLongLong", ToUnsignedLongLong);
- REGISTER_SYNC("Utils_checkProfile", CheckProfile);
-
-#undef REGISTER_SYNC
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&UtilsInstance::M, this, _1, _2))
+ REGISTER_METHOD(UtilsGetPkgApiVersion);
+ REGISTER_METHOD(UtilsCheckPrivilegeAccess);
+ REGISTER_METHOD(UtilsCheckBackwardCompabilityPrivilegeAccess);
+ REGISTER_METHOD(UtilsToLongLong);
+ REGISTER_METHOD(UtilsToUnsignedLongLong);
+ REGISTER_METHOD(UtilsCheckProfile);
+#undef REGISTER_METHOD
}
-void UtilsInstance::GetPkgApiVersion(const picojson::value& args, picojson::object& out) {
+void UtilsInstance::UtilsGetPkgApiVersion(const picojson::value& args, picojson::object& out) {
ScopeLogger();
std::string api_version;
ReportSuccess(picojson::value(api_version), out);
}
-void UtilsInstance::CheckPrivilegeAccess(const picojson::value& args, picojson::object& out) {
+void UtilsInstance::UtilsCheckPrivilegeAccess(const picojson::value& args, picojson::object& out) {
ScopeLogger();
const auto& privilege = args.get("privilege").to_str();
CHECK_PRIVILEGE_ACCESS(privilege, &out);
ReportSuccess(out);
}
-void UtilsInstance::CheckBackwardCompabilityPrivilegeAccess(const picojson::value& args,
- picojson::object& out) {
+void UtilsInstance::UtilsCheckBackwardCompabilityPrivilegeAccess(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
const auto& current_priv = args.get("current_privilege").to_str();
const auto& prev_priv = args.get("previous_privilege").to_str();
} // namespace
-void UtilsInstance::ToLongLong(const picojson::value& args, picojson::object& out) {
+void UtilsInstance::UtilsToLongLong(const picojson::value& args, picojson::object& out) {
ScopeLogger();
const auto& n = args.get("n");
ReportSuccess(picojson::value(static_cast<double>(output)), out);
}
-void UtilsInstance::ToUnsignedLongLong(const picojson::value& args, picojson::object& out) {
+void UtilsInstance::UtilsToUnsignedLongLong(const picojson::value& args, picojson::object& out) {
ScopeLogger();
const auto& n = args.get("n");
ReportSuccess(picojson::value(static_cast<double>(output)), out);
}
-void UtilsInstance::CheckProfile(const picojson::value& args, picojson::object& out) {
+void UtilsInstance::UtilsCheckProfile(const picojson::value& args, picojson::object& out) {
ScopeLogger();
std::string profile = "common";
}
private:
- void GetPkgApiVersion(const picojson::value& args, picojson::object& out);
- void CheckPrivilegeAccess(const picojson::value& args, picojson::object& out);
- void CheckBackwardCompabilityPrivilegeAccess(const picojson::value& args, picojson::object& out);
+ void UtilsGetPkgApiVersion(const picojson::value& args, picojson::object& out);
+ void UtilsCheckPrivilegeAccess(const picojson::value& args, picojson::object& out);
+ void UtilsCheckBackwardCompabilityPrivilegeAccess(const picojson::value& args,
+ picojson::object& out);
- void ToLongLong(const picojson::value& args, picojson::object& out);
- void ToUnsignedLongLong(const picojson::value& args, picojson::object& out);
- void CheckProfile(const picojson::value& args, picojson::object& out);
+ void UtilsToLongLong(const picojson::value& args, picojson::object& out);
+ void UtilsToUnsignedLongLong(const picojson::value& args, picojson::object& out);
+ void UtilsCheckProfile(const picojson::value& args, picojson::object& out);
};
} // namespace utils
} // namespace extension
function VoiceControlClientManager() {}
VoiceControlClientManager.prototype.getVoiceControlClient = function() {
- var result = native_.callSync('VoiceControlClientManager_getVoiceControlClient', {});
+ var result = native_.callSync('VoiceControlClientManagerGetVoiceControlClient', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
function VoiceControlClient() {}
VoiceControlClient.prototype.getCurrentLanguage = function() {
- var result = native_.callSync('VoiceControlClient_getCurrentLanguage', {});
+ var result = native_.callSync('VoiceControlClientGetCurrentLanguage', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
type: args.type
};
- var result = native_.callSync('VoiceControlClient_setCommandList', data);
+ var result = native_.callSync('VoiceControlClientSetCommandList', data);
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
args.type = VoiceControlCommandType.FOREGROUND;
}
- var result = native_.callSync('VoiceControlClient_unsetCommandList', {
+ var result = native_.callSync('VoiceControlClientUnsetCommandList', {
type: args.type
});
return VcResultListener.addListener(
args.listener,
- 'VoiceControlClient_addResultListener'
+ 'VoiceControlClientAddResultListener'
);
};
var args = validator_.validateArgs(arguments, [{ name: 'id', type: types_.LONG }]);
- VcResultListener.removeListener(args.id, 'VoiceControlClient_removeResultListener');
+ VcResultListener.removeListener(args.id, 'VoiceControlClientRemoveResultListener');
};
VoiceControlClient.prototype.addLanguageChangeListener = function(listener) {
return VcLangListener.addListener(
args.listener,
- 'VoiceControlClient_addLanguageChangeListener'
+ 'VoiceControlClientAddLanguageChangeListener'
);
};
VcLangListener.removeListener(
args.id,
- 'VoiceControlClient_removeLanguageChangeListener'
+ 'VoiceControlClientRemoveLanguageChangeListener'
);
};
VoiceControlClient.prototype.release = function() {
- var result = native_.callSync('VoiceControlClient_release', {});
+ var result = native_.callSync('VoiceControlClientRelease', {});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
VoiceControlInstance::VoiceControlInstance() : voice_control_client() {
ScopeLogger();
using namespace std::placeholders;
-#define REGISTER_SYNC(c, x) \
- RegisterSyncHandler(c, std::bind(&VoiceControlInstance::x, this, _1, _2));
- REGISTER_SYNC("VoiceControlClient_getCurrentLanguage", GetCurrentLanguage);
- REGISTER_SYNC("VoiceControlClient_setCommandList", SetCommandList);
- REGISTER_SYNC("VoiceControlClient_unsetCommandList", UnsetCommandList);
- REGISTER_SYNC("VoiceControlClient_addResultListener", AddResultListener);
- REGISTER_SYNC("VoiceControlClient_removeResultListener", RemoveResultListener);
- REGISTER_SYNC("VoiceControlClient_addLanguageChangeListener", AddLanguageChangeListener);
- REGISTER_SYNC("VoiceControlClient_removeLanguageChangeListener", RemoveLanguageChangeListener);
- REGISTER_SYNC("VoiceControlClient_release", Release);
- REGISTER_SYNC("VoiceControlClientManager_getVoiceControlClient", GetVoiceControlClient);
-#undef REGISTER_SYNC
+
+#define REGISTER_METHOD(M) \
+ RegisterSyncHandler(#M, std::bind(&VoiceControlInstance::M, this, _1, _2))
+ REGISTER_METHOD(VoiceControlClientGetCurrentLanguage);
+ REGISTER_METHOD(VoiceControlClientSetCommandList);
+ REGISTER_METHOD(VoiceControlClientUnsetCommandList);
+ REGISTER_METHOD(VoiceControlClientAddResultListener);
+ REGISTER_METHOD(VoiceControlClientRemoveResultListener);
+ REGISTER_METHOD(VoiceControlClientAddLanguageChangeListener);
+ REGISTER_METHOD(VoiceControlClientRemoveLanguageChangeListener);
+ REGISTER_METHOD(VoiceControlClientRelease);
+ REGISTER_METHOD(VoiceControlClientManagerGetVoiceControlClient);
+#undef REGISTER_METHOD
}
VoiceControlInstance::~VoiceControlInstance() {
return; \
}
-void VoiceControlInstance::GetVoiceControlClient(const picojson::value& args,
- picojson::object& out) {
+void VoiceControlInstance::VoiceControlClientManagerGetVoiceControlClient(
+ const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeVoiceControl, &out);
ReportSuccess(out);
}
-void VoiceControlInstance::Release(const picojson::value& args, picojson::object& out) {
+void VoiceControlInstance::VoiceControlClientRelease(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
int ret = VC_ERROR_NONE;
ReportSuccess(out);
}
-void VoiceControlInstance::GetCurrentLanguage(const picojson::value& args, picojson::object& out) {
+void VoiceControlInstance::VoiceControlClientGetCurrentLanguage(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
std::string language;
}
}
-void VoiceControlInstance::SetCommandList(const picojson::value& args, picojson::object& out) {
+void VoiceControlInstance::VoiceControlClientSetCommandList(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeVoiceControl, &out);
}
}
-void VoiceControlInstance::UnsetCommandList(const picojson::value& args, picojson::object& out) {
+void VoiceControlInstance::VoiceControlClientUnsetCommandList(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeVoiceControl, &out);
}
}
-void VoiceControlInstance::AddResultListener(const picojson::value& args, picojson::object& out) {
+void VoiceControlInstance::VoiceControlClientAddResultListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
common::PlatformResult result = voice_control_client.AddResultListener();
}
}
-void VoiceControlInstance::RemoveResultListener(const picojson::value& args,
- picojson::object& out) {
+void VoiceControlInstance::VoiceControlClientRemoveResultListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
common::PlatformResult result = voice_control_client.RemoveResultListener();
}
}
-void VoiceControlInstance::AddLanguageChangeListener(const picojson::value& args,
- picojson::object& out) {
+void VoiceControlInstance::VoiceControlClientAddLanguageChangeListener(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
common::PlatformResult result = voice_control_client.AddLanguageChangeListener();
}
}
-void VoiceControlInstance::RemoveLanguageChangeListener(const picojson::value& args,
- picojson::object& out) {
+void VoiceControlInstance::VoiceControlClientRemoveLanguageChangeListener(
+ const picojson::value& args, picojson::object& out) {
ScopeLogger();
common::PlatformResult result = voice_control_client.RemoveLanguageChangeListener();
virtual ~VoiceControlInstance();
private:
- void GetVoiceControlClient(const picojson::value& args, picojson::object& out);
- void Release(const picojson::value& args, picojson::object& out);
-
- void GetCurrentLanguage(const picojson::value& args, picojson::object& out);
- void SetCommandList(const picojson::value& args, picojson::object& out);
- void UnsetCommandList(const picojson::value& args, picojson::object& out);
- void AddResultListener(const picojson::value& args, picojson::object& out);
- void RemoveResultListener(const picojson::value& args, picojson::object& out);
- void AddLanguageChangeListener(const picojson::value& args, picojson::object& out);
- void RemoveLanguageChangeListener(const picojson::value& args, picojson::object& out);
+ void VoiceControlClientManagerGetVoiceControlClient(const picojson::value& args,
+ picojson::object& out);
+ void VoiceControlClientRelease(const picojson::value& args, picojson::object& out);
+
+ void VoiceControlClientGetCurrentLanguage(const picojson::value& args, picojson::object& out);
+ void VoiceControlClientSetCommandList(const picojson::value& args, picojson::object& out);
+ void VoiceControlClientUnsetCommandList(const picojson::value& args, picojson::object& out);
+ void VoiceControlClientAddResultListener(const picojson::value& args, picojson::object& out);
+ void VoiceControlClientRemoveResultListener(const picojson::value& args, picojson::object& out);
+ void VoiceControlClientAddLanguageChangeListener(const picojson::value& args,
+ picojson::object& out);
+ void VoiceControlClientRemoveLanguageChangeListener(const picojson::value& args,
+ picojson::object& out);
static void VcLanguageChangedCb(const char* previous, const char* current, void* user_data);
static void VcResultCb(vc_result_event_e event, vc_cmd_list_h cmd_list, const char* result,
callArgs.instanceId = this.id;
callArgs.seconds = args.seconds;
- var ret = native.callSync('WidgetInstance_changeUpdatePeriod', callArgs);
+ var ret = native.callSync('WidgetInstanceChangeUpdatePeriod', callArgs);
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
callArgs.data = args.data;
callArgs.updateIfPaused = args.updateIfPaused;
- var ret = native.callSync('WidgetInstance_sendContent', callArgs);
+ var ret = native.callSync('WidgetInstanceSendContent', callArgs);
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
}
};
- var result = native.call('WidgetInstance_getContent', callArgs, callback);
+ var result = native.call('WidgetInstanceGetContent', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
+var widgetToListenerManagerMapping = {};
+
function Widget(data) {
+ if (!widgetToListenerManagerMapping.hasOwnProperty(data.id)) {
+ widgetToListenerManagerMapping[data.id] = new xwalk.utils.CommonListenerManager(
+ native,
+ 'WidgetStateChangeCallback_' + data.id
+ );
+ }
Object.defineProperties(this, {
id: {
value: data.id,
callArgs.locale = args.locale;
}
- var ret = native.callSync('Widget_getName', callArgs);
+ var ret = native.callSync('WidgetGetName', callArgs);
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
var callArgs = {};
callArgs.widgetId = this.id;
- var result = native.call('Widget_getInstances', callArgs, callback);
+ var result = native.call('WidgetGetInstances', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
callArgs.widgetId = this.id;
callArgs.sizeType = args.sizeType;
- var ret = native.callSync('Widget_getVariant', callArgs);
+ var ret = native.callSync('WidgetGetVariant', callArgs);
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
var callArgs = {};
callArgs.widgetId = this.id;
- var result = native.call('Widget_getVariants', callArgs, callback);
+ var result = native.call('WidgetGetVariants', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
};
-function ListenerManager(native, listenerName) {
- this.listeners = {};
- this.nextId = 1;
- this.nativeSet = false;
- this.native = native;
- this.listenerName = listenerName;
-}
-
-ListenerManager.prototype.onListenerCalled = function(msg) {
- for (var watchId in this.listeners) {
- if (this.listeners.hasOwnProperty(watchId)) {
- this.listeners[watchId](this.native.getResultObject(msg));
- }
- }
-};
-
-ListenerManager.prototype.addListener = function(callback) {
- var id = this.nextId;
- if (!this.nativeSet) {
- this.native.addListener(this.listenerName, this.onListenerCalled.bind(this));
- this.nativeSet = true;
- }
- this.listeners[id] = callback;
- ++this.nextId;
- return id;
-};
-
-ListenerManager.prototype.removeListener = function(watchId) {
- if (this.listeners.hasOwnProperty(watchId)) {
- delete this.listeners[watchId];
- }
-};
-
-var WIDGET_STATE_CHANGE_LISTENER = 'WidgetStateChangeCallback';
-var widgetStateChangeListener = new ListenerManager(native, WIDGET_STATE_CHANGE_LISTENER);
-
Widget.prototype.addStateChangeListener = function() {
var args = validator.validateMethod(arguments, [
{
}
]);
- var result = native.callSync('Widget_addStateChangeListener', { widgetId: this.id });
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
+ if (widgetToListenerManagerMapping[this.id].numberOfListeners == 0) {
+ var result = native.callSync('WidgetAddStateChangeListener', {
+ widgetId: this.id
+ });
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ }
}
var func = function(msg) {
- if (msg.widgetId === this.id) {
- args.eventCallback(new WidgetInstance(msg, this), msg.event);
+ var result = native.getResultObject(msg);
+ if (result.widgetId === this.id) {
+ args.eventCallback(new WidgetInstance(result, this), result.event);
}
}.bind(this);
- return widgetStateChangeListener.addListener(func);
+ return widgetToListenerManagerMapping[this.id].addListener(func);
};
Widget.prototype.removeStateChangeListener = function() {
}
]);
- widgetStateChangeListener.removeListener(args.watchId);
-
- var result = native.callSync('Widget_removeStateChangeListener', {
- widgetId: this.id
- });
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
+ widgetToListenerManagerMapping[this.id].removeListener(args.watchId);
+ if (widgetToListenerManagerMapping[this.id].numberOfListeners == 0) {
+ var result = native.callSync('WidgetRemoveStateChangeListener', {
+ widgetId: this.id
+ });
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ }
}
};
var callArgs = {};
callArgs.widgetId = args.widgetId;
- var ret = native.callSync('WidgetServiceManager_getWidget', callArgs);
+ var ret = native.callSync('WidgetServiceManagerGetWidget', callArgs);
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
callArgs.packageId = args.packageId;
}
- var result = native.call('WidgetServiceManager_getWidgets', callArgs, callback);
+ var result = native.call('WidgetServiceManagerGetWidgets', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
}
var callArgs = {};
callArgs.id = args.id;
- var ret = native.callSync('WidgetServiceManager_getPrimaryWidgetId', callArgs);
+ var ret = native.callSync('WidgetServiceManagerGetPrimaryWidgetId', callArgs);
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
var callArgs = {};
callArgs.sizeType = args.sizeType;
- var ret = native.callSync('WidgetServiceManager_getSize', callArgs);
+ var ret = native.callSync('WidgetServiceManagerGetSize', callArgs);
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
std::mutex WidgetServiceInstance::listener_mutex_;
namespace {
-const common::ListenerToken kWidgetChangeCallbackToken{"WidgetStateChangeCallback"};
-
const std::string kPrivilegeWidgetService = "http://tizen.org/privilege/widget.viewer";
const std::string kLocale = "locale";
obj->insert(std::make_pair(key, picojson::value(val)));
}
+common::ListenerToken getWidgetStateChangeListenerToken(const std::string& callback_token,
+ const std::string& widget_id) {
+ common::ListenerToken kWidgetChangeCallbackToken{callback_token + "_" + widget_id};
+ return kWidgetChangeCallbackToken;
+}
+
} // namespace
WidgetServiceInstance::WidgetServiceInstance() {
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&WidgetServiceInstance::x, this, _1));
-
- REGISTER_SYNC("WidgetServiceManager_getWidget", GetWidget);
- REGISTER_SYNC("WidgetServiceManager_getPrimaryWidgetId", GetPrimaryWidgetId);
- REGISTER_SYNC("WidgetServiceManager_getSize", GetSize);
- REGISTER_SYNC("Widget_getName", GetName);
- REGISTER_SYNC("Widget_getVariant", GetVariant);
- REGISTER_SYNC("Widget_addStateChangeListener", AddStateChangeListener);
- REGISTER_SYNC("Widget_removeStateChangeListener", RemoveStateChangeListener);
- REGISTER_SYNC("WidgetInstance_changeUpdatePeriod", ChangeUpdatePeriod);
- REGISTER_SYNC("WidgetInstance_sendContent", SendContent);
-
-#undef REGISTER_SYNC
-
-#define REGISTER_ASYNC(c, x) RegisterHandler(c, std::bind(&WidgetServiceInstance::x, this, _1, _2));
-
- REGISTER_ASYNC("WidgetServiceManager_getWidgets", GetWidgets);
- REGISTER_ASYNC("Widget_getInstances", GetInstances);
- REGISTER_ASYNC("Widget_getVariants", GetVariants);
- REGISTER_ASYNC("WidgetInstance_getContent", GetContent);
-#undef REGISTER_ASYNC
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&WidgetServiceInstance::M, this, _1))
+ REGISTER_METHOD(WidgetServiceManagerGetWidget);
+ REGISTER_METHOD(WidgetServiceManagerGetPrimaryWidgetId);
+ REGISTER_METHOD(WidgetServiceManagerGetSize);
+ REGISTER_METHOD(WidgetGetName);
+ REGISTER_METHOD(WidgetGetVariant);
+ REGISTER_METHOD(WidgetAddStateChangeListener);
+ REGISTER_METHOD(WidgetRemoveStateChangeListener);
+ REGISTER_METHOD(WidgetInstanceChangeUpdatePeriod);
+ REGISTER_METHOD(WidgetInstanceSendContent);
+#undef REGISTER_METHOD
+
+#define REGISTER_METHOD(M) RegisterHandler(#M, std::bind(&WidgetServiceInstance::M, this, _1, _2))
+ REGISTER_METHOD(WidgetServiceManagerGetWidgets);
+ REGISTER_METHOD(WidgetGetInstances);
+ REGISTER_METHOD(WidgetGetVariants);
+ REGISTER_METHOD(WidgetInstanceGetContent);
+#undef REGISTER_METHOD
}
WidgetServiceInstance::~WidgetServiceInstance() {
listener_map_.clear();
}
-TizenResult WidgetServiceInstance::GetWidget(const picojson::object& args) {
+TizenResult WidgetServiceInstance::WidgetServiceManagerGetWidget(const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeWidgetService);
return TizenSuccess(value);
}
-TizenResult WidgetServiceInstance::GetWidgets(const picojson::object& args,
- const common::AsyncToken& token) {
+TizenResult WidgetServiceInstance::WidgetServiceManagerGetWidgets(const picojson::object& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeWidgetService);
return TizenSuccess();
}
-TizenResult WidgetServiceInstance::GetPrimaryWidgetId(const picojson::object& args) {
+TizenResult WidgetServiceInstance::WidgetServiceManagerGetPrimaryWidgetId(
+ const picojson::object& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeWidgetService);
return TizenSuccess(picojson::value(widget_id));
}
-TizenResult WidgetServiceInstance::GetSize(const picojson::object& args) {
+TizenResult WidgetServiceInstance::WidgetServiceManagerGetSize(const picojson::object& args) {
ScopeLogger();
CHECK_EXIST(args, kSizeType, out)
return TizenSuccess(value);
}
-TizenResult WidgetServiceInstance::GetName(picojson::object const& args) {
+TizenResult WidgetServiceInstance::WidgetGetName(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeWidgetService);
return TizenSuccess(picojson::value(name));
}
-TizenResult WidgetServiceInstance::GetInstances(picojson::object const& args,
- const common::AsyncToken& token) {
+TizenResult WidgetServiceInstance::WidgetGetInstances(picojson::object const& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_EXIST(args, kWidgetId, out)
return TizenSuccess();
}
-TizenResult WidgetServiceInstance::GetVariant(picojson::object const& args) {
+TizenResult WidgetServiceInstance::WidgetGetVariant(picojson::object const& args) {
ScopeLogger();
CHECK_EXIST(args, kWidgetId, out)
return TizenSuccess(value);
}
-TizenResult WidgetServiceInstance::GetVariants(picojson::object const& args,
- const common::AsyncToken& token) {
+TizenResult WidgetServiceInstance::WidgetGetVariants(picojson::object const& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeWidgetService);
std::lock_guard<std::mutex> lock(listener_mutex_);
const auto it = listener_map_.find(widget_id);
if (listener_map_.end() != it) {
- Post(kWidgetChangeCallbackToken, TizenSuccess{response});
+ Post(getWidgetStateChangeListenerToken("WidgetStateChangeCallback", widget_id),
+ TizenSuccess{response});
return;
}
LoggerW("widget id was not found.");
}
-TizenResult WidgetServiceInstance::AddStateChangeListener(picojson::object const& args) {
+TizenResult WidgetServiceInstance::WidgetAddStateChangeListener(picojson::object const& args) {
ScopeLogger();
CHECK_PRIVILEGE(kPrivilegeWidgetService);
return TizenSuccess();
}
-TizenResult WidgetServiceInstance::RemoveStateChangeListener(picojson::object const& args) {
+TizenResult WidgetServiceInstance::WidgetRemoveStateChangeListener(picojson::object const& args) {
ScopeLogger();
CHECK_EXIST(args, kWidgetId, out)
return TizenSuccess();
}
-TizenResult WidgetServiceInstance::ChangeUpdatePeriod(picojson::object const& args) {
+TizenResult WidgetServiceInstance::WidgetInstanceChangeUpdatePeriod(picojson::object const& args) {
ScopeLogger();
CHECK_EXIST(args, kWidgetId, out)
return TizenSuccess();
}
-TizenResult WidgetServiceInstance::SendContent(picojson::object const& args) {
+TizenResult WidgetServiceInstance::WidgetInstanceSendContent(picojson::object const& args) {
ScopeLogger();
CHECK_EXIST(args, kWidgetId, out)
return TizenSuccess();
}
-TizenResult WidgetServiceInstance::GetContent(picojson::object const& args,
- const common::AsyncToken& token) {
+TizenResult WidgetServiceInstance::WidgetInstanceGetContent(picojson::object const& args,
+ const common::AsyncToken& token) {
ScopeLogger();
CHECK_EXIST(args, kWidgetId, out)
private:
// WidgetManager
- common::TizenResult GetWidget(picojson::object const& args);
- common::TizenResult GetWidgets(picojson::object const& args, const common::AsyncToken& token);
- common::TizenResult GetPrimaryWidgetId(picojson::object const& args);
- common::TizenResult GetSize(picojson::object const& args);
+ common::TizenResult WidgetServiceManagerGetWidget(picojson::object const& args);
+ common::TizenResult WidgetServiceManagerGetWidgets(picojson::object const& args,
+ const common::AsyncToken& token);
+ common::TizenResult WidgetServiceManagerGetPrimaryWidgetId(picojson::object const& args);
+ common::TizenResult WidgetServiceManagerGetSize(picojson::object const& args);
// Widget
- common::TizenResult GetName(picojson::object const& args);
- common::TizenResult GetInstances(picojson::object const& args, const common::AsyncToken& token);
- common::TizenResult GetVariant(picojson::object const& args);
- common::TizenResult GetVariants(picojson::object const& args, const common::AsyncToken& token);
- common::TizenResult AddStateChangeListener(picojson::object const& args);
- common::TizenResult RemoveStateChangeListener(picojson::object const& args);
+ common::TizenResult WidgetGetName(picojson::object const& args);
+ common::TizenResult WidgetGetInstances(picojson::object const& args,
+ const common::AsyncToken& token);
+ common::TizenResult WidgetGetVariant(picojson::object const& args);
+ common::TizenResult WidgetGetVariants(picojson::object const& args,
+ const common::AsyncToken& token);
+ common::TizenResult WidgetAddStateChangeListener(picojson::object const& args);
+ common::TizenResult WidgetRemoveStateChangeListener(picojson::object const& args);
// WidgetInstance
- common::TizenResult ChangeUpdatePeriod(picojson::object const& args);
- common::TizenResult SendContent(picojson::object const& args);
- common::TizenResult GetContent(picojson::object const& args, const common::AsyncToken& token);
+ common::TizenResult WidgetInstanceChangeUpdatePeriod(picojson::object const& args);
+ common::TizenResult WidgetInstanceSendContent(picojson::object const& args);
+ common::TizenResult WidgetInstanceGetContent(picojson::object const& args,
+ const common::AsyncToken& token);
static std::mutex listener_mutex_;
std::map<std::string, int> listener_map_;
#!/bin/bash
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+ SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
+ SOURCE="$(readlink "$SOURCE")"
+ [[ $SOURCE != /* ]] && SOURCE="$SCRIPT_DIR/$SOURCE"
+ # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
+done
+SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
+
# https://clangformat.com/
-command -v clang-format >/dev/null 2>&1 || {
+if [ ! "$(command -v clang-format)" ]; then
echo >&2 "clang-format is required, but it's not installed";
echo "-------------------------------------------------------------------------------------";
echo "To install clang-format on Debian/Ubuntu, execute the following commands."
echo " sudo ln -s /usr/bin/clang-format-3.9 /usr/bin/clang-format"
echo "-------------------------------------------------------------------------------------";
exit 1;
- }
+fi
config='{
BasedOnStyle: Google,
formatC++() {
printf "."
- # ignoring file not found errors
- ls "$1"/*.cc &>/dev/null && clang-format -i -style="$config" "$1"/*.cc;
- ls "$1"/*.cpp &>/dev/null && clang-format -i -style="$config" "$1"/*.cpp
- ls "$1"/*.h &>/dev/null && clang-format -i -style="$config" "$1"/*.h
- ls "$1"/*.hpp &>/dev/null && clang-format -i -style="$config" "$1"/*.hpp
-}
-
-checkDirectoriesRecursively() {
- dirs="$(find $1 -type d)"
- for d in $dirs;
- do
- if [[ -d "$d" ]]; then
- #echo "FORMAT $d"
- formatC++ "$d";
- fi
- done
+ find -- "$1" -type f \( -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) | \
+ grep -v 'src/google' | xargs -n1 --no-run-if-empty clang-format -i -style="$config"
}
checkUpdatedFiles() {
- files=$(git diff-index --name-only --diff-filter=AM HEAD --)
- for f in $files;
- do
- printf "."
- if [ ${f: -3} == ".cc" ] || [ ${f: -4} == ".cpp" ] || [ ${f: -2} == ".h" ] || [ ${f: -4} == ".hpp" ]; then
- clang-format -i -style="$config" "$f";
- fi
- done
+ while IFS= read -r -d '' f; do
+ if [ "${f: -3}" == ".cc" ] || [ "${f: -4}" == ".cpp" ] || [ "${f: -2}" == ".h" ] || \
+ [ "${f: -4}" == ".hpp" ]; then
+ printf '.'
+ clang-format -i -style="$config" "$f";
+ fi
+ done < <(git diff-index -z --name-only --diff-filter=AM HEAD --)
}
printf "C/C++ reformatting: ";
if [[ $# -eq 0 ]]; then
- checkDirectoriesRecursively "src/"
+ formatC++ "$SCRIPT_DIR/../../src/"
elif [[ "$1" == "-u" ]]; then
checkUpdatedFiles
else
- checkDirectoriesRecursively "$1"
+ formatC++ "$1"
fi
printf " DONE C/C++ reformatting\n"
#!/bin/bash
-dir="$(dirname "$(readlink -f "$0")")"
-dir2analyze="$(pwd)/src"
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+ SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
+ SOURCE="$(readlink "$SOURCE")"
+ [[ $SOURCE != /* ]] && SOURCE="$SCRIPT_DIR/$SOURCE"
+ # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
+done
+SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
+echo "$SCRIPT_DIR"
+
+dir2analyze="$SCRIPT_DIR/../../src"
analyzeJS="false";
analyzeC="false";
files_to_update="";
echo "coding style. THIS COULD CHANGE YOUR FILES. Please commit your changes locally"
echo "if you want to have meaningful changes divided from style-only changes"
echo "Using it without specifying a path would analyse \"src\" from current directory."
- printf -- "\nUsage: $(basename $0) [directory] [options ...]\n"
+ printf -- "\nUsage: %s [directory] [options ...]\n" "$(basename "$0")"
printf -- "Options:\n"
printf -- "-u\t\tcheck all JS/C/C++ files that has been modified since last commit and fix issues\n"
printf -- "-uc\t\tcheck all C/C++ files that has been modified since last commit and fix issues\n"
}
formatJsAndC++() {
- path="$(readlink -f $1)"
+ path="$(readlink -f "$1")"
if [[ "$analyzeC" == "true" ]]; then
echo "Reformatting C++ sources recursively for directory $path";
- $dir/c++_clang_formatter.sh "$path";
+ "$SCRIPT_DIR/c++_clang_formatter.sh" "$path";
else
echo "no C++ sources reformatting - please use '-c' option to enable it";
fi
if [[ "$analyzeJS" == "true" ]]; then
echo "Reformatting JS sources recursively for directory $path";
- $dir/js_eslint_formatter.sh "$path";
+ "$SCRIPT_DIR/js_eslint_formatter.sh" "$path";
else
echo "no JS sources reformatting - please use '-js' option to enable it";
fi
}
backupUpdatedFiles() {
- files_to_update=$(git diff-index --name-only --diff-filter=AM HEAD --);
+ files_to_update="$(git diff-index -z --name-only --diff-filter=AM HEAD --)";
if [[ "$files_to_update" == "" ]]; then
- echo "There are no updated files to dormat";
+ echo "There are no updated files to format";
exit;
fi
time_stamp=$(date +%Y-%m-%d-%T);
dir_name="backup_${time_stamp}";
echo "Creating backup of not commited changes in directory: $dir_name";
mkdir -p "${dir_name}";
- for f in "$files_to_update"
- do
- cp $f "$dir_name";
- done
+ while IFS= read -r -d '' file; do
+ cp -- "$file" "$dir_name";
+ done <<< "$files_to_update"
}
formatUpdatedJsAndC++() {
fi
echo "Reformatting C++ and JS sources from list:";
git diff-index --name-only --diff-filter=AM HEAD --;
- $dir/c++_clang_formatter.sh -u;
- $dir/js_eslint_formatter.sh -u;
+ "$SCRIPT_DIR/c++_clang_formatter.sh" -u;
+ "$SCRIPT_DIR/js_eslint_formatter.sh" -u;
}
formatUpdatedJs() {
fi
echo "Reformatting JS sources from list:";
git diff-index --name-only --diff-filter=AM HEAD --;
- $dir/js_eslint_formatter.sh -u;
+ "$SCRIPT_DIR/js_eslint_formatter.sh" -u;
}
formatUpdatedC++() {
- if [["$files_to_update" == "" ]]; then
+ if [[ "$files_to_update" == "" ]]; then
exit
fi
echo "Reformatting C++ sources from list:";
git diff-index --name-only --diff-filter=AM HEAD --;
- $dir/c++_clang_formatter.sh -u;
+ "$SCRIPT_DIR/c++_clang_formatter.sh" -u;
}
for arg in "$@";
if [[ -d "$arg" ]]; then
dir2analyze="$arg";
else
- (>&2 printf "ERROR: directory '$arg' does not exist\n\n")
+ (>&2 printf "ERROR: directory %s does not exist\n\n" "$arg")
printHelp
exit 1
fi
fi
done
-formatJsAndC++ "$dir2analyze"
\ No newline at end of file
+formatJsAndC++ "$dir2analyze"
#!/bin/bash
-script_dir="$(dirname "$(readlink -f "$0")")"
+
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+ SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
+ SOURCE="$(readlink "$SOURCE")"
+ [[ $SOURCE != /* ]] && SOURCE="$SCRIPT_DIR/$SOURCE"
+ # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
+done
+SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
+
config_file="eslint_config_mandatory_length90.js"
-dir2analyze="$(pwd)/src";
+dir2analyze="$SCRIPT_DIR/../../src";
analyzeJS="false";
analyzeC="false";
echo "Script for validation source code about coding style rules violations."
echo "The script would not change any files, only print report about found issues."
echo "Using it without specifying a path would analyse \"src\" from current directory."
- printf -- "\nUsage: $(basename $0) [directory] [options ...]\n"
+ printf -- "\nUsage: %s [directory] [options ...]\n" "$(basename "$0")"
printf -- "Options:\n"
printf -- "-u\t\tcheck all JS/C/C++ files that has been modified since last commit\n"
printf -- "-uc\t\tcheck all C/C++ files that has been modified since last commit\n"
}
checkEslint() {
- command -v eslint >/dev/null 2>&1 || {
- echo >&2 "eslint is required, but it's not installed.";
+ if [ ! "$(command -v eslint)" ]; then
+ echo "eslint is required, but it's not installed." 1>&2;
echo "-------------------------------------------------------------------------------------";
echo "If you want to make ESLint available to tools that run across all of your projects, we recommend installing ESLint globally. You can do so using npm"
echo "(it need to be installed on your machine - check https://www.rosehosting.com/blog/install-npm-on-ubuntu-16-04/):"
echo "$ sudo npm install -g eslint"
echo "-------------------------------------------------------------------------------------";
exit 1;
- }
+ fi
}
checkC() {
printf "."
echo "Checking C style of $1 directory"
- $script_dir/cpplint_tizen_dir.sh "$1"
+ "$SCRIPT_DIR/cpplint_tizen_dir.sh" "$1"
}
checkJS() {
- ls "$1"/*.js &>/dev/null
- if [[ "$?" -eq 0 ]]; then
- printf "."
- echo "Checking JS style of $1 directory"
- eslint -c "$script_dir/$config_file" "$1"/*.js
- fi
+ printf "."
+ find -- "$1" -type f -name '*.js' -print0 | \
+ xargs --null --no-run-if-empty eslint -c "$SCRIPT_DIR/config_file"
}
checkJsAndC++() {
- path=$(readlink -f $1)
+ path="$(readlink -f "$1")"
if [[ "$analyzeC" = true ]]; then
echo "Checking C++ recursively for directory $path"
checkC "$path"
if [[ "$analyzeJS" = "true" ]]; then
echo "Checking JS recursively for directory $path"
checkEslint
- dirs=$(find $path -type d)
- for d in $dirs;
- do
- if [[ -d "$d" ]]; then
- checkJS "$d";
- fi
- done
+ checkJS "$path"
else
echo "no JS sources validation";
fi
checkUpdatedJs() {
echo "Validating updated JS files:";
- files=$(git diff-index --name-only --diff-filter=AM HEAD --)
- config_file="$script_path/eslintrc_mandatory_4spaces.js"
+ files="$(git diff-index -z --name-only --diff-filter=AM HEAD --)"
+ config_file="$SCRIPT_DIR/eslintrc_mandatory_4spaces.js"
counter=0
- for f in $files;
- do
- if [[ ${f: -3} == ".js" ]]; then
+ while IFS= read -r -d '' f; do
+ if [[ "${f: -3}" == ".js" ]]; then
echo "Checking: $f"
counter=$((counter+1))
- eslint --no-eslintrc -c "$config_file" $f
+ eslint --no-eslintrc -c "$config_file" "$f"
fi
- done
+ done <<< "$(printf "%s" "$files")"
if [[ "$counter" -eq 0 ]]; then
echo "No updated JS files to validate."
else
checkUpdatedC++() {
echo "Validating updated C++ files:";
- patch_cpp=`dirname $0`/cpplint_tizen_160919.py
- files=$(git diff-index --name-only --diff-filter=AM HEAD --)
+ patch_cpp="$SCRIPT_DIR/cpplint_tizen_160919.py"
+ files="$(git diff-index -z --name-only --diff-filter=AM HEAD --)"
counter=0
- for f in $files;
- do
- if [ ${f: -3} == ".cc" ] || [ ${f: -4} == ".cpp" ] || [ ${f: -2} == ".h" ] || [ ${f: -4} == ".hpp" ]; then
- echo "Checking: $f\n"
+ while IFS= read -r -d '' f; do
+ if [ "${f: -3}" == ".cc" ] || [ "${f: -4}" == ".cpp" ] || [ "${f: -2}" == ".h" ] || \
+ [ "${f: -4}" == ".hpp" ]; then
+ echo "Checking: $f"
counter=$((counter+1))
- python $patch_cpp $f;
+ python "$patch_cpp" "$f";
fi
- done
+ done <<< "$(printf "%s" "$files")"
if [[ "$counter" -eq 0 ]]; then
echo "No updated C++ files to validate."
else
if [[ -d "$arg" ]]; then
dir2analyze="$arg";
else
- (>&2 printf "ERROR: directory '$arg' does not exist\n\n")
+ (>&2 printf "ERROR: directory %s does not exist\n\n" "$arg")
printHelp
exit 1
fi
#!/bin/bash
-patch_cpp=`dirname $0`/cpplint_tizen_160919.py
-
-# check rule to cpp
-for i in `find $1 -name "*.cpp" -o -name "*.cc"`
-do
- python $patch_cpp $i
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+ SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
+ SOURCE="$(readlink "$SOURCE")"
+ [[ $SOURCE != /* ]] && SOURCE="$SCRIPT_DIR/$SOURCE"
+ # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
+SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
-for i in `find $1 -name "*.h"`
-do
- python $patch_cpp $i
-done
+patch_cpp="$SCRIPT_DIR/cpplint_tizen_160919.py"
+
+# check rule to cpp
+find -- "$1" \( -name "*.cpp" -o name "*.cc" \) -exec python "$patch_cpp" {} \;
+find -- "$1" -name "*.h" -exec python "$patch_cpp" {} \;
# https://github.sec.samsung.net/RS-SA/coding-style-guides/tree/master/javascript
# https://eslint.org/
-command -v eslint >/dev/null 2>&1 || {
-
+if [ ! "$(command -v eslint)" ]; then
echo >&2 "eslint is required, but it's not installed";
echo "-------------------------------------------------------------------------------------";
echo "To install eslint on Debian/Ubuntu, execute the following commands."
echo "sudo npm install -g eslint"
echo "-------------------------------------------------------------------------------------";
exit 1;
-}
+fi
#https://prettier.io/docs/en/install.html
-command -v prettier >/dev/null 2>&1 || {
-
+if [ ! "$(command -v prettier)" ]; then
echo >&2 "prettier is required, but it's not installed";
echo "-------------------------------------------------------------------------------------";
echo "To install prettier on Debian/Ubuntu, execute the following commands."
echo "sudo npm install -g prettier"
echo "-------------------------------------------------------------------------------------";
exit 1;
-}
+fi
-script_path="$( cd "$(dirname "$0")" ; pwd -P )";
+script_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
config_file="$script_path/eslintrc_mandatory_4spaces.js"
prettier_config_file="$script_path/prettier.config.js"
-formatJSDirectory() {
- ls $1/*.js &>/dev/null
- if [[ $? -eq 0 ]]; then
- for f in $(ls $1/*.js)
- do
- formatJSFile $f;
- done
- fi
-}
-
formatJSFile() {
printf "."
# fixing line breaks using prettier
prettier --config "$prettier_config_file" "$1" --write
# using eslint for fixing some js issues
- eslint --no-eslintrc -c "$config_file" $1 --fix
+ eslint --no-eslintrc -c "$config_file" "$1" --fix
# issues that are not fixed, will be printed fur the user to take care of them
}
-checkDirectoriesRecursive() {
- dirs=$(find $1 -type d)
- for d in $dirs;
- do
- if [[ -d $d ]]; then
- formatJSDirectory $d;
- fi
- done
+formatJSPath() {
+ while IFS= read -r -d '' f; do
+ formatJSFile "$f";
+ done < <(find -- "$1" -type f -name "*.js" -print0)
}
checkUpdatedFiles() {
- files=$(git diff-index --name-only --diff-filter=AM HEAD --)
- for f in $files;
- do
- if [[ ${f: -3} == ".js" ]]; then
- formatJSFile $f;
+ while IFS= read -r -d '' f; do
+ if [[ "${f: -3}" == ".js" ]]; then
+ formatJSFile "$f";
fi
- done
+ done < <(git diff-index -z --name-only --diff-filter=AM HEAD --)
}
printf "JS reformatting: ";
if [[ $# -eq 0 ]]; then
- checkDirectoriesRecursive src/
+ formatJSPath "$script_path/../../src/"
elif [[ "$1" == "-u" ]]; then
checkUpdatedFiles
else
- checkDirectoriesRecursive $1
+ formatJSPath "$1"
fi
echo " DONE JS reformatting"
-# Copyright (c) 2013 Intel Corporation. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
import os
import sys
-import subprocess
+import argparse
+import mergejs
+
TEMPLATE = """\
-extern const char %s[];
-const char %s[] = { %s, 0 };
+extern const char {}[];
+const char {}[] = {{ {}, 0 }};
"""
-js_code = sys.argv[1]
-cmd = "python " + os.path.dirname(__file__) + "/mergejs.py -f" + js_code
-lines = subprocess.check_output(cmd, shell=True)
-c_code = ', '.join(str(ord(c)) for c in lines)
-symbol_name = sys.argv[2]
-output = open(sys.argv[3], "w")
-output.write(TEMPLATE % (symbol_name, symbol_name, c_code))
-output.close()
+def encode(text):
+ return ', '.join(str(ord(c)) for c in text)
+
+
+def generate_cpp_code(input_file, symbol):
+ code = mergejs.process_file(input_file)
+ return TEMPLATE.format(symbol, symbol, encode(code))
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument("input", help="input js file path")
+ parser.add_argument("symbol", help="symbol name to use")
+ parser.add_argument("output", help="output file path")
+ opts = parser.parse_args()
+
+ with open(opts.output, "w") as output:
+ cpp = generate_cpp_code(opts.input, opts.symbol)
+ output.write(cpp)
+
+++ /dev/null
-#!/usr/bin/python
-
-import slimit
-
-def minimize(code):
- return slimit.minify(code)
-
-#!/usr/bin/env python
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
-# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
-import fileinput
import sys
-import getopt
-import glob
import os
-import js_minimize
+import re
+import argparse
+import slimit
-class Utils:
- reqfiles = []
- searchfile = '*_api.js'
- startwith = "//= require('"
- endwith = "')"
- code = ""
- @classmethod
- def get_require(self, s):
- try:
- start = s.index(self.startwith) + len(self.startwith)
- end = s.index(self.endwith, start)
- filename = s[start:end]
- self.reqfiles.append(filename)
- except ValueError:
- return ""
+MATCHER = re.compile("^//=\s*require\(['\"](.*)['\"]\)")
- @classmethod
- def find_require(self):
- p = os.path.join('./', self.searchfile)
- filenames = glob.glob(self.searchfile)
- for fname in filenames:
- with open(fname, 'r') as myfile:
- for line in myfile:
- self.get_require(line)
- @classmethod
- def print_lines(self, filename):
- with open(filename, 'r') as file:
- for line in file:
- self.code += line
+def _process_file(path, includes_directory="js"):
+ lines = []
+ with open(path, "r") as source_file:
+ for line in source_file:
+ m = MATCHER.match(line.strip())
+ if m != None:
+ include_path = os.path.join(includes_directory, m.group(1))
+ lines += _process_file(include_path, includes_directory)
+ else:
+ lines.append(line.strip())
+ return lines
- @classmethod
- def merge_js_files(self, path):
- self.find_require()
- if len(self.reqfiles) == 0:
- s = os.path.join('./', self.searchfile)
- sfiles = glob.glob(s)
- for fname in sfiles:
- self.print_lines(fname)
- else:
- js = '*.js'
- p = os.path.join(path, js)
- filenames = glob.glob(p)
- for fname in self.reqfiles:
- fname = path + '/' + fname
- if fname in filenames:
- self.print_lines(fname)
- @classmethod
- def minize_code(self):
- self.code = js_minimize.minimize(self.code)
+def process_file(path, includes_directory="js"):
+ lines = _process_file(path, includes_directory)
+ return slimit.minify("\n".join(lines))
- @classmethod
- def main(self, argv):
- path = 'js'
- try:
- opts, args = getopt.getopt(argv,"hf:p:",["file=", "path="])
- except getopt.GetoptError:
- print __file__ + ' -h'
- sys.exit()
- if len(argv) > 0:
- for opt, arg in opts:
- if opt in ("-h"):
- print 'Help:'
- print ''
- print __file__ + '-f <file> -p <path>'
- print ''
- print '<opt> \t <opt> \t\t <description>'
- print '-f \t --file \t Name of the file where script searching for require files:'
- print '\t \t \t ' + self.startwith + 'file_name.js' + self.endwith
- print '-p \t --path \t Path to "' + path + '" directory'
- print ''
- sys.exit()
- elif opt in ("-f", "--file"):
- self.searchfile = arg
- elif opt in ("-p", "--path"):
- path = arg
- self.merge_js_files(path)
- self.minize_code()
- print self.code
-if Utils.__module__ == "__main__":
- Utils.main(sys.argv[1:])
+if __name__ == '__main__':
+ opt_parser = argparse.ArgumentParser()
+ opt_parser.add_argument("--file", "-f", type=str, help="input file name")
+ opt_parser.add_argument("--path", "-p", type=str, default="js", help="path to the includes directory")
+
+ opts = opt_parser.parse_args()
+ code = process_file(opts.file, opts.path)
+
+ print(code)
+
exit 2
fi
-exec $1 > $2
+exec "$1" > "$2"
--- /dev/null
+config/src_scope.cfg
\ No newline at end of file
--- /dev/null
+# SAM
+SAM-Tools is a set of tools for measuring S/W Architecture Maturity (SAM).
+SAM analyzes both code and architecture in order to identify problems which may impact
+software maintenance.
+
+# Requirements
+
+[**SAM-Tools** repository](https://github.sec.samsung.net/RS7-Architectural-Refactoring/SAM-Tools) - clone it into directory on the same level as webapi-plugins - This path can be changed in `tools/sam/sam_cli.cfg` file.
+
+# Usage
+Simply run tools/sam/run_sam.sh script - from webapi-plugins/ directory
+with gbs profile and one of the parameter below:
+
+ -a Build project and generate report.
+
+ -b Build project and scan for files - without generating report.
+
+ -g Generate report - without building - assumes that first step was made earlier.
+
+i.e:
+
+ webapi-plugins(SAM)$ tools/sam/run_sam.sh -a 55unified
+
+Analysis Report will be located in output/html/ directory.
+
+Script assumes that `55unified` profile exists in ~/.gbs.conf file.
+
+# Links
+
+[Architecture Manager](https://code.sec.samsung.net/architecturemanager/app/sam/Tizen_Unified/Tizen_Unified/latest/overview)
+
+[Getting Started](https://github.sec.samsung.net/RS7-Architectural-Refactoring/SAM-Tools/wiki/Getting-Started)
+
+[SAM Metric](https://github.sec.samsung.net/RS7-Architectural-Refactoring/SAM-Tools/wiki/Metrics-in-SAM)
\ No newline at end of file
--- /dev/null
+#~/git/webapi-plugins/src/googletest
+#~/git/webapi-plugins/src/googlemock
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env bash
+
+export WEBAPI_DIRECTORY="${PWD}"
+DIR_NAME="${PWD##*/}"
+
+export BUILD_PROFILE="55unified"
+
+PATH_TO_SAM_TOOLS="$WEBAPI_DIRECTORY/../SAM-Tools"
+
+export WEBAPI_VERSION=$(sed packaging/webapi-plugins.spec -n -e "s/Version: *\(.*\)/\1/p")
+
+if [ "$DIR_NAME" != "webapi-plugins" ] ; then
+ echo "Script must be executed from webapi-plugins directory"
+ exit 0
+fi
+
+function usage {
+echo "Usage:
+$0 <parameters> GBS_PROFILE
+
+Parameters:
+ -a Build project and generate report.
+
+ -b Build project and scan for files - without generating report.
+
+ -g Generate report - without building - assumes that first step was made earlier."
+}
+
+function build {
+ "$PATH_TO_SAM_TOOLS/1_sam_cli_scan.sh" "tools/sam/sam_cli.cfg"
+}
+
+function generate {
+ echo "# This file is autogenerated, do not modify it manually" > "tools/sam/config/src_scope.cfg"
+ echo "/home/abuild/rpmbuild/BUILD/webapi-plugins-$WEBAPI_VERSION" >> "tools/sam/config/src_scope.cfg"
+ echo "$WEBAPI_DIRECTORY" >> "tools/sam/config/src_scope.cfg"
+
+ "$PATH_TO_SAM_TOOLS/2_sam_cli_sam.sh" "tools/sam/sam_cli.cfg"
+}
+
+function main {
+ LOOP=false
+ while getopts "a:b:g:" opt; do
+ LOOP=true
+ case "$opt" in
+ "a") BUILD_PROFILE=$OPTARG
+ build
+ generate
+ ;;
+ "b") BUILD_PROFILE=$OPTARG
+ build
+ ;;
+ "g") BUILD_PROFILE=$OPTARG
+ generate
+ ;;
+ esac
+ done
+ if [ "$LOOP" = false ] ; then
+ usage
+ fi
+}
+
+main "$@"
--- /dev/null
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019 The SAM Tool Authors. All rights reserved.
+#
+# SAM (S/W Architecture Maturity)
+#
+# Samsung Research,
+# Samsung Electronics Co., Ltd.
+#
+# This software and its documentation are confidential and proprietary
+# information of Samsung Electronics Co., Ltd. No part of the software and
+# documents may be copied, reproduced, transmitted, translated, or reduced to
+# any electronic medium or machine-readable form without the prior written
+# consent of Samsung Electronics.
+#
+# Samsung Electronics makes no representations with respect to the contents,
+# and assumes no responsibility for any errors that might appear in the
+# software and documents. This publication and the contents here of are subject
+# to change without notice.
+#
+
+################################
+# Project Name
+################################
+SAM_PRJ_NAME="webapi-plugins"
+
+
+################################
+# Source Code
+################################
+BUILD_CMD="gbs build -A armv7l -P $BUILD_PROFILE --include-all"
+CLEAN_CMD=""
+SRC_PATH="$WEBAPI_DIRECTORY"
+SRC_LANG="auto_c_cpp" # Supported languages : c, cpp, auto_c_cpp, java, cs
+SRC_SCOPE="tools/sam/config/src_scope.cfg" # Scoping list
+SRC_EXCLUDE="tools/sam/config/src_exclude.cfg" # Excluding list
+
+
+################################
+# SCRA
+################################
+SCRA_SKIP=FALSE # Options : TRUE, FALSE
+SCRA_RAW_DATA_PATH=".scap/workspace/scra"
+SCRA_ROOT_TO_CUT="/home/abuild/rpmbuild/BUILD/webapi-plugins-$WEBAPI_VERSION"
+# SCRA_USE_PARAM=TRUE
+
+
+################################
+# ART_BEAN (Convert SCRA data)
+################################
+ART_BEAN_SKIP=FALSE # Options : TRUE, FALSE
+
+
+################################
+# PMD CPD (Duplicated Code)
+################################
+PMD_SKIP=FALSE # Options : TRUE, FALSE
+PMD_RAW_DATA_PATH=".scap/workspace/pmd"
+PMD_USE_BUILT_PATH=FALSE # Options : TRUE, FALSE
+PMD_ROOT_TO_CUT=$SRC_PATH
+#PMD_EXCLUDE_LIST="config/src_exclude.cfg" # Excluding list of PMD
+#PMD_RESULT_DETAIL_MODE=FALSE # Options : TRUE, FALSE
+#PMD_HEAP_SIZE=2048m
+#PMD_ENCODING="utf-8"
+
+
+################################
+# Metrix++ (Preprocessor)
+###############################
+MPP_SKIP=FALSE
+MPP_RAW_DATA_PATH=".scap/workspace/metrixpp"
+MPP_ROOT_TO_CUT=$SRC_PATH
+
+
+################################
+# Advanced Option
+################################
+#ADVANCED_SAM_OPTION="config/sam.cfg"
+#USE_EMBEDDED_LIB=TRUE
+
+SCAP_TOOL_PATH="hub/code-analysis-hub/bin/scap"
+SCAP=$SCAP_TOOL_PATH