]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/js/test/test-jq.js
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
22 * JavaScript test suite for ThriftTest.thrift. These tests
23 * will run only with jQuery (-gen js:jquery) Apache Thrift
24 * interfaces. To create client code:
25 * $ thrift -gen js:jquery ThriftTest.thrift
28 * ++ test.js for generic tests
29 * ++ test-nojq.js for "-gen js" only tests
33 //////////////////////////////////
34 //jQuery asynchronous tests
35 jQuery
.ajaxSetup({ timeout
: 0 });
37 QUnit
.module('jQ Async Manual');
39 QUnit
.test('testI32', function(assert
) {
41 const done
= assert
.async(2);
43 const transport
= new Thrift
.Transport();
44 const protocol
= new Thrift
.Protocol(transport
);
45 const client
= new ThriftTest
.ThriftTestClient(protocol
);
47 const jqxhr
= jQuery
.ajax({
49 data
: client
.send_testI32(Math
.pow(-2, 31)),
53 success: function(res
) {
54 transport
.setRecvBuffer(res
);
55 assert
.equal(client
.recv_testI32(), Math
.pow(-2, 31));
58 error: function() { assert
.ok(false); },
59 complete: function() {
66 QUnit
.test('testI64', function(assert
) {
68 const done
= assert
.async(2);
70 const transport
= new Thrift
.Transport();
71 const protocol
= new Thrift
.Protocol(transport
);
72 const client
= new ThriftTest
.ThriftTestClient(protocol
);
76 //This is usually 2^61 but JS cannot represent anything over 2^52 accurately
77 data
: client
.send_testI64(Math
.pow(-2, 52)),
81 success: function(res
) {
82 transport
.setRecvBuffer(res
);
83 //This is usually 2^61 but JS cannot represent anything over 2^52 accurately
84 assert
.equal(client
.recv_testI64(), Math
.pow(-2, 52));
87 error: function() { assert
.ok(false); },
88 complete: function() {
96 QUnit
.module('jQ Async');
97 QUnit
.test('I32', function(assert
) {
100 const done
= assert
.async(3);
101 client
.testI32(Math
.pow(2, 30), function(result
) {
102 assert
.equal(result
, Math
.pow(2, 30));
106 const jqxhr
= client
.testI32(Math
.pow(-2, 31), function(result
) {
107 assert
.equal(result
, Math
.pow(-2, 31));
111 jqxhr
.success(function(result
) {
112 assert
.equal(result
, Math
.pow(-2, 31));
117 QUnit
.test('I64', function(assert
) {
120 const done
= assert
.async(4);
121 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
122 client
.testI64(Math
.pow(2, 52), function(result
) {
123 assert
.equal(result
, Math
.pow(2, 52));
127 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
128 client
.testI64(Math
.pow(-2, 52), function(result
) {
129 assert
.equal(result
, Math
.pow(-2, 52));
132 .error(function(xhr
, status
, e
) { assert
.ok(false, e
.message
); })
133 .success(function(result
) {
134 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
135 assert
.equal(result
, Math
.pow(-2, 52));
138 .complete(function() {
144 QUnit
.test('Xception', function(assert
) {
147 const done
= assert
.async(2);
149 const dfd
= client
.testException('Xception', function(result
) {
153 .error(function(xhr
, status
, e
) {
154 assert
.equal(e
.errorCode
, 1001);
155 assert
.equal(e
.message
, 'Xception');
157 $(document
).ajaxError( function() { done(); } );