_storage_unittest.cc
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/cast/net/rtp/packet_storage.h"

#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <vector>

#include "base/test/simple_test_tick_clock.h"
#include "base/time/time.h"
#include "media/cast/constants.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace media {
namespace cast {

static const size_t kStoredFrames = 10;

// Generate |number_of_frames| and store into |*storage|.
// First frame has 1 packet, second frame has 2 packets, etc.
static void StoreFrames(int number_of_frames,
                        FrameId first_frame_id,
                        PacketStorage* storage) {
  const int kSsrc = 1;
  for (int i = 0; i < number_of_frames; ++i) {
    SendPacketVector packets;
    // First frame has 1 packet, second frame has 2 packets, etc.
    const int number_of_packets = i + 1;
    for (int j = 0; j < number_of_packets; ++j) {
      Packet test_packet(1, 0);
      packets.push_back(
          std::make_pair(PacketKey(base::TimeTicks(), kSsrc, first_frame_id + i,
                                   base::checked_cast<uint16_t>(j)),
                         new base::RefCountedData<Packet>(test_packet)));
    }
    storage->StoreFrame(first_frame_id, packets);
    ++first_frame_id;
  }
}

TEST(PacketStorageTest, NumberOfStoredFrames) {
  PacketStorage storage;

  // Use a big frame ID to make sure none of the offset calculations are
  // overflowing.
  const FrameId frame_id = FrameId::first() +
                           std::numeric_limits<int32_t>::max() +
                           std::numeric_limits<int32_t>::max();
  StoreFrames(kMaxUnackedFrames / 2, frame_id, &storage);
  EXPECT_EQ(static_cast<size_t>(kMaxUnackedFrames / 2),
            storage.GetNumberOfStoredFrames());
}

TEST(PacketStorageTest, StoreAndGetFrames) {
  PacketStorage storage;

  // Use a big frame ID to make sure none of the offset calculations are
  // overflowing.
  const FrameId first_frame_id = FrameId::first() +
                                 std::numeric_limits<int32_t>::max() +
                                 std::numeric_limits<int32_t>::max();

  StoreFrames(kStoredFrames, first_frame_id, &storage);
  EXPECT_EQ(std::min<size_t>(kMaxUnackedFrames, kStoredFrames),
            storage.GetNumberOfStoredFrames());

  // Expect we get the correct frames by looking at the number of
  // packets.
  for (size_t i = 0; i < kStoredFrames; ++i) {
    ASSERT_TRUE(storage.GetFramePackets(first_frame_id + i));
    EXPECT_EQ(i + 1, storage.GetFramePackets(first_frame_id + i)->size());
  }

  // Expect not to see packets for frames not stored.
  ASSERT_FALSE(storage.GetFramePackets(first_frame_id - 1));
  ASSERT_FALSE(storage.GetFramePackets(first_frame_id + kStoredFrames + 1));
}

TEST(PacketStorageTest, FramesReleased) {
  PacketStorage storage;

  const FrameId first_frame_id = FrameId::first();
  StoreFrames(5, first_frame_id, &storage);
  EXPECT_EQ(std::min<size_t>(kMaxUnackedFrames, 5),
            storage.GetNumberOfStoredFrames());

  for (FrameId frame_id = first_frame_id; frame_id < first_frame_id + 5;
       ++frame_id) {
    EXPECT_TRUE(storage.GetFramePackets(frame_id));
  }

  storage.ReleaseFrame(first_frame_id + 2);
  EXPECT_EQ(4u, storage.GetNumberOfStoredFrames());
  EXPECT_FALSE(storage.GetFramePackets(first_frame_id + 2));

  storage.ReleaseFrame(first_frame_id + 0);
  EXPECT_EQ(3u, storage.GetNumberOfStoredFrames());
  EXPECT_FALSE(storage.GetFramePackets(first_frame_id + 0));

  storage.ReleaseFrame(first_frame_id + 3);
  EXPECT_EQ(2u, storage.GetNumberOfStoredFrames());
  EXPECT_FALSE(storage.GetFramePackets(first_frame_id + 3));

  storage.ReleaseFrame(first_frame_id + 4);
  EXPECT_EQ(1u, storage.GetNumberOfStoredFrames());
  EXPECT_FALSE(storage.GetFramePackets(first_frame_id + 4));

  storage.ReleaseFrame(first_frame_id + 1);
  EXPECT_EQ(0u, storage.GetNumberOfStoredFrames());
  EXPECT_FALSE(storage.GetFramePackets(first_frame_id + 1));
}

}  // namespace cast
}  // namespace media
Heading into the second half of September, PP and PE prices across China and Southeast Asia found some support from skyrocketing crude oil futures early in the week before oil prices erased half of their gains late on Tuesday.
State-owned Saudi Aramco’s facilities in the eastern part of Saudi Arabia were targeted by multiple disruptive drone attacks on the night of September 14, causing the biggest ever disruption to world oil supplies.
Following the incident, the international oil future markets closed with sharp gains of more than $8/bbl on Monday, September 16 and several Saudi producers were forced to reduce operating rates at their plants.
Having already displayed a slight recovery over the past week, local PP and PE prices in China have posted relatively more visible increases recently on the back of the rallying energy complex.
Following crude oil, January LLDPE and PP futures on the Dalian Commodity Exchange posted notable total gains of CNY630/ton ($89/ton) and CNY388/ton ($54/ton) on September 16-17, respectively.
However, both WTI and Brent crude futures cancelled half of their gains on September 17, Tuesday’s settlements.
A few traders reported that two major Chinese local producers’ combined polyolefin inventories were lower this week as buyers in anticipation of further price gains intended to secure some cargoes prior to the approaching Golden Week in early October.
Except for showing some short-lived pick-ups, demand for PP and PE applications has been weak since the end of the Chinese New Year holidays in February.
This week, the number of done deals has improved as the recent gains in local polyolefin prices up to CNY300/ton ($42/ton) have pushed buyers to urge for some purchases.
Although local PP and PE prices in China have responded to the jump in crude oil futures immediately, import prices, which hit 10-year-lows for many PE products and 2-year-lows for homo PP in early September, have followed a largely steady trend so far.
Some sellers have withheld their offers in order to see a clearer picture of the market before taking any steps. Others, meanwhile, have reported that notional market levels for PE have already increased by $20-30/ton.
The cautious mood across import markets has mostly prevailed given the impact of the weak yuan amidst the ongoing trade dispute with the US and China’s weak economic data.
The recent spike in crude oil futures has created firmer expectations in Southeast Asian PP and PE markets even under the shadow of thin buying interest.
On top of limited demand and economic concerns, the recent downward correction in oil prices is also triggering questions about the sustainability of the recent improvement in market sentiment for PP and PE among players.>>IMAGE in a compelling story spanning centuries and continents, chronicling the adventures of a current-day Templar Knight as he struggles to keep good and evil in balance.
It’s a change of direction for author Daniel McVicar. After finding success on American television he relocated to Turin, Italy, where he is now a European-based actor and filmmaker. Turin (Torino) is a real-life city of magic and mystery, most famous as the home of the legendary Shroud of Turin. This rich backdrop is an important character itself in the complex tapestry of The Last Cavalier.
Smart, fun and