Device/Descriptor: pass pointer to OpenOnPort()
[xcsoar.git] / test / src / harness_task2.cpp
blob16645ebf6b940002aa594180c44cb1893fcc50e9
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "harness_task.hpp"
24 #include "test_debug.hpp"
25 #include "harness_waypoints.hpp"
27 #include "Task/Factory/AbstractTaskFactory.hpp"
28 #include "Util/StaticArray.hpp"
30 static TaskPointFactoryType
31 GetRandomType(const LegalPointSet &l)
33 StaticArray<TaskPointFactoryType, LegalPointSet::N> types;
34 l.CopyTo(std::back_inserter(types));
35 return types[(rand() % types.size())];
38 bool test_task_bad(TaskManager& task_manager,
39 const Waypoints& waypoints)
41 test_task_random(task_manager,waypoints,2);
43 task_manager.SetFactory(TaskFactoryType::RACING);
44 AbstractTaskFactory& fact = task_manager.GetFactory();
46 const Waypoint* wp = random_waypoint(waypoints);
48 ok (!fact.CreateFinish((TaskPointFactoryType)20,*wp),"bad finish type",0);
49 ok (!fact.CreateStart((TaskPointFactoryType)20,*wp),"bad start type",0);
50 ok (!fact.CreateIntermediate((TaskPointFactoryType)20,*wp),"bad intermediate type",0);
52 // now create a taskpoint from FAI
54 const TaskPointFactoryType s = GetRandomType(fact.GetIntermediateTypes());
56 // test it is bad for AAT
58 task_manager.SetFactory(TaskFactoryType::AAT);
60 AbstractTaskFactory& bfact = task_manager.GetFactory();
62 ok (!bfact.CreateIntermediate(s,*wp),"bad intermediate type (after task change)",0);
64 bfact.Remove(1);
65 ok (bfact.Validate(),"ok with one tp",0);
67 bfact.Remove(1);
68 ok (bfact.Validate(),"ok with zero tps (just start and finish)",0);
70 ok (bfact.Remove(task_manager.TaskSize()-1,false),"remove finish manually",0);
71 ok (!bfact.Validate(),"aat is invalid (no finish)",0);
73 return true;