/*
Copyright (C) 2009 Facundo DomÃnguez
This file is part of Spacejunk.
Spacejunk is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see .
*/
#include "testdeleteiterator.h"
#include "eventlistenerlist.h"
#include
class EventListener {
public:
int id;
EventListener(int id) : id(id) {}
operator int () { return id; }
};
typedef EventListenerList EventList;
int mod(int k,int shift){
return (k + shift) % 3;
};
void DeleteIteratorTest(){
EventList l;
for(int k=0;k<3;k++) {
l.addListener(EventListener(0));
l.addListener(EventListener(1));
l.addListener(EventListener(2));
for(EventList::iterator i=l.begin();i!=l.end();i++){
if (*i==mod(k,2))
l.deleteListener(*i);
for(EventList::iterator i=l.begin();i!=l.end();i++){
if (*i==mod(k,1))
l.deleteListener(*i);
}
}
int c=0;
for(EventList::iterator i=l.begin();i!=l.end();i++){
c++;
assert(*i==mod(k,0));
}
assert(c==1);
l.deleteListener(EventListener(mod(k,0)));
assert(l.begin()==l.end());
assert(!l.dic.isIterating());
assert(l.listeners.size()==0);
}
};