VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/tests/TestDeque.cpp@ 102457

Last change on this file since 102457 was 101927, checked in by vboxsync, 15 months ago

libs/xpcom: Remove unused code in nsDeque.{cpp,h}, bugref:10545

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#include "nsDeque.h"
39#include "nsCRT.h"
40#include <stdio.h>
41
42class _TestDeque {
43public:
44 _TestDeque() {
45 SelfTest();
46 }
47 int SelfTest();
48 nsresult OriginalTest();
49 nsresult OriginalFlaw();
50 nsresult AssignFlaw();
51};
52static _TestDeque sTestDeque;
53
54/**
55 * conduct automated self test for this class
56 *
57 * @param
58 * @return
59 */
60int _TestDeque::SelfTest() {
61 /* the old deque should have failed a bunch of these tests */
62 int results=0;
63 results+=OriginalTest();
64 results+=OriginalFlaw();
65 results+=AssignFlaw();
66 return results;
67}
68
69nsresult _TestDeque::OriginalTest() {
70 int ints[200];
71 int count=sizeof(ints)/sizeof(int);
72 int i=0;
73 int* temp;
74 nsDeque theDeque; //construct a simple one...
75
76 for (i=0;i<count;i++) { //initialize'em
77 ints[i]=10*(1+i);
78 }
79 for (i=0;i<70;i++) {
80 theDeque.Push(&ints[i]);
81 }
82 for (i=0;i<56;i++) {
83 temp=(int*)theDeque.Pop();
84 }
85 for (i=0;i<55;i++) {
86 theDeque.Push(&ints[i]);
87 }
88 for (i=0;i<35;i++) {
89 temp=(int*)theDeque.Pop();
90 }
91 for (i=0;i<35;i++) {
92 theDeque.Push(&ints[i]);
93 }
94 for (i=0;i<38;i++) {
95 temp=(int*)theDeque.Pop();
96 }
97 return NS_OK;
98}
99
100nsresult _TestDeque::OriginalFlaw() {
101 int ints[200];
102 int i=0;
103 int* temp;
104 nsDeque secondDeque;
105 /**
106 * Test 1. Origin near end, semi full, call Peek().
107 * you start, mCapacity is 8
108 */
109 printf("fill array\n");
110 for (i=32; i; --i)
111 ints[i]=i*3+10;
112 printf("push 6 times\n");
113 for (i=0; i<6; i++)
114 secondDeque.Push(&ints[i]);
115 printf("popfront 4 times:\n");
116 for (i=4; i; --i) {
117 temp=(int*)secondDeque.PopFront();
118 printf("%d\t",*temp);
119 }
120 printf("push 4 times\n");
121 for (int j=4; j; --j)
122 secondDeque.Push(&ints[++i]);
123 printf("origin should now be about 4\n");
124 printf("and size should be 6\n");
125 printf("origin+size>capacity\n");
126
127 /*<akk> Oh, I see ... it's a circular buffer */
128 printf("but the old code wasn't behaving accordingly.\n");
129
130 /*right*/
131 printf("we shouldn't crash or anything interesting, ");
132
133 temp=(int*)secondDeque.Peek();
134 printf("peek: %d\n",*temp);
135 return NS_OK;
136}
137
138nsresult _TestDeque::AssignFlaw() {
139 nsDeque src, dest;
140 return NS_OK;
141}
142
143int main (void) {
144 _TestDeque test;
145 return 0;
146}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette