This source file includes following definitions.
- TEST
- TEST
#include "chrome/browser/chromeos/drive/job_queue.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace drive {
TEST(JobQueueTest, BasicJobQueueOperations) {
const int kNumMaxConcurrentJobs = 3;
const int kNumPriorityLevels = 2;
enum {HIGH_PRIORITY, LOW_PRIORITY};
JobQueue queue(kNumMaxConcurrentJobs, kNumPriorityLevels);
EXPECT_EQ(0U, queue.GetNumberOfJobs());
queue.Push(101, LOW_PRIORITY);
queue.Push(102, HIGH_PRIORITY);
queue.Push(103, LOW_PRIORITY);
queue.Push(104, HIGH_PRIORITY);
JobID id;
EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
EXPECT_EQ(102, id);
EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
EXPECT_EQ(104, id);
EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
EXPECT_EQ(101, id);
EXPECT_FALSE(queue.PopForRun(LOW_PRIORITY, &id));
EXPECT_EQ(4U, queue.GetNumberOfJobs());
queue.MarkFinished(104);
EXPECT_EQ(3U, queue.GetNumberOfJobs());
EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
EXPECT_EQ(103, id);
queue.Push(105, LOW_PRIORITY);
queue.MarkFinished(101);
queue.MarkFinished(102);
queue.MarkFinished(103);
EXPECT_EQ(1U, queue.GetNumberOfJobs());
EXPECT_FALSE(queue.PopForRun(HIGH_PRIORITY, &id));
EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
EXPECT_EQ(105, id);
}
TEST(JobQueueTest, JobQueueRemove) {
const int kNumMaxConcurrentJobs = 3;
const int kNumPriorityLevels = 2;
enum {HIGH_PRIORITY, LOW_PRIORITY};
JobQueue queue(kNumMaxConcurrentJobs, kNumPriorityLevels);
EXPECT_EQ(0U, queue.GetNumberOfJobs());
queue.Push(101, LOW_PRIORITY);
queue.Push(102, HIGH_PRIORITY);
queue.Push(103, LOW_PRIORITY);
queue.Push(104, HIGH_PRIORITY);
EXPECT_EQ(4U, queue.GetNumberOfJobs());
queue.Remove(101);
queue.Remove(104);
EXPECT_EQ(2U, queue.GetNumberOfJobs());
JobID id;
EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
EXPECT_EQ(102, id);
EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
EXPECT_EQ(103, id);
queue.MarkFinished(102);
queue.MarkFinished(103);
EXPECT_EQ(0U, queue.GetNumberOfJobs());
EXPECT_FALSE(queue.PopForRun(LOW_PRIORITY, &id));
}
}